You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@camel.apache.org by da...@apache.org on 2014/12/10 17:32:12 UTC

[02/15] camel git commit: CAMEL-8137: Bean component should detect override methods that are assignable by type, so duplicate methods is not reported as error.

CAMEL-8137: Bean component should detect override methods that are assignable by type, so duplicate methods is not reported as error.


Project: http://git-wip-us.apache.org/repos/asf/camel/repo
Commit: http://git-wip-us.apache.org/repos/asf/camel/commit/f5bb673a
Tree: http://git-wip-us.apache.org/repos/asf/camel/tree/f5bb673a
Diff: http://git-wip-us.apache.org/repos/asf/camel/diff/f5bb673a

Branch: refs/heads/master
Commit: f5bb673aff138e42a0936d3997392a82512a86da
Parents: 9251690
Author: Claus Ibsen <da...@apache.org>
Authored: Wed Dec 10 11:05:38 2014 +0100
Committer: Claus Ibsen <da...@apache.org>
Committed: Wed Dec 10 11:05:38 2014 +0100

----------------------------------------------------------------------
 .../apache/camel/component/bean/BeanInfo.java   | 34 +++++++++++++-------
 1 file changed, 23 insertions(+), 11 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/camel/blob/f5bb673a/camel-core/src/main/java/org/apache/camel/component/bean/BeanInfo.java
----------------------------------------------------------------------
diff --git a/camel-core/src/main/java/org/apache/camel/component/bean/BeanInfo.java b/camel-core/src/main/java/org/apache/camel/component/bean/BeanInfo.java
index c386ae5..7f74407 100644
--- a/camel-core/src/main/java/org/apache/camel/component/bean/BeanInfo.java
+++ b/camel-core/src/main/java/org/apache/camel/component/bean/BeanInfo.java
@@ -298,21 +298,36 @@ public class BeanInfo {
 
         LOG.trace("Introspecting class: {}", clazz);
 
-        // favor interface methods, and then other declared methods which does not override the existing methods
-        List<Method> interfaceMethods = getInterfaceMethods(clazz);
+        // favor declared methods, and then filter out duplicate interface methods
+        Set<Method> methods = new HashSet<Method>(Arrays.asList(clazz.getDeclaredMethods()));
+
+        // it may have duplicate methods already in the declared list of methods, so lets remove those
         Set<Method> overrides = new HashSet<Method>();
-        Set<Method> extraMethods = new HashSet<Method>(Arrays.asList(clazz.getDeclaredMethods()));
+        for (Method source : methods) {
+            for (Method target : methods) {
+                // skip overselves
+                if (ObjectHelper.isOverridingMethod(source, target, true)) {
+                    continue;
+                }
+
+                if (ObjectHelper.isOverridingMethod(source, target, false)) {
+                    overrides.add(target);
+                }
+            }
+        }
+        methods.removeAll(overrides);
+        overrides.clear();
+
+        List<Method> extraMethods = getInterfaceMethods(clazz);
         for (Method target : extraMethods) {
-            for (Method interfaceMethod : interfaceMethods) {
-                if (ObjectHelper.isOverridingMethod(interfaceMethod, target, false)) {
+            for (Method source : methods) {
+                if (ObjectHelper.isOverridingMethod(source, target, false)) {
                     overrides.add(target);
                 }
             }
         }
         // remove all the overrides methods
         extraMethods.removeAll(overrides);
-
-        List<Method> methods = interfaceMethods;
         methods.addAll(extraMethods);
 
         // now introspect the methods and filter non valid methods
@@ -897,10 +912,7 @@ public class BeanInfo {
         while (clazz != null && !clazz.equals(Object.class)) {
             for (Class<?> interfaceClazz : clazz.getInterfaces()) {
                 for (Method interfaceMethod : interfaceClazz.getDeclaredMethods()) {
-                    // must be a public method
-                    if (Modifier.isPublic(interfaceMethod.getModifiers())) {
-                        answer.add(interfaceMethod);
-                    }
+                    answer.add(interfaceMethod);
                 }
             }
             clazz = clazz.getSuperclass();