Title: [1455] trunk/qdox/src/main/java/com/thoughtworks/qdox: Add DefaultJavaParameterizedType

Diff

Modified: trunk/qdox/src/main/java/com/thoughtworks/qdox/builder/TypeAssembler.java (1454 => 1455)


--- trunk/qdox/src/main/java/com/thoughtworks/qdox/builder/TypeAssembler.java	2011-12-27 17:29:56 UTC (rev 1454)
+++ trunk/qdox/src/main/java/com/thoughtworks/qdox/builder/TypeAssembler.java	2011-12-28 11:19:55 UTC (rev 1455)
@@ -1,9 +1,29 @@
 package com.thoughtworks.qdox.builder;
 
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements.  See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership.  The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License.  You may obtain a copy of the License at
+ *
+ *   http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied.  See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+
 import java.util.LinkedList;
 import java.util.List;
 
 import com.thoughtworks.qdox.model.JavaType;
+import com.thoughtworks.qdox.model.impl.DefaultJavaParameterizedType;
 import com.thoughtworks.qdox.model.impl.DefaultJavaWildcardType;
 import com.thoughtworks.qdox.model.impl.JavaClassParent;
 import com.thoughtworks.qdox.model.impl.DefaultJavaType;
@@ -41,7 +61,7 @@
         }
         else
         {
-            DefaultJavaType typeResult = DefaultJavaType.createUnresolved( typeDef.getName(), typeDef.getDimensions() + dimensions, context );
+            DefaultJavaParameterizedType typeResult = new DefaultJavaParameterizedType( null, typeDef.getName(), typeDef.getDimensions() + dimensions, context );
             if ( typeDef.getActualArgumentTypes() != null && !typeDef.getActualArgumentTypes().isEmpty() )
             {
                 List<JavaType> actualArgumentTypes = new LinkedList<JavaType>();

Modified: trunk/qdox/src/main/java/com/thoughtworks/qdox/model/JavaParameterizedType.java (1454 => 1455)


--- trunk/qdox/src/main/java/com/thoughtworks/qdox/model/JavaParameterizedType.java	2011-12-27 17:29:56 UTC (rev 1454)
+++ trunk/qdox/src/main/java/com/thoughtworks/qdox/model/JavaParameterizedType.java	2011-12-28 11:19:55 UTC (rev 1455)
@@ -1,10 +1,33 @@
 package com.thoughtworks.qdox.model;
 
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements.  See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership.  The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License.  You may obtain a copy of the License at
+ *
+ *   http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied.  See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+
 import java.util.List;
 
+/**
+ * Equivalent of {@link java.lang.reflect.ParameterizedType}.
+ * 
+ * @since 2.0
+ * @author Robert Scholte
+ */
 public interface JavaParameterizedType extends JavaType
 {
-
     List<JavaType> getActualTypeArguments();
-
-}
+}
\ No newline at end of file

Added: trunk/qdox/src/main/java/com/thoughtworks/qdox/model/impl/DefaultJavaParameterizedType.java (0 => 1455)


--- trunk/qdox/src/main/java/com/thoughtworks/qdox/model/impl/DefaultJavaParameterizedType.java	                        (rev 0)
+++ trunk/qdox/src/main/java/com/thoughtworks/qdox/model/impl/DefaultJavaParameterizedType.java	2011-12-28 11:19:55 UTC (rev 1455)
@@ -0,0 +1,157 @@
+package com.thoughtworks.qdox.model.impl;
+
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements.  See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership.  The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License.  You may obtain a copy of the License at
+ *
+ *   http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied.  See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+
+import java.util.Collections;
+import java.util.Iterator;
+import java.util.List;
+
+import com.thoughtworks.qdox.model.JavaParameterizedType;
+import com.thoughtworks.qdox.model.JavaType;
+
+public class DefaultJavaParameterizedType extends DefaultJavaType implements JavaParameterizedType
+{
+    private List<JavaType> actualArgumentTypes = Collections.emptyList();
+
+    
+    public DefaultJavaParameterizedType( String fullName, int dimensions, JavaClassParent context )
+    {
+        super( fullName, dimensions, context );
+    }
+
+    public DefaultJavaParameterizedType( String fullName, int dimensions )
+    {
+        super( fullName, dimensions );
+    }
+
+    public DefaultJavaParameterizedType( String name, JavaClassParent context )
+    {
+        super( name, context );
+    }
+
+    public DefaultJavaParameterizedType( String fullName, String name, int dimensions, JavaClassParent context )
+    {
+        super( fullName, name, dimensions, context );
+    }
+
+    public DefaultJavaParameterizedType( String fullName )
+    {
+        super( fullName );
+    }
+
+    /**
+     * 
+     * @return the actualTypeArguments or null
+     */
+    public List<JavaType> getActualTypeArguments()
+    {
+        return actualArgumentTypes;
+    }
+    
+    public void setActualArgumentTypes( List<JavaType> actualArgumentTypes )
+    {
+        this.actualArgumentTypes = actualArgumentTypes;
+    }
+    
+    /**
+     * The FQN representation of an Object for code usage
+     * This implementation ignores generics
+     *
+     * Some examples how Objects will be translated
+     * <pre>
+     * Object > java.lang.object
+     * java.util.List<T> > java.util.List
+     * ? > ?
+     * T > T
+     * anypackage.Outer.Inner > anypackage.Outer.Inner
+     * </pre>
+
+     * @since 1.8
+     * @return generic type representation for code usage 
+     */
+    public String getGenericValue()
+    {
+        StringBuffer result = new StringBuffer( getValue() );
+        if ( !actualArgumentTypes.isEmpty() )
+        {
+            result.append( "<" );
+            for ( Iterator<JavaType> iter = actualArgumentTypes.iterator(); iter.hasNext(); )
+            {
+                result.append( iter.next().getGenericValue() );
+                if ( iter.hasNext() )
+                {
+                    result.append( "," );
+                }
+            }
+            result.append( ">" );
+        }
+        for ( int i = 0; i < getDimensions(); i++ )
+        {
+            result.append( "[]" );
+        }
+        return result.toString();
+    }
+    
+    public String getGenericCanonicalName()
+    {
+        StringBuffer result = new StringBuffer( getCanonicalName() );
+        if ( !actualArgumentTypes.isEmpty() )
+        {
+            result.append( "<" );
+            for ( Iterator<JavaType> iter = actualArgumentTypes.iterator(); iter.hasNext(); )
+            {
+                result.append( iter.next().getCanonicalName() );
+                if ( iter.hasNext() )
+                {
+                    result.append( "," );
+                }
+            }
+            result.append( ">" );
+        }
+        for ( int i = 0; i < getDimensions(); i++ )
+        {
+            result.append( "[]" );
+        }
+        return result.toString();
+    }
+
+    public String getGenericFullyQualifiedName()
+    {
+        StringBuffer result = new StringBuffer( isResolved() ? fullName : name );
+        if ( !actualArgumentTypes.isEmpty() )
+        {
+            result.append( "<" );
+            for ( Iterator<JavaType> iter = actualArgumentTypes.iterator(); iter.hasNext(); )
+            {
+                result.append( iter.next().getGenericFullyQualifiedName() );
+                if ( iter.hasNext() )
+                {
+                    result.append( "," );
+                }
+            }
+            result.append( ">" );
+        }
+        for ( int i = 0; i < getDimensions(); i++ )
+        {
+            result.append( "[]" );
+        }
+        return result.toString();   
+    }
+}
\ No newline at end of file

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


--- trunk/qdox/src/main/java/com/thoughtworks/qdox/model/impl/DefaultJavaType.java	2011-12-27 17:29:56 UTC (rev 1454)
+++ trunk/qdox/src/main/java/com/thoughtworks/qdox/model/impl/DefaultJavaType.java	2011-12-28 11:19:55 UTC (rev 1455)
@@ -40,15 +40,14 @@
 import com.thoughtworks.qdox.model.JavaType;
 import com.thoughtworks.qdox.model.JavaTypeVariable;
 
-public class DefaultJavaType implements JavaClass, JavaType, JavaParameterizedType, Serializable {
+public class DefaultJavaType implements JavaClass, JavaType, Serializable {
 
     public static final DefaultJavaType VOID = new DefaultJavaType("void");
 
-    private String name;
+    protected final String name;
     private JavaClassParent context;
-    private String fullName;
+    protected String fullName;
     private int dimensions;
-    private List<JavaType> actualArgumentTypes = Collections.emptyList();
     
     public DefaultJavaType( String name, JavaClassParent context )
     {
@@ -129,19 +128,6 @@
     public String getGenericValue()
     {
         StringBuffer result = new StringBuffer( getValue() );
-        if ( !actualArgumentTypes.isEmpty() )
-        {
-            result.append( "<" );
-            for ( Iterator<JavaType> iter = actualArgumentTypes.iterator(); iter.hasNext(); )
-            {
-                result.append( iter.next().getGenericValue() );
-                if ( iter.hasNext() )
-                {
-                    result.append( "," );
-                }
-            }
-            result.append( ">" );
-        }
         for ( int i = 0; i < dimensions; i++ )
         {
             result.append( "[]" );
@@ -234,20 +220,6 @@
     }
 
     /**
-     * 
-     * @return the actualTypeArguments or null
-     */
-    public List<JavaType> getActualTypeArguments()
-    {
-        return actualArgumentTypes;
-    }
-    
-    public void setActualArgumentTypes( List<JavaType> actualArgumentTypes )
-    {
-        this.actualArgumentTypes = actualArgumentTypes;
-    }
-    
-    /**
      * Equivalent of {@link Class#toString()}. 
      * Converts the object to a string.
      * 
@@ -447,8 +419,8 @@
         List<JavaType> actualTypeArguments = getActualTypeArguments(base); 
         if ( !actualTypeArguments.isEmpty() )
         {
-            DefaultJavaType typeResult =
-                new DefaultJavaType( base.getFullyQualifiedName(), base.getValue(), getDimensions( base ),
+            DefaultJavaParameterizedType typeResult =
+                new DefaultJavaParameterizedType( base.getFullyQualifiedName(), base.getValue(), getDimensions( base ),
                           ((DefaultJavaType)base).getJavaClassParent() );
 
             List<JavaType> actualTypes = new LinkedList<JavaType>();
@@ -490,19 +462,6 @@
     public String getGenericFullyQualifiedName()
     {
         StringBuffer result = new StringBuffer( isResolved() ? fullName : name );
-        if ( !actualArgumentTypes.isEmpty() )
-        {
-            result.append( "<" );
-            for ( Iterator<JavaType> iter = actualArgumentTypes.iterator(); iter.hasNext(); )
-            {
-                result.append( iter.next().getGenericFullyQualifiedName() );
-                if ( iter.hasNext() )
-                {
-                    result.append( "," );
-                }
-            }
-            result.append( ">" );
-        }
         for ( int i = 0; i < dimensions; i++ )
         {
             result.append( "[]" );
@@ -514,19 +473,6 @@
     public String getGenericCanonicalName()
     {
         StringBuffer result = new StringBuffer( getCanonicalName() );
-        if ( !actualArgumentTypes.isEmpty() )
-        {
-            result.append( "<" );
-            for ( Iterator<JavaType> iter = actualArgumentTypes.iterator(); iter.hasNext(); )
-            {
-                result.append( iter.next().getCanonicalName() );
-                if ( iter.hasNext() )
-                {
-                    result.append( "," );
-                }
-            }
-            result.append( ">" );
-        }
         for ( int i = 0; i < dimensions; i++ )
         {
             result.append( "[]" );

To unsubscribe from this list please visit:

http://xircles.codehaus.org/manage_email

Reply via email to