Title: [678] trunk/qdox/src/test/com/thoughtworks/qdox/model: Fix for QDOX-182: Type.toString() for inner classes
Revision
678
Author
rfscholte
Date
2009-11-15 07:08:32 -0600 (Sun, 15 Nov 2009)

Log Message

Fix for QDOX-182: Type.toString() for inner classes
added documentation

Modified Paths

Diff

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

--- trunk/qdox/src/java/com/thoughtworks/qdox/model/Type.java	2009-10-23 23:19:23 UTC (rev 677)
+++ trunk/qdox/src/java/com/thoughtworks/qdox/model/Type.java	2009-11-15 13:08:32 UTC (rev 678)
@@ -78,16 +78,61 @@
         return getFullyQualifiedName();
     }
 
+    /**
+     * Returns the FQN of an Object or the handler of a Type
+     * If the name of the can't be resolved based on the imports and the classes on the classpath the name will be returned
+     * InnerClasses will use the $ sign
+     * 
+     * Some examples how names will be translated 
+     * <pre>
+     * Object > java.lang.Object
+     * java.util.List > java.util.List
+     * ?  > ?
+     * T  > T
+     * anypackage.Outer.Inner > anypackage.Outer$Inner
+     * </pre>
+     * 
+     * @return
+     */
     public String getFullyQualifiedName() {
+        
         return isResolved() ? fullName : name;
     }
 
+    /**
+     * 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>
+     * 
+     * @return type representation for code usage
+     */
     public String getValue() {
         return getFullyQualifiedName().replaceAll( "\\$", "." );
     }
     
     /**
+     * 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());
@@ -139,6 +184,11 @@
     	return result;
     }
 
+    /**
+     * Checks if the FQN of this Type is resolved 
+     * 
+     * @return 
+     */
     public boolean isResolved() {
         if (fullName == null && context != null) {
             fullName = context.resolveType(name);
@@ -156,22 +206,49 @@
         return getValue().compareTo(((Type) o).getValue());
     }
 
+    /**
+     * Returns true if this Type is an array
+     * 
+     * @return
+     */
     public boolean isArray() {
         return dimensions > 0;
     }
 
+    /**
+     * Returns the depth of this array, 0 if it's not an array
+     * 
+     * @return The depth of this array
+     */
     public int getDimensions() {
         return dimensions;
     }
 
+    /**
+     * Returns getValue() extended with the array information 
+     * 
+     * @return
+     */
     public String toString() {
-        if (dimensions == 0) return getFullyQualifiedName();
-        StringBuffer buff = new StringBuffer(getFullyQualifiedName());
+        if (dimensions == 0) return getValue();
+        StringBuffer buff = new StringBuffer(getValue());
         for (int i = 0; i < dimensions; i++) buff.append("[]");
         String result = buff.toString();
         return result;
     }
 
+    /**
+     * Returns getGenericValue() extended with the array information
+     * 
+     * <pre>
+     * Object > java.lang.Object
+     * Object[] > java.lang.Object[]
+     * List<Object> > java.lang.List<java.lang.Object>
+     * Outer.Inner > Outer.Inner 
+     * Outer.Inner<Object>[][] > Outer.Inner<java.lang.Object>[][] 
+     * </pre>
+     * @return 
+     */
     public String toGenericString() {
         if (dimensions == 0) return getGenericValue();
         StringBuffer buff = new StringBuffer(getGenericValue());

Modified: trunk/qdox/src/test/com/thoughtworks/qdox/model/TypeTest.java (677 => 678)

--- trunk/qdox/src/test/com/thoughtworks/qdox/model/TypeTest.java	2009-10-23 23:19:23 UTC (rev 677)
+++ trunk/qdox/src/test/com/thoughtworks/qdox/model/TypeTest.java	2009-11-15 13:08:32 UTC (rev 678)
@@ -1,5 +1,7 @@
 package com.thoughtworks.qdox.model;
 
+import java.io.StringReader;
+
 import junit.framework.TestCase;
 
 import com.thoughtworks.qdox.JavaClassContext;
@@ -63,11 +65,22 @@
         assertEquals(true, javaClass.getMethodBySignature("notify", null).getReturns().isPrimitive());
 
     } 
+    
+    public void testInnerClassToString() {
+        ClassLibrary classLibrary = new ClassLibrary( ClassLoader.getSystemClassLoader() );
 
+        String source = "public class Outer {\n" +
+            " private Inner ia;" +
+            " public class Inner { }" +
+            "}";
+        JavaDocBuilder builder = new JavaDocBuilder(classLibrary);
+        builder.addSource( new StringReader( source )  );
+        assertEquals("Outer.Inner", builder.getClassByName( "Outer" ).getFieldByName( "ia" ).getType().toString());
+        assertEquals("Outer.Inner", builder.getClassByName( "Outer" ).getFieldByName( "ia" ).getType().toGenericString());
+    }
+    
     private void assertNotEquals(Object o1, Object o2) {
         assertTrue(o2.toString() + " should not equal " + o1.toString(),
                 !o2.equals(o1));
     }
-
-    
 }


To unsubscribe from this list please visit:

http://xircles.codehaus.org/manage_email

Reply via email to