Repository: tapestry-5
Updated Branches:
  refs/heads/master 3fbcb2602 -> 127f62edf


TAP5-2032, TAP5-2449, TAP5-1493: consider overridden methods first so we
don't end up resolving types on the wrong classes


Project: http://git-wip-us.apache.org/repos/asf/tapestry-5/repo
Commit: http://git-wip-us.apache.org/repos/asf/tapestry-5/commit/127f62ed
Tree: http://git-wip-us.apache.org/repos/asf/tapestry-5/tree/127f62ed
Diff: http://git-wip-us.apache.org/repos/asf/tapestry-5/diff/127f62ed

Branch: refs/heads/master
Commit: 127f62edf90b2a838896626143f2ca9e6a718a76
Parents: 3fbcb26
Author: Jochen Kemnade <[email protected]>
Authored: Fri Nov 3 09:41:29 2017 +0100
Committer: Jochen Kemnade <[email protected]>
Committed: Fri Nov 3 09:45:08 2017 +0100

----------------------------------------------------------------------
 .../services/ClassPropertyAdapterImpl.java      | 31 ++++++++++++--------
 .../internal/services/PropertyAccessImpl.java   |  3 +-
 .../ioc/specs/PropertyAccessImplSpec.groovy     | 23 +++++++++++++++
 3 files changed, 44 insertions(+), 13 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/tapestry-5/blob/127f62ed/beanmodel/src/main/java/org/apache/tapestry5/ioc/internal/services/ClassPropertyAdapterImpl.java
----------------------------------------------------------------------
diff --git 
a/beanmodel/src/main/java/org/apache/tapestry5/ioc/internal/services/ClassPropertyAdapterImpl.java
 
b/beanmodel/src/main/java/org/apache/tapestry5/ioc/internal/services/ClassPropertyAdapterImpl.java
index 9c5f36c4..8164ec7 100644
--- 
a/beanmodel/src/main/java/org/apache/tapestry5/ioc/internal/services/ClassPropertyAdapterImpl.java
+++ 
b/beanmodel/src/main/java/org/apache/tapestry5/ioc/internal/services/ClassPropertyAdapterImpl.java
@@ -41,19 +41,26 @@ public class ClassPropertyAdapterImpl implements 
ClassPropertyAdapter
 
         // lazy init
         Map<String, List<Method>> nonBridgeMethods = null;
-        
+
         for (PropertyDescriptor pd : descriptors)
         {
             // Indexed properties will have a null propertyType (and a non-null
             // indexedPropertyType). We ignore indexed properties.
 
+            String name = pd.getName();
+
+            if (adapters.containsKey(name))
+            {
+                continue;
+            }
+
             final Class<?> thisPropertyType = pd.getPropertyType();
             if (thisPropertyType == null)
                 continue;
 
             Method readMethod = pd.getReadMethod();
             Method writeMethod = pd.getWriteMethod();
-            
+
             // TAP5-1493
             if (readMethod != null && readMethod.isBridge())
             {
@@ -61,15 +68,15 @@ public class ClassPropertyAdapterImpl implements 
ClassPropertyAdapter
                 {
                     nonBridgeMethods = groupNonBridgeMethodsByName(beanType);
                 }
-                readMethod = findMethodWithSameNameAndParamCount(readMethod, 
nonBridgeMethods); 
+                readMethod = findMethodWithSameNameAndParamCount(readMethod, 
nonBridgeMethods);
             }
-            
+
             // TAP5-1548, TAP5-1885: trying to find a getter which 
Introspector missed
             if (readMethod == null) {
                 final String prefix = thisPropertyType != boolean.class ? 
"get" : "is";
                 try
                 {
-                    Method method = beanType.getMethod(prefix + 
capitalize(pd.getName()));
+                    Method method = beanType.getMethod(prefix + 
capitalize(name));
                     final Class<?> returnType = method.getReturnType();
                     if (returnType.equals(thisPropertyType) || 
returnType.isInstance(thisPropertyType)) {
                         readMethod = method;
@@ -83,7 +90,7 @@ public class ClassPropertyAdapterImpl implements 
ClassPropertyAdapter
                     // getter doesn't exist.
                 }
             }
-            
+
             if (writeMethod != null && writeMethod.isBridge())
             {
                 if (nonBridgeMethods == null)
@@ -92,12 +99,12 @@ public class ClassPropertyAdapterImpl implements 
ClassPropertyAdapter
                 }
                 writeMethod = findMethodWithSameNameAndParamCount(writeMethod, 
nonBridgeMethods);
             }
-            
+
             // TAP5-1548, TAP5-1885: trying to find a setter which 
Introspector missed
             if (writeMethod == null) {
                 try
                 {
-                    Method method = beanType.getMethod("set" + 
capitalize(pd.getName()), pd.getPropertyType());
+                    Method method = beanType.getMethod("set" + 
capitalize(name), pd.getPropertyType());
                     final Class<?> returnType = method.getReturnType();
                     if (returnType.equals(void.class)) {
                         writeMethod = method;
@@ -115,7 +122,7 @@ public class ClassPropertyAdapterImpl implements 
ClassPropertyAdapter
             Class propertyType = readMethod == null ? thisPropertyType : 
GenericsUtils.extractGenericReturnType(
                     beanType, readMethod);
 
-            PropertyAdapter pa = new PropertyAdapterImpl(this, pd.getName(), 
propertyType, readMethod, writeMethod);
+            PropertyAdapter pa = new PropertyAdapterImpl(this, name, 
propertyType, readMethod, writeMethod);
 
             adapters.put(pa.getName(), pa);
         }
@@ -145,7 +152,7 @@ public class ClassPropertyAdapterImpl implements 
ClassPropertyAdapter
      * Find a replacement for the method (if one exists)
      * @param method A method
      * @param groupedMethods Methods mapped by name
-     * @return A method from groupedMethods with the same name / param count 
+     * @return A method from groupedMethods with the same name / param count
      *         (default to providedmethod if none found)
      */
     private Method findMethodWithSameNameAndParamCount(Method method, 
Map<String, List<Method>> groupedMethods) {
@@ -161,7 +168,7 @@ public class ClassPropertyAdapterImpl implements 
ClassPropertyAdapter
                 }
             }
         }
-        
+
         // default to the provided method
         return method;
     }
@@ -169,7 +176,7 @@ public class ClassPropertyAdapterImpl implements 
ClassPropertyAdapter
     /**
      * Find all of the public methods that are not bridge methods and
      * group them by method name
-     * 
+     *
      * {@see Method#isBridge()}
      * @param type Bean type
      * @return

http://git-wip-us.apache.org/repos/asf/tapestry-5/blob/127f62ed/beanmodel/src/main/java/org/apache/tapestry5/ioc/internal/services/PropertyAccessImpl.java
----------------------------------------------------------------------
diff --git 
a/beanmodel/src/main/java/org/apache/tapestry5/ioc/internal/services/PropertyAccessImpl.java
 
b/beanmodel/src/main/java/org/apache/tapestry5/ioc/internal/services/PropertyAccessImpl.java
index 0c7b942..e6cd3e3 100644
--- 
a/beanmodel/src/main/java/org/apache/tapestry5/ioc/internal/services/PropertyAccessImpl.java
+++ 
b/beanmodel/src/main/java/org/apache/tapestry5/ioc/internal/services/PropertyAccessImpl.java
@@ -100,6 +100,8 @@ public class PropertyAccessImpl implements PropertyAccess
 
             List<PropertyDescriptor> descriptors = CollectionFactory.newList();
 
+            addAll(descriptors, info.getPropertyDescriptors());
+
             // Introspector misses:
             // - interface methods not implemented in an abstract class 
(TAP5-921)
             // - default methods (TAP5-2449)
@@ -107,7 +109,6 @@ public class PropertyAccessImpl implements PropertyAccess
 
             addPropertiesFromScala(forClass, descriptors);
 
-            addAll(descriptors, info.getPropertyDescriptors());
 
             return new ClassPropertyAdapterImpl(forClass, descriptors);
         }

http://git-wip-us.apache.org/repos/asf/tapestry-5/blob/127f62ed/tapestry-ioc/src/test/groovy/ioc/specs/PropertyAccessImplSpec.groovy
----------------------------------------------------------------------
diff --git 
a/tapestry-ioc/src/test/groovy/ioc/specs/PropertyAccessImplSpec.groovy 
b/tapestry-ioc/src/test/groovy/ioc/specs/PropertyAccessImplSpec.groovy
index 7fa6581..8ea3ee9 100644
--- a/tapestry-ioc/src/test/groovy/ioc/specs/PropertyAccessImplSpec.groovy
+++ b/tapestry-ioc/src/test/groovy/ioc/specs/PropertyAccessImplSpec.groovy
@@ -810,4 +810,27 @@ class PropertyAccessImplSpec extends Specification {
     pa != null
     
   }
+  
+  public interface IdentifiableEnum<E extends Enum<E>, ID extends Number> {
+    ID getId();
+  }
+  
+  public enum ById implements IdentifiableEnum<ById, Byte> {
+    ;
+    public Byte getId() {
+      return null
+    }
+  }
+  
+  @Issue("TAP5-2032")
+  def "create adapter for enum class with overridden methods"(){
+    given:
+    def adapter = access.getAdapter(ById)
+    when:
+    def propertyNames = adapter.propertyNames
+    then:
+    !propertyNames.empty
+  }
+  
+
 }

Reply via email to