Title: [586] trunk/qdox/src/test/com/thoughtworks/qdox: fixed and improved JavaMethod.toString()

Diff

Modified: trunk/qdox/src/java/com/thoughtworks/qdox/model/JavaMethod.java (585 => 586)

--- trunk/qdox/src/java/com/thoughtworks/qdox/model/JavaMethod.java	2009-03-19 21:46:58 UTC (rev 585)
+++ trunk/qdox/src/java/com/thoughtworks/qdox/model/JavaMethod.java	2009-03-20 22:04:41 UTC (rev 586)
@@ -358,17 +358,10 @@
 		result.append(getName());
 		result.append("(");
 		for(int paramIndex=0;paramIndex<getParameters().length;paramIndex++) {
-			if(paramIndex>1) {
+			if(paramIndex>0) {
 				result.append(",");
 			}
-			String typeValue = getParameters()[paramIndex].getType().getValue();
-			for(int typeIndex=0;typeIndex<typeParameters.length; typeIndex++) {
-				if(typeParameters[typeIndex].getName().equals(getParameters()[paramIndex].getType().getValue())) {
-					typeValue = typeParameters[typeIndex].getValue() + " "+ getParameters()[paramIndex].getName();
-					
-					break;
-				}
-			}
+			String typeValue = getParameters()[paramIndex].getType().getResolvedValue(getTypeParameters());
 			result.append(typeValue);
 		}
 		result.append(")");

Modified: trunk/qdox/src/java/com/thoughtworks/qdox/model/JavaParameter.java (585 => 586)

--- trunk/qdox/src/java/com/thoughtworks/qdox/model/JavaParameter.java	2009-03-19 21:46:58 UTC (rev 585)
+++ trunk/qdox/src/java/com/thoughtworks/qdox/model/JavaParameter.java	2009-03-20 22:04:41 UTC (rev 586)
@@ -66,23 +66,12 @@
      * @since 1.10
      */
     public String getResolvedValue() {
-    	return getResolvedType().getValue();
+		return type.getResolvedValue(getParentMethod().getTypeParameters());
     }
 
 	public String getResolvedGenericValue() {
-		return getResolvedType().getGenericValue();
+		return type.getResolvedGenericValue(getParentMethod().getTypeParameters());
 	}
 	
-	private Type getResolvedType() {
-		Type result = type;
-		if(getParentMethod().getTypeParameters() != null) {
-			for(int typeIndex=0;typeIndex<getParentMethod().getTypeParameters().length; typeIndex++) {
-				if(getParentMethod().getTypeParameters()[typeIndex].getName().equals(type.getValue())) {
-					result = getParentMethod().getTypeParameters()[typeIndex];
-				}
-			}
-    	}
-		return result;
-	}
 
 }

Modified: trunk/qdox/src/java/com/thoughtworks/qdox/model/Type.java (585 => 586)

--- trunk/qdox/src/java/com/thoughtworks/qdox/model/Type.java	2009-03-19 21:46:58 UTC (rev 585)
+++ trunk/qdox/src/java/com/thoughtworks/qdox/model/Type.java	2009-03-20 22:04:41 UTC (rev 586)
@@ -90,6 +90,41 @@
     	}
         return result.toString();
     }
+    
+    protected String getGenericValue(TypeVariable[] typeVariableList) {
+    	StringBuffer result = new StringBuffer(getResolvedValue(typeVariableList));
+    	if(actualArgumentTypes != null && actualArgumentTypes.length > 0) {
+    		for(int index = 0;index < actualArgumentTypes.length; index++) {
+    			result.append(actualArgumentTypes[index].getResolvedGenericValue(typeVariableList));
+    			if(index + 1 != actualArgumentTypes.length) {
+    				result.append(",");
+    			}
+    		}
+    	}
+        return result.toString();
+    }
+    
+    protected String getResolvedValue(TypeVariable[] typeParameters) {
+    	String result = getValue();
+    	for(int typeIndex=0;typeIndex<typeParameters.length; typeIndex++) {
+			if(typeParameters[typeIndex].getName().equals(getValue())) {
+				result = typeParameters[typeIndex].getValue();
+				break;
+			}
+		}
+    	return result;
+    }
+    
+    protected String getResolvedGenericValue(TypeVariable[] typeParameters) {
+    	String result = getGenericValue(typeParameters);
+    	for(int typeIndex=0;typeIndex<typeParameters.length; typeIndex++) {
+			if(typeParameters[typeIndex].getName().equals(getValue())) {
+				result = typeParameters[typeIndex].getGenericValue();
+				break;
+			}
+		}
+    	return result;
+    }
 
     public boolean isResolved() {
         if (fullName == null && context != null) {

Modified: trunk/qdox/src/test/com/thoughtworks/qdox/JSR14Test.java (585 => 586)

--- trunk/qdox/src/test/com/thoughtworks/qdox/JSR14Test.java	2009-03-19 21:46:58 UTC (rev 585)
+++ trunk/qdox/src/test/com/thoughtworks/qdox/JSR14Test.java	2009-03-20 22:04:41 UTC (rev 586)
@@ -324,7 +324,7 @@
     // second assert is based on java's Method.toString()
     // http://java.sun.com/j2se/1.5.0/docs/api/java/lang/reflect/Method.html#toString()
     // 3rd and 4th are resolved Types, based on <T extends StringBuffer> in method
-    public void testGenericMethodDeclaration() throws Exception {
+    public void testGenericMethodDeclarationSingleParameter() throws Exception {
     	String source = "package com.thoughtworks.qdox;" +
     			"import java.util.*;\n" +
     			"public class TestQDOX150 {\n" +
@@ -338,11 +338,31 @@
     	JavaParameter paramType = javaMethod.getParameters()[0];
     	Type returnType = javaMethod.getReturns();
     	assertEquals("myMethod(request)", javaMethod.getCallSignature());
-    	assertEquals("public java.util.List com.thoughtworks.qdox.TestQDOX150.myMethod(java.lang.StringBuffer request) throws java.lang.Exception", javaMethod.toString());
+    	assertEquals("public java.util.List com.thoughtworks.qdox.TestQDOX150.myMethod(java.lang.StringBuffer) throws java.lang.Exception", javaMethod.toString());
     	assertEquals("java.lang.StringBuffer", paramType.getResolvedValue());
     	assertEquals("<T extends java.lang.StringBuffer>", paramType.getResolvedGenericValue());
     	assertEquals("java.util.List", returnType.getValue());
     	assertEquals("java.util.List<java.lang.StringBuffer>", returnType.getGenericValue());
-    	
     }
+    
+    public void testGenericMethodDeclarationMultipleParameters() throws Exception {
+    	String source = "package com.thoughtworks.qdox;" +
+    			"import java.util.*;\n" +
+    			"public class TestQDOX150 {\n" +
+    			" public <T extends StringBuffer> List<StringBuffer> myMethod( T request, List<T> list ) throws Exception {\n" +
+    			"  return null;\n" +
+    			" }\n" +
+    			"}\n";
+    	JavaSource javaSource = builder.addSource(new StringReader(source));
+    	JavaClass javaClass = javaSource.getClasses()[0];
+    	JavaMethod javaMethod = javaClass.getMethods()[0];
+    	JavaParameter paramType = javaMethod.getParameters()[1];
+    	assertEquals("myMethod(request, list)", javaMethod.getCallSignature());
+    	assertEquals("public java.util.List com.thoughtworks.qdox.TestQDOX150.myMethod(java.lang.StringBuffer,java.util.List) throws java.lang.Exception", javaMethod.toString());
+    	assertEquals("java.util.List", paramType.getResolvedValue());
+    	assertEquals("java.util.List<T extends java.lang.StringBuffer>", paramType.getResolvedGenericValue());
+    }
+
+    
+    
 }

Modified: trunk/qdox/src/test/com/thoughtworks/qdox/model/JavaMethodTest.java (585 => 586)

--- trunk/qdox/src/test/com/thoughtworks/qdox/model/JavaMethodTest.java	2009-03-19 21:46:58 UTC (rev 585)
+++ trunk/qdox/src/test/com/thoughtworks/qdox/model/JavaMethodTest.java	2009-03-20 22:04:41 UTC (rev 586)
@@ -358,6 +358,4 @@
     private void assertNotEquals(Object o1, Object o2) {
         assertTrue(o1.toString() + " should not equals " + o2.toString(), !o1.equals(o2));
     }
-    
-
 }


To unsubscribe from this list please visit:

http://xircles.codehaus.org/manage_email

Reply via email to