Title: [1489] trunk/qdox/src: Refactoring gwt-maven-plugin with qdox-2.0-alpha-1 exposed an issue with MGWT-186.

Diff

Modified: trunk/qdox/src/main/java/com/thoughtworks/qdox/model/impl/AbstractBaseMethod.java (1488 => 1489)


--- trunk/qdox/src/main/java/com/thoughtworks/qdox/model/impl/AbstractBaseMethod.java	2012-01-06 18:46:40 UTC (rev 1488)
+++ trunk/qdox/src/main/java/com/thoughtworks/qdox/model/impl/AbstractBaseMethod.java	2012-03-08 22:25:41 UTC (rev 1489)
@@ -126,15 +126,18 @@
         return getParameterTypes( false );
     }
 
+    /** {@inheritDoc} */
     public List<JavaType> getParameterTypes( boolean resolve )
     {
         List<JavaType> result = new LinkedList<JavaType>();
-        for (JavaParameter parameter : this.getParameters()) {
+        for ( JavaParameter parameter : this.getParameters() )
+        {
             result.add( parameter.getType() );
         }
         return result;
     }
 
+    /** {@inheritDoc} */
     public String getSourceCode()
     {
     	return sourceCode;

Modified: trunk/qdox/src/main/java/com/thoughtworks/qdox/model/impl/DefaultJavaType.java (1488 => 1489)


--- trunk/qdox/src/main/java/com/thoughtworks/qdox/model/impl/DefaultJavaType.java	2012-01-06 18:46:40 UTC (rev 1488)
+++ trunk/qdox/src/main/java/com/thoughtworks/qdox/model/impl/DefaultJavaType.java	2012-03-08 22:25:41 UTC (rev 1489)
@@ -391,8 +391,19 @@
     protected static JavaType resolve( JavaType base, JavaClass declaringClass, JavaClass callingClass )
     {
         JavaType result = base;
+        
+        String concreteClassName;
+        if ( base instanceof JavaClass )
+        {
+            JavaClass baseClass = (JavaClass) base;
+            concreteClassName = ( baseClass.isArray() ?  baseClass.getComponentType().getFullyQualifiedName() : baseClass.getFullyQualifiedName() );
+        }
+        else
+        {
+            concreteClassName = base.getFullyQualifiedName();
+        }
 
-        int typeIndex = getTypeVariableIndex( declaringClass, base.getFullyQualifiedName() );
+        int typeIndex = getTypeVariableIndex( declaringClass, concreteClassName );
 
         if ( typeIndex >= 0 )
         {
@@ -408,7 +419,9 @@
                 {
                     if ( fqn.equals( implement.getFullyQualifiedName() ) )
                     {
-                        result = resolve( getActualTypeArguments( implement ).get( typeIndex ), implement, implement );
+                        JavaType actualType = getActualTypeArguments( implement ).get( typeIndex );
+                        JavaType resolvedType = new DefaultJavaType( actualType.getFullyQualifiedName(), actualType.getValue(), getDimensions( base ), implement.getParent() ); 
+                        result = resolve( resolvedType , implement, implement );
                         break;
                     }
                 }
@@ -419,8 +432,13 @@
         List<JavaType> actualTypeArguments = getActualTypeArguments(base); 
         if ( !actualTypeArguments.isEmpty() )
         {
+            String value = base.getValue();
+            if( value.indexOf( '[' ) > 0 )
+            {
+                value = value.substring( 0, value.indexOf( '[' ) );
+            }
             DefaultJavaParameterizedType typeResult =
-                new DefaultJavaParameterizedType( base.getFullyQualifiedName(), base.getValue(), getDimensions( base ),
+                new DefaultJavaParameterizedType( concreteClassName, value, getDimensions( base ),
                           ((DefaultJavaType)base).getJavaClassParent() );
 
             List<JavaType> actualTypes = new LinkedList<JavaType>();

Modified: trunk/qdox/src/main/java/com/thoughtworks/qdox/model/impl/JavaMethodDelegate.java (1488 => 1489)


--- trunk/qdox/src/main/java/com/thoughtworks/qdox/model/impl/JavaMethodDelegate.java	2012-01-06 18:46:40 UTC (rev 1488)
+++ trunk/qdox/src/main/java/com/thoughtworks/qdox/model/impl/JavaMethodDelegate.java	2012-03-08 22:25:41 UTC (rev 1489)
@@ -67,21 +67,23 @@
         return result;
     }
 
+    /** {@inheritDoc} */
     public List<JavaType> getParameterTypes( boolean resolve )
     {
         List<JavaType> result = new LinkedList<JavaType>();
-        for (JavaType type: originalMethod.getParameterTypes( resolve ) )
+        for ( JavaType type : originalMethod.getParameterTypes( resolve ) )
         {
             JavaType curType = DefaultJavaType.resolve( type, originalMethod.getParentClass(), callingClass );
-            //According to java-specs, if it could be resolved the upper boundary, so Object, should be returned  
+            // According to java-specs, if it could be resolved the upper boundary, so Object, should be returned
             if ( !resolve && !type.getFullyQualifiedName().equals( curType.getFullyQualifiedName() ) )
             {
-                result.add(new DefaultJavaType( "java.lang.Object", 0, callingClass ));
+                result.add( new DefaultJavaType( "java.lang.Object", 0, callingClass ) );
             }
-            else {
-                result.add(curType);
+            else
+            {
+                result.add( curType );
             }
-            
+
         }
         return result;
     }

Modified: trunk/qdox/src/test/java/com/thoughtworks/qdox/GenericsTest.java (1488 => 1489)


--- trunk/qdox/src/test/java/com/thoughtworks/qdox/GenericsTest.java	2012-01-06 18:46:40 UTC (rev 1488)
+++ trunk/qdox/src/test/java/com/thoughtworks/qdox/GenericsTest.java	2012-03-08 22:25:41 UTC (rev 1489)
@@ -1,12 +1,16 @@
 package com.thoughtworks.qdox;
 
+import static org.mockito.Mockito.*;
+
 import java.io.StringReader;
+import java.util.Collections;
 
 import junit.framework.TestCase;
 
 import com.thoughtworks.qdox.model.JavaClass;
 import com.thoughtworks.qdox.model.JavaField;
 import com.thoughtworks.qdox.model.JavaMethod;
+import com.thoughtworks.qdox.model.JavaType;
 
 /**
  * @author <a href="" Walnes</a>
@@ -279,6 +283,7 @@
         assertEquals( "java.lang.String", method.getReturnType( true ).getFullyQualifiedName() );
     }
     
+    //GWT-186
     public void testMethodReturnTypeImplements() throws Exception {
         String source1="public interface GenericDao<TEntity, TKey> {\n" + 
         		"public List<TEntity> getAll();\n" + 
@@ -319,6 +324,12 @@
         method = builder.getClassByName( "SubjectService" ).getMethodBySignature( "asMap", null, true );
         assertEquals( "Map<java.lang.Long,Subject>", method.getReturnType( true ).getGenericFullyQualifiedName() );
         assertEquals( "Map<Long,Subject>", method.getReturnType( true ).getGenericValue() );
+        
+        JavaType tEntity = mock( JavaType.class );
+        when( tEntity.getFullyQualifiedName() ).thenReturn( "TEntity[]" );
+        method = builder.getClassByName( "SubjectDao" ).getMethodBySignature( "persist", Collections.singletonList( tEntity ), true );
+        assertNotNull( method );
+        assertEquals( "Subject[]", method.getParameterTypes( true ).get( 0 ).getGenericFullyQualifiedName() );
     }
     
     //for QDOX-210

Modified: trunk/qdox/src/test/java/com/thoughtworks/qdox/model/impl/DefaultTypeTest.java (1488 => 1489)


--- trunk/qdox/src/test/java/com/thoughtworks/qdox/model/impl/DefaultTypeTest.java	2012-01-06 18:46:40 UTC (rev 1488)
+++ trunk/qdox/src/test/java/com/thoughtworks/qdox/model/impl/DefaultTypeTest.java	2012-03-08 22:25:41 UTC (rev 1489)
@@ -11,61 +11,62 @@
 import org.junit.Test;
 
 import com.thoughtworks.qdox.library.ClassLibrary;
-import com.thoughtworks.qdox.library.ClassLoaderLibrary;
-import com.thoughtworks.qdox.model.JavaClass;
 import com.thoughtworks.qdox.model.JavaSource;
 import com.thoughtworks.qdox.model.JavaTypeTest;
-import com.thoughtworks.qdox.model.impl.DefaultJavaSource;
-import com.thoughtworks.qdox.model.impl.DefaultJavaType;
 
-
-public class DefaultTypeTest extends JavaTypeTest<DefaultJavaType>
+public class DefaultTypeTest
+    extends JavaTypeTest<DefaultJavaType>
 {
 
     public JavaSource newJavaSource( ClassLibrary library )
     {
-        return new DefaultJavaSource(library);
+        return new DefaultJavaSource( library );
     }
 
     public DefaultJavaType newType( String fullname )
     {
-        return new DefaultJavaType(fullname);
+        return new DefaultJavaType( fullname );
     }
 
     public DefaultJavaType newType( String fullname, int dimensions )
     {
-        return new DefaultJavaType(fullname, dimensions);
+        return new DefaultJavaType( fullname, dimensions );
     }
 
     public DefaultJavaType newType( String fullname, int dimensions, JavaSource source )
     {
-        return new DefaultJavaType(fullname, dimensions, source);
+        return new DefaultJavaType( fullname, dimensions, source );
     }
-    
+
     @Test
-    public void testArrayType() throws Exception {
-        DefaultJavaType type = newType("int", 1);
-        assertTrue(type.isArray());
+    public void testArrayType()
+        throws Exception
+    {
+        DefaultJavaType type = newType( "int", 1 );
+        assertTrue( type.isArray() );
     }
 
     @Test
-    public void testComponentType() throws Exception {
-        assertNull( newType("int").getComponentType());
-        assertEquals("int", newType("int", 1).getComponentType().getFullyQualifiedName());
-        assertEquals("long", newType("long", 3).getComponentType().getFullyQualifiedName());
+    public void testComponentType()
+        throws Exception
+    {
+        assertNull( newType( "int" ).getComponentType() );
+        assertEquals( "int", newType( "int", 1 ).getComponentType().getFullyQualifiedName() );
+        assertEquals( "long", newType( "long", 3 ).getComponentType().getFullyQualifiedName() );
     }
-    
+
     @Test
-    public void testResolving() throws Exception {
-        JavaSource src = ""
-        when(src.getImports()).thenReturn( Collections.singletonList( "foo.*" ) );
-        DefaultJavaType type = DefaultJavaType.createUnresolved("Bar", 0, src);
-        assertEquals(false, type.isResolved());
-        
-        when(src.resolveType( "Bar" )).thenReturn( "foo.Bar" );
-        assertEquals(true, type.isResolved());
-        assertEquals("Bar", type.getValue());
-        assertEquals("foo.Bar", type.getFullyQualifiedName());
+    public void testResolving()
+        throws Exception
+    {
+        JavaSource src = "" JavaSource.class );
+        when( src.getImports() ).thenReturn( Collections.singletonList( "foo.*" ) );
+        DefaultJavaType type = DefaultJavaType.createUnresolved( "Bar", 0, src );
+        assertEquals( false, type.isResolved() );
+
+        when( src.resolveType( "Bar" ) ).thenReturn( "foo.Bar" );
+        assertEquals( true, type.isResolved() );
+        assertEquals( "Bar", type.getValue() );
+        assertEquals( "foo.Bar", type.getFullyQualifiedName() );
     }
-
 }
\ No newline at end of file

To unsubscribe from this list please visit:

http://xircles.codehaus.org/manage_email

Reply via email to