File tree Expand file tree Collapse file tree 3 files changed +37
-6
lines changed
src/main/java/de/danielbechler/diff Expand file tree Collapse file tree 3 files changed +37
-6
lines changed Original file line number Diff line number Diff line change @@ -63,6 +63,22 @@ public Collection<PropertyAwareAccessor> getAccessors()
6363 return accessors ;
6464 }
6565
66+ /**
67+ * @param name The property name to find an accessor for.
68+ * @return The accessor for the given property name or null if none is found.
69+ */
70+ public PropertyAwareAccessor getAccessorByName (final String name )
71+ {
72+ for (PropertyAwareAccessor accessor : accessors )
73+ {
74+ if (accessor .getPropertyName ().equals (name ))
75+ {
76+ return accessor ;
77+ }
78+ }
79+ return null ;
80+ }
81+
6682 public void setInstanceFactory (final InstanceFactory instanceFactory )
6783 {
6884 this .instanceFactory = instanceFactory ;
Original file line number Diff line number Diff line change @@ -14,19 +14,26 @@ public class DefaultIntrospector implements Introspector
1414 public TypeInfo introspect (final Class <?> type )
1515 {
1616 final TypeInfo typeInfo = new TypeInfo (type );
17+
18+ final Collection <PropertyAwareAccessor > getterSetterAccessors = getterSetterIntrospector .introspect (type ).getAccessors ();
19+ for (final PropertyAwareAccessor getterSetterAccessor : getterSetterAccessors )
20+ {
21+ typeInfo .addPropertyAccessor (getterSetterAccessor );
22+ }
23+
1724 if (returnFields )
1825 {
1926 final Collection <PropertyAwareAccessor > fieldAccessors = fieldIntrospector .introspect (type ).getAccessors ();
2027 for (final PropertyAwareAccessor fieldAccessor : fieldAccessors )
2128 {
22- typeInfo .addPropertyAccessor (fieldAccessor );
29+ final String propertyName = fieldAccessor .getPropertyName ();
30+ if (typeInfo .getAccessorByName (propertyName ) == null )
31+ {
32+ typeInfo .addPropertyAccessor (fieldAccessor );
33+ }
2334 }
2435 }
25- final Collection <PropertyAwareAccessor > getterSetterAccessors = getterSetterIntrospector .introspect (type ).getAccessors ();
26- for (final PropertyAwareAccessor getterSetterAccessor : getterSetterAccessors )
27- {
28- typeInfo .addPropertyAccessor (getterSetterAccessor );
29- }
36+
3037 return typeInfo ;
3138 }
3239
Original file line number Diff line number Diff line change @@ -102,4 +102,12 @@ public boolean isExcludedByAnnotation()
102102 ObjectDiffProperty annotation = getFieldAnnotation (ObjectDiffProperty .class );
103103 return annotation != null && annotation .excluded ();
104104 }
105+
106+ @ Override
107+ public String toString ()
108+ {
109+ return "FieldAccessor{" +
110+ "field=" + field +
111+ '}' ;
112+ }
105113}
You can’t perform that action at this time.
0 commit comments