velocity-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From cbris...@apache.org
Subject svn commit: r1790686 - in /velocity/engine/trunk/velocity-engine-core/src: main/java/org/apache/velocity/util/introspection/MethodMap.java test/resources/conversion/compare/matrix.cmp
Date Sat, 08 Apr 2017 14:35:26 GMT
Author: cbrisson
Date: Sat Apr  8 14:35:26 2017
New Revision: 1790686

URL: http://svn.apache.org/viewvc?rev=1790686&view=rev
Log:
[engine] Debug new method disambiguation

Modified:
    velocity/engine/trunk/velocity-engine-core/src/main/java/org/apache/velocity/util/introspection/MethodMap.java
    velocity/engine/trunk/velocity-engine-core/src/test/resources/conversion/compare/matrix.cmp

Modified: velocity/engine/trunk/velocity-engine-core/src/main/java/org/apache/velocity/util/introspection/MethodMap.java
URL: http://svn.apache.org/viewvc/velocity/engine/trunk/velocity-engine-core/src/main/java/org/apache/velocity/util/introspection/MethodMap.java?rev=1790686&r1=1790685&r2=1790686&view=diff
==============================================================================
--- velocity/engine/trunk/velocity-engine-core/src/main/java/org/apache/velocity/util/introspection/MethodMap.java
(original)
+++ velocity/engine/trunk/velocity-engine-core/src/main/java/org/apache/velocity/util/introspection/MethodMap.java
Sat Apr  8 14:35:26 2017
@@ -183,12 +183,16 @@ public class MethodMap
          * one of STRICTLY_CONVERTIBLE, IMPLICITLY_CONVERTIBLE and EXPLICITLY_CONVERTIBLE_
*/
         int applicability;
 
+        /* whether the method has varrags */
+        boolean varargs;
+
         Match(Method method, int applicability, Class[] unboxedArgs)
         {
             this.method = method;
             this.applicability = applicability;
             this.methodTypes = method.getParameterTypes();
             this.specificity = compare(methodTypes, unboxedArgs);
+            this.varargs = methodTypes.length > 0 && methodTypes[methodTypes.length
- 1].isArray();
         }
     }
 
@@ -198,7 +202,7 @@ public class MethodMap
         {
             if (cls != null && cls != Object.class) return false;
         }
-        return true;
+        return args.length > 0;
     }
 
     private Method getBestMatch(List<Method> methods, Class[] args)
@@ -211,7 +215,7 @@ public class MethodMap
         }
         for (Method method : methods)
         {
-            int applicability = getApplicability(method, args);
+            int applicability = getApplicability(method, unboxedArgs);
             if (applicability > NOT_CONVERTIBLE)
             {
                 Match match = new Match(method, applicability, unboxedArgs);
@@ -240,11 +244,35 @@ public class MethodMap
                         {
                             it.remove();
                         }
+                        /* compare applicability */
+                        else if (best.applicability > match.applicability)
+                        {
+                            keepMethod = false;
+                        }
+                        else if (best.applicability < match.applicability)
+                        {
+                            it.remove();
+                        }
                         /* compare methods between them */
                         else
                         {
                             /* but only if some provided args are non null and not Object
*/
-                            if (!onlyNullOrObjects(args))
+                            if (onlyNullOrObjects(args))
+                            {
+                                /* in this case we only favor non-varrags methods */
+                                if (match.varargs != best.varargs)
+                                {
+                                    if (match.varargs)
+                                    {
+                                        keepMethod = false;
+                                    }
+                                    else if (best.varargs)
+                                    {
+                                        it.remove();
+                                    }
+                                }
+                            }
+                            else
                             {
                                 switch (compare(match.methodTypes, best.methodTypes))
                                 {
@@ -256,14 +284,6 @@ public class MethodMap
                                         break;
                                     case EQUIVALENT:
                                     case INCOMPARABLE:
-                                        /* compare applicability */
-                                        if (best.applicability > match.applicability)
-                                        {
-                                            keepMethod = false;
-                                        } else if (best.applicability < match.applicability)
-                                        {
-                                            it.remove();
-                                        }
                                         /* otherwise it's an equivalent match */
                                         break;
                                 }

Modified: velocity/engine/trunk/velocity-engine-core/src/test/resources/conversion/compare/matrix.cmp
URL: http://svn.apache.org/viewvc/velocity/engine/trunk/velocity-engine-core/src/test/resources/conversion/compare/matrix.cmp?rev=1790686&r1=1790685&r2=1790686&view=diff
==============================================================================
--- velocity/engine/trunk/velocity-engine-core/src/test/resources/conversion/compare/matrix.cmp
(original)
+++ velocity/engine/trunk/velocity-engine-core/src/test/resources/conversion/compare/matrix.cmp
Sat Apr  8 14:35:26 2017
@@ -99,7 +99,7 @@
           <td> <span class="explicit">explicit</span></td>
           <td> <span class="explicit">explicit</span></td>
           <td> <span class="explicit">explicit</span></td>
-          <td> <span class="none">none</span></td>
+          <td> <span class="explicit">explicit</span></td>
           <td> <span class="explicit">explicit</span></td>
           <td> <span class="none">none</span></td>
           <td><span class="none">none</span></td>
@@ -147,7 +147,7 @@
           <td> <span class="explicit">explicit</span></td>
           <td> <span class="explicit">explicit</span></td>
           <td> <span class="explicit">explicit</span></td>
-          <td> <span class="none">none</span></td>
+          <td> <span class="explicit">explicit</span></td>
           <td> <span class="explicit">explicit</span></td>
           <td> <span class="none">none</span></td>
           <td><span class="none">none</span></td>
@@ -171,7 +171,7 @@
           <td> <span class="explicit">explicit</span></td>
           <td> <span class="explicit">explicit</span></td>
           <td> <span class="explicit">explicit</span></td>
-          <td> <span class="none">none</span></td>
+          <td> <span class="explicit">explicit</span></td>
           <td> <span class="explicit">explicit</span></td>
           <td> <span class="none">none</span></td>
           <td><span class="none">none</span></td>
@@ -195,7 +195,7 @@
           <td> <span class="explicit">explicit</span></td>
           <td> <span class="explicit">explicit</span></td>
           <td> <span class="explicit">explicit</span></td>
-          <td> <span class="none">none</span></td>
+          <td> <span class="explicit">explicit</span></td>
           <td> <span class="explicit">explicit</span></td>
           <td> <span class="none">none</span></td>
           <td><span class="none">none</span></td>
@@ -219,7 +219,7 @@
           <td>  <span class="implicit">implicit</span></td>
           <td> <span class="explicit">explicit</span></td>
           <td> <span class="explicit">explicit</span></td>
-          <td> <span class="none">none</span></td>
+          <td> <span class="explicit">explicit</span></td>
           <td> <span class="explicit">explicit</span></td>
           <td> <span class="none">none</span></td>
           <td><span class="none">none</span></td>
@@ -243,7 +243,7 @@
           <td>  <span class="implicit">implicit</span></td>
           <td>  <span class="implicit">implicit</span></td>
           <td> <span class="explicit">explicit</span></td>
-          <td> <span class="none">none</span></td>
+          <td> <span class="explicit">explicit</span></td>
           <td> <span class="explicit">explicit</span></td>
           <td> <span class="none">none</span></td>
           <td><span class="none">none</span></td>
@@ -291,7 +291,7 @@
           <td> <span class="explicit">explicit</span></td>
           <td> <span class="explicit">explicit</span></td>
           <td> <span class="explicit">explicit</span></td>
-          <td> <span class="none">none</span></td>
+          <td> <span class="explicit">explicit</span></td>
           <td> <span class="explicit">explicit</span></td>
           <td> <span class="none">none</span></td>
           <td> <span class="strict">strict</span></td>
@@ -339,7 +339,7 @@
           <td> <span class="explicit">explicit</span></td>
           <td> <span class="explicit">explicit</span></td>
           <td> <span class="explicit">explicit</span></td>
-          <td> <span class="none">none</span></td>
+          <td> <span class="explicit">explicit</span></td>
           <td> <span class="explicit">explicit</span></td>
           <td> <span class="none">none</span></td>
           <td> <span class="strict">strict</span></td>
@@ -363,7 +363,7 @@
           <td> <span class="explicit">explicit</span></td>
           <td> <span class="explicit">explicit</span></td>
           <td> <span class="explicit">explicit</span></td>
-          <td> <span class="none">none</span></td>
+          <td> <span class="explicit">explicit</span></td>
           <td> <span class="explicit">explicit</span></td>
           <td> <span class="none">none</span></td>
           <td> <span class="strict">strict</span></td>
@@ -387,7 +387,7 @@
           <td> <span class="explicit">explicit</span></td>
           <td> <span class="explicit">explicit</span></td>
           <td> <span class="explicit">explicit</span></td>
-          <td> <span class="none">none</span></td>
+          <td> <span class="explicit">explicit</span></td>
           <td> <span class="explicit">explicit</span></td>
           <td> <span class="none">none</span></td>
           <td> <span class="strict">strict</span></td>
@@ -411,7 +411,7 @@
           <td> <span class="strict">strict</span></td>
           <td> <span class="explicit">explicit</span></td>
           <td> <span class="explicit">explicit</span></td>
-          <td> <span class="none">none</span></td>
+          <td> <span class="explicit">explicit</span></td>
           <td> <span class="explicit">explicit</span></td>
           <td> <span class="none">none</span></td>
           <td> <span class="strict">strict</span></td>
@@ -435,7 +435,7 @@
           <td> <span class="explicit">explicit</span></td>
           <td> <span class="strict">strict</span></td>
           <td> <span class="explicit">explicit</span></td>
-          <td> <span class="none">none</span></td>
+          <td> <span class="explicit">explicit</span></td>
           <td> <span class="explicit">explicit</span></td>
           <td> <span class="none">none</span></td>
           <td> <span class="strict">strict</span></td>



Mime
View raw message