Trail:

Changeset 39

Show
Ignore:
Timestamp:
02/09/09 11:41:59 (3 years ago)
Author:
harald
Message:
  • Recursive generics support
Files:

Legend:

Unmodified
Added
Removed
Modified
Copied
Moved
  • trunk/out/templates/cs/class.vm

    r33 r39  
    11#* @vtlvariable name="typeDescriptor" type="org.fluffnstuff.asdoclet.generator.velocity.TypeDescriptor" *# 
    2 #macro(generic $descriptor) 
    3 #if($descriptor.typeArguments)<#foreach($arg in $descriptor.typeArguments)#if($velocityCount>1), #end#if($arg == "?")$descriptor.bounds.get($arg)#else$arg#end#end>#end 
     2#macro(dimensions $dimension) 
     3#set($foo = $dimension - 1) 
     4#if($dimension > 0)[]#dimensions($foo)#end 
    45#end 
    56#macro(bounds $descriptor) 
    6 #foreach($arg in $descriptor.bounds.keySet())#if($velocityCount==1) where #{else}, #end$arg : $descriptor.bounds.get($arg)#if($genericTypes.get($descriptor.bounds.get($arg)))#generic($genericTypes.get($descriptor.bounds.get($arg)))#end#end 
     7#foreach($arg in $descriptor.bounds.keySet())#if($velocityCount==1) where #{else}, #end$arg : #type($descriptor.bounds.get($arg))#end 
     8#end 
     9#macro(generics $type) 
     10#if($type.arguments)<#foreach($argument in $type.arguments)#if($velocityCount>1), #end#if($argument.name == "?")#type($type.bounds.get("?"))#else#type($argument)#end#end>#end 
     11#end 
     12#macro(type $type) 
     13$type.name#generics($type)#dimensions($type.dimensions) 
    714#end 
    815#macro(implements $descriptor) 
    9 #if($descriptor.superClass) : $descriptor.superClass#foreach($interface in $descriptor.interfaces), $interface#end#else#foreach($interface in $descriptor.interfaces)#if($velocityCount == 1) : #{else}, #end$interface#end#end 
     16#if($descriptor.superClass) : #type($descriptor.superClass)#foreach($interface in $descriptor.interfaces), #type($interface)#end#else#foreach($interface in $descriptor.interfaces)#if($velocityCount == 1) : #{else}, #end#type($interface)#end#end 
    1017#end 
    1118#macro(params $descriptor) 
    12 #foreach($parameterDescriptor in $descriptor.parameterDescriptors)#if($velocityCount>1), #end$parameterDescriptor.qualifiedTypeName#generic($parameterDescriptor) $parameterDescriptor.parameterName#end 
     19#foreach($parameterDescriptor in $descriptor.parameterDescriptors)#if($velocityCount>1), #end#type($parameterDescriptor) $parameterDescriptor.parameterName#end 
    1320#end 
    1421#* 
    1522        CLASS 
    1623*# 
    17 using System; 
    18  
    1924namespace $typeDescriptor.nameSpace { 
    2025#if($typeDescriptor.description)        /** 
     
    2227         */ 
    2328#end 
    24         [Serializable] 
    25         public class $typeDescriptor.typeName#generic($typeDescriptor)#implements($typeDescriptor)#bounds($typeDescriptor) { 
     29#foreach($annotation in $typeDescriptor.annotations)    [$annotation.name] 
     30#end 
     31        public class $typeDescriptor.typeName#generics($typeDescriptor)#implements($typeDescriptor)#bounds($typeDescriptor) { 
    2632#foreach($fieldDescriptor in $typeDescriptor.fieldDescriptors) 
    2733#if($fieldDescriptor.description)               /** 
     
    2935                 */ 
    3036#end 
    31                 #if($fieldDescriptor.modifier == "static")public const#else$fieldDescriptor.modifier#end $fieldDescriptor.qualifiedTypeName#generic($fieldDescriptor) $fieldDescriptor.fieldName#if($fieldDescriptor.value) = $fieldDescriptor.value#end; 
     37                #if($fieldDescriptor.modifier == "static")public const#else$fieldDescriptor.modifier#end #type($fieldDescriptor) $fieldDescriptor.fieldName#if($fieldDescriptor.value) = $fieldDescriptor.value#end; 
    3238#end 
    3339#foreach($propertyDescriptor in $typeDescriptor.propertyDescriptors) 
    34                 $propertyDescriptor.modifier #if($propertyDescriptor.override)override#{else}virtual#end $propertyDescriptor.qualifiedTypeName#generic($propertyDescriptor) $propertyDescriptor.propertyName { #if($propertyDescriptor.getter)get { return this.$propertyDescriptor.fieldName; }#end#if($propertyDescriptor.setter)set { this.$propertyDescriptor.fieldName = value; }#end } 
     40                $propertyDescriptor.modifier #if($propertyDescriptor.override)override#{else}virtual#end #type($propertyDescriptor) $propertyDescriptor.propertyName { #if($propertyDescriptor.getter)get { return this.$propertyDescriptor.fieldName; }#end#if($propertyDescriptor.setter)set { this.$propertyDescriptor.fieldName = value; }#end } 
    3541#end 
    3642#foreach($methodDescriptor in $typeDescriptor.methodDescriptors) 
     
    3945                 */ 
    4046#end 
    41                 $methodDescriptor.modifier $methodDescriptor.qualifiedTypeName#generic($methodDescriptor) ${methodDescriptor.methodName}(#params($methodDescriptor)) #if($methodDescriptor.body)$methodDescriptor.body 
     47                $methodDescriptor.modifier #type($methodDescriptor) ${methodDescriptor.upperMethodName}(#params($methodDescriptor)) #if($methodDescriptor.body)$methodDescriptor.body 
    4248#else{} 
    4349#end 
  • trunk/out/templates/cs/enum.vm

    r33 r39  
    11#* @vtlvariable name="typeDescriptor" type="org.fluffnstuff.asdoclet.generator.velocity.TypeDescriptor" *# 
    2 #macro(generic $descriptor) 
    3 #if($descriptor.typeArguments)<#foreach($arg in $descriptor.typeArguments)#if($velocityCount>1), #end#if($arg == "?")$descriptor.bounds.get($arg)#else$arg#end#end>#end 
     2#macro(dimensions $dimension) 
     3#set($foo = $dimension - 1) 
     4#if($dimension > 0)[]#dimensions($foo)#end 
    45#end 
    56#macro(bounds $descriptor) 
    6 #foreach($arg in $descriptor.bounds.keySet())#if($velocityCount==1) where #{else}, #end$arg : $descriptor.bounds.get($arg)#if($genericTypes.get($descriptor.bounds.get($arg)))#generic($genericTypes.get($descriptor.bounds.get($arg)))#end#end 
     7#foreach($arg in $descriptor.bounds.keySet())#if($velocityCount==1) where #{else}, #end$arg : #type($descriptor.bounds.get($arg))#end 
     8#end 
     9#macro(generics $type) 
     10#if($type.arguments)<#foreach($argument in $type.arguments)#if($velocityCount>1), #end#if($argument.name == "?")#type($type.bounds.get("?"))#else#type($argument)#end#end>#end 
     11#end 
     12#macro(type $type) 
     13$type.name#generics($type)#dimensions($type.dimensions) 
    714#end 
    815#macro(implements $descriptor) 
    9 #if($descriptor.superClass) : $descriptor.superClass#foreach($interface in $descriptor.interfaces), $interface#end#else#foreach($interface in $descriptor.interfaces)#if($velocityCount == 1) : #{else}, #end$interface#end#end 
     16#if($descriptor.superClass) : #type($descriptor.superClass)#foreach($interface in $descriptor.interfaces), #type($interface)#end#else#foreach($interface in $descriptor.interfaces)#if($velocityCount == 1) : #{else}, #end#type($interface)#end#end 
    1017#end 
    1118#macro(params $descriptor) 
    12 #foreach($parameterDescriptor in $descriptor.parameterDescriptors)#if($velocityCount>1), #end$parameterDescriptor.qualifiedTypeName#generic($parameterDescriptor) $parameterDescriptor.parameterName#end 
     19#foreach($parameterDescriptor in $descriptor.parameterDescriptors)#if($velocityCount>1), #end#type($parameterDescriptor) $parameterDescriptor.parameterName#end 
    1320#end 
    1421#* 
     
    2027         */ 
    2128#end 
    22         public enum $typeDescriptor.typeName#generic($typeDescriptor)#bounds($typeDescriptor) {#foreach($fieldDescriptor in $typeDescriptor.fieldDescriptors)#if($velocityCount>1), #end 
     29#foreach($annotation in $typeDescriptor.annotations)    [$annotation.name] 
     30#end 
     31        public enum $typeDescriptor.typeName#generics($typeDescriptor)#bounds($typeDescriptor) {#foreach($fieldDescriptor in $typeDescriptor.fieldDescriptors)#if($velocityCount>1), #end 
    2332 
    2433                $fieldDescriptor.fieldName#end 
  • trunk/out/templates/cs/interface.vm

    r33 r39  
    11#* @vtlvariable name="typeDescriptor" type="org.fluffnstuff.asdoclet.generator.velocity.TypeDescriptor" *# 
    2 #macro(generic $descriptor) 
    3 #if($descriptor.typeArguments)<#foreach($arg in $descriptor.typeArguments)#if($velocityCount>1), #end#if($arg == "?")$descriptor.bounds.get($arg)#else$arg#end#end>#end 
     2#macro(dimensions $dimension) 
     3#set($foo = $dimension - 1) 
     4#if($dimension > 0)[]#dimensions($foo)#end 
    45#end 
    56#macro(bounds $descriptor) 
    6 #foreach($arg in $descriptor.bounds.keySet())#if($velocityCount==1) where #{else}, #end$arg : $descriptor.bounds.get($arg)#if($genericTypes.get($descriptor.bounds.get($arg)))#generic($genericTypes.get($descriptor.bounds.get($arg)))#end#end 
     7#foreach($arg in $descriptor.bounds.keySet())#if($velocityCount==1) where #{else}, #end$arg : #type($descriptor.bounds.get($arg))#end 
     8#end 
     9#macro(generics $type) 
     10#if($type.arguments)<#foreach($argument in $type.arguments)#if($velocityCount>1), #end#if($argument.name == "?")#type($type.bounds.get("?"))#else#type($argument)#end#end>#end 
     11#end 
     12#macro(type $type) 
     13$type.name#generics($type)#dimensions($type.dimensions) 
    714#end 
    815#macro(implements $descriptor) 
    9 #if($descriptor.superClass) : $descriptor.superClass#foreach($interface in $descriptor.interfaces), $interface#end#else#foreach($interface in $descriptor.interfaces)#if($velocityCount == 1) : #{else}, #end$interface#end#end 
     16#if($descriptor.superClass) : #type($descriptor.superClass)#foreach($interface in $descriptor.interfaces), #type($interface)#end#else#foreach($interface in $descriptor.interfaces)#if($velocityCount == 1) : #{else}, #end#type($interface)#end#end 
    1017#end 
    1118#macro(params $descriptor) 
    12 #foreach($parameterDescriptor in $descriptor.parameterDescriptors)#if($velocityCount>1), #end$parameterDescriptor.qualifiedTypeName#generic($parameterDescriptor) $parameterDescriptor.parameterName#end 
     19#foreach($parameterDescriptor in $descriptor.parameterDescriptors)#if($velocityCount>1), #end#type($parameterDescriptor) $parameterDescriptor.parameterName#end 
    1320#end 
    1421#* 
     
    2027         */ 
    2128#end 
    22         public interface $typeDescriptor.typeName#generic($typeDescriptor)#implements($typeDescriptor)#bounds($typeDescriptor) { 
     29#foreach($annotation in $typeDescriptor.annotations)    [$annotation.name] 
     30#end 
     31        public interface $typeDescriptor.typeName#generics($typeDescriptor)#implements($typeDescriptor)#bounds($typeDescriptor) { 
    2332#foreach($propertyDescriptor in $typeDescriptor.propertyDescriptors) 
    24                 $propertyDescriptor.modifier $propertyDescriptor.qualifiedTypeName#generic($propertyDescriptor) $propertyDescriptor.propertyName { #if($propertyDescriptor.getter)get;#end#if($propertyDescriptor.setter)set;#end } 
     33                $propertyDescriptor.modifier #type($propertyDescriptor) $propertyDescriptor.propertyName { #if($propertyDescriptor.getter)get;#end#if($propertyDescriptor.setter)set;#end } 
    2534#end 
    2635 
     
    3039                 */ 
    3140#end 
    32                 $methodDescriptor.modifier $methodDescriptor.qualifiedTypeName#generic($methodDescriptor) ${methodDescriptor.methodName}(#params($methodDescriptor)); 
     41                $methodDescriptor.modifier #type($methodDescriptor) ${methodDescriptor.upperMethodName}(#params($methodDescriptor)); 
    3342#end 
    3443        } 
  • trunk/out/templates/cs/proxy.vm

    r33 r39  
    11#* @vtlvariable name="typeDescriptor" type="org.fluffnstuff.asdoclet.generator.velocity.TypeDescriptor" *# 
    2 #macro(generic $descriptor) 
    3 #if($descriptor.typeArguments)<#foreach($arg in $descriptor.typeArguments)#if($velocityCount>1), #end#if($arg == "?")$descriptor.bounds.get($arg)#else$arg#end#end>#end 
     2#macro(dimensions $dimension) 
     3#set($foo = $dimension - 1) 
     4#if($dimension > 0)[]#dimensions($foo)#end 
    45#end 
    56#macro(bounds $descriptor) 
    6 #foreach($arg in $descriptor.bounds.keySet())#if($velocityCount==1) where #{else}, #end$arg : $descriptor.bounds.get($arg)#if($genericTypes.get($descriptor.bounds.get($arg)))#generic($genericTypes.get($descriptor.bounds.get($arg)))#end#end 
     7#foreach($arg in $descriptor.bounds.keySet())#if($velocityCount==1) where #{else}, #end$arg : #type($descriptor.bounds.get($arg))#end 
     8#end 
     9#macro(generics $type) 
     10#if($type.arguments)<#foreach($argument in $type.arguments)#if($velocityCount>1), #end#if($argument.name == "?")#type($type.bounds.get("?"))#else#type($argument)#end#end>#end 
     11#end 
     12#macro(type $type) 
     13$type.name#generics($type)#dimensions($type.dimensions) 
    714#end 
    815#macro(implements $descriptor) 
    9 #if($descriptor.superClass) : $descriptor.superClass#foreach($interface in $descriptor.interfaces), $interface#end#else#foreach($interface in $descriptor.interfaces)#if($velocityCount == 1) : #{else}, #end$interface#end#end 
     16#if($descriptor.superClass) : #type($descriptor.superClass)#foreach($interface in $descriptor.interfaces), #type($interface)#end#else#foreach($interface in $descriptor.interfaces)#if($velocityCount == 1) : #{else}, #end#type($interface)#end#end 
    1017#end 
    1118#macro(params $descriptor) 
    12 #foreach($parameterDescriptor in $descriptor.parameterDescriptors)#if($velocityCount>1), #end$parameterDescriptor.qualifiedTypeName#generic($parameterDescriptor) $parameterDescriptor.parameterName#end 
     19#foreach($parameterDescriptor in $descriptor.parameterDescriptors)#if($velocityCount>1), #end#type($parameterDescriptor) $parameterDescriptor.parameterName#end 
    1320#end 
    1421#* 
     
    2027         */ 
    2128#end 
    22         public class $typeDescriptor.typeName#generic($typeDescriptor)#implements($typeDescriptor)#bounds($typeDescriptor) { 
     29#foreach($annotation in $typeDescriptor.annotations)    [$annotation.name] 
     30#end 
     31        public class $typeDescriptor.typeName#generics($typeDescriptor)#implements($typeDescriptor)#bounds($typeDescriptor) { 
    2332        protected virtual T dispatchCall<T>(string methodName, params object[] args) where T : class { 
    2433            return  null;  
     
    3039                 */ 
    3140#end 
    32                 public virtual $methodDescriptor.modifier $methodDescriptor.qualifiedTypeName#generic($methodDescriptor) ${methodDescriptor.methodName}(#params($methodDescriptor)) { 
     41                public virtual $methodDescriptor.modifier #type($methodDescriptor) ${methodDescriptor.upperMethodName}(#params($methodDescriptor)) { 
    3342#if($methodDescriptor.qualifiedTypeName == "void") 
    3443                        dispatchCall<object>("${methodDescriptor.methodName}"#foreach($parameterDescriptor in $methodDescriptor.parameterDescriptors), $parameterDescriptor.parameterName#end); 
    3544#else 
    36                         return dispatchCall<$methodDescriptor.qualifiedTypeName#if($methodDescriptor.typeArguments)<#foreach($arg in $methodDescriptor.typeArguments)#if($velocityCount>1), #end$arg#end>#end>("${methodDescriptor.methodName}"#foreach($parameterDescriptor in $methodDescriptor.parameterDescriptors), $parameterDescriptor.parameterName#end); 
     45                        return dispatchCall<#type($methodDescriptor)#if($methodDescriptor.typeArguments)<#foreach($arg in $methodDescriptor.typeArguments)#if($velocityCount>1), #end$arg#end>#end>("${methodDescriptor.methodName}"#foreach($parameterDescriptor in $methodDescriptor.parameterDescriptors), $parameterDescriptor.parameterName#end); 
    3746#end 
    3847                } 
  • trunk/src/org/fluffnstuff/asdoclet/AsDoclet.java

    r35 r39  
    3232 
    3333                for (ClassDoc classDoc : docs) { 
     34                        System.out.println("Processing " + classDoc.qualifiedName()); 
    3435                        if (TagParser.hasClassTags(generator, classDoc)) { 
    3536                                Handler handler = createHandler(generator, classDoc); 
  • trunk/src/org/fluffnstuff/asdoclet/generator/AsGenerator.java

    r33 r39  
    55import java.text.MessageFormat; 
    66import java.util.Collection; 
    7 import java.util.Map
     7import java.util.TreeSet
    88 
    99import org.apache.commons.lang.StringUtils; 
    1010import org.fluffnstuff.asdoclet.handler.Constants; 
    1111import org.fluffnstuff.asdoclet.map.TypeMap; 
     12import org.fluffnstuff.asdoclet.generator.utils.GeneratorUtils; 
    1213 
    1314import uk.co.badgersinfoil.metaas.ActionScriptFactory; 
     
    1920import uk.co.badgersinfoil.metaas.dom.ASInterfaceType; 
    2021import uk.co.badgersinfoil.metaas.dom.ASMethod; 
    21 import uk.co.badgersinfoil.metaas.dom.ASPackage; 
    2222import uk.co.badgersinfoil.metaas.dom.ASType; 
    2323import uk.co.badgersinfoil.metaas.dom.Visibility; 
     
    4040        private TypeMap typeMap; 
    4141        private TypeMap annotationMap; 
    42         private Map<String, String> bounds; 
     42 
     43        private Collection<String> imports; 
     44        private Collection<String> proxyImports; 
    4345 
    4446        public AsGenerator(String destination, String namespace, TypeMap typeMap, TypeMap annotationMap) { 
     
    8183        } 
    8284 
     85        public TypeMap getAnnotationMap() { 
     86                return annotationMap; 
     87        } 
     88 
    8389        public TypeMap getTypeMap() { 
    8490                return typeMap; 
     
    9096        } 
    9197 
    92         public void addConstant(String constantType, Collection<String> typeArguments, Map<String, String> bounds, String name, String value, String comment) { 
    93                 createConst((ASClassType) type, name, value, constantType, comment); 
    94         } 
    95  
    96         public void addEnumField(String name, String comment) { 
    97                 addConstant("String", null, null, name, MessageFormat.format("\"{0}\"", name), comment); 
    98         } 
    99  
    100         public void addField(int modifier, String fieldType, Collection<String> typeArguments, Map<String, String> bounds, String fieldName, String value, String comment) { 
    101                 fieldType = resolveTypeArguments(fieldType, bounds); 
    102  
    103                 ASClassType classType = (ASClassType) type; 
    104                 if (classType.getField(fieldName) == null) classType.newField(fieldName, getVisibility(modifier), fieldType); 
    105         } 
    106  
    107         public void addGetter(int modifier, String fieldType, Collection<String> typeArguments, Map<String, String> bounds, String propertyName, String comment, boolean override) { 
    108                 fieldType = resolveTypeArguments(fieldType, bounds); 
     98        public void addConstant(Type classType, Type constantType, String name, String value, String comment) { 
     99                createConst((ASClassType) type, name, value, constantType.getName(), comment); 
     100        } 
     101 
     102        public void addEnumField(Type classType, String name, String comment) { 
     103                Type type = GeneratorUtils.getType(String.class.getCanonicalName(), this); 
     104                addConstant(classType, type, name, MessageFormat.format("\"{0}\"", name), comment); 
     105        } 
     106 
     107        public void addField(Type classType, int modifier, Type fieldType, String fieldName, String value, String comment) { 
     108                fieldType = resolveTypeArguments(classType, fieldType); 
     109 
     110                ASClassType asClassType = (ASClassType) type; 
     111                if (asClassType.getField(fieldName) == null) asClassType.newField(fieldName, getVisibility(modifier), fieldType.getName()); 
     112        } 
     113 
     114        public void addGetter(Type classType, int modifier, Type fieldType, String propertyName, String comment, boolean override) { 
     115                fieldType = resolveTypeArguments(classType, fieldType); 
    109116 
    110117                if (type instanceof ASClassType) { 
    111                         addField(Modifier.PRIVATE, fieldType, typeArguments, bounds, "_" + propertyName, null, null); 
    112                         beginMethod(modifier, fieldType, typeArguments, bounds, "get " + propertyName); 
     118                        addField(classType, Modifier.PRIVATE, fieldType, "_" + propertyName, null, null); 
     119                        beginMethod(classType, modifier, fieldType, "get " + propertyName); 
    113120                        method.setOverride(override); 
    114121                        method.addStmt("return _" + propertyName + ";"); 
    115122                } else { 
    116                         beginMethod(modifier, fieldType, typeArguments, bounds, "get " + propertyName); 
     123                        beginMethod(classType, modifier, fieldType, "get " + propertyName); 
    117124                } 
    118125 
     
    120127        } 
    121128 
    122         public void addInterface(String name) { 
     129        public void addInterface(Type name) { 
    123130                if (type instanceof ASInterfaceType) { 
    124131                        ASInterfaceType interfaceType = (ASInterfaceType) type; 
    125                         interfaceType.addSuperInterface(name); 
     132                        interfaceType.addSuperInterface(name.getName()); 
    126133                } else { 
    127134                        ASClassType classType = (ASClassType) type; 
    128                         classType.addImplementedInterface(name); 
    129                 } 
    130         } 
    131  
    132         public void addParameter(String type, Collection<String> typeArguments, Map<String, String> bounds, String name) { 
    133                 type = resolveTypeArguments(type, bounds); 
    134  
    135                 method.addParam(name, type); 
    136                 if (proxyUnit != null) proxyMethod.addParam(name, type); 
    137         } 
    138  
    139         public void addSetter(int modifier, String fieldType, Collection<String> typeArguments, Map<String, String> bounds, String propertyName, String comment, boolean override) { 
    140                 fieldType = resolveTypeArguments(fieldType, bounds); 
     135                        classType.addImplementedInterface(name.getName()); 
     136                } 
     137                addImport(name.getName()); 
     138        } 
     139 
     140        public void addParameter(Type classType, Type type, String name) { 
     141                type = resolveTypeArguments(classType, type); 
     142 
     143                method.addParam(name, type.getName()); 
     144                if (proxyUnit != null) proxyMethod.addParam(name, type.getName()); 
     145 
     146                addImport(type.getName()); 
     147        } 
     148 
     149        public void addSetter(Type classType, int modifier, Type fieldType, String propertyName, String comment, boolean override) { 
     150                fieldType = resolveTypeArguments(classType, fieldType); 
    141151 
    142152                if (type instanceof ASClassType) { 
    143                         addField(Modifier.PRIVATE, fieldType, typeArguments, bounds, "_" + propertyName, null, null); 
    144                         beginMethod(modifier, "void", typeArguments, bounds, "set " + propertyName); 
     153                        addField(classType, Modifier.PRIVATE, fieldType, "_" + propertyName, null, null); 
     154                        beginMethod(classType, modifier, Type.VOID, "set " + propertyName); 
    145155                        method.setOverride(override); 
    146                         method.addParam("value", fieldType); 
     156                        method.addParam("value", fieldType.getName()); 
    147157                        method.addStmt("_" + propertyName + "=value;"); 
    148158                } else { 
    149                         beginMethod(modifier, "void", typeArguments, bounds, "set " + propertyName); 
    150                         method.addParam("value", fieldType); 
     159                        beginMethod(classType, modifier, Type.VOID, "set " + propertyName); 
     160                        method.addParam("value", fieldType.getName()); 
    151161                } 
    152162 
     
    154164        } 
    155165 
    156         public void addTypeAnnotation(String tag) { 
    157                 type.newMetaTag(tag); 
    158         } 
    159  
    160         public void beginClass(String name, boolean bindable, Collection<String> typeArguments, Map<String, String> bounds) { 
    161                 newClass(name, false); 
    162  
    163                 if (bindable) addTypeAnnotation("Bindable"); 
    164                 addTypeAnnotation("RemoteClass(alias=\"" + name + "\")"); 
    165  
    166                 this.bounds = bounds; 
    167         } 
    168  
    169         public void beginEnum(String name) { 
     166        public void addTypeAnnotation(Type tag) { 
     167                type.newMetaTag(tag.getName()); 
     168        } 
     169 
     170        public void beginClass(Type classType) { 
     171                System.out.println("Creating ActionScript class " + classType); 
     172 
     173                newClass(classType, false); 
     174                addTypeAnnotation(GeneratorUtils.getType("RemoteClass(alias=\"" + classType.getName() + "\")", this)); 
     175        } 
     176 
     177        public void beginEnum(Type name) { 
     178                System.out.println("Creating ActionScript enumeration " + name); 
     179 
    170180                newClass(name, true); 
    171181        } 
    172182 
    173         public void beginInterface(String name, Collection<String> typeArguments, Map<String, String> bounds) { 
    174                 unit = project.newInterface(name); 
     183        public void beginInterface(Type name) { 
     184                System.out.println("Creating ActionScript interface " + name); 
     185 
     186                unit = project.newInterface(name.getName()); 
    175187                type = unit.getType(); 
    176  
    177                 this.bounds = bounds; 
    178         } 
    179  
    180         public void beginMethod(int modifier, String returnType, Collection<String> typeArguments, Map<String, String> bounds, String methodName) { 
    181                 returnType = resolveTypeArguments(returnType, bounds); 
    182  
    183                 method = type.newMethod(methodName, getVisibility(modifier), returnType); 
     188                imports = new TreeSet<String>(); 
     189        } 
     190 
     191        public void beginMethod(Type classType, int modifier, Type returnType, String methodName) { 
     192                returnType = resolveTypeArguments(classType, returnType); 
     193 
     194                method = type.newMethod(methodName, getVisibility(modifier), returnType.getName()); 
    184195 
    185196                if (proxyUnit != null) { 
     
    187198                        createConst(eventType, proxyMethodName, MessageFormat.format("\"{0}\"", methodName), "String", null); 
    188199 
    189                         proxyMethod = proxyType.newMethod(methodName, Visibility.PUBLIC, returnType); 
    190                 } 
    191         } 
    192  
    193         public void beginProxy(String proxyName, Collection<String> typeArguments, Map<String, String> bounds, String returnType, String baseType, Collection<String> proxyImports, String interfaceType) { 
    194                 ASCompilationUnit eventUnit = project.newClass(proxyName + "Events"); 
    195                 proxyUnit = project.newClass(proxyName); 
     200                        proxyMethod = proxyType.newMethod(methodName, Visibility.PUBLIC, returnType.getName()); 
     201                } 
     202 
     203                addImport(returnType.getName()); 
     204        } 
     205 
     206        public void beginProxy(Type proxy, Type returnType, Type baseType, Type interfaceType) { 
     207                System.out.println("Creating ActionScript proxy " + proxy.getName()); 
     208 
     209                ASCompilationUnit eventUnit = project.newClass(proxy.getName() + "Events"); 
     210                proxyUnit = project.newClass(proxy.getName()); 
    196211 
    197212                eventType = (ASClassType) eventUnit.getType(); 
    198213                proxyType = (ASClassType) proxyUnit.getType(); 
    199214 
    200                 proxyType.addImplementedInterface(interfaceType); 
    201  
    202                 if (baseType != null) { 
    203                         proxyType.setSuperclass(baseType); 
    204                         proxyImports.add(baseType); 
    205                 } 
    206  
    207                 if (!Constants.TYPE_VOID.equals(returnType)) proxyImports.add(returnType); 
    208  
    209                 ASMethod callMethod = proxyType.newMethod(Constants.METHOD_CALL, Visibility.PROTECTED, returnType); 
     215                proxyType.addImplementedInterface(interfaceType.getName()); 
     216 
     217                proxyImports = new TreeSet<String>(); 
     218                proxyImports.add(interfaceType.getName()); 
     219 
     220                if (baseType != Type.NULL) { 
     221                        proxyType.setSuperclass(baseType.getName()); 
     222                        proxyImports.add(baseType.getName()); 
     223                } 
     224 
     225                if (returnType != Type.NULL) proxyImports.add(returnType.getName()); 
     226 
     227                ASMethod callMethod = proxyType.newMethod(Constants.METHOD_CALL, Visibility.PROTECTED, returnType.getName()); 
    210228                callMethod.addParam("name", "String"); 
    211229                callMethod.addParam("...args", null); 
    212230                callMethod.addStmt("throw new Error(\"Not Implemented\");"); 
    213231 
    214                 ASMethod resultMethod = proxyType.newMethod(Constants.METHOD_ON_RESULT, Visibility.PROTECTED, Constants.TYPE_VOID); 
     232                ASMethod resultMethod = proxyType.newMethod(Constants.METHOD_ON_RESULT, Visibility.PROTECTED, Type.VOID.getName()); 
    215233                resultMethod.addParam("result", "Object"); 
    216234 
    217                 ASMethod statusMethod = proxyType.newMethod(Constants.METHOD_ON_STATUS, Visibility.PROTECTED, Constants.TYPE_VOID); 
     235                ASMethod statusMethod = proxyType.newMethod(Constants.METHOD_ON_STATUS, Visibility.PROTECTED, Type.VOID.getName()); 
    218236                statusMethod.addParam("status", "Object"); 
    219237        } 
    220238 
    221         public void endClass(Collection<String> imports) { 
    222                 endInterface(imports); 
     239        public void endClass() { 
     240                end(); 
    223241        } 
    224242 
    225243        public void endEnum() { 
    226         } 
    227  
    228         public void endInterface(Collection<String> imports) { 
    229                 ASPackage packge = unit.getPackage(); 
    230                 for (String imp : imports) { 
    231                         packge.addImport(imp); 
    232                 } 
     244                end(); 
     245        } 
     246 
     247        public void endInterface() { 
     248                end(); 
    233249        } 
    234250 
     
    247263        } 
    248264 
    249         public void endProxy(Collection<String> proxyImports) { 
    250                 if (proxyUnit != null) { 
    251                         ASPackage packge = proxyUnit.getPackage(); 
    252                         for (String imp : proxyImports) { 
    253                                 packge.addImport(imp); 
    254                         } 
    255                 } 
    256  
     265        public void endProxy() { 
     266                proxyImports.addAll(imports); 
     267                for (String imp : proxyImports) proxyUnit.getPackage().addImport(imp); 
     268                proxyImports = null; 
    257269                proxyUnit = null; 
    258270        } 
     
    263275        } 
    264276 
    265         public String getAnnotation(String name, Collection<String> imports) { 
    266                 return annotationMap.getType(name, false, false, false, imports); 
    267         } 
    268  
    269277        public String getName() { 
    270278                return "actionscript"; 
    271279        } 
    272280 
    273         public String getType(String name, int dimensions, boolean primitive, boolean generic, boolean enumeration, Collection<String> imports) { 
    274                 if (dimensions > 0) return "Array"; 
    275                 return typeMap.getType(name, primitive, generic, enumeration, imports); 
     281        public boolean isDebug() { 
     282                return false; 
     283        } 
     284 
     285        public Type postProcessType(Type type) { 
     286                if (type.getDimensions() > 0) return GeneratorUtils.getType(Collection.class.getCanonicalName(), this); 
     287                return type; 
    276288        } 
    277289 
     
    280292        } 
    281293 
    282         public void setSuperclass(String name, boolean exception) { 
    283                 ((ASClassType) type).setSuperclass(name); 
     294        public void setSuperclass(Type name, boolean exception) { 
     295                ((ASClassType) type).setSuperclass(name.getName()); 
     296                addImport(name.getName()); 
    284297        } 
    285298 
     
    296309 
    297310                if (!StringUtils.isEmpty(comment)) field.setDescription(comment.trim()); 
     311        } 
     312 
     313        private void end() { 
     314                if (unit != null) for (String imp : imports) { 
     315                        unit.getPackage().addImport(imp); 
     316                } 
    298317        } 
    299318 
     
    321340        } 
    322341 
    323         private void newClass(String name, boolean isFinal) { 
    324                 unit = project.newClass(name); 
     342        private void newClass(Type classType, boolean isFinal) { 
     343                unit = project.newClass(classType.getName()); 
    325344                type = unit.getType(); 
    326345                ((ASClassType) type).setFinal(isFinal); 
    327         } 
    328  
    329         private String resolveTypeArguments(String returnType, Map<String, String> bounds) { 
    330                 if (this.bounds != null && this.bounds.containsKey(returnType)) { 
    331                         String type = this.bounds.get(returnType); 
     346 
     347                imports = new TreeSet<String>(); 
     348        } 
     349 
     350        private Type resolveTypeArguments(Type classType, Type type) { 
     351                String name = type.getName(); 
     352                if (classType.getBounds() != null && classType.getBounds().containsKey(name)) { 
     353                        type = classType.getBounds().get(type.getName()); 
    332354                        if (type != null) { 
    333                                 unit.getPackage().removeImport(type); 
    334                                 unit.getPackage().addImport(type); 
     355                                name = type.getName(); 
     356                                addImport(name); 
    335357                        } else { 
    336                                 type = "object"
     358                                type = GeneratorUtils.getType(Object.class.getCanonicalName(), this)
    337359                        } 
    338                         return type; 
    339                 } 
    340  
    341                 return returnType; 
     360                } 
     361 
     362                return type; 
     363        } 
     364 
     365        private void addImport(String name) { 
     366                if (name.indexOf('.') > -1) { 
     367                        imports.add(name); 
     368                        if (proxyImports != null) proxyImports.add(name); 
     369                } 
    342370        } 
    343371} 
  • trunk/src/org/fluffnstuff/asdoclet/generator/Generator.java

    r31 r39  
    11package org.fluffnstuff.asdoclet.generator; 
    22 
    3 import java.util.Collection; 
    4 import java.util.Map; 
     3import org.fluffnstuff.asdoclet.map.TypeMap; 
    54 
    65public interface Generator { 
    76        void addBody(String body); 
    87 
    9         void addConstant(String constantType, Collection<String> typeArguments, Map<String, String> bounds, String name, String value, String comment); 
     8        void addConstant(Type classType, Type constantType, String name, String value, String comment); 
    109 
    11         void addEnumField(String name, String comment); 
     10        void addEnumField(Type classType, String name, String comment); 
    1211 
    13         void addField(int modifier, String fieldType, Collection<String> typeArguments, Map<String, String> bounds, String propertyName, String value, String comment); 
     12        void addField(Type classType, int modifier, Type fieldType, String fieldName, String value, String comment); 
    1413 
    15         void addGetter(int modifier, String fieldType, Collection<String> typeArguments, Map<String, String> bounds, String propertyName, String comment, boolean override); 
     14        void addGetter(Type classType, int modifier, Type fieldType, String propertyName, String comment, boolean override); 
    1615 
    17         void addInterface(String name); 
     16        void addInterface(Type type); 
    1817 
    19         void addParameter(String type, Collection<String> typeArguments, Map<String, String> bounds, String name); 
     18        void addParameter(Type classType, Type type, String name); 
    2019 
    21         void addSetter(int modifier, String fieldType, Collection<String> typeArguments, Map<String, String> bounds, String propertyName, String comment, boolean override); 
     20        void addSetter(Type classType, int modifier, Type fieldType, String propertyName, String comment, boolean override); 
    2221 
    23         void addTypeAnnotation(String tag); 
     22        void addTypeAnnotation(Type annotation); 
    2423 
    25         void beginClass(String name, boolean bindable, Collection<String> typeArguments, Map<String, String> bounds); 
     24        void beginClass(Type type); 
    2625 
    27         void beginEnum(String name); 
     26        void beginEnum(Type type); 
    2827 
    29         void beginInterface(String name, Collection<String> typeArguments, Map<String, String> bounds); 
     28        void beginInterface(Type type); 
    3029 
    31         void beginMethod(int modifier, String returnType, Collection<String> typeArguments, Map<String, String> bounds, String methodName); 
     30        void beginMethod(Type classType, int modifier, Type returnType, String methodName); 
    3231 
    33         void beginProxy(String proxyName, Collection<String> typeArguments, Map<String, String> bounds, String returnType, String baseType, Collection<String> proxyImports, String interfaceType); 
     32        void beginProxy(Type type, Type returnType, Type baseType, Type interfaceType); 
    3433 
    35         void endClass(Collection<String> imports); 
     34        void endClass(); 
    3635 
    3736        void endEnum(); 
    3837 
    39         void endInterface(Collection<String> imports); 
     38        void endInterface(); 
    4039 
    4140        void endMethod(); 
    4241 
    43         void endProxy(Collection<String> proxyImports); 
     42        void endProxy(); 
    4443 
    4544        void generate() throws Exception; 
    4645 
    47         String getAnnotation(String name, Collection<String> imports); 
     46        TypeMap getAnnotationMap(); 
    4847 
    4948        String getName(); 
    5049 
    51         String getType(String name, int dimensions, boolean primitive, boolean generic, boolean enumeration, Collection<String> imports); 
     50        TypeMap getTypeMap(); 
     51 
     52        boolean isDebug(); 
     53 
     54        Type postProcessType(Type type); 
    5255 
    5356        void setMethodDescription(String description); 
    5457 
    55         void setSuperclass(String name, boolean exception); 
     58        void setSuperclass(Type type, boolean exception); 
    5659 
    5760        void setTypeDescription(String description); 
  • trunk/src/org/fluffnstuff/asdoclet/generator/VelocityGenerator.java

    r33 r39  
    88import java.util.Collection; 
    99import java.util.Map; 
    10 import java.util.HashMap; 
    1110 
    1211import org.apache.commons.lang.StringUtils; 
     
    2322import org.fluffnstuff.asdoclet.generator.velocity.ProxyDescriptor; 
    2423import org.fluffnstuff.asdoclet.generator.velocity.TypeDescriptor; 
    25 import org.fluffnstuff.asdoclet.handler.Constants; 
     24import org.fluffnstuff.asdoclet.generator.utils.GeneratorUtils; 
    2625import org.fluffnstuff.asdoclet.map.TypeMap; 
    2726 
     
    4241        private TypeMap annotationMap; 
    4342        private TypeMap typeMap; 
    44         private Map<String, TypeDescriptor> genericTypes = new HashMap<String, TypeDescriptor>(); 
    4543 
    4644        public VelocityGenerator(String destination, String namespace, String language, TypeMap typeMap, TypeMap annotationMap) throws Exception { 
     
    9189        } 
    9290 
     91        public TypeMap getAnnotationMap() { 
     92                return annotationMap; 
     93        } 
     94 
     95        public TypeMap getTypeMap() { 
     96                return typeMap; 
     97        } 
     98 
    9399// --------------------- Interface Generator --------------------- 
    94100 
     
    97103        } 
    98104 
    99         public void addConstant(String constantType, Collection<String> typeArguments, Map<String, String> bounds, String name, String value, String comment) { 
    100                 addField(Modifier.STATIC, constantType, typeArguments, bounds, name, value, comment); 
    101         } 
    102  
    103         public void addEnumField(String name, String comment) { 
    104                 addField(0, null, null, null, name, null, comment); 
    105         } 
    106  
    107         public void addField(int modifier, String fieldType, Collection<String> typeArguments, Map<String, String> bounds, String propertyName, String value, String comment) { 
    108                 fieldDescriptor = new FieldDescriptor(modifier, fieldType, typeArguments, bounds, propertyName, value); 
     105        public void addConstant(Type classType, Type constantType, String name, String value, String comment) { 
     106                addField(classType, Modifier.STATIC, constantType, name, value, comment); 
     107        } 
     108 
     109        public void addEnumField(Type classType, String name, String comment) { 
     110                addField(classType, 0, Type.EMPTY, name, null, comment); 
     111        } 
     112 
     113        public void addField(Type classType, int modifier, Type fieldType, String propertyName, String value, String comment) { 
     114                fieldDescriptor = new FieldDescriptor(modifier, fieldType, propertyName, value); 
    109115                setFieldDescription(comment); 
    110116 
     
    112118        } 
    113119 
    114         public void addGetter(int modifier, String returnType, Collection<String> typeArguments, Map<String, String> bounds, String propertyName, String description, boolean override) { 
    115                 PropertyDescriptor propertyDescriptor = new PropertyDescriptor(modifier, returnType, typeArguments, bounds, propertyName); 
     120        public void addGetter(Type classType, int modifier, Type returnType, String propertyName, String description, boolean override) { 
     121                PropertyDescriptor propertyDescriptor = new PropertyDescriptor(modifier, returnType, propertyName); 
    116122                propertyDescriptor.setGetter(true); 
    117123                propertyDescriptor.setOverride(propertyDescriptor.isOverride() || override); 
     
    120126 
    121127                if (typeDescriptor instanceof ClassDescriptor) { 
    122                         addField(Modifier.PRIVATE, returnType, typeArguments, bounds, propertyName, null, description); 
    123                 } 
    124         } 
    125  
    126         public void addInterface(String name) { 
     128                        addField(classType, Modifier.PRIVATE, returnType, propertyName, null, description); 
     129                } 
     130        } 
     131 
     132        public void addInterface(Type name) { 
    127133                typeDescriptor.addInterface(name); 
    128134        } 
    129135 
    130         public void addParameter(String type, Collection<String> typeArguments, Map<String, String> bounds, String name) { 
    131                 ParameterDescriptor parameterDescriptor = new ParameterDescriptor(type, typeArguments, bounds, name); 
     136        public void addParameter(Type classType, Type type, String name) { 
     137                ParameterDescriptor parameterDescriptor = new ParameterDescriptor(type, name); 
    132138                methodDescriptor.addParameterDescriptor(parameterDescriptor); 
    133139        } 
    134140 
    135         public void addSetter(int modifier, String returnType, Collection<String> typeArguments, Map<String, String> bounds, String propertyName, String description, boolean override) { 
    136                 PropertyDescriptor propertyDescriptor = new PropertyDescriptor(modifier, "void", typeArguments, bounds, propertyName); 
     141        public void addSetter(Type classType, int modifier, Type returnType, String propertyName, String description, boolean override) { 
     142                PropertyDescriptor propertyDescriptor = new PropertyDescriptor(modifier, Type.VOID, propertyName); 
    137143                propertyDescriptor.setSetter(true); 
    138144                propertyDescriptor.setOverride(propertyDescriptor.isOverride() || override); 
     
    141147 
    142148                if (typeDescriptor instanceof ClassDescriptor) { 
    143                         addField(Modifier.PRIVATE, returnType, typeArguments, bounds, propertyName, null, description); 
    144                 } 
    145         } 
    146  
    147         public void addTypeAnnotation(String annotation) { 
     149                        addField(classType, Modifier.PRIVATE, returnType, propertyName, null, description); 
     150                } 
     151        } 
     152 
     153        public void addTypeAnnotation(Type annotation) { 
    148154                typeDescriptor.addAnnotation(annotation); 
    149155        } 
    150156 
    151         public void beginClass(String name, boolean bindable, Collection<String> typeArguments, Map<String, String> bounds) { 
    152                 beginType(new ClassDescriptor(name, typeArguments, bounds)); 
    153         } 
    154  
    155         public void beginEnum(String name) { 
    156                 beginType(new EnumDescriptor(name)); 
    157         } 
    158  
    159         public void beginInterface(String name, Collection<String> typeArguments, Map<String, String> bounds) { 
    160                 beginType(new InterfaceDescriptor(name, typeArguments, bounds)); 
    161         } 
    162  
    163         public void beginMethod(int modifier, String returnType, Collection<String> typeArguments, Map<String, String> bounds, String methodName) { 
    164                 methodDescriptor = new MethodDescriptor(modifier, returnType, typeArguments, bounds, methodName); 
    165                 typeDescriptor.addMethodDescriptor(methodDescriptor); 
     157        public void beginClass(Type type) { 
     158                beginType(new ClassDescriptor(type)); 
     159        } 
     160 
     161        public void beginEnum(Type type) { 
     162                beginType(new EnumDescriptor(type)); 
     163        } 
     164 
     165        public void beginInterface(Type type) { 
     166                beginType(new InterfaceDescriptor(type)); 
     167        } 
     168 
     169        public void beginMethod(Type classType, int modifier, Type returnType, String methodName) { 
     170                methodDescriptor = new MethodDescriptor(modifier, returnType, methodName); 
     171                if (typeDescriptor != null) typeDescriptor.addMethodDescriptor(methodDescriptor); 
    166172                if (proxyTypeDescriptor != null) proxyTypeDescriptor.addMethodDescriptor(methodDescriptor); 
    167173        } 
    168174 
    169         public void beginProxy(String proxyName, Collection<String> typeArguments, Map<String, String> bounds, String returnType, String baseType, Collection<String> proxyImports, String interfaceType) { 
    170                 proxyTypeDescriptor = new ProxyDescriptor(proxyName, typeArguments, bounds); 
     175        public void beginProxy(Type proxy, Type returnType, Type baseType, Type interfaceType) { 
     176                proxyTypeDescriptor = new ProxyDescriptor(proxy); 
    171177                proxyTypeDescriptor.addInterface(interfaceType); 
    172178 
    173                 if (baseType != null) { 
    174                         proxyTypeDescriptor.setSuperclass(baseType); 
    175                         proxyImports.add(baseType); 
    176                 } 
     179                if (baseType != Type.NULL) proxyTypeDescriptor.setSuperclass(baseType); 
    177180 
    178181                typeDescriptors.add(proxyTypeDescriptor); 
    179  
    180                 if (!Constants.TYPE_VOID.equals(returnType)) proxyImports.add(returnType); 
    181         } 
    182  
    183         public void endClass(Collection<String> imports) { 
     182        } 
     183 
     184        public void endClass() { 
    184185                typeDescriptor = null; 
    185186        } 
     
    189190        } 
    190191 
    191         public void endInterface(Collection<String> imports) { 
     192        public void endInterface() { 
    192193                typeDescriptor = null; 
    193194        } 
     
    197198        } 
    198199 
    199         public void endProxy(Collection<String> proxyImports) { 
     200        public void endProxy() { 
    200201                proxyTypeDescriptor = null; 
    201202        } 
     
    221222                        Template template = Velocity.getTemplate("templates/" + language + "/" + s); 
    222223 
    223                         context.put("genericTypes", genericTypes); 
    224224                        context.put("typeDescriptor", descriptor); 
    225225                        template.merge(context, writer); 
     
    228228        } 
    229229 
    230         public String getAnnotation(String name, Collection<String> imports) { 
    231                 return annotationMap.getType(name, false, false, false, imports); 
    232         } 
    233  
    234230        public String getName() { 
    235231                return language; 
    236232        } 
    237233 
    238         public String getType(String name, int dimensions, boolean primitive, boolean generic, boolean enumeration, Collection<String> imports) { 
    239                 // todo if (generic) genericTypes.add(name); 
    240                 String type = typeMap.getType(name, primitive, generic, enumeration, imports); 
    241                 for (int i = 0; i < dimensions; i++) type += "[]"; // todo at least for c# 
     234        public boolean isDebug() { 
     235                return false; 
     236        } 
     237 
     238        public Type postProcessType(Type type) { 
    242239                return type; 
    243240        } 
     
    247244        } 
    248245 
    249         public void setSuperclass(String name, boolean exception) { 
    250                 ((ClassDescriptor) typeDescriptor).setSuperclass(name); 
     246        public void setSuperclass(Type type, boolean exception) { 
     247                ((ClassDescriptor) typeDescriptor).setSuperclass(type); 
    251248 
    252249                if (exception && CSHARP.equals(language)) { 
    253                         beginMethod(Modifier.PUBLIC, "", null, null, typeDescriptor.getTypeName()); 
     250                        beginMethod(type, Modifier.PUBLIC, Type.EMPTY, typeDescriptor.getTypeName()); 
    254251                        addBody(" : base() {}"); 
    255252                        endMethod(); 
    256253 
    257                         beginMethod(Modifier.PUBLIC, "", null, null, typeDescriptor.getTypeName()); 
    258                         addParameter(getType(String.class.getCanonicalName(), 0, false, false, false, null), null, null, "message"); 
     254                        beginMethod(type, Modifier.PUBLIC, Type.EMPTY, typeDescriptor.getTypeName()); 
     255                        addParameter(type, GeneratorUtils.getType(String.class.getCanonicalName(), this), "message"); 
    259256                        addBody(" : base(message) {}"); 
    260257                        endMethod(); 
    261258 
    262                         beginMethod(Modifier.PUBLIC, "", null, null, typeDescriptor.getTypeName()); 
    263                         addParameter(getType(String.class.getCanonicalName(), 0, false, false, false, null), null, null, "message"); 
    264                         addParameter(getType(Exception.class.getCanonicalName(), 0, false, false, false, null), null, null, "exception"); 
     259                        beginMethod(type, Modifier.PUBLIC, Type.EMPTY, typeDescriptor.getTypeName()); 
     260                        addParameter(type, GeneratorUtils.getType(String.class.getCanonicalName(), this), "message"); 
     261                        addParameter(type, GeneratorUtils.getType(Exception.class.getCanonicalName(), this), "exception"); 
    265262                        addBody(" : base(message, exception) {}"); 
    266263                        endMethod(); 
     
    275272                this.typeDescriptor = typeDescriptor; 
    276273                typeDescriptors.add(typeDescriptor); 
    277  
    278                 if (typeDescriptor.getTypeArguments() != null) genericTypes.put(typeDescriptor.getQualifiedTypeName(), typeDescriptor); 
     274        } 
     275 
     276        public void setBounds(Map<String, Type> bounds) { 
     277                if (proxyTypeDescriptor != null) proxyTypeDescriptor.getBounds().putAll(bounds); 
    279278        } 
    280279 
  • trunk/src/org/fluffnstuff/asdoclet/generator/velocity/ClassDescriptor.java

    r31 r39  
    22 
    33import java.util.Collection; 
    4 import java.util.Map; 
     4 
     5import org.fluffnstuff.asdoclet.generator.Type; 
    56 
    67public class ClassDescriptor extends TypeDescriptor { 
    7         private String superClass; 
     8        private Type superClass; 
    89 
    9         public ClassDescriptor(String className, Collection<String> typeArguments, Map<String, String> bounds) { 
    10                 super(className, typeArguments, bounds); 
     10        public ClassDescriptor(Type type) { 
     11                super(type); 
    1112        } 
    1213 
    13         public String getSuperClass() { 
     14        public Type getSuperClass() { 
    1415                return superClass; 
     16        } 
     17 
     18        @Override 
     19        public Collection<String> getImportsInternal() { 
     20                Collection<String> imports = super.getImportsInternal(); 
     21                if (superClass != null) { 
     22                        imports.add(superClass.getName()); 
     23                        imports.addAll(superClass.getImports()); 
     24                } 
     25                return imports; 
    1526        } 
    1627 
     
    1930        } 
    2031 
    21         public void setSuperclass(String superClass) { 
     32        public void setSuperclass(Type superClass) { 
    2233                this.superClass = superClass; 
    2334        } 
  • trunk/src/org/fluffnstuff/asdoclet/generator/velocity/Descriptor.java

    r31 r39  
    33import java.util.ArrayList; 
    44import java.util.Collection; 
    5 import java.util.Map; 
    65 
    7 import org.apache.commons.lang.ClassUtils
     6import org.fluffnstuff.asdoclet.generator.Type
    87 
    9 public class Descriptor { 
    10         private String typeName; 
     8public class Descriptor extends Type { 
    119        private String description; 
    12         private Collection<String> typeArguments; 
    13         private Collection<String> annotations = new ArrayList<String>(); 
    14         private Map<String, String> bounds; 
     10        private Collection<Type> annotations = new ArrayList<Type>(); 
    1511 
    16         public Descriptor(String typeName, Collection<String> typeArguments, Map<String, String> bounds) { 
    17                 this.typeName = typeName; 
    18                 this.typeArguments = typeArguments; 
    19                 this.bounds = bounds; 
     12        public Descriptor(Type type) { 
     13                super(type.getName(), type.getArguments(), type.getBounds(), type.getDimensions()); 
    2014        } 
    2115 
    22         public Collection<String> getAnnotations() { 
     16        public Collection<Type> getAnnotations() { 
    2317                return annotations; 
    24         } 
    25  
    26         public Map<String, String> getBounds() { 
    27                 return bounds; 
    2818        } 
    2919 
     
    3626        } 
    3727 
    38         public Collection<String> getTypeArguments() { 
    39                 return typeArguments; 
    40         } 
    41  
    42         public void addAnnotation(String annotation) { 
     28        public void addAnnotation(Type annotation) { 
    4329                annotations.add(annotation); 
    4430        } 
    4531 
    46         public String getNameSpace() { 
    47                 return ClassUtils.getPackageName(typeName); 
    48         } 
    49  
    50         public String getQualifiedTypeName() { 
    51                 return typeName; 
    52         } 
    53  
    54         public String getTypeName() { 
    55                 return ClassUtils.getShortClassName(typeName); 
     32        @Override 
     33        public Collection<String> getImportsInternal() { 
     34                return addImports(super.getImportsInternal(), annotations); 
    5635        } 
    5736} 
  • trunk/src/org/fluffnstuff/asdoclet/generator/velocity/EnumDescriptor.java

    r31 r39  
    11package org.fluffnstuff.asdoclet.generator.velocity; 
    22 
     3import org.fluffnstuff.asdoclet.generator.Type; 
     4 
    35public class EnumDescriptor extends TypeDescriptor { 
    4         public EnumDescriptor(String typeName) { 
    5                 super(typeName, null, null); 
     6        public EnumDescriptor(Type typeName) { 
     7                super(typeName); 
    68        } 
    79 
  • trunk/src/org/fluffnstuff/asdoclet/generator/velocity/FieldDescriptor.java

    r31 r39  
    22 
    33import java.lang.reflect.Modifier; 
    4 import java.util.Collection; 
    5 import java.util.Map
     4 
     5import org.fluffnstuff.asdoclet.generator.Type
    66 
    77public class FieldDescriptor extends Descriptor { 
     
    1010        private int modifier; 
    1111 
    12         public FieldDescriptor(int modifier, String type, Collection<String> typeArguments, Map<String, String> bounds, String fieldName, String value) { 
    13                 super(type, typeArguments, bounds); 
     12        public FieldDescriptor(int modifier, Type type, String fieldName, String value) { 
     13                super(type); 
    1414 
    1515                this.fieldName = fieldName; 
  • trunk/src/org/fluffnstuff/asdoclet/generator/velocity/InterfaceDescriptor.java

    r31 r39  
    11package org.fluffnstuff.asdoclet.generator.velocity; 
    22 
    3 import java.util.Collection; 
    4 import java.util.Map; 
     3import org.fluffnstuff.asdoclet.generator.Type; 
    54 
    65public class InterfaceDescriptor extends TypeDescriptor { 
    7         public InterfaceDescriptor(String typeName, Collection<String> typeArguments, Map<String, String> bounds) { 
    8                 super(typeName, typeArguments, bounds); 
     6        public InterfaceDescriptor(Type type) { 
     7                super(type); 
    98        } 
    109 
  • trunk/src/org/fluffnstuff/asdoclet/generator/velocity/MethodDescriptor.java

    r31 r39  
    33import java.util.ArrayList; 
    44import java.util.Collection; 
    5 import java.util.Map; 
     5 
     6import org.fluffnstuff.asdoclet.generator.Type; 
    67 
    78public class MethodDescriptor extends FieldDescriptor { 
     
    910        private String body; 
    1011 
    11         public MethodDescriptor(int modifier, String returnType, Collection<String> typeArguments, Map<String, String> bounds, String methodName) { 
    12                 super(modifier, returnType, typeArguments, bounds, methodName, null); 
     12        public MethodDescriptor(int modifier, Type type, String methodName) { 
     13                super(modifier, type, methodName, null); 
    1314        } 
    1415 
     
    2930        } 
    3031 
     32        @Override 
     33        public Collection<String> getImportsInternal() { 
     34                return addImports(super.getImportsInternal(), parameterDescriptors); 
     35        } 
     36 
    3137        public String getMethodName() { 
    3238                return getFieldName(); 
    3339        } 
     40 
     41        public String getUpperMethodName() { 
     42                return getPropertyName(); 
     43        } 
    3444} 
  • trunk/src/org/fluffnstuff/asdoclet/generator/velocity/ParameterDescriptor.java

    r31 r39  
    11package org.fluffnstuff.asdoclet.generator.velocity; 
    22 
    3 import java.util.Collection; 
    4 import java.util.Map; 
     3import org.fluffnstuff.asdoclet.generator.Type; 
    54 
    65public class ParameterDescriptor extends Descriptor { 
    76        private String parameterName; 
    87 
    9         public ParameterDescriptor(String parameterType, Collection<String> typeArguments, Map<String, String> bounds, String parameterName) { 
    10                 super(parameterType, typeArguments, bounds); 
     8        public ParameterDescriptor(Type parameterType, String parameterName) { 
     9                super(parameterType); 
    1110                this.parameterName = parameterName; 
    1211        } 
  • trunk/src/org/fluffnstuff/asdoclet/generator/velocity/PropertyDescriptor.java

    r31 r39  
    22 
    33import java.lang.reflect.Modifier; 
    4 import java.util.Collection; 
    5 import java.util.Map
     4 
     5import org.fluffnstuff.asdoclet.generator.Type
    66 
    77public class PropertyDescriptor extends Descriptor { 
     
    1212        private boolean override; 
    1313 
    14         public PropertyDescriptor(int modifier, String type, Collection<String> typeArguments, Map<String, String> bounds, String fieldName) { 
    15                 super(type, typeArguments, bounds); 
     14        public PropertyDescriptor(int modifier, Type type, String fieldName) { 
     15                super(type); 
    1616 
    1717                this.fieldName = fieldName; 
  • trunk/src/org/fluffnstuff/asdoclet/generator/velocity/ProxyDescriptor.java

    r31 r39  
    11package org.fluffnstuff.asdoclet.generator.velocity; 
    22 
    3 import java.util.Collection; 
    4 import java.util.Map; 
     3import org.fluffnstuff.asdoclet.generator.Type; 
    54 
    65public class ProxyDescriptor extends ClassDescriptor { 
    7         public ProxyDescriptor(String className, Collection<String> typeArguments, Map<String, String> bounds) { 
    8                 super(className, typeArguments, bounds); 
     6        public ProxyDescriptor(Type type) { 
     7                super(type); 
    98        } 
    109 
  • trunk/src/org/fluffnstuff/asdoclet/generator/velocity/TypeDescriptor.java

    r33 r39  
    66import java.util.Map; 
    77 
     8import org.fluffnstuff.asdoclet.generator.Type; 
     9 
    810public abstract class TypeDescriptor extends Descriptor { 
    911        private Map<String, PropertyDescriptor> propertyDescriptors = new LinkedHashMap<String, PropertyDescriptor>(); 
    1012        private Map<String, FieldDescriptor> fieldDescriptors = new LinkedHashMap<String, FieldDescriptor>(); 
    1113        private Collection<MethodDescriptor> methodDescriptors = new ArrayList<MethodDescriptor>(); 
    12         private Collection<String> interfaces = new ArrayList<String>(); 
     14        private Collection<Type> interfaces = new ArrayList<Type>(); 
    1315 
    14         public TypeDescriptor(String typeName, Collection<String> typeArguments, Map<String, String> bounds) { 
    15                 super(typeName, typeArguments, bounds); 
     16        public TypeDescriptor(Type type) { 
     17                super(type); 
    1618        } 
    1719 
    18         public Collection<String> getInterfaces() { 
     20        @Override 
     21        public Collection<String> getImportsInternal() { 
     22                Collection<String> imports = super.getImportsInternal(); 
     23 
     24                addImports(imports, propertyDescriptors.values()); 
     25                addImports(imports, fieldDescriptors.values()); 
     26                addImports(imports, methodDescriptors); 
     27                addImports(imports, interfaces); 
     28 
     29                return imports; 
     30        } 
     31 
     32        public Collection<Type> getInterfaces() { 
    1933                return interfaces; 
    2034        } 
     
    2842        } 
    2943 
    30         public void addInterface(String interfaceName) { 
     44        public void addInterface(Type interfaceName) { 
    3145                interfaces.add(interfaceName); 
    3246        } 
  • trunk/src/org/fluffnstuff/asdoclet/handler/AbstractHandler.java

    r33 r39  
    33import java.beans.Introspector; 
    44import java.lang.reflect.Modifier; 
    5 import java.util.ArrayList; 
    6 import java.util.Collection; 
    75import java.util.HashMap; 
    86import java.util.Map; 
    97 
    108import org.fluffnstuff.asdoclet.generator.Generator; 
     9import org.fluffnstuff.asdoclet.generator.utils.GeneratorUtils; 
    1110 
    1211import com.sun.javadoc.AnnotationDesc; 
     
    1514import com.sun.javadoc.FieldDoc; 
    1615import com.sun.javadoc.MethodDoc; 
    17 import com.sun.javadoc.ParameterizedType; 
    1816import com.sun.javadoc.Type; 
    1917 
     
    4543        } 
    4644 
    47         protected Collection<String> getClassArguments(ClassDoc classDoc, Map<String, String> bounds) { 
    48                 Collection<String> args = null; 
    49                 if (classDoc != null) { 
    50                         for (com.sun.javadoc.TypeVariable arg : classDoc.typeParameters()) { 
    51                                 String type = getGenerator().getType(arg.qualifiedTypeName(), getDimensions(arg), arg.isPrimitive(), false, isEnum(arg), null); 
     45        protected void processBeanProperty(ClassDoc classDoc, org.fluffnstuff.asdoclet.generator.Type classType, MethodDoc methodDoc, Map<String, String> commands) { 
     46                Map<String, String> methodCommands = new HashMap<String, String>(commands); 
     47                TagParser.processTags(methodDoc.tags(getGenerator().getName() + Constants.TAG_PROPERTY), methodCommands); 
    5248 
    53                                 if (args == null) args = new ArrayList<String>(); 
    54                                 args.add(type); 
     49                boolean ignoreProperty = TagParser.getBooleanCommand(Constants.COMMAND_IGNORE, commands); 
    5550 
    56                                getTypeBounds(arg, type, bounds); 
    57                         } 
    58                 } 
    59                 return args
    60         } 
     51                if (!ignoreProperty) { 
     52                        String propertyName = getBeanPropertyName(methodDoc); 
     53                       if (propertyName != null) { 
     54                               Type returnType = methodDoc.returnType()
     55                               org.fluffnstuff.asdoclet.generator.Type fieldType = getFieldType(methodDoc, findField(classDoc, propertyName), methodCommands); 
    6156 
    62         protected int getDimensions(Type returnType) { 
    63                 return returnType.dimension().length() / 2
    64        
     57                               if (fieldType == null) { 
     58                                       fieldType = GeneratorUtils.getType(returnType, getGenerator())
     59                               
    6560 
    66         protected boolean isEnum(Type type) { 
    67                 return type.asClassDoc() != null && type.asClassDoc().isEnum(); 
    68         } 
     61                                String name = methodDoc.name(); 
     62                                String comment = methodDoc.commentText(); 
    6963 
    70         private void getTypeBounds(Type arg, String type, Map<String, String> args) { 
    71                 Type[] types = null; 
    72                 if (arg.asTypeVariable() != null) { 
    73                         types = arg.asTypeVariable().bounds(); 
    74                 } else if (arg.asWildcardType() != null) { 
    75                         types = arg.asWildcardType().extendsBounds(); 
    76                         args.put("?", getGenerator().getType(Object.class.getCanonicalName(), 0, false, false, false, null)); // default, will be overridden 
    77                 } 
    78                 if (types != null) { 
    79                         Type boundType = types.length > 0 ? types[0] : null; 
    80  
    81                         String bound = null; 
    82                         if (boundType != null) { 
    83                                 bound = getGenerator().getType(boundType.qualifiedTypeName(), getDimensions(boundType), boundType.isPrimitive(), false, isEnum(boundType), null); 
    84                         } 
    85  
    86                         if (!"null".equals(bound)) args.put(type, bound); 
    87                 } 
    88         } 
    89  
    90         protected void processBeanProperties(ClassDoc classDoc, Collection<String> imports, Map<String, String> commands) { 
    91                 for (MethodDoc methodDoc : classDoc.methods()) { 
    92                         Map<String, String> methodCommands = new HashMap<String, String>(commands); 
    93                         TagParser.processTags(methodDoc.tags(getGenerator().getName() + Constants.TAG_PROPERTY), methodCommands); 
    94  
    95                         boolean ignoreProperty = TagParser.getBooleanCommand(Constants.COMMAND_IGNORE, commands); 
    96  
    97                         if (!ignoreProperty) { 
    98                                 String propertyName = getBeanPropertyName(methodDoc); 
    99                                 if (propertyName != null) { 
    100                                         Type returnType = methodDoc.returnType(); 
    101                                         String fieldType = getFieldType(methodDoc, findField(classDoc, propertyName), imports, methodCommands); 
    102                                         Collection<String> arguments = null; 
    103                                         Map<String, String> bounds = new HashMap<String, String>(); 
    104  
    105                                         if (fieldType == null) { 
    106                                                 arguments = getTypeArguments(returnType.asParameterizedType(), bounds); 
    107                                                 fieldType = getGenerator().getType(returnType.qualifiedTypeName(), getDimensions(returnType), returnType.isPrimitive(), arguments != null, isEnum(returnType), returnType.asTypeVariable() == null ? imports : null); 
    108                                         } 
    109  
    110                                         String name = methodDoc.name(); 
    111                                         String comment = methodDoc.commentText(); 
    112  
    113                                         if (!"null".equals(fieldType) && (name.startsWith("get") || name.startsWith("is"))) { 
    114                                                 String setterName = "set" + propertyName.substring(0, 1).toUpperCase() + propertyName.substring(1); 
     64                                if (fieldType != org.fluffnstuff.asdoclet.generator.Type.NULL && (name.startsWith("get") || name.startsWith("is"))) { 
     65                                        String setterName = "set" + propertyName.substring(0, 1).toUpperCase() + propertyName.substring(1); 
    11566 
    11667 
    117                                                 if (classDoc.isInterface()) { 
    118                                                         getGenerator().addGetter(0, fieldType, arguments, bounds, propertyName, comment, false); 
    119                                                         if (findMethod(setterName, classDoc)) getGenerator().addSetter(0, fieldType, arguments, bounds, propertyName, comment, false); 
    120                                                 } else { 
    121                                                         boolean overridden = isOverridden(classDoc, name); 
    122                                                         getGenerator().addGetter(Modifier.PUBLIC, fieldType, arguments, bounds, propertyName, comment, overridden); 
    123                                                         // always generate setter, serialization doesn't work otherwise 
    124                                                         getGenerator().addSetter(Modifier.PUBLIC, fieldType, arguments, bounds, propertyName, comment, overridden); 
    125                                                 } 
     68                                        if (classDoc.isInterface()) { 
     69                                                getGenerator().addGetter(classType, 0, fieldType, propertyName, comment, false); 
     70                                                if (findMethod(setterName, classDoc)) getGenerator().addSetter(classType, 0, fieldType, propertyName, comment, false); 
     71                                        } else { 
     72                                                boolean overridden = isOverridden(classDoc, name); 
     73                                                getGenerator().addGetter(classType, Modifier.PUBLIC, fieldType, propertyName, comment, overridden); 
     74                                                // always generate setter, serialization doesn't work otherwise 
     75                                                getGenerator().addSetter(classType, Modifier.PUBLIC, fieldType, propertyName, comment, overridden); 
    12676                                        } 
    12777                                } 
     
    14090        } 
    14191 
    142         private String getFieldType(MethodDoc methodDoc, FieldDoc fieldDoc, Collection<String> imports, Map<String, String> methodCommands) { 
     92        private org.fluffnstuff.asdoclet.generator.Type getFieldType(MethodDoc methodDoc, FieldDoc fieldDoc, Map<String, String> methodCommands) { 
    14393                String overriddenType = TagParser.getStringCommand(Constants.COMMAND_TYPE, methodCommands); 
    144                 String fieldType; 
     94                org.fluffnstuff.asdoclet.generator.Type fieldType; 
    14595 
    14696                if (overriddenType == null) { 
    147                         fieldType = checkAnnotations(imports, methodDoc.annotations()); 
     97                        fieldType = checkAnnotations(methodDoc.annotations()); 
    14898 
    14999                        if (fieldType == null && fieldDoc != null) { 
    150                                 fieldType = checkAnnotations(imports, fieldDoc.annotations()); 
     100                                fieldType = checkAnnotations(fieldDoc.annotations()); 
    151101                        } 
    152102                } else { 
    153                         if (overriddenType.contains(".")) imports.add(overriddenType); 
    154                         fieldType = overriddenType; 
     103                        fieldType = GeneratorUtils.getType(overriddenType, getGenerator()); 
    155104                } 
    156105 
     
    158107        } 
    159108 
    160         private String checkAnnotations(Collection<String> imports, AnnotationDesc[] annotationDescs) { 
    161                 String fieldType = null; 
     109        private org.fluffnstuff.asdoclet.generator.Type checkAnnotations(AnnotationDesc[] annotationDescs) { 
     110                org.fluffnstuff.asdoclet.generator.Type fieldType = null; 
     111 
    162112                for (AnnotationDesc annotationDesc : annotationDescs) { 
    163113                        AnnotationTypeDoc annotationTypeDoc = annotationDesc.annotationType(); 
    164                         fieldType = getGenerator().getAnnotation(annotationTypeDoc.qualifiedTypeName(), imports); 
     114                        fieldType = GeneratorUtils.getAnnotation(annotationTypeDoc.qualifiedTypeName(), getGenerator()); 
    165115                        if (fieldType != null) break; 
    166116                } 
     
    179129 
    180130                return fieldDoc; 
    181         } 
    182  
    183         protected Collection<String> getTypeArguments(ParameterizedType parameterizedType, Map<String, String> bounds) { 
    184                 Collection<String> args = null; 
    185                 if (parameterizedType != null) { 
    186                         args = new ArrayList<String>(); 
    187                         for (Type arg : parameterizedType.typeArguments()) { 
    188                                 String type = getGenerator().getType(arg.qualifiedTypeName(), getDimensions(arg), arg.isPrimitive(), false, isEnum(arg), null); 
    189                                 args.add(type); 
    190  
    191                                 if (bounds != null) getTypeBounds(arg, type, bounds); 
    192                         } 
    193                 } 
    194                 return args; 
    195131        } 
    196132 
     
    227163                getGenerator().setTypeDescription(description.toString()); 
    228164        } 
     165 
     166        protected void processInterfaces(ClassDoc classDoc, Map<String, String> commands) { 
     167                for (Type type : classDoc.interfaceTypes()) { 
     168                        org.fluffnstuff.asdoclet.generator.Type interfaceName = GeneratorUtils.getType(type, getGenerator()); 
     169 
     170                        if (interfaceName != org.fluffnstuff.asdoclet.generator.Type.NULL && !(commands.containsKey(Constants.COMMAND_IGNORE) && commands.get(Constants.COMMAND_IGNORE).contains(interfaceName.getName()))) { 
     171                                getGenerator().addInterface(interfaceName); 
     172                        } 
     173                } 
     174        } 
    229175} 
  • trunk/src/org/fluffnstuff/asdoclet/handler/ClassHandler.java

    r31 r39  
    11package org.fluffnstuff.asdoclet.handler; 
    22 
    3 import java.util.Collection; 
    4 import java.util.HashMap; 
    53import java.util.Map; 
    6 import java.util.TreeSet
     4import java.util.StringTokenizer
    75 
    86import org.fluffnstuff.asdoclet.generator.Generator; 
     7import org.fluffnstuff.asdoclet.generator.utils.GeneratorUtils; 
    98 
    109import com.sun.javadoc.ClassDoc; 
    1110import com.sun.javadoc.FieldDoc; 
     11import com.sun.javadoc.MethodDoc; 
    1212import com.sun.javadoc.Type; 
    1313 
     
    2020 
    2121        public void process(ClassDoc classDoc) { 
    22                 Collection<String> imports = new TreeSet<String>(); 
    2322                Map<String, String> commands = TagParser.processClassTags(getGenerator(), classDoc); 
    2423 
    25                 boolean bindable = TagParser.getBooleanCommand(Constants.COMMAND_BINDABLE, commands); 
    2624                String ignore = TagParser.getStringCommand(Constants.COMMAND_IGNORE, "", commands); 
    2725 
    28                 Map<String, String> bounds = new HashMap<String, String>(); 
    29                 Collection<String> arguments = getClassArguments(classDoc, bounds); 
    30                 getGenerator().beginClass(classDoc.qualifiedTypeName(), bindable, arguments, bounds); 
     26                org.fluffnstuff.asdoclet.generator.Type type = GeneratorUtils.getType(classDoc, getGenerator()); 
    3127 
    32                 processSuperClass(classDoc, ignore, imports); 
    33                 processInterfaces(classDoc, commands, imports); 
     28                getGenerator().beginClass(type); 
     29 
     30                if (commands.containsKey(Constants.COMMAND_ANNOTATION)) { 
     31                        StringTokenizer tokenizer = new StringTokenizer(commands.get(Constants.COMMAND_ANNOTATION), ","); 
     32                        while (tokenizer.hasMoreTokens()) { 
     33                                getGenerator().addTypeAnnotation(GeneratorUtils.getType(tokenizer.nextToken(), getGenerator())); 
     34                        } 
     35                } 
     36 
     37                processSuperClass(classDoc, ignore); 
     38                processInterfaces(classDoc, commands); 
    3439                processClassComment(classDoc); 
    35                 processClassConstants(classDoc, imports); 
    36                 processBeanProperties(classDoc, imports, commands); 
     40                processClassConstants(type, classDoc); 
     41                processBeanProperties(type, classDoc, commands); 
    3742 
    38                 getGenerator().endClass(imports); 
     43                getGenerator().endClass(); 
    3944        } 
    4045 
    41         private void processClassConstants(ClassDoc classDoc, Collection<String> imports) { 
     46        private void processBeanProperties(org.fluffnstuff.asdoclet.generator.Type type, ClassDoc classDoc, Map<String, String> commands) { 
     47                for (MethodDoc methodDoc : classDoc.methods()) { 
     48                        processBeanProperty(classDoc, type, methodDoc, commands); 
     49                } 
     50        } 
     51 
     52        private void processClassConstants(org.fluffnstuff.asdoclet.generator.Type classType, ClassDoc classDoc) { 
    4253                for (FieldDoc fieldDoc : classDoc.fields()) { 
    4354                        if (fieldDoc.isFinal() && fieldDoc.isPublic()) { 
    44                                 Type fieldType = fieldDoc.type(); 
    45                                 Map<String, String> bounds = new HashMap<String, String>(); 
    46                                 Collection<String> arguments = getTypeArguments(fieldType.asParameterizedType(), bounds); 
    47                                 String type = getGenerator().getType(fieldType.qualifiedTypeName(), getDimensions(fieldType), fieldType.isPrimitive(), arguments != null, isEnum(fieldType), imports); 
    48                                 getGenerator().addConstant(type, arguments, bounds, fieldDoc.name(), fieldDoc.constantValueExpression(), fieldDoc.commentText()); 
     55                                org.fluffnstuff.asdoclet.generator.Type type = GeneratorUtils.getType(fieldDoc.type(), getGenerator()); 
     56                                getGenerator().addConstant(classType, type, fieldDoc.name(), fieldDoc.constantValueExpression(), fieldDoc.commentText()); 
    4957                        } 
    5058                } 
    5159        } 
    5260 
    53         protected void processInterfaces(ClassDoc classDoc, Map<String, String> commands, Collection<String> imports) { 
    54                 for (Type type : classDoc.interfaceTypes()) { 
    55                         if (!commands.containsKey(Constants.COMMAND_IGNORE) || !commands.get(Constants.COMMAND_IGNORE).contains(type.qualifiedTypeName())) { 
    56                                 String interfaceClass = getGenerator().getType(type.qualifiedTypeName(), 0, false, false, false, imports); 
    57                                 if (!"null".equals(interfaceClass)) getGenerator().addInterface(interfaceClass); 
    58                         } 
    59                 } 
    60         } 
     61        private void processSuperClass(ClassDoc classDoc, String ignore) { 
     62                Type type = classDoc.superclassType(); 
     63                if ((type != null) && !type.qualifiedTypeName().equals(Object.class.getCanonicalName())) { 
     64                        org.fluffnstuff.asdoclet.generator.Type superClass = GeneratorUtils.getType(type, getGenerator()); 
    6165 
    62         private void processSuperClass(ClassDoc classDoc, String ignore, Collection<String> imports) { 
    63                 Type type = classDoc.superclassType(); 
    64                 if (type != null) { 
    65                         String superClassName = type.qualifiedTypeName(); 
    66                         if (!superClassName.equals(Object.class.getName())) { 
    67                                 superClassName = getGenerator().getType(superClassName, 0, false, false, false, null); 
    68                                 if (!Object.class.getName().equals(superClassName) && !ignore.contains(superClassName)) { 
    69                                         getGenerator().setSuperclass(superClassName, isException(classDoc)); 
    70                                         imports.add(superClassName); 
    71                                 } 
     66                        if (superClass != org.fluffnstuff.asdoclet.generator.Type.NULL && !ignore.contains(superClass.getName())) { 
     67                                getGenerator().setSuperclass(superClass, isException(classDoc)); 
    7268                        } 
    7369                } 
  • trunk/src/org/fluffnstuff/asdoclet/handler/Constants.java

    r17 r39  
    22 
    33final public class Constants { 
    4     public static final String TAG_CLASS = ".class"; 
    5     public static final String TAG_METHOD = ".method"; 
    6     public static final String TAG_PROPERTY = ".property"; 
     4       public static final String TAG_CLASS = ".class"; 
     5       public static final String TAG_METHOD = ".method"; 
     6       public static final String TAG_PROPERTY = ".property"; 
    77 
    8     public static final String COMMAND_BEAN = "bean"; 
     8       public static final String COMMAND_BEAN = "bean"; 
    99 
    10     public static final String COMMAND_ASYNC = "async"; 
    11     public static final String COMMAND_ASYNC_RETURN_TYPE = "async.returntype"; 
     10       public static final String COMMAND_ASYNC = "async"; 
     11       public static final String COMMAND_ASYNC_RETURN_TYPE = "async.returntype"; 
    1212 
    13     public static final String COMMAND_PROXY = "proxy"; 
    14     public static final String COMMAND_PROXY_BASE_CLASS = "proxy.baseclass"; 
    15     public static final String COMMAND_PROXY_NAME = "proxy.name"; 
     13       public static final String COMMAND_PROXY = "proxy"; 
     14       public static final String COMMAND_PROXY_BASE_CLASS = "proxy.baseclass"; 
     15       public static final String COMMAND_PROXY_NAME = "proxy.name"; 
    1616 
    17     public static final String COMMAND_BINDABLE = "bindable"; 
    18     public static final String COMMAND_IGNORE = "ignore"; 
    19     public static final String COMMAND_TYPE = "type"; 
     17       public static final String COMMAND_ANNOTATION = "annotation"; 
     18       public static final String COMMAND_IGNORE = "ignore"; 
     19       public static final String COMMAND_TYPE = "type"; 
    2020 
    21     public static final String METHOD_ON_RESULT = "onResult"; 
    22     public static final String METHOD_ON_STATUS = "onStatus"; 
    23     public static final String METHOD_CALL = "dispatchCall"; 
     21       public static final String METHOD_ON_RESULT = "onResult"; 
     22       public static final String METHOD_ON_STATUS = "onStatus"; 
     23       public static final String METHOD_CALL = "dispatchCall"; 
    2424 
    25     public static final String TYPE_VOID = "void"; 
    26  
    27     private Constants() { 
    28     } 
     25        private Constants() { 
     26        } 
    2927} 
  • trunk/src/org/fluffnstuff/asdoclet/handler/EnumHandler.java

    r11 r39  
    33import com.sun.javadoc.ClassDoc; 
    44import com.sun.javadoc.FieldDoc; 
     5 
    56import org.fluffnstuff.asdoclet.generator.Generator; 
     7import org.fluffnstuff.asdoclet.generator.Type; 
     8import org.fluffnstuff.asdoclet.generator.utils.GeneratorUtils; 
    69 
    710public class EnumHandler extends AbstractHandler { 
    8     public EnumHandler(Generator generator) { 
    9         super(generator); 
    10    
     11       public EnumHandler(Generator generator) { 
     12               super(generator); 
     13       
    1114 
    1215// --------------------- Interface Handler --------------------- 
    1316 
    14     public void process(ClassDoc classDoc) { 
    15         getGenerator().beginEnum(classDoc.qualifiedTypeName()); 
    16         processClassComment(classDoc); 
    17         processEnumConstants(classDoc); 
     17        public void process(ClassDoc classDoc) { 
     18                Type type = GeneratorUtils.getType(classDoc.qualifiedName(), getGenerator()); 
    1819 
    19         getGenerator().endEnum(); 
    20     } 
     20                getGenerator().beginEnum(type); 
     21                processClassComment(classDoc); 
     22                processEnumConstants(type, classDoc); 
    2123 
    22     private void processEnumConstants(ClassDoc classDoc) { 
    23         for (FieldDoc fieldDoc : classDoc.enumConstants()) getGenerator().addEnumField(fieldDoc.name(), fieldDoc.commentText()); 
    24     } 
     24                getGenerator().endEnum(); 
     25        } 
     26 
     27        private void processEnumConstants(Type type, ClassDoc classDoc) { 
     28                for (FieldDoc fieldDoc : classDoc.enumConstants()) getGenerator().addEnumField(type, fieldDoc.name(), fieldDoc.commentText()); 
     29        } 
    2530} 
  • trunk/src/org/fluffnstuff/asdoclet/handler/InterfaceHandler.java

    r37 r39  
    11package org.fluffnstuff.asdoclet.handler; 
    22 
    3 import java.util.Collection; 
    43import java.util.HashMap; 
    54import java.util.Map; 
    6 import java.util.TreeSet; 
    75 
    86import org.fluffnstuff.asdoclet.generator.Generator; 
     7import org.fluffnstuff.asdoclet.generator.utils.GeneratorUtils; 
    98 
    109import com.sun.javadoc.ClassDoc; 
     
    2524                commands.putAll(TagParser.processClassTags(getGenerator(), classDoc)); 
    2625 
    27                 Collection<String> imports = new TreeSet<String>(); 
    28                 Collection<String> proxyImports = new TreeSet<String>(); 
    29  
    3026                boolean proxy = TagParser.getBooleanCommand(Constants.COMMAND_PROXY, commands); 
    31                 String asyncReturnType = TagParser.getStringCommand(Constants.COMMAND_ASYNC_RETURN_TYPE, Constants.TYPE_VOID, commands); 
     27                String asyncReturnType = TagParser.getStringCommand(Constants.COMMAND_ASYNC_RETURN_TYPE, org.fluffnstuff.asdoclet.generator.Type.VOID.getName(), commands); // todo 
     28                org.fluffnstuff.asdoclet.generator.Type type2 = GeneratorUtils.getType(asyncReturnType, getGenerator()); 
    3229 
    3330                if (proxy) { 
    34                         String interfaceName = classDoc.qualifiedTypeName(); 
    35                         Map<String, String> bounds = new HashMap<String, String>(); 
    36                         Collection<String> arguments = getClassArguments(classDoc, bounds); 
    37  
     31                        org.fluffnstuff.asdoclet.generator.Type interfaceName = GeneratorUtils.getType(classDoc, getGenerator()); 
    3832                        String proxyName = TagParser.getStringCommand(Constants.COMMAND_PROXY_NAME, interfaceName + "Proxy", commands); 
    3933                        String baseType = TagParser.getStringCommand(Constants.COMMAND_PROXY_BASE_CLASS, commands); 
    4034 
    41                         String interfaceType = getGenerator().getType(interfaceName, 0, false, false, isEnum(classDoc), proxyImports); 
    42                         getGenerator().beginProxy(proxyName, arguments, bounds, asyncReturnType, baseType, proxyImports, interfaceType); 
     35                        org.fluffnstuff.asdoclet.generator.Type type1 = GeneratorUtils.getType(proxyName, getGenerator()); 
     36                        org.fluffnstuff.asdoclet.generator.Type type3 = GeneratorUtils.getType(baseType, getGenerator()); 
     37                        getGenerator().beginProxy(type1, type2, type3, interfaceName); 
    4338                } 
    4439 
    45                 processInterfaceInternal(classDoc, asyncReturnType, commands, proxyImports, imports); 
     40                processInterfaceInternal(classDoc, type2, commands); 
    4641 
    4742                if (proxy) { 
    48                         proxyImports.addAll(imports); 
    49                         getGenerator().endProxy(proxyImports); 
     43                        traverseInterfaces(classDoc, commands, type2); 
     44                        getGenerator().endProxy(); 
    5045                } 
    5146        } 
    5247 
    53         private void processInterfaceInternal(ClassDoc classDoc, String asyncReturnType, Map<String, String> parentCommands, Collection<String> proxyImports, Collection<String> imports) { 
     48        private void processInterfaceInternal(ClassDoc classDoc, org.fluffnstuff.asdoclet.generator.Type asyncReturnType, Map<String, String> parentCommands) { 
    5449                Map<String, String> commands = new HashMap<String, String>(); 
    55                 String interfaceName = classDoc.qualifiedTypeName(); 
    5650 
    57                 Map<String, String> bounds = new HashMap<String, String>(); 
    58                 Collection<String> arguments = getClassArguments(classDoc, bounds); 
     51                org.fluffnstuff.asdoclet.generator.Type interfaceName = GeneratorUtils.getType(classDoc, getGenerator()); 
    5952 
    6053                if (parentCommands != null) commands.putAll(parentCommands); 
     
    6356                boolean bean = TagParser.getBooleanCommand(Constants.COMMAND_BEAN, commands); 
    6457 
    65                 getGenerator().beginInterface(interfaceName, arguments, bounds); 
    66  
    67                 if (bean) { 
    68                         processBeanProperties(classDoc, imports, commands); 
    69                 } else { 
    70                         processMethods(classDoc, commands, imports, asyncReturnType); 
    71                 } 
     58                getGenerator().beginInterface(interfaceName); 
    7259 
    7360                processClassComment(classDoc); 
    74                 processInterfaces(classDoc, commands, imports); 
     61                processInterfaces(classDoc, commands); 
     62                processMethods(classDoc, interfaceName, commands, asyncReturnType, bean); 
    7563 
    76                 getGenerator().endInterface(imports); 
    77  
    78                 traverseInterfaces(classDoc, commands, asyncReturnType, proxyImports, imports); 
     64                getGenerator().endInterface(); 
    7965        } 
    8066 
    81         private void processMethods(ClassDoc classDoc, Map<String, String> commands, Collection<String> imports, String asyncReturnType) { 
     67        private void processMethods(ClassDoc classDoc, org.fluffnstuff.asdoclet.generator.Type classType, Map<String, String> commands, org.fluffnstuff.asdoclet.generator.Type asyncReturnType, boolean bean) { 
    8268                for (MethodDoc methodDoc : classDoc.methods()) { 
    83                         Type returnType = methodDoc.returnType(); 
     69                        boolean getter = (methodDoc.name().startsWith("get") || methodDoc.name().startsWith("is")) && (methodDoc.parameters().length == 0); 
     70                        boolean setter = methodDoc.name().startsWith("set") && (methodDoc.parameters().length == 1); 
    8471 
    85                         Map<String, String> bounds = new HashMap<String, String>(); 
    86                         Collection<String> args = getTypeArguments(returnType.asParameterizedType(), bounds); 
    87  
    88                         String type = getGenerator().getType(returnType.qualifiedTypeName(), getDimensions(returnType), returnType.isPrimitive(), args != null, isEnum(returnType), null); 
    89                         processMethod(methodDoc, commands, imports, type, args, bounds, asyncReturnType); 
     72                        if (bean && (getter || setter)) { 
     73                               processBeanProperty(classDoc, classType, methodDoc, commands); 
     74                        } else { 
     75                               processMethod(classDoc, classType, methodDoc, commands, asyncReturnType); 
     76                        } 
    9077                } 
    9178        } 
    9279 
    93         private void processMethod(MethodDoc methodDoc, Map<String, String> commands, Collection<String> imports, String returnType, Collection<String> typeArguments, Map<String, String> bounds, String asyncReturnType) { 
     80        private void processMethod(ClassDoc classDoc, org.fluffnstuff.asdoclet.generator.Type classType, MethodDoc methodDoc, Map<String, String> commands, org.fluffnstuff.asdoclet.generator.Type asyncReturnType) { 
    9481                Map<String, String> methodCommands = new HashMap<String, String>(commands); 
     82                org.fluffnstuff.asdoclet.generator.Type returnType = GeneratorUtils.getType(methodDoc.returnType(), getGenerator()); 
    9583 
    9684                TagParser.processTags(methodDoc.tags(getGenerator().getName() + Constants.TAG_METHOD), methodCommands); 
     
    10189                if (!ignore) { 
    10290                        if (async) { 
    103                                 if (!Constants.TYPE_VOID.equals(asyncReturnType)) imports.add(asyncReturnType); 
    104                                 getGenerator().beginMethod(0, asyncReturnType, null, null, methodDoc.name()); 
     91                                getGenerator().beginMethod(classType, 0, asyncReturnType, methodDoc.name()); 
    10592                        } else { 
    106                                 getGenerator().beginMethod(0, returnType, typeArguments, bounds, methodDoc.name()); 
     93                                getGenerator().beginMethod(classType, 0, returnType, methodDoc.name()); 
    10794                        } 
    10895 
    10996                        for (Parameter parameter : methodDoc.parameters()) { 
    11097                                Type parameterType = parameter.type(); 
    111                                 Map<String, String> parameterBounds = new HashMap<String, String>(); 
    112                                 Collection<String> parameterArguments = getTypeArguments(parameterType.asParameterizedType(), parameterBounds); 
    113                                 String type = getGenerator().getType(parameterType.qualifiedTypeName(), getDimensions(parameterType), parameterType.isPrimitive(), parameterArguments != null, isEnum(parameterType), parameterType.asTypeVariable() == null ? imports : null); 
    114                                 getGenerator().addParameter(type, parameterArguments, parameterBounds, parameter.name()); 
     98 
     99                                org.fluffnstuff.asdoclet.generator.Type type = GeneratorUtils.getType(parameterType, getGenerator()); 
     100                                getGenerator().addParameter(classType, type, parameter.name()); 
    115101                        } 
    116102 
     
    131117        } 
    132118 
    133         private void processInterfaces(ClassDoc classDoc, Map<String, String> commands, Collection<String> imports) { 
    134                 for (Type type : classDoc.interfaceTypes()) { 
    135                         if (!commands.containsKey(Constants.COMMAND_IGNORE) || !commands.get(Constants.COMMAND_IGNORE).contains(type.qualifiedTypeName())) { 
    136                                 String interfaceClass = getGenerator().getType(type.qualifiedTypeName(), 0, false, false, false, imports); 
    137                                 if (!"null".equals(interfaceClass)) { 
    138                                         getGenerator().addInterface(interfaceClass); 
    139                                 } 
    140                         } 
    141                 } 
    142         } 
     119        private void traverseInterfaces(ClassDoc interfaceDoc, Map<String, String> parentCommands, org.fluffnstuff.asdoclet.generator.Type asyncReturnType) { 
     120                for (Type type : interfaceDoc.interfaceTypes()) { 
     121                        ClassDoc classDoc = type.asClassDoc(); 
     122                        org.fluffnstuff.asdoclet.generator.Type interfaceClass = GeneratorUtils.getType(type, getGenerator()); 
    143123 
    144         private void traverseInterfaces(ClassDoc classDoc, Map<String, String> commands, String asyncReturnType, Collection<String> proxyImports, Collection<String> imports) { 
    145                 for (Type type : classDoc.interfaceTypes()) { 
    146                         if (!commands.containsKey(Constants.COMMAND_IGNORE) || !commands.get(Constants.COMMAND_IGNORE).contains(type.qualifiedTypeName())) { 
    147                                 String interfaceClass = getGenerator().getType(type.qualifiedTypeName(), 0, false, false, false, null); 
    148                                 if (!"null".equals(interfaceClass)) { 
    149                                         processInterfaceInternal(type.asClassDoc(), asyncReturnType, commands, proxyImports, imports); 
    150                                 } 
     124                        if (interfaceClass != org.fluffnstuff.asdoclet.generator.Type.NULL || (parentCommands.containsKey(Constants.COMMAND_IGNORE) && parentCommands.get(Constants.COMMAND_IGNORE).contains(interfaceClass.getName()))) { 
     125                                Map<String, String> commands = new HashMap<String, String>(); 
     126 
     127                                commands.putAll(parentCommands); 
     128                                commands.putAll(TagParser.processClassTags(getGenerator(), classDoc)); 
     129 
     130                                boolean bean = TagParser.getBooleanCommand(Constants.COMMAND_BEAN, commands); 
     131                                processMethods(classDoc, interfaceClass, commands, asyncReturnType, bean); 
     132 
     133                                traverseInterfaces(classDoc, commands, asyncReturnType); 
    151134                        } 
    152135                } 
  • trunk/src/org/fluffnstuff/asdoclet/map/ClassTypeMap.java

    r20 r39  
    11package org.fluffnstuff.asdoclet.map; 
    2  
    3 import java.util.Collection; 
    42 
    53public class ClassTypeMap extends TypeMap { 
    64        @Override 
    7         public String getType(String typeName, boolean primitive, boolean generic, boolean enumeration, Collection<String> imports) { 
     5        public String getType(String typeName, boolean generic, boolean enumeration) { 
    86                String asType = getRawType(typeName, generic, enumeration); 
    97 
    108                if (asType == null) { 
    11                         if (imports != null && !primitive) imports.add(typeName); 
    129                        asType = typeName; 
    1310                } 
  • trunk/src/org/fluffnstuff/asdoclet/map/TypeMap.java

    r20 r39  
    11package org.fluffnstuff.asdoclet.map; 
    22 
    3 import java.util.Collection; 
    43import java.util.HashMap; 
    54import java.util.Map; 
     
    2221        } 
    2322 
    24         public String getType(String typeName, boolean primitive, boolean generic, boolean enumeration, Collection<String> imports) { 
     23        public String getType(String typeName, boolean generic, boolean enumeration) { 
    2524                return getRawType(typeName, generic, enumeration); 
    2625        }