velocity-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From nbu...@apache.org
Subject svn commit: r928988 - in /velocity/engine/trunk/src: java/org/apache/velocity/util/introspection/MethodMap.java test/org/apache/velocity/test/issues/Velocity753TestCase.java
Date Tue, 30 Mar 2010 05:06:25 GMT
Author: nbubna
Date: Tue Mar 30 05:06:24 2010
New Revision: 928988

URL: http://svn.apache.org/viewvc?rev=928988&view=rev
Log:
VELOCITY-753 make Object always less specific when comparing method parameter types

Added:
    velocity/engine/trunk/src/test/org/apache/velocity/test/issues/Velocity753TestCase.java
  (with props)
Modified:
    velocity/engine/trunk/src/java/org/apache/velocity/util/introspection/MethodMap.java

Modified: velocity/engine/trunk/src/java/org/apache/velocity/util/introspection/MethodMap.java
URL: http://svn.apache.org/viewvc/velocity/engine/trunk/src/java/org/apache/velocity/util/introspection/MethodMap.java?rev=928988&r1=928987&r2=928988&view=diff
==============================================================================
--- velocity/engine/trunk/src/java/org/apache/velocity/util/introspection/MethodMap.java (original)
+++ velocity/engine/trunk/src/java/org/apache/velocity/util/introspection/MethodMap.java Tue
Mar 30 05:06:24 2010
@@ -209,6 +209,7 @@ public class MethodMap
                 
         if (equivalentMatches != null)
         {
+            System.out.println("ambiguous: "+equivalentMatches);
             throw new AmbiguousException();
         }
         return bestMatch;
@@ -260,10 +261,12 @@ public class MethodMap
                 boolean last = (i == c1.length - 1);
                 c1MoreSpecific =
                     c1MoreSpecific ||
-                    isStrictConvertible(c2[i], c1[i], last);
+                    isStrictConvertible(c2[i], c1[i], last) ||
+                    c2[i] == Object.class;//Object is always least-specific
                 c2MoreSpecific =
                     c2MoreSpecific ||
-                    isStrictConvertible(c1[i], c2[i], last);
+                    isStrictConvertible(c1[i], c2[i], last) ||
+                    c1[i] == Object.class;//Object is always least-specific
             }
         }
 

Added: velocity/engine/trunk/src/test/org/apache/velocity/test/issues/Velocity753TestCase.java
URL: http://svn.apache.org/viewvc/velocity/engine/trunk/src/test/org/apache/velocity/test/issues/Velocity753TestCase.java?rev=928988&view=auto
==============================================================================
--- velocity/engine/trunk/src/test/org/apache/velocity/test/issues/Velocity753TestCase.java
(added)
+++ velocity/engine/trunk/src/test/org/apache/velocity/test/issues/Velocity753TestCase.java
Tue Mar 30 05:06:24 2010
@@ -0,0 +1,63 @@
+package org.apache.velocity.test.issues;
+
+/*
+ * 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.    
+ */
+
+import java.text.NumberFormat;
+import org.apache.velocity.test.BaseTestCase;
+
+/**
+ * This class tests VELOCITY-753.
+ */
+public class Velocity753TestCase extends BaseTestCase
+{
+    public Velocity753TestCase(String name)
+    {
+        super(name);
+    }
+
+    public void testFloatArg() throws Exception
+    { 
+        // verify precedence outside of Velocity 
+        Tool tool = new Tool(); 
+        Float f = new Float(5.23); 
+        assertEquals("object", tool.test(f)); 
+
+        context.put("tool", tool); 
+        context.put("float", f); 
+
+        String template = "$tool.test($float)"; 
+        // in reflection-land, Float and float are equivalent, so double is selected
+        assertEvalEquals("double", template); 
+    } 
+
+    public static class Tool
+    {
+        public String test(double d)
+        {
+            return "double";
+        }
+
+        public String test(Object o)
+        {
+            return "object";
+        }
+    }
+
+}

Propchange: velocity/engine/trunk/src/test/org/apache/velocity/test/issues/Velocity753TestCase.java
------------------------------------------------------------------------------
    svn:executable = *



Mime
View raw message