- Revision
- 731
- Author
- rfscholte
- Date
- 2010-05-31 14:16:25 -0500 (Mon, 31 May 2010)
Log Message
Fix for QDOX-210: Resolve Type.actualArgumentTypes with JavaClass.getMethods(true)
Modified Paths
Diff
Modified: trunk/qdox/src/java/com/thoughtworks/qdox/model/JavaClass.java (730 => 731)
--- trunk/qdox/src/java/com/thoughtworks/qdox/model/JavaClass.java 2010-05-03 20:27:45 UTC (rev 730) +++ trunk/qdox/src/java/com/thoughtworks/qdox/model/JavaClass.java 2010-05-31 19:16:25 UTC (rev 731) @@ -329,24 +329,24 @@ } private void addMethodsFromSuperclassAndInterfaces(Set signatures, - List methodList, JavaClass clazz) { - JavaMethod[] methods = clazz.getMethods(); + List methodList, JavaClass callingClazz) { + JavaMethod[] methods = callingClazz.getMethods(); addNewMethods(signatures, methodList, methods); - JavaClass superclass = clazz.getSuperJavaClass(); + JavaClass superclass = callingClazz.getSuperJavaClass(); // TODO workaround for a bug in getSuperJavaClass - if ((superclass != null) && (superclass != clazz)) { - addMethodsFromSuperclassAndInterfaces(signatures, methodList, + if ((superclass != null) && (superclass != callingClazz)) { + callingClazz.addMethodsFromSuperclassAndInterfaces(signatures, methodList, superclass); } - JavaClass[] implementz = clazz.getImplementedInterfaces(); + JavaClass[] implementz = callingClazz.getImplementedInterfaces(); for (int i = 0; i < implementz.length; i++) { if (implementz[i] != null) { - addMethodsFromSuperclassAndInterfaces(signatures, methodList, + callingClazz.addMethodsFromSuperclassAndInterfaces(signatures, methodList, implementz[i]); } } @@ -361,7 +361,7 @@ String signature = method.getDeclarationSignature(false); if (!signatures.contains(signature)) { - methodList.add(method); + methodList.add( new JavaMethodDelegate( this, method ) ); signatures.add(signature); } }
Modified: trunk/qdox/src/java/com/thoughtworks/qdox/model/Type.java (730 => 731)
--- trunk/qdox/src/java/com/thoughtworks/qdox/model/Type.java 2010-05-03 20:27:45 UTC (rev 730) +++ trunk/qdox/src/java/com/thoughtworks/qdox/model/Type.java 2010-05-31 19:16:25 UTC (rev 731) @@ -115,7 +115,8 @@ * @return type representation for code usage */ public String getValue() { - return getFullyQualifiedName().replaceAll( "\\$", "." ); + String fqn = getFullyQualifiedName(); + return ( fqn == null ? "" : fqn.replaceAll( "\\$", "." ) ); } /** @@ -400,10 +401,11 @@ { if ( fqn.equals( subclass.getImplements()[i].getFullyQualifiedName() ) ) { - result = subclass.getImplements()[i].getActualTypeArguments()[typeIndex]; + result = subclass.getImplements()[i].getActualTypeArguments()[typeIndex].resolve( subclass.getImplementedInterfaces()[i] ); break; } } + //no direct interface available, try indirect } }
Modified: trunk/qdox/src/test/com/thoughtworks/qdox/GenericsTest.java (730 => 731)
--- trunk/qdox/src/test/com/thoughtworks/qdox/GenericsTest.java 2010-05-03 20:27:45 UTC (rev 730) +++ trunk/qdox/src/test/com/thoughtworks/qdox/GenericsTest.java 2010-05-31 19:16:25 UTC (rev 731) @@ -319,6 +319,31 @@ assertEquals( "Map<java.lang.Long,Subject>", method.getReturnType( true ).getGenericValue() ); } + //for QDOX-210 + public void testResolveTypeGetMethod() throws Exception { + String source1="import java.util.*;" + + "public interface GenericDao<TEntity, TKey> {\n" + + "public List<TEntity> getAll();\n" + + "public TEntity getRandom();\n" + + "public TEntity findById(TKey key);\n" + + "public TEntity persist(TEntity entity);\n" + + "public TEntity[] persist(TEntity[] entities);\n" + + "public void delete(TEntity entity);\n" + + "public Map<TKey, TEntity> asMap();" + + "}\r\n"; + String source2="public interface SubjectDao extends GenericDao<Subject, Long> {\n" + + "}"; + String source3="public interface SubjectService extends RemoteService, SubjectDao {\r\n" + + "}"; + builder.addSource( new StringReader( source1 ) ); + builder.addSource( new StringReader( source2 ) ); + builder.addSource( new StringReader( source3 ) ); + + JavaMethod method = builder.getClassByName( "SubjectService" ).getMethods( true )[0]; + assertEquals( "getAll", method.getName() ); + assertEquals( "java.util.List<Subject>", method.getReturnType( true ).getGenericValue() ); + } + }
To unsubscribe from this list please visit:
