Title: [1151] trunk/qdox/src/main/java/com/thoughtworks/qdox/model: Add methods to find constructors by signature

Diff

Modified: trunk/qdox/src/main/java/com/thoughtworks/qdox/model/AbstractBaseMethod.java (1150 => 1151)

--- trunk/qdox/src/main/java/com/thoughtworks/qdox/model/AbstractBaseMethod.java	2011-04-06 19:58:08 UTC (rev 1150)
+++ trunk/qdox/src/main/java/com/thoughtworks/qdox/model/AbstractBaseMethod.java	2011-04-06 20:32:21 UTC (rev 1151)
@@ -61,15 +61,8 @@
         this.exceptions = exceptions;
     }
 
-    public boolean signatureMatches( String name, List<Type> parameterTypes )
+    protected boolean signatureMatches( List<Type> parameterTypes, boolean varArgs )
     {
-        return signatureMatches( name, parameterTypes, false );
-    }
-
-    public boolean signatureMatches( String name, List<Type> parameterTypes, boolean varArg )
-    {
-        if (!name.equals(this.getName())) return false;
-        
         List<Type> parameterTypeList;
         if( parameterTypes == null) {
             parameterTypeList = Collections.emptyList();
@@ -78,14 +71,18 @@
             parameterTypeList = parameterTypes;
         }
         
-        if (parameterTypeList.size() != this.getParameters().size()) return false;
+        if (parameterTypeList.size() != this.getParameters().size()) 
+        {
+            return false;   
+        }
         
-        for (int i = 0; i < parameters.size(); i++) {
-            if (!parameters.get(i).getType().equals(parameterTypes.get(i))) {
+        for (int i = 0; i < getParameters().size(); i++) 
+        {
+            if (!getParameters().get(i).getType().equals(parameterTypes.get(i))) {
                 return false;
             }
         }
-        return (this.varArgs == varArg);
+        return (this.varArgs == varArgs);
     }
 
     public boolean isPublic()

Modified: trunk/qdox/src/main/java/com/thoughtworks/qdox/model/DefaultJavaClass.java (1150 => 1151)

--- trunk/qdox/src/main/java/com/thoughtworks/qdox/model/DefaultJavaClass.java	2011-04-06 19:58:08 UTC (rev 1150)
+++ trunk/qdox/src/main/java/com/thoughtworks/qdox/model/DefaultJavaClass.java	2011-04-06 20:32:21 UTC (rev 1151)
@@ -322,11 +322,37 @@
         return type;
     }
 
+    /**
+     * @since 2.0
+     */
     public List<JavaConstructor> getConstructors()
     {
         return constructors;
     }
     
+    /**
+     * @since 2.0
+     */
+    public JavaConstructor getConstructor( List<Type> parameterTypes )
+    {
+        return getConstructor( parameterTypes, false );
+    }
+    
+    /**
+     * @since 2.0
+     */
+    public JavaConstructor getConstructor( List<Type> parameterTypes, boolean varArgs )
+    {
+        for ( JavaConstructor constructor : getConstructors() )
+        {
+            if ( constructor.signatureMatches( parameterTypes, varArgs ) )
+            {
+                return constructor;
+            }
+        }
+        return null;
+    }
+    
     /* (non-Javadoc)
      * @see com.thoughtworks.qdox.model.JavaClass#getMethods()
      */
@@ -397,7 +423,6 @@
                 return method;
             }
         }
-
         return null;
     }
     

Modified: trunk/qdox/src/main/java/com/thoughtworks/qdox/model/DefaultJavaConstructor.java (1150 => 1151)

--- trunk/qdox/src/main/java/com/thoughtworks/qdox/model/DefaultJavaConstructor.java	2011-04-06 19:58:08 UTC (rev 1150)
+++ trunk/qdox/src/main/java/com/thoughtworks/qdox/model/DefaultJavaConstructor.java	2011-04-06 20:32:21 UTC (rev 1151)
@@ -3,6 +3,11 @@
 import java.util.Iterator;
 import java.util.List;
 
+/**
+ * 
+ * @author Robert
+ * @since 2.0
+ */
 public class DefaultJavaConstructor
     extends AbstractBaseMethod implements JavaConstructor
 {
@@ -13,6 +18,16 @@
         return 0;
     }
 
+    public boolean signatureMatches( List<Type> parameterTypes )
+    {
+        return signatureMatches( parameterTypes, false );
+    }
+    
+    public boolean signatureMatches( List<Type> parameterTypes, boolean varArgs )
+    {
+        return super.signatureMatches( parameterTypes, varArgs );
+    }
+    
     public String getCodeBlock()
     {
         return getModelWriter().writeConstructor( this ).toString();

Modified: trunk/qdox/src/main/java/com/thoughtworks/qdox/model/DefaultJavaMethod.java (1150 => 1151)

--- trunk/qdox/src/main/java/com/thoughtworks/qdox/model/DefaultJavaMethod.java	2011-04-06 19:58:08 UTC (rev 1150)
+++ trunk/qdox/src/main/java/com/thoughtworks/qdox/model/DefaultJavaMethod.java	2011-04-06 20:32:21 UTC (rev 1151)
@@ -362,4 +362,19 @@
     {
         return returns;
     }
+    
+    public boolean signatureMatches( String name, List<Type> parameterTypes )
+    {
+        return signatureMatches( name, parameterTypes, false );
+    }
+    
+    public boolean signatureMatches( String name, List<Type> parameterTypes, boolean varArg )
+    {
+        if (!name.equals(this.getName())) 
+        {
+            return false;    
+        } 
+        return signatureMatches( parameterTypes, varArg );
+    }
+    
 }

Modified: trunk/qdox/src/main/java/com/thoughtworks/qdox/model/JavaClass.java (1150 => 1151)

--- trunk/qdox/src/main/java/com/thoughtworks/qdox/model/JavaClass.java	2011-04-06 19:58:08 UTC (rev 1150)
+++ trunk/qdox/src/main/java/com/thoughtworks/qdox/model/JavaClass.java	2011-04-06 20:32:21 UTC (rev 1151)
@@ -100,10 +100,29 @@
     
     /**
      * 
-     * @return the list of constrcutors
+     * @return the list of constructors
      * @since 2.0
      */
     public List<JavaConstructor> getConstructors();
+    
+    
+    /**
+     * 
+     * @param parameterTypes
+     * @return the constructor matching the parameterTypes, otherwise <code>null</code>
+     * @since 2.0
+     */
+    public JavaConstructor getConstructor(List<Type> parameterTypes);
+    
+    /**
+     * 
+     * @param parameterTypes
+     * @param varArg
+     * @return the constructor matching the parameterTypes and the varArg, otherwise <code>null</code>
+     * @since 2.0
+     */
+    public JavaConstructor getConstructor(List<Type> parameterTypes, boolean varArg);
+    
 
     /**
      * @since 1.3

Modified: trunk/qdox/src/main/java/com/thoughtworks/qdox/model/JavaConstructor.java (1150 => 1151)

--- trunk/qdox/src/main/java/com/thoughtworks/qdox/model/JavaConstructor.java	2011-04-06 19:58:08 UTC (rev 1150)
+++ trunk/qdox/src/main/java/com/thoughtworks/qdox/model/JavaConstructor.java	2011-04-06 20:32:21 UTC (rev 1151)
@@ -2,6 +2,11 @@
 
 import java.util.List;
 
+/**
+ * 
+ * @author Robert
+ * @since 2.0
+ */
 public interface JavaConstructor
     extends JavaAnnotatedElement, JavaGenericDeclaration, JavaMember
 {
@@ -20,4 +25,8 @@
 
     public boolean isVarArgs();
 
+    public boolean signatureMatches( List<Type> parameterTypes );
+
+    public boolean signatureMatches( List<Type> parameterTypes, boolean varArgs );
+
 }

Modified: trunk/qdox/src/main/java/com/thoughtworks/qdox/model/JavaMethod.java (1150 => 1151)

--- trunk/qdox/src/main/java/com/thoughtworks/qdox/model/JavaMethod.java	2011-04-06 19:58:08 UTC (rev 1150)
+++ trunk/qdox/src/main/java/com/thoughtworks/qdox/model/JavaMethod.java	2011-04-06 20:32:21 UTC (rev 1151)
@@ -64,18 +64,18 @@
     public boolean equals( Object obj );
 
     /**
-     * This method is NOT varArg aware. The overloaded method is.
+     * This method is NOT varArg aware.
      * 
      * @param name
      * @param parameterTypes
      * @return
-     * @deprecated use overloaded method 
      */
     public boolean signatureMatches( String name, List<Type> parameterTypes );
 
     /**
      * @param name method name
      * @param parameterTypes parameter types or null if there are no parameters.
+     * @param varArg <code>true</code> is signature should match a varArg-method, otherwise <code>false</code>
      * @return true if the signature and parameters match.
      */
     public boolean signatureMatches( String name, List<Type> parameterTypes, boolean varArg );


To unsubscribe from this list please visit:

http://xircles.codehaus.org/manage_email

Reply via email to