Title: [1302] trunk/qdox/src/main/java/com/thoughtworks/qdox/model: Improve usage of generics for TypeVariable, though still not ready

Diff

Modified: trunk/qdox/src/main/java/com/thoughtworks/qdox/builder/ModelBuilder.java (1301 => 1302)

--- trunk/qdox/src/main/java/com/thoughtworks/qdox/builder/ModelBuilder.java	2011-08-21 10:34:20 UTC (rev 1301)
+++ trunk/qdox/src/main/java/com/thoughtworks/qdox/builder/ModelBuilder.java	2011-08-21 12:15:25 UTC (rev 1302)
@@ -37,8 +37,6 @@
 import com.thoughtworks.qdox.model.DefaultJavaSource;
 import com.thoughtworks.qdox.model.DocletTag;
 import com.thoughtworks.qdox.model.DocletTagFactory;
-import com.thoughtworks.qdox.model.JavaClass;
-import com.thoughtworks.qdox.model.JavaClassParent;
 import com.thoughtworks.qdox.model.JavaGenericDeclaration;
 import com.thoughtworks.qdox.model.JavaParameter;
 import com.thoughtworks.qdox.model.JavaSource;
@@ -302,13 +300,13 @@
         currentMethod.setSourceCode(def.getBody());
     }
 
-    private TypeVariable<?> createTypeVariable( TypeVariableDef typeVariableDef, JavaGenericDeclaration genericDeclaration )
+    private <G extends JavaGenericDeclaration> TypeVariable<G> createTypeVariable( TypeVariableDef typeVariableDef, G genericDeclaration)
     {
         if ( typeVariableDef == null )
         {
             return null;
         }
-        TypeVariable<?> result = new TypeVariable( null, typeVariableDef.getName(), genericDeclaration );
+        TypeVariable<G> result = new TypeVariable<G>( null, typeVariableDef.getName(), genericDeclaration );
 
         if ( typeVariableDef.getBounds() != null && !typeVariableDef.getBounds().isEmpty() )
         {

Modified: trunk/qdox/src/main/java/com/thoughtworks/qdox/model/JavaGenericDeclaration.java (1301 => 1302)

--- trunk/qdox/src/main/java/com/thoughtworks/qdox/model/JavaGenericDeclaration.java	2011-08-21 10:34:20 UTC (rev 1301)
+++ trunk/qdox/src/main/java/com/thoughtworks/qdox/model/JavaGenericDeclaration.java	2011-08-21 12:15:25 UTC (rev 1302)
@@ -36,6 +36,4 @@
      * @return a list of typeParameters, never <code>null</code> 
      */
     List<TypeVariable<?>> getTypeParameters();
-    
-    JavaClass getDeclaringClass();
 }

Modified: trunk/qdox/src/main/java/com/thoughtworks/qdox/model/Type.java (1301 => 1302)

--- trunk/qdox/src/main/java/com/thoughtworks/qdox/model/Type.java	2011-08-21 10:34:20 UTC (rev 1301)
+++ trunk/qdox/src/main/java/com/thoughtworks/qdox/model/Type.java	2011-08-21 12:15:25 UTC (rev 1302)
@@ -819,11 +819,6 @@
         return resolveRealClass().getDerivedClasses();
     }
     
-    public JavaClass getDeclaringClass()
-    {
-        return resolveRealClass().getDeclaringClass();
-    }
-
     public List<DocletTag> getTagsByName( String name, boolean superclasses )
     {
         return resolveRealClass().getTagsByName( name, superclasses );

Modified: trunk/qdox/src/main/java/com/thoughtworks/qdox/model/TypeVariable.java (1301 => 1302)

--- trunk/qdox/src/main/java/com/thoughtworks/qdox/model/TypeVariable.java	2011-08-21 10:34:20 UTC (rev 1301)
+++ trunk/qdox/src/main/java/com/thoughtworks/qdox/model/TypeVariable.java	2011-08-21 12:15:25 UTC (rev 1302)
@@ -36,10 +36,32 @@
 
     public TypeVariable( String fullName, String name, D genericDeclaration )
     {
-        super( fullName, name, 0, genericDeclaration.getDeclaringClass() );
+        super( fullName, name, 0, getContext( genericDeclaration ) );
         this.genericDeclaration = genericDeclaration;
     }
 
+    private static JavaClass getContext( JavaGenericDeclaration genericDeclaration )
+    {
+        JavaClass result;
+        if ( genericDeclaration instanceof JavaClass )
+        {
+            result = (JavaClass) genericDeclaration;
+        }
+        else if ( genericDeclaration instanceof JavaMethod )
+        {
+            result = ( (JavaMethod) genericDeclaration ).getDeclaringClass();
+        }
+        else if ( genericDeclaration instanceof JavaConstructor )
+        {
+            result = ( (JavaConstructor) genericDeclaration ).getDeclaringClass();
+        }
+        else
+        {
+            throw new IllegalArgumentException( "Unknown GenericDeclatation implementation" );
+        }
+        return result;
+    }
+
     /**
      * @return the bounds
      */


To unsubscribe from this list please visit:

http://xircles.codehaus.org/manage_email

Reply via email to