Changeset 39
- Timestamp:
- 02/09/09 11:41:59 (3 years ago)
- Files:
-
- trunk/out/templates/cs/class.vm (modified) (4 diffs)
- trunk/out/templates/cs/enum.vm (modified) (2 diffs)
- trunk/out/templates/cs/interface.vm (modified) (3 diffs)
- trunk/out/templates/cs/proxy.vm (modified) (3 diffs)
- trunk/src/org/fluffnstuff/asdoclet/AsDoclet.java (modified) (1 diff)
- trunk/src/org/fluffnstuff/asdoclet/generator/AsGenerator.java (modified) (13 diffs)
- trunk/src/org/fluffnstuff/asdoclet/generator/Generator.java (modified) (1 diff)
- trunk/src/org/fluffnstuff/asdoclet/generator/Type.java (added)
- trunk/src/org/fluffnstuff/asdoclet/generator/VelocityGenerator.java (modified) (14 diffs)
- trunk/src/org/fluffnstuff/asdoclet/generator/utils (added)
- trunk/src/org/fluffnstuff/asdoclet/generator/utils/GeneratorUtils.java (added)
- trunk/src/org/fluffnstuff/asdoclet/generator/velocity/ClassDescriptor.java (modified) (2 diffs)
- trunk/src/org/fluffnstuff/asdoclet/generator/velocity/Descriptor.java (modified) (2 diffs)
- trunk/src/org/fluffnstuff/asdoclet/generator/velocity/EnumDescriptor.java (modified) (1 diff)
- trunk/src/org/fluffnstuff/asdoclet/generator/velocity/FieldDescriptor.java (modified) (2 diffs)
- trunk/src/org/fluffnstuff/asdoclet/generator/velocity/InterfaceDescriptor.java (modified) (1 diff)
- trunk/src/org/fluffnstuff/asdoclet/generator/velocity/MethodDescriptor.java (modified) (3 diffs)
- trunk/src/org/fluffnstuff/asdoclet/generator/velocity/ParameterDescriptor.java (modified) (1 diff)
- trunk/src/org/fluffnstuff/asdoclet/generator/velocity/PropertyDescriptor.java (modified) (2 diffs)
- trunk/src/org/fluffnstuff/asdoclet/generator/velocity/ProxyDescriptor.java (modified) (1 diff)
- trunk/src/org/fluffnstuff/asdoclet/generator/velocity/TypeDescriptor.java (modified) (2 diffs)
- trunk/src/org/fluffnstuff/asdoclet/handler/AbstractHandler.java (modified) (7 diffs)
- trunk/src/org/fluffnstuff/asdoclet/handler/ClassHandler.java (modified) (2 diffs)
- trunk/src/org/fluffnstuff/asdoclet/handler/Constants.java (modified) (1 diff)
- trunk/src/org/fluffnstuff/asdoclet/handler/EnumHandler.java (modified) (1 diff)
- trunk/src/org/fluffnstuff/asdoclet/handler/InterfaceHandler.java (modified) (5 diffs)
- trunk/src/org/fluffnstuff/asdoclet/map/ClassTypeMap.java (modified) (1 diff)
- trunk/src/org/fluffnstuff/asdoclet/map/TypeMap.java (modified) (2 diffs)
Legend:
- Unmodified
- Added
- Removed
- Modified
- Copied
- Moved
trunk/out/templates/cs/class.vm
r33 r39 1 1 #* @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 4 5 #end 5 6 #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) 7 14 #end 8 15 #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#end16 #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 10 17 #end 11 18 #macro(params $descriptor) 12 #foreach($parameterDescriptor in $descriptor.parameterDescriptors)#if($velocityCount>1), #end $parameterDescriptor.qualifiedTypeName#generic($parameterDescriptor) $parameterDescriptor.parameterName#end19 #foreach($parameterDescriptor in $descriptor.parameterDescriptors)#if($velocityCount>1), #end#type($parameterDescriptor) $parameterDescriptor.parameterName#end 13 20 #end 14 21 #* 15 22 CLASS 16 23 *# 17 using System;18 19 24 namespace $typeDescriptor.nameSpace { 20 25 #if($typeDescriptor.description) /** … … 22 27 */ 23 28 #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) { 26 32 #foreach($fieldDescriptor in $typeDescriptor.fieldDescriptors) 27 33 #if($fieldDescriptor.description) /** … … 29 35 */ 30 36 #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; 32 38 #end 33 39 #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 } 35 41 #end 36 42 #foreach($methodDescriptor in $typeDescriptor.methodDescriptors) … … 39 45 */ 40 46 #end 41 $methodDescriptor.modifier $methodDescriptor.qualifiedTypeName#generic($methodDescriptor) ${methodDescriptor.methodName}(#params($methodDescriptor)) #if($methodDescriptor.body)$methodDescriptor.body47 $methodDescriptor.modifier #type($methodDescriptor) ${methodDescriptor.upperMethodName}(#params($methodDescriptor)) #if($methodDescriptor.body)$methodDescriptor.body 42 48 #else{} 43 49 #end trunk/out/templates/cs/enum.vm
r33 r39 1 1 #* @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 4 5 #end 5 6 #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) 7 14 #end 8 15 #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#end16 #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 10 17 #end 11 18 #macro(params $descriptor) 12 #foreach($parameterDescriptor in $descriptor.parameterDescriptors)#if($velocityCount>1), #end $parameterDescriptor.qualifiedTypeName#generic($parameterDescriptor) $parameterDescriptor.parameterName#end19 #foreach($parameterDescriptor in $descriptor.parameterDescriptors)#if($velocityCount>1), #end#type($parameterDescriptor) $parameterDescriptor.parameterName#end 13 20 #end 14 21 #* … … 20 27 */ 21 28 #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 23 32 24 33 $fieldDescriptor.fieldName#end trunk/out/templates/cs/interface.vm
r33 r39 1 1 #* @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 4 5 #end 5 6 #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) 7 14 #end 8 15 #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#end16 #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 10 17 #end 11 18 #macro(params $descriptor) 12 #foreach($parameterDescriptor in $descriptor.parameterDescriptors)#if($velocityCount>1), #end $parameterDescriptor.qualifiedTypeName#generic($parameterDescriptor) $parameterDescriptor.parameterName#end19 #foreach($parameterDescriptor in $descriptor.parameterDescriptors)#if($velocityCount>1), #end#type($parameterDescriptor) $parameterDescriptor.parameterName#end 13 20 #end 14 21 #* … … 20 27 */ 21 28 #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) { 23 32 #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 } 25 34 #end 26 35 … … 30 39 */ 31 40 #end 32 $methodDescriptor.modifier $methodDescriptor.qualifiedTypeName#generic($methodDescriptor) ${methodDescriptor.methodName}(#params($methodDescriptor));41 $methodDescriptor.modifier #type($methodDescriptor) ${methodDescriptor.upperMethodName}(#params($methodDescriptor)); 33 42 #end 34 43 } trunk/out/templates/cs/proxy.vm
r33 r39 1 1 #* @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 4 5 #end 5 6 #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) 7 14 #end 8 15 #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#end16 #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 10 17 #end 11 18 #macro(params $descriptor) 12 #foreach($parameterDescriptor in $descriptor.parameterDescriptors)#if($velocityCount>1), #end $parameterDescriptor.qualifiedTypeName#generic($parameterDescriptor) $parameterDescriptor.parameterName#end19 #foreach($parameterDescriptor in $descriptor.parameterDescriptors)#if($velocityCount>1), #end#type($parameterDescriptor) $parameterDescriptor.parameterName#end 13 20 #end 14 21 #* … … 20 27 */ 21 28 #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) { 23 32 protected virtual T dispatchCall<T>(string methodName, params object[] args) where T : class { 24 33 return null; … … 30 39 */ 31 40 #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)) { 33 42 #if($methodDescriptor.qualifiedTypeName == "void") 34 43 dispatchCall<object>("${methodDescriptor.methodName}"#foreach($parameterDescriptor in $methodDescriptor.parameterDescriptors), $parameterDescriptor.parameterName#end); 35 44 #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); 37 46 #end 38 47 } trunk/src/org/fluffnstuff/asdoclet/AsDoclet.java
r35 r39 32 32 33 33 for (ClassDoc classDoc : docs) { 34 System.out.println("Processing " + classDoc.qualifiedName()); 34 35 if (TagParser.hasClassTags(generator, classDoc)) { 35 36 Handler handler = createHandler(generator, classDoc); trunk/src/org/fluffnstuff/asdoclet/generator/AsGenerator.java
r33 r39 5 5 import java.text.MessageFormat; 6 6 import java.util.Collection; 7 import java.util. Map;7 import java.util.TreeSet; 8 8 9 9 import org.apache.commons.lang.StringUtils; 10 10 import org.fluffnstuff.asdoclet.handler.Constants; 11 11 import org.fluffnstuff.asdoclet.map.TypeMap; 12 import org.fluffnstuff.asdoclet.generator.utils.GeneratorUtils; 12 13 13 14 import uk.co.badgersinfoil.metaas.ActionScriptFactory; … … 19 20 import uk.co.badgersinfoil.metaas.dom.ASInterfaceType; 20 21 import uk.co.badgersinfoil.metaas.dom.ASMethod; 21 import uk.co.badgersinfoil.metaas.dom.ASPackage;22 22 import uk.co.badgersinfoil.metaas.dom.ASType; 23 23 import uk.co.badgersinfoil.metaas.dom.Visibility; … … 40 40 private TypeMap typeMap; 41 41 private TypeMap annotationMap; 42 private Map<String, String> bounds; 42 43 private Collection<String> imports; 44 private Collection<String> proxyImports; 43 45 44 46 public AsGenerator(String destination, String namespace, TypeMap typeMap, TypeMap annotationMap) { … … 81 83 } 82 84 85 public TypeMap getAnnotationMap() { 86 return annotationMap; 87 } 88 83 89 public TypeMap getTypeMap() { 84 90 return typeMap; … … 90 96 } 91 97 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); 109 116 110 117 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); 113 120 method.setOverride(override); 114 121 method.addStmt("return _" + propertyName + ";"); 115 122 } else { 116 beginMethod( modifier, fieldType, typeArguments, bounds, "get " + propertyName);123 beginMethod(classType, modifier, fieldType, "get " + propertyName); 117 124 } 118 125 … … 120 127 } 121 128 122 public void addInterface( Stringname) {129 public void addInterface(Type name) { 123 130 if (type instanceof ASInterfaceType) { 124 131 ASInterfaceType interfaceType = (ASInterfaceType) type; 125 interfaceType.addSuperInterface(name );132 interfaceType.addSuperInterface(name.getName()); 126 133 } else { 127 134 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); 141 151 142 152 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); 145 155 method.setOverride(override); 146 method.addParam("value", fieldType );156 method.addParam("value", fieldType.getName()); 147 157 method.addStmt("_" + propertyName + "=value;"); 148 158 } 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()); 151 161 } 152 162 … … 154 164 } 155 165 156 public void addTypeAnnotation( Stringtag) {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 170 180 newClass(name, true); 171 181 } 172 182 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()); 175 187 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()); 184 195 185 196 if (proxyUnit != null) { … … 187 198 createConst(eventType, proxyMethodName, MessageFormat.format("\"{0}\"", methodName), "String", null); 188 199 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()); 196 211 197 212 eventType = (ASClassType) eventUnit.getType(); 198 213 proxyType = (ASClassType) proxyUnit.getType(); 199 214 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()); 210 228 callMethod.addParam("name", "String"); 211 229 callMethod.addParam("...args", null); 212 230 callMethod.addStmt("throw new Error(\"Not Implemented\");"); 213 231 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()); 215 233 resultMethod.addParam("result", "Object"); 216 234 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()); 218 236 statusMethod.addParam("status", "Object"); 219 237 } 220 238 221 public void endClass( Collection<String> imports) {222 end Interface(imports);239 public void endClass() { 240 end(); 223 241 } 224 242 225 243 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(); 233 249 } 234 250 … … 247 263 } 248 264 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; 257 269 proxyUnit = null; 258 270 } … … 263 275 } 264 276 265 public String getAnnotation(String name, Collection<String> imports) {266 return annotationMap.getType(name, false, false, false, imports);267 }268 269 277 public String getName() { 270 278 return "actionscript"; 271 279 } 272 280 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; 276 288 } 277 289 … … 280 292 } 281 293 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()); 284 297 } 285 298 … … 296 309 297 310 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 } 298 317 } 299 318 … … 321 340 } 322 341 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()); 325 344 type = unit.getType(); 326 345 ((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()); 332 354 if (type != null) { 333 unit.getPackage().removeImport(type);334 unit.getPackage().addImport(type);355 name = type.getName(); 356 addImport(name); 335 357 } else { 336 type = "object";358 type = GeneratorUtils.getType(Object.class.getCanonicalName(), this); 337 359 } 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 } 342 370 } 343 371 } trunk/src/org/fluffnstuff/asdoclet/generator/Generator.java
r31 r39 1 1 package org.fluffnstuff.asdoclet.generator; 2 2 3 import java.util.Collection; 4 import java.util.Map; 3 import org.fluffnstuff.asdoclet.map.TypeMap; 5 4 6 5 public interface Generator { 7 6 void addBody(String body); 8 7 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); 10 9 11 void addEnumField( String name, String comment);10 void addEnumField(Type classType, String name, String comment); 12 11 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); 14 13 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); 16 15 17 void addInterface( String name);16 void addInterface(Type type); 18 17 19 void addParameter( String type, Collection<String> typeArguments, Map<String, String> bounds, String name);18 void addParameter(Type classType, Type type, String name); 20 19 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); 22 21 23 void addTypeAnnotation( String tag);22 void addTypeAnnotation(Type annotation); 24 23 25 void beginClass( String name, boolean bindable, Collection<String> typeArguments, Map<String, String> bounds);24 void beginClass(Type type); 26 25 27 void beginEnum( String name);26 void beginEnum(Type type); 28 27 29 void beginInterface( String name, Collection<String> typeArguments, Map<String, String> bounds);28 void beginInterface(Type type); 30 29 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); 32 31 33 void beginProxy( String proxyName, Collection<String> typeArguments, Map<String, String> bounds, String returnType, String baseType, Collection<String> proxyImports, StringinterfaceType);32 void beginProxy(Type type, Type returnType, Type baseType, Type interfaceType); 34 33 35 void endClass( Collection<String> imports);34 void endClass(); 36 35 37 36 void endEnum(); 38 37 39 void endInterface( Collection<String> imports);38 void endInterface(); 40 39 41 40 void endMethod(); 42 41 43 void endProxy( Collection<String> proxyImports);42 void endProxy(); 44 43 45 44 void generate() throws Exception; 46 45 47 String getAnnotation(String name, Collection<String> imports);46 TypeMap getAnnotationMap(); 48 47 49 48 String getName(); 50 49 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); 52 55 53 56 void setMethodDescription(String description); 54 57 55 void setSuperclass( String name, boolean exception);58 void setSuperclass(Type type, boolean exception); 56 59 57 60 void setTypeDescription(String description); trunk/src/org/fluffnstuff/asdoclet/generator/VelocityGenerator.java
r33 r39 8 8 import java.util.Collection; 9 9 import java.util.Map; 10 import java.util.HashMap;11 10 12 11 import org.apache.commons.lang.StringUtils; … … 23 22 import org.fluffnstuff.asdoclet.generator.velocity.ProxyDescriptor; 24 23 import org.fluffnstuff.asdoclet.generator.velocity.TypeDescriptor; 25 import org.fluffnstuff.asdoclet. handler.Constants;24 import org.fluffnstuff.asdoclet.generator.utils.GeneratorUtils; 26 25 import org.fluffnstuff.asdoclet.map.TypeMap; 27 26 … … 42 41 private TypeMap annotationMap; 43 42 private TypeMap typeMap; 44 private Map<String, TypeDescriptor> genericTypes = new HashMap<String, TypeDescriptor>();45 43 46 44 public VelocityGenerator(String destination, String namespace, String language, TypeMap typeMap, TypeMap annotationMap) throws Exception { … … 91 89 } 92 90 91 public TypeMap getAnnotationMap() { 92 return annotationMap; 93 } 94 95 public TypeMap getTypeMap() { 96 return typeMap; 97 } 98 93 99 // --------------------- Interface Generator --------------------- 94 100 … … 97 103 } 98 104 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); 109 115 setFieldDescription(comment); 110 116 … … 112 118 } 113 119 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); 116 122 propertyDescriptor.setGetter(true); 117 123 propertyDescriptor.setOverride(propertyDescriptor.isOverride() || override); … … 120 126 121 127 if (typeDescriptor instanceof ClassDescriptor) { 122 addField( Modifier.PRIVATE, returnType, typeArguments, bounds, propertyName, null, description);123 } 124 } 125 126 public void addInterface( Stringname) {128 addField(classType, Modifier.PRIVATE, returnType, propertyName, null, description); 129 } 130 } 131 132 public void addInterface(Type name) { 127 133 typeDescriptor.addInterface(name); 128 134 } 129 135 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); 132 138 methodDescriptor.addParameterDescriptor(parameterDescriptor); 133 139 } 134 140 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); 137 143 propertyDescriptor.setSetter(true); 138 144 propertyDescriptor.setOverride(propertyDescriptor.isOverride() || override); … … 141 147 142 148 if (typeDescriptor instanceof ClassDescriptor) { 143 addField( Modifier.PRIVATE, returnType, typeArguments, bounds, propertyName, null, description);144 } 145 } 146 147 public void addTypeAnnotation( Stringannotation) {149 addField(classType, Modifier.PRIVATE, returnType, propertyName, null, description); 150 } 151 } 152 153 public void addTypeAnnotation(Type annotation) { 148 154 typeDescriptor.addAnnotation(annotation); 149 155 } 150 156 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); 166 172 if (proxyTypeDescriptor != null) proxyTypeDescriptor.addMethodDescriptor(methodDescriptor); 167 173 } 168 174 169 public void beginProxy( String proxyName, Collection<String> typeArguments, Map<String, String> bounds, String returnType, String baseType, Collection<String> proxyImports, StringinterfaceType) {170 proxyTypeDescriptor = new ProxyDescriptor(proxy Name, typeArguments, bounds);175 public void beginProxy(Type proxy, Type returnType, Type baseType, Type interfaceType) { 176 proxyTypeDescriptor = new ProxyDescriptor(proxy); 171 177 proxyTypeDescriptor.addInterface(interfaceType); 172 178 173 if (baseType != null) { 174 proxyTypeDescriptor.setSuperclass(baseType); 175 proxyImports.add(baseType); 176 } 179 if (baseType != Type.NULL) proxyTypeDescriptor.setSuperclass(baseType); 177 180 178 181 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() { 184 185 typeDescriptor = null; 185 186 } … … 189 190 } 190 191 191 public void endInterface( Collection<String> imports) {192 public void endInterface() { 192 193 typeDescriptor = null; 193 194 } … … 197 198 } 198 199 199 public void endProxy( Collection<String> proxyImports) {200 public void endProxy() { 200 201 proxyTypeDescriptor = null; 201 202 } … … 221 222 Template template = Velocity.getTemplate("templates/" + language + "/" + s); 222 223 223 context.put("genericTypes", genericTypes);224 224 context.put("typeDescriptor", descriptor); 225 225 template.merge(context, writer); … … 228 228 } 229 229 230 public String getAnnotation(String name, Collection<String> imports) {231 return annotationMap.getType(name, false, false, false, imports);232 }233 234 230 public String getName() { 235 231 return language; 236 232 } 237 233 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) { 242 239 return type; 243 240 } … … 247 244 } 248 245 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); 251 248 252 249 if (exception && CSHARP.equals(language)) { 253 beginMethod( Modifier.PUBLIC, "", null, null, typeDescriptor.getTypeName());250 beginMethod(type, Modifier.PUBLIC, Type.EMPTY, typeDescriptor.getTypeName()); 254 251 addBody(" : base() {}"); 255 252 endMethod(); 256 253 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"); 259 256 addBody(" : base(message) {}"); 260 257 endMethod(); 261 258 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"); 265 262 addBody(" : base(message, exception) {}"); 266 263 endMethod(); … … 275 272 this.typeDescriptor = typeDescriptor; 276 273 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); 279 278 } 280 279 trunk/src/org/fluffnstuff/asdoclet/generator/velocity/ClassDescriptor.java
r31 r39 2 2 3 3 import java.util.Collection; 4 import java.util.Map; 4 5 import org.fluffnstuff.asdoclet.generator.Type; 5 6 6 7 public class ClassDescriptor extends TypeDescriptor { 7 private StringsuperClass;8 private Type superClass; 8 9 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); 11 12 } 12 13 13 public StringgetSuperClass() {14 public Type getSuperClass() { 14 15 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; 15 26 } 16 27 … … 19 30 } 20 31 21 public void setSuperclass( StringsuperClass) {32 public void setSuperclass(Type superClass) { 22 33 this.superClass = superClass; 23 34 } trunk/src/org/fluffnstuff/asdoclet/generator/velocity/Descriptor.java
r31 r39 3 3 import java.util.ArrayList; 4 4 import java.util.Collection; 5 import java.util.Map;6 5 7 import org. apache.commons.lang.ClassUtils;6 import org.fluffnstuff.asdoclet.generator.Type; 8 7 9 public class Descriptor { 10 private String typeName; 8 public class Descriptor extends Type { 11 9 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>(); 15 11 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()); 20 14 } 21 15 22 public Collection< String> getAnnotations() {16 public Collection<Type> getAnnotations() { 23 17 return annotations; 24 }25 26 public Map<String, String> getBounds() {27 return bounds;28 18 } 29 19 … … 36 26 } 37 27 38 public Collection<String> getTypeArguments() { 39 return typeArguments; 40 } 41 42 public void addAnnotation(String annotation) { 28 public void addAnnotation(Type annotation) { 43 29 annotations.add(annotation); 44 30 } 45 31 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); 56 35 } 57 36 } trunk/src/org/fluffnstuff/asdoclet/generator/velocity/EnumDescriptor.java
r31 r39 1 1 package org.fluffnstuff.asdoclet.generator.velocity; 2 2 3 import org.fluffnstuff.asdoclet.generator.Type; 4 3 5 public class EnumDescriptor extends TypeDescriptor { 4 public EnumDescriptor( StringtypeName) {5 super(typeName , null, null);6 public EnumDescriptor(Type typeName) { 7 super(typeName); 6 8 } 7 9 trunk/src/org/fluffnstuff/asdoclet/generator/velocity/FieldDescriptor.java
r31 r39 2 2 3 3 import java.lang.reflect.Modifier; 4 import java.util.Collection; 5 import java.util.Map;4 5 import org.fluffnstuff.asdoclet.generator.Type; 6 6 7 7 public class FieldDescriptor extends Descriptor { … … 10 10 private int modifier; 11 11 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); 14 14 15 15 this.fieldName = fieldName; trunk/src/org/fluffnstuff/asdoclet/generator/velocity/InterfaceDescriptor.java
r31 r39 1 1 package org.fluffnstuff.asdoclet.generator.velocity; 2 2 3 import java.util.Collection; 4 import java.util.Map; 3 import org.fluffnstuff.asdoclet.generator.Type; 5 4 6 5 public class InterfaceDescriptor extends TypeDescriptor { 7 public InterfaceDescriptor( String typeName, Collection<String> typeArguments, Map<String, String> bounds) {8 super(type Name, typeArguments, bounds);6 public InterfaceDescriptor(Type type) { 7 super(type); 9 8 } 10 9 trunk/src/org/fluffnstuff/asdoclet/generator/velocity/MethodDescriptor.java
r31 r39 3 3 import java.util.ArrayList; 4 4 import java.util.Collection; 5 import java.util.Map; 5 6 import org.fluffnstuff.asdoclet.generator.Type; 6 7 7 8 public class MethodDescriptor extends FieldDescriptor { … … 9 10 private String body; 10 11 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); 13 14 } 14 15 … … 29 30 } 30 31 32 @Override 33 public Collection<String> getImportsInternal() { 34 return addImports(super.getImportsInternal(), parameterDescriptors); 35 } 36 31 37 public String getMethodName() { 32 38 return getFieldName(); 33 39 } 40 41 public String getUpperMethodName() { 42 return getPropertyName(); 43 } 34 44 } trunk/src/org/fluffnstuff/asdoclet/generator/velocity/ParameterDescriptor.java
r31 r39 1 1 package org.fluffnstuff.asdoclet.generator.velocity; 2 2 3 import java.util.Collection; 4 import java.util.Map; 3 import org.fluffnstuff.asdoclet.generator.Type; 5 4 6 5 public class ParameterDescriptor extends Descriptor { 7 6 private String parameterName; 8 7 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); 11 10 this.parameterName = parameterName; 12 11 } trunk/src/org/fluffnstuff/asdoclet/generator/velocity/PropertyDescriptor.java
r31 r39 2 2 3 3 import java.lang.reflect.Modifier; 4 import java.util.Collection; 5 import java.util.Map;4 5 import org.fluffnstuff.asdoclet.generator.Type; 6 6 7 7 public class PropertyDescriptor extends Descriptor { … … 12 12 private boolean override; 13 13 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); 16 16 17 17 this.fieldName = fieldName; trunk/src/org/fluffnstuff/asdoclet/generator/velocity/ProxyDescriptor.java
r31 r39 1 1 package org.fluffnstuff.asdoclet.generator.velocity; 2 2 3 import java.util.Collection; 4 import java.util.Map; 3 import org.fluffnstuff.asdoclet.generator.Type; 5 4 6 5 public 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); 9 8 } 10 9 trunk/src/org/fluffnstuff/asdoclet/generator/velocity/TypeDescriptor.java
r33 r39 6 6 import java.util.Map; 7 7 8 import org.fluffnstuff.asdoclet.generator.Type; 9 8 10 public abstract class TypeDescriptor extends Descriptor { 9 11 private Map<String, PropertyDescriptor> propertyDescriptors = new LinkedHashMap<String, PropertyDescriptor>(); 10 12 private Map<String, FieldDescriptor> fieldDescriptors = new LinkedHashMap<String, FieldDescriptor>(); 11 13 private Collection<MethodDescriptor> methodDescriptors = new ArrayList<MethodDescriptor>(); 12 private Collection< String> interfaces = new ArrayList<String>();14 private Collection<Type> interfaces = new ArrayList<Type>(); 13 15 14 public TypeDescriptor( String typeName, Collection<String> typeArguments, Map<String, String> bounds) {15 super(type Name, typeArguments, bounds);16 public TypeDescriptor(Type type) { 17 super(type); 16 18 } 17 19 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() { 19 33 return interfaces; 20 34 } … … 28 42 } 29 43 30 public void addInterface( StringinterfaceName) {44 public void addInterface(Type interfaceName) { 31 45 interfaces.add(interfaceName); 32 46 } trunk/src/org/fluffnstuff/asdoclet/handler/AbstractHandler.java
r33 r39 3 3 import java.beans.Introspector; 4 4 import java.lang.reflect.Modifier; 5 import java.util.ArrayList;6 import java.util.Collection;7 5 import java.util.HashMap; 8 6 import java.util.Map; 9 7 10 8 import org.fluffnstuff.asdoclet.generator.Generator; 9 import org.fluffnstuff.asdoclet.generator.utils.GeneratorUtils; 11 10 12 11 import com.sun.javadoc.AnnotationDesc; … … 15 14 import com.sun.javadoc.FieldDoc; 16 15 import com.sun.javadoc.MethodDoc; 17 import com.sun.javadoc.ParameterizedType;18 16 import com.sun.javadoc.Type; 19 17 … … 45 43 } 46 44 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); 52 48 53 if (args == null) args = new ArrayList<String>(); 54 args.add(type); 49 boolean ignoreProperty = TagParser.getBooleanCommand(Constants.COMMAND_IGNORE, commands); 55 50 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); 61 56 62 protected int getDimensions(Type returnType) {63 return returnType.dimension().length() / 2;64 }57 if (fieldType == null) { 58 fieldType = GeneratorUtils.getType(returnType, getGenerator()); 59 } 65 60 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(); 69 63 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); 115 66 116 67 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); 126 76 } 127 77 } … … 140 90 } 141 91 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) { 143 93 String overriddenType = TagParser.getStringCommand(Constants.COMMAND_TYPE, methodCommands); 144 StringfieldType;94 org.fluffnstuff.asdoclet.generator.Type fieldType; 145 95 146 96 if (overriddenType == null) { 147 fieldType = checkAnnotations( imports,methodDoc.annotations());97 fieldType = checkAnnotations(methodDoc.annotations()); 148 98 149 99 if (fieldType == null && fieldDoc != null) { 150 fieldType = checkAnnotations( imports,fieldDoc.annotations());100 fieldType = checkAnnotations(fieldDoc.annotations()); 151 101 } 152 102 } else { 153 if (overriddenType.contains(".")) imports.add(overriddenType); 154 fieldType = overriddenType; 103 fieldType = GeneratorUtils.getType(overriddenType, getGenerator()); 155 104 } 156 105 … … 158 107 } 159 108 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 162 112 for (AnnotationDesc annotationDesc : annotationDescs) { 163 113 AnnotationTypeDoc annotationTypeDoc = annotationDesc.annotationType(); 164 fieldType = getGenerator().getAnnotation(annotationTypeDoc.qualifiedTypeName(), imports);114 fieldType = GeneratorUtils.getAnnotation(annotationTypeDoc.qualifiedTypeName(), getGenerator()); 165 115 if (fieldType != null) break; 166 116 } … … 179 129 180 130 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;195 131 } 196 132 … … 227 163 getGenerator().setTypeDescription(description.toString()); 228 164 } 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 } 229 175 } trunk/src/org/fluffnstuff/asdoclet/handler/ClassHandler.java
r31 r39 1 1 package org.fluffnstuff.asdoclet.handler; 2 2 3 import java.util.Collection;4 import java.util.HashMap;5 3 import java.util.Map; 6 import java.util. TreeSet;4 import java.util.StringTokenizer; 7 5 8 6 import org.fluffnstuff.asdoclet.generator.Generator; 7 import org.fluffnstuff.asdoclet.generator.utils.GeneratorUtils; 9 8 10 9 import com.sun.javadoc.ClassDoc; 11 10 import com.sun.javadoc.FieldDoc; 11 import com.sun.javadoc.MethodDoc; 12 12 import com.sun.javadoc.Type; 13 13 … … 20 20 21 21 public void process(ClassDoc classDoc) { 22 Collection<String> imports = new TreeSet<String>();23 22 Map<String, String> commands = TagParser.processClassTags(getGenerator(), classDoc); 24 23 25 boolean bindable = TagParser.getBooleanCommand(Constants.COMMAND_BINDABLE, commands);26 24 String ignore = TagParser.getStringCommand(Constants.COMMAND_IGNORE, "", commands); 27 25 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()); 31 27 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); 34 39 processClassComment(classDoc); 35 processClassConstants( classDoc, imports);36 processBeanProperties( classDoc, imports, commands);40 processClassConstants(type, classDoc); 41 processBeanProperties(type, classDoc, commands); 37 42 38 getGenerator().endClass( imports);43 getGenerator().endClass(); 39 44 } 40 45 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) { 42 53 for (FieldDoc fieldDoc : classDoc.fields()) { 43 54 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()); 49 57 } 50 58 } 51 59 } 52 60 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()); 61 65 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)); 72 68 } 73 69 } trunk/src/org/fluffnstuff/asdoclet/handler/Constants.java
r17 r39 2 2 3 3 final 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"; 7 7 8 public static final String COMMAND_BEAN = "bean";8 public static final String COMMAND_BEAN = "bean"; 9 9 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"; 12 12 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"; 16 16 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"; 20 20 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"; 24 24 25 public static final String TYPE_VOID = "void"; 26 27 private Constants() { 28 } 25 private Constants() { 26 } 29 27 } trunk/src/org/fluffnstuff/asdoclet/handler/EnumHandler.java
r11 r39 3 3 import com.sun.javadoc.ClassDoc; 4 4 import com.sun.javadoc.FieldDoc; 5 5 6 import org.fluffnstuff.asdoclet.generator.Generator; 7 import org.fluffnstuff.asdoclet.generator.Type; 8 import org.fluffnstuff.asdoclet.generator.utils.GeneratorUtils; 6 9 7 10 public class EnumHandler extends AbstractHandler { 8 public EnumHandler(Generator generator) {9 super(generator);10 }11 public EnumHandler(Generator generator) { 12 super(generator); 13 } 11 14 12 15 // --------------------- Interface Handler --------------------- 13 16 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()); 18 19 19 getGenerator().endEnum(); 20 } 20 getGenerator().beginEnum(type); 21 processClassComment(classDoc); 22 processEnumConstants(type, classDoc); 21 23 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 } 25 30 } trunk/src/org/fluffnstuff/asdoclet/handler/InterfaceHandler.java
r37 r39 1 1 package org.fluffnstuff.asdoclet.handler; 2 2 3 import java.util.Collection;4 3 import java.util.HashMap; 5 4 import java.util.Map; 6 import java.util.TreeSet;7 5 8 6 import org.fluffnstuff.asdoclet.generator.Generator; 7 import org.fluffnstuff.asdoclet.generator.utils.GeneratorUtils; 9 8 10 9 import com.sun.javadoc.ClassDoc; … … 25 24 commands.putAll(TagParser.processClassTags(getGenerator(), classDoc)); 26 25 27 Collection<String> imports = new TreeSet<String>();28 Collection<String> proxyImports = new TreeSet<String>();29 30 26 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()); 32 29 33 30 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()); 38 32 String proxyName = TagParser.getStringCommand(Constants.COMMAND_PROXY_NAME, interfaceName + "Proxy", commands); 39 33 String baseType = TagParser.getStringCommand(Constants.COMMAND_PROXY_BASE_CLASS, commands); 40 34 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); 43 38 } 44 39 45 processInterfaceInternal(classDoc, asyncReturnType, commands, proxyImports, imports);40 processInterfaceInternal(classDoc, type2, commands); 46 41 47 42 if (proxy) { 48 proxyImports.addAll(imports);49 getGenerator().endProxy( proxyImports);43 traverseInterfaces(classDoc, commands, type2); 44 getGenerator().endProxy(); 50 45 } 51 46 } 52 47 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) { 54 49 Map<String, String> commands = new HashMap<String, String>(); 55 String interfaceName = classDoc.qualifiedTypeName();56 50 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()); 59 52 60 53 if (parentCommands != null) commands.putAll(parentCommands); … … 63 56 boolean bean = TagParser.getBooleanCommand(Constants.COMMAND_BEAN, commands); 64 57 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); 72 59 73 60 processClassComment(classDoc); 74 processInterfaces(classDoc, commands, imports); 61 processInterfaces(classDoc, commands); 62 processMethods(classDoc, interfaceName, commands, asyncReturnType, bean); 75 63 76 getGenerator().endInterface(imports); 77 78 traverseInterfaces(classDoc, commands, asyncReturnType, proxyImports, imports); 64 getGenerator().endInterface(); 79 65 } 80 66 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) { 82 68 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); 84 71 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 } 90 77 } 91 78 } 92 79 93 private void processMethod( MethodDoc methodDoc, Map<String, String> commands, Collection<String> imports, String returnType, Collection<String> typeArguments, Map<String, String> bounds, StringasyncReturnType) {80 private void processMethod(ClassDoc classDoc, org.fluffnstuff.asdoclet.generator.Type classType, MethodDoc methodDoc, Map<String, String> commands, org.fluffnstuff.asdoclet.generator.Type asyncReturnType) { 94 81 Map<String, String> methodCommands = new HashMap<String, String>(commands); 82 org.fluffnstuff.asdoclet.generator.Type returnType = GeneratorUtils.getType(methodDoc.returnType(), getGenerator()); 95 83 96 84 TagParser.processTags(methodDoc.tags(getGenerator().getName() + Constants.TAG_METHOD), methodCommands); … … 101 89 if (!ignore) { 102 90 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()); 105 92 } else { 106 getGenerator().beginMethod( 0, returnType, typeArguments, bounds, methodDoc.name());93 getGenerator().beginMethod(classType, 0, returnType, methodDoc.name()); 107 94 } 108 95 109 96 for (Parameter parameter : methodDoc.parameters()) { 110 97 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()); 115 101 } 116 102 … … 131 117 } 132 118 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()); 143 123 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); 151 134 } 152 135 } trunk/src/org/fluffnstuff/asdoclet/map/ClassTypeMap.java
r20 r39 1 1 package org.fluffnstuff.asdoclet.map; 2 3 import java.util.Collection;4 2 5 3 public class ClassTypeMap extends TypeMap { 6 4 @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) { 8 6 String asType = getRawType(typeName, generic, enumeration); 9 7 10 8 if (asType == null) { 11 if (imports != null && !primitive) imports.add(typeName);12 9 asType = typeName; 13 10 } trunk/src/org/fluffnstuff/asdoclet/map/TypeMap.java
r20 r39 1 1 package org.fluffnstuff.asdoclet.map; 2 2 3 import java.util.Collection;4 3 import java.util.HashMap; 5 4 import java.util.Map; … … 22 21 } 23 22 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) { 25 24 return getRawType(typeName, generic, enumeration); 26 25 }