Title: [725] trunk/qdox/src/test/com/thoughtworks/qdox/model: Fix for QDOX-201: methodSignature with varArg support
Revision
725
Author
rfscholte
Date
2010-03-30 11:04:01 -0500 (Tue, 30 Mar 2010)

Log Message

Fix for QDOX-201: methodSignature with varArg support 

Modified Paths

Diff

Modified: trunk/qdox/src/java/com/thoughtworks/qdox/model/JavaClass.java (724 => 725)

--- trunk/qdox/src/java/com/thoughtworks/qdox/model/JavaClass.java	2010-03-25 08:44:45 UTC (rev 724)
+++ trunk/qdox/src/java/com/thoughtworks/qdox/model/JavaClass.java	2010-03-30 16:04:01 UTC (rev 725)
@@ -375,17 +375,29 @@
      * @return the matching method or null if no match is found.
      */
     public JavaMethod getMethodBySignature(String name, Type[] parameterTypes) {
+        return getMethod( name, parameterTypes, false );
+    }
+
+    /**
+     * This should be the signature for getMethodBySignature
+     * 
+     * @param name
+     * @param parameterTypes
+     * @param varArgs
+     * @return
+     */
+    public JavaMethod getMethod(String name, Type[] parameterTypes, boolean varArgs) {
         JavaMethod[] methods = getMethods();
 
         for (int i = 0; i < methods.length; i++) {
-            if (methods[i].signatureMatches(name, parameterTypes, false)) {
+            if (methods[i].signatureMatches(name, parameterTypes, varArgs)) {
                 return methods[i];
             }
         }
 
         return null;
     }
-
+    
     /**
      * 
      * @param name
@@ -408,6 +420,7 @@
      */
     public JavaMethod getMethodBySignature(String name, Type[] parameterTypes,
                                            boolean superclasses, boolean varArg) {
+        
         JavaMethod[] result = getMethodsBySignature(name, parameterTypes,
                 superclasses, varArg);
 
@@ -438,7 +451,7 @@
                                               Type[] parameterTypes, boolean superclasses, boolean varArg) {
         List result = new ArrayList();
 
-        JavaMethod methodInThisClass = getMethodBySignature(name, parameterTypes);
+        JavaMethod methodInThisClass = getMethod(name, parameterTypes, varArg);
 
         if (methodInThisClass != null) {
             result.add(methodInThisClass);

Modified: trunk/qdox/src/test/com/thoughtworks/qdox/model/JavaClassTest.java (724 => 725)

--- trunk/qdox/src/test/com/thoughtworks/qdox/model/JavaClassTest.java	2010-03-25 08:44:45 UTC (rev 724)
+++ trunk/qdox/src/test/com/thoughtworks/qdox/model/JavaClassTest.java	2010-03-30 16:04:01 UTC (rev 725)
@@ -617,4 +617,23 @@
     }
     
     
+    // QDOX-201
+    public void testGetVarArgMethodSignature() {
+        JavaMethod simpleMethod = new JavaMethod( "doSomething" );
+        simpleMethod.addParameter( new JavaParameter( new Type("String"), "param", false ) );
+        JavaMethod varArgMethod = new JavaMethod( "doSomething" );
+        varArgMethod.addParameter( new JavaParameter( new Type("String"), "param", true ) );
+        
+        cls.addMethod( simpleMethod );
+        cls.addMethod( varArgMethod );
+        
+        assertEquals( simpleMethod, cls.getMethodBySignature( "doSomething", new Type[] {new Type("String")} ) );
+        assertEquals( simpleMethod, cls.getMethodBySignature( "doSomething", new Type[] {new Type("String")}, false ) );
+        assertEquals( simpleMethod, cls.getMethodBySignature( "doSomething", new Type[] {new Type("String")}, true ) );
+        assertEquals( simpleMethod, cls.getMethodBySignature( "doSomething", new Type[] {new Type("String")}, false, false ) );
+        assertEquals( varArgMethod, cls.getMethodBySignature( "doSomething", new Type[] {new Type("String")}, false, true ) );
+        assertEquals( simpleMethod, cls.getMethodBySignature( "doSomething", new Type[] {new Type("String")}, true, false ) );
+        assertEquals( varArgMethod, cls.getMethodBySignature( "doSomething", new Type[] {new Type("String")}, true, true ) );
+    }
+    
 }


To unsubscribe from this list please visit:

http://xircles.codehaus.org/manage_email

Reply via email to