You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@velocity.apache.org by cb...@apache.org on 2016/10/02 07:43:40 UTC
svn commit: r1763040 - in /velocity/engine/trunk/velocity-engine-core/src:
main/java/org/apache/velocity/util/introspection/
test/java/org/apache/velocity/test/ test/java/org/apache/velocity/test/misc/
Author: cbrisson
Date: Sun Oct 2 07:43:40 2016
New Revision: 1763040
URL: http://svn.apache.org/viewvc?rev=1763040&view=rev
Log:
enhance Uberspector method disambiguation (+testcase)
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/java/org/apache/velocity/test/UberspectorTestCase.java
velocity/engine/trunk/velocity-engine-core/src/test/java/org/apache/velocity/test/misc/UberspectorTestObject.java
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=1763040&r1=1763039&r2=1763040&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 Sun Oct 2 07:43:40 2016
@@ -238,6 +238,7 @@ public class MethodMap
bestMatchTypes = methodTypes;
bestMatchComp = compare(bestMatchTypes, unboxedArgs);
equivalentMatches = null;
+ ambiguities = 0;
}
break;
}
@@ -246,6 +247,24 @@ public class MethodMap
break;
case INCOMPARABLE:
+ /* do not retain method if it's more specific than (or incomparable to) provided (unboxed) arguments
+ * while best batch is less specific
+ */
+ if (bestMatchComp == LESS_SPECIFIC && compare(methodTypes, unboxedArgs) != LESS_SPECIFIC)
+ {
+ break;
+ }
+ /* retain it anyway if less specific than (unboxed) provided args while
+ * bestmatch is more specific or incomparable
+ */
+ if (bestMatchComp != LESS_SPECIFIC && compare(methodTypes, unboxedArgs) == LESS_SPECIFIC)
+ {
+ bestMatch = method;
+ bestMatchTypes = methodTypes;
+ bestMatchComp = compare(bestMatchTypes, unboxedArgs);
+ equivalentMatches = null;
+ break;
+ }
if (equivalentMatches == null)
{
equivalentMatches = new ArrayList(bestMatchTypes.length);
@@ -255,9 +274,9 @@ public class MethodMap
case LESS_SPECIFIC:
/* retain it anyway if less specific than (unboxed) provided args while
- * bestmatch is more specific
+ * bestmatch is more specific or incomparable
*/
- if (bestMatchComp == MORE_SPECIFIC && compare(methodTypes, unboxedArgs) == LESS_SPECIFIC)
+ if (bestMatchComp != LESS_SPECIFIC && compare(methodTypes, unboxedArgs) == LESS_SPECIFIC)
{
bestMatch = method;
bestMatchTypes = methodTypes;
Modified: velocity/engine/trunk/velocity-engine-core/src/test/java/org/apache/velocity/test/UberspectorTestCase.java
URL: http://svn.apache.org/viewvc/velocity/engine/trunk/velocity-engine-core/src/test/java/org/apache/velocity/test/UberspectorTestCase.java?rev=1763040&r1=1763039&r2=1763040&view=diff
==============================================================================
--- velocity/engine/trunk/velocity-engine-core/src/test/java/org/apache/velocity/test/UberspectorTestCase.java (original)
+++ velocity/engine/trunk/velocity-engine-core/src/test/java/org/apache/velocity/test/UberspectorTestCase.java Sun Oct 2 07:43:40 2016
@@ -77,7 +77,7 @@ public class UberspectorTestCase
// Don't screw up on empty properties. That should map to get("")
assertNotNull(getter);
- assertEquals("Found wrong method", "get", getter. getMethodName());
+ assertEquals("Found wrong method", "get", getter.getMethodName());
}
public void testEmptyPropertySetter()
@@ -259,6 +259,24 @@ public class UberspectorTestCase
assertEquals("Found wrong method", "setpremium", setter.getMethodName());
}
+ public void testDisambiguation()
+ throws Exception
+ {
+ VelPropertySet setter;
+
+ Uberspect u = ri.getUberspect();
+ UberspectorTestObject uto = new UberspectorTestObject();
+
+ // setUnambigous() - String
+ setter = u.getPropertySet(uto, "unambiguous", "string", null);
+ assertNotNull(setter);
+ setter.invoke(uto, "string");
+
+ // setUnambigous() - HashMap
+ setter = u.getPropertySet(uto, "unambiguous", new HashMap(), null);
+ assertNotNull(setter);
+ setter.invoke(uto, new HashMap());
+ }
/*
*
Modified: velocity/engine/trunk/velocity-engine-core/src/test/java/org/apache/velocity/test/misc/UberspectorTestObject.java
URL: http://svn.apache.org/viewvc/velocity/engine/trunk/velocity-engine-core/src/test/java/org/apache/velocity/test/misc/UberspectorTestObject.java?rev=1763040&r1=1763039&r2=1763040&view=diff
==============================================================================
--- velocity/engine/trunk/velocity-engine-core/src/test/java/org/apache/velocity/test/misc/UberspectorTestObject.java (original)
+++ velocity/engine/trunk/velocity-engine-core/src/test/java/org/apache/velocity/test/misc/UberspectorTestObject.java Sun Oct 2 07:43:40 2016
@@ -19,6 +19,8 @@ package org.apache.velocity.test.misc;
* under the License.
*/
+import java.util.Map;
+
public class UberspectorTestObject
{
private String regular;
@@ -29,6 +31,8 @@ public class UberspectorTestObject
private String ambigous;
+ private String unambiguous;
+
/**
* @return the premium
*/
@@ -116,4 +120,14 @@ public class UberspectorTestObject
{
this.ambigous = ambigous.toString();
}
+
+ public void setUnambiguous(String unambiguous)
+ {
+ this.unambiguous = unambiguous;
+ }
+
+ public void setUnambiguous(Map unambiguous)
+ {
+ this.unambiguous = unambiguous.toString();
+ }
}