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 2017/02/19 10:08:53 UTC

[1/3] camel git commit: Removed useless code

Repository: camel
Updated Branches:
  refs/heads/master 41ea7c7ad -> b7667a422


Removed useless code


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

Branch: refs/heads/master
Commit: b7667a4222399f1d63f3df9fbf0e610104e8fd18
Parents: 8889b82
Author: aldettinger <al...@gmail.com>
Authored: Sat Feb 18 23:02:28 2017 +0100
Committer: Claus Ibsen <da...@apache.org>
Committed: Sun Feb 19 10:03:36 2017 +0100

----------------------------------------------------------------------
 .../bean/BeanInfoOverloadedWithSubTypeParamTest.java          | 7 +------
 1 file changed, 1 insertion(+), 6 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/camel/blob/b7667a42/camel-core/src/test/java/org/apache/camel/component/bean/BeanInfoOverloadedWithSubTypeParamTest.java
----------------------------------------------------------------------
diff --git a/camel-core/src/test/java/org/apache/camel/component/bean/BeanInfoOverloadedWithSubTypeParamTest.java b/camel-core/src/test/java/org/apache/camel/component/bean/BeanInfoOverloadedWithSubTypeParamTest.java
index d0714d6..deda491 100644
--- a/camel-core/src/test/java/org/apache/camel/component/bean/BeanInfoOverloadedWithSubTypeParamTest.java
+++ b/camel-core/src/test/java/org/apache/camel/component/bean/BeanInfoOverloadedWithSubTypeParamTest.java
@@ -26,12 +26,10 @@ public class BeanInfoOverloadedWithSubTypeParamTest extends ContextTestSupport {
 
     public void testBeanInfoOverloadedWithSubTypedParam() {
         BeanInfo beanInfo = new BeanInfo(context, Bean.class);
-        Assert.assertEquals(3, beanInfo.getMethods().size());
+        Assert.assertEquals(2, beanInfo.getMethods().size());
     }
 
     class Bean {
-        public void doSomething(RequestA request) {
-        }
 
         public void doSomething(RequestB request) {
         }
@@ -40,9 +38,6 @@ public class BeanInfoOverloadedWithSubTypeParamTest extends ContextTestSupport {
         }
     }
 
-    class RequestA {
-    }
-
     class RequestB {
     }
 


[2/3] camel git commit: CAMEL-10396: Corrected a bug where BeanInfo was missing a method overload

Posted by da...@apache.org.
CAMEL-10396: Corrected a bug where BeanInfo was missing a method overload


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

Branch: refs/heads/master
Commit: 8889b827193d6c5b08c801a4dbb457a43af2f958
Parents: ec7ffa1
Author: aldettinger <al...@gmail.com>
Authored: Sat Feb 18 16:28:55 2017 +0100
Committer: Claus Ibsen <da...@apache.org>
Committed: Sun Feb 19 10:03:36 2017 +0100

----------------------------------------------------------------------
 .../apache/camel/component/bean/BeanInfo.java   | 34 +++++++++++---------
 .../org/apache/camel/util/ObjectHelper.java     |  9 ++++++
 .../camel/component/bean/MyOtherFooBean.java    | 11 +++++--
 .../org/apache/camel/util/ObjectHelperTest.java | 24 ++++++++++++++
 4 files changed, 59 insertions(+), 19 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/camel/blob/8889b827/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 ffeea3e..1efe61c 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
@@ -405,10 +405,8 @@ public class BeanInfo {
 
         MethodInfo methodInfo = createMethodInfo(clazz, method);
 
-        // methods already registered should be preferred to use instead of super classes of existing methods
-        // we want to us the method from the sub class over super classes, so if we have already registered
-        // the method then use it (we are traversing upwards: sub (child) -> super (farther) )
-        MethodInfo existingMethodInfo = overridesExistingMethod(methodInfo);
+        // Foster the use of a potentially already registered most specific override
+        MethodInfo existingMethodInfo = findMostSpecificOverride(methodInfo);
         if (existingMethodInfo != null) {
             LOG.trace("This method is already overridden in a subclass, so the method from the sub class is preferred: {}", existingMethodInfo);
             return existingMethodInfo;
@@ -905,20 +903,24 @@ public class BeanInfo {
     }
 
     /**
-     * Does the given method info override an existing method registered before (from a subclass)
+     * Gets the most specific override of a given method, if any. Indeed,
+     * overrides may have already been found while inspecting sub classes. Or
+     * the given method could override an interface extra method.
      *
-     * @param methodInfo  the method to test
-     * @return the already registered method to use, null if not overriding any
+     * @param proposedMethodInfo the method for which a more specific override is
+     *            searched
+     * @return The already registered most specific override if any, otherwise
+     *         <code>null</code>
      */
-    private MethodInfo overridesExistingMethod(MethodInfo methodInfo) {
-        for (MethodInfo info : methodMap.values()) {
-            Method source = info.getMethod();
-            Method target = methodInfo.getMethod();
-
-            boolean override = ObjectHelper.isOverridingMethod(source, target);
-            if (override) {
-                // same name, same parameters, then its overrides an existing class
-                return info;
+    private MethodInfo findMostSpecificOverride(MethodInfo proposedMethodInfo) {
+        for (MethodInfo alreadyRegisteredMethodInfo : methodMap.values()) {
+            Method alreadyRegisteredMethod = alreadyRegisteredMethodInfo.getMethod();
+            Method proposedMethod = proposedMethodInfo.getMethod();
+
+            if (ObjectHelper.isOverridingMethod(proposedMethod, alreadyRegisteredMethod, false)) {
+                return alreadyRegisteredMethodInfo;
+            } else if (ObjectHelper.isOverridingMethod(alreadyRegisteredMethod, proposedMethod, false)) {
+                return proposedMethodInfo;
             }
         }
 

http://git-wip-us.apache.org/repos/asf/camel/blob/8889b827/camel-core/src/main/java/org/apache/camel/util/ObjectHelper.java
----------------------------------------------------------------------
diff --git a/camel-core/src/main/java/org/apache/camel/util/ObjectHelper.java b/camel-core/src/main/java/org/apache/camel/util/ObjectHelper.java
index 7331437..b87cbc6 100644
--- a/camel-core/src/main/java/org/apache/camel/util/ObjectHelper.java
+++ b/camel-core/src/main/java/org/apache/camel/util/ObjectHelper.java
@@ -1327,6 +1327,15 @@ public final class ObjectHelper {
      * @return <tt>true</tt> if it override, <tt>false</tt> otherwise
      */
     public static boolean isOverridingMethod(Method source, Method target, boolean exact) {
+
+        if (source.equals(target)) {
+            return true;
+        } else if (source.getDeclaringClass() == target.getDeclaringClass()) {
+            return false;
+        } else if (!source.getDeclaringClass().isAssignableFrom(target.getDeclaringClass())) {
+            return false;
+        }
+
         if (!source.getName().equals(target.getName())) {
             return false;
         }

http://git-wip-us.apache.org/repos/asf/camel/blob/8889b827/camel-core/src/test/java/org/apache/camel/component/bean/MyOtherFooBean.java
----------------------------------------------------------------------
diff --git a/camel-core/src/test/java/org/apache/camel/component/bean/MyOtherFooBean.java b/camel-core/src/test/java/org/apache/camel/component/bean/MyOtherFooBean.java
index 0333478..fa2a519 100644
--- a/camel-core/src/test/java/org/apache/camel/component/bean/MyOtherFooBean.java
+++ b/camel-core/src/test/java/org/apache/camel/component/bean/MyOtherFooBean.java
@@ -16,9 +16,6 @@
  */
 package org.apache.camel.component.bean;
 
-/**
- * @version 
- */
 public class MyOtherFooBean {
 
     public String echo(String s) {
@@ -28,4 +25,12 @@ public class MyOtherFooBean {
     public Integer echo(Integer i) {
         return i.intValue() * i.intValue();
     }
+
+    public String toString(Object input) {
+        return "toString(Object) was called";
+    }
+
+    public String toString(String input) {
+        return "toString(String) was called";
+    }
 }

http://git-wip-us.apache.org/repos/asf/camel/blob/8889b827/camel-core/src/test/java/org/apache/camel/util/ObjectHelperTest.java
----------------------------------------------------------------------
diff --git a/camel-core/src/test/java/org/apache/camel/util/ObjectHelperTest.java b/camel-core/src/test/java/org/apache/camel/util/ObjectHelperTest.java
index 0253eca..7997664 100644
--- a/camel-core/src/test/java/org/apache/camel/util/ObjectHelperTest.java
+++ b/camel-core/src/test/java/org/apache/camel/util/ObjectHelperTest.java
@@ -37,6 +37,7 @@ import junit.framework.TestCase;
 import org.apache.camel.CamelContext;
 import org.apache.camel.Exchange;
 import org.apache.camel.Message;
+import org.apache.camel.component.bean.MyOtherFooBean;
 import org.apache.camel.component.bean.MyStaticClass;
 import org.apache.camel.impl.DefaultCamelContext;
 import org.apache.camel.impl.DefaultMessage;
@@ -866,4 +867,27 @@ public class ObjectHelperTest extends TestCase {
             assertEquals("expected2 must be specified on: holder", iae.getMessage());
         }
     }
+
+    public void testSameMethodIsOverride() throws Exception {
+        Method m = MyOtherFooBean.class.getMethod("toString", Object.class);
+        assertTrue(ObjectHelper.isOverridingMethod(m, m, false));
+    }
+
+    public void testOverloadIsNotOverride() throws Exception {
+        Method m1 = MyOtherFooBean.class.getMethod("toString", Object.class);
+        Method m2 = MyOtherFooBean.class.getMethod("toString", String.class);
+        assertFalse(ObjectHelper.isOverridingMethod(m2, m1, false));
+    }
+
+    public void testOverrideEquivalentSignatureFromSiblingClassIsNotOverride() throws Exception {
+        Method m1 = Double.class.getMethod("intValue");
+        Method m2 = Float.class.getMethod("intValue");
+        assertFalse(ObjectHelper.isOverridingMethod(m2, m1, false));
+    }
+
+    public void testOverrideEquivalentSignatureFromUpperClassIsOverride() throws Exception {
+        Method m1 = Double.class.getMethod("intValue");
+        Method m2 = Number.class.getMethod("intValue");
+        assertTrue(ObjectHelper.isOverridingMethod(m2, m1, false));
+    }
 }


[3/3] camel git commit: CAMEL-10396: Corrected a bug where BeanInfo was missing a method overload

Posted by da...@apache.org.
CAMEL-10396: Corrected a bug where BeanInfo was missing a method overload


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

Branch: refs/heads/master
Commit: ec7ffa11a02c6e13cacd9c3fc48de34bc6c9dee4
Parents: 41ea7c7
Author: aldettinger <al...@gmail.com>
Authored: Sat Feb 18 16:27:31 2017 +0100
Committer: Claus Ibsen <da...@apache.org>
Committed: Sun Feb 19 10:03:36 2017 +0100

----------------------------------------------------------------------
 .../BeanInfoOverloadedWithSubTypeParamTest.java | 51 ++++++++++++++++++++
 .../BeanOverloadsWithAssignableParamTest.java   | 41 ++++++++++++++++
 2 files changed, 92 insertions(+)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/camel/blob/ec7ffa11/camel-core/src/test/java/org/apache/camel/component/bean/BeanInfoOverloadedWithSubTypeParamTest.java
----------------------------------------------------------------------
diff --git a/camel-core/src/test/java/org/apache/camel/component/bean/BeanInfoOverloadedWithSubTypeParamTest.java b/camel-core/src/test/java/org/apache/camel/component/bean/BeanInfoOverloadedWithSubTypeParamTest.java
new file mode 100644
index 0000000..d0714d6
--- /dev/null
+++ b/camel-core/src/test/java/org/apache/camel/component/bean/BeanInfoOverloadedWithSubTypeParamTest.java
@@ -0,0 +1,51 @@
+/**
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements.  See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License.  You may obtain a copy of the License at
+ *
+ *      http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package org.apache.camel.component.bean;
+
+import org.apache.camel.ContextTestSupport;
+import org.junit.Assert;
+
+/**
+ * @version
+ */
+public class BeanInfoOverloadedWithSubTypeParamTest extends ContextTestSupport {
+
+    public void testBeanInfoOverloadedWithSubTypedParam() {
+        BeanInfo beanInfo = new BeanInfo(context, Bean.class);
+        Assert.assertEquals(3, beanInfo.getMethods().size());
+    }
+
+    class Bean {
+        public void doSomething(RequestA request) {
+        }
+
+        public void doSomething(RequestB request) {
+        }
+
+        public void doSomething(RequestC request) {
+        }
+    }
+
+    class RequestA {
+    }
+
+    class RequestB {
+    }
+
+    class RequestC extends RequestB {
+    }
+}

http://git-wip-us.apache.org/repos/asf/camel/blob/ec7ffa11/camel-core/src/test/java/org/apache/camel/component/bean/BeanOverloadsWithAssignableParamTest.java
----------------------------------------------------------------------
diff --git a/camel-core/src/test/java/org/apache/camel/component/bean/BeanOverloadsWithAssignableParamTest.java b/camel-core/src/test/java/org/apache/camel/component/bean/BeanOverloadsWithAssignableParamTest.java
new file mode 100644
index 0000000..ad13a27
--- /dev/null
+++ b/camel-core/src/test/java/org/apache/camel/component/bean/BeanOverloadsWithAssignableParamTest.java
@@ -0,0 +1,41 @@
+/**
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements.  See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License.  You may obtain a copy of the License at
+ *
+ *      http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package org.apache.camel.component.bean;
+
+import org.apache.camel.ContextTestSupport;
+import org.apache.camel.builder.RouteBuilder;
+import org.apache.camel.component.mock.MockEndpoint;
+
+public class BeanOverloadsWithAssignableParamTest extends ContextTestSupport {
+
+    public void testToStringWithStringParam() throws Exception {
+        MockEndpoint mock = getMockEndpoint("mock:stringParamResult");
+        mock.expectedBodiesReceived("toString(String) was called");
+        template.sendBody("direct:stringParam", "");
+        assertMockEndpointsSatisfied();
+    }
+
+    @Override
+    protected RouteBuilder createRouteBuilder() throws Exception {
+        return new RouteBuilder() {
+            @Override
+            public void configure() throws Exception {
+                from("direct:stringParam").bean(new MyOtherFooBean(), "toString(String)").to("mock:stringParamResult");
+            }
+        };
+    }
+}