Changeset 6
- Timestamp:
- 07/17/08 16:52:03 (4 years ago)
- Files:
-
- trunk/out/templates/cs/class.vm (modified) (1 diff)
- trunk/out/templates/cs/enum.vm (modified) (1 diff)
- trunk/out/templates/cs/interface.vm (modified) (1 diff)
- trunk/src/org/fluffnstuff/asdoclet/AsDoclet.java (modified) (5 diffs)
- trunk/src/org/fluffnstuff/asdoclet/generator/AsGenerator.java (modified) (3 diffs)
- trunk/src/org/fluffnstuff/asdoclet/generator/Generator.java (modified) (1 diff)
- trunk/src/org/fluffnstuff/asdoclet/generator/VelocityGenerator.java (modified) (4 diffs)
- trunk/src/org/fluffnstuff/asdoclet/handler/AbstractHandler.java (modified) (2 diffs)
- trunk/src/org/fluffnstuff/asdoclet/handler/ClassHandler.java (modified) (5 diffs)
- trunk/src/org/fluffnstuff/asdoclet/handler/EnumHandler.java (modified) (1 diff)
- trunk/src/org/fluffnstuff/asdoclet/handler/InterfaceHandler.java (modified) (6 diffs)
- trunk/src/org/fluffnstuff/asdoclet/map/ClassTypeMap.java (modified) (1 diff)
- trunk/src/org/fluffnstuff/asdoclet/map/TypeMap.java (modified) (3 diffs)
- trunk/src/org/fluffnstuff/asdoclet/util (added)
- trunk/src/org/fluffnstuff/asdoclet/util/EnumUtil.java (added)
Legend:
- Unmodified
- Added
- Removed
- Modified
- Copied
- Moved
trunk/out/templates/cs/class.vm
r5 r6 1 namespace $classDescriptor.nameSpace { 2 public class $classDescriptor.typeName { 3 #foreach($fieldDescriptor in $classDescriptor.fieldDescriptors) 4 $fieldDescriptor.modifier $fieldDescriptor.typeName $fieldDescriptor.fieldName { set; get; }; 1 namespace $typeDescriptor.nameSpace { 2 #if($typeDescriptor.description) /** 3 * $typeDescriptor.description 4 */ 5 #end 6 public class $typeDescriptor.typeName#if($typeDescriptor.superClass) : $typeDescriptor.superClass#foreach($interface in $typeDescriptor.interfaces), $interface#end#else#foreach($interface in $typeDescriptor.interfaces)#if($velocityCount == 1) : #{else}, #end$interface#end#end { 7 #foreach($fieldDescriptor in $typeDescriptor.fieldDescriptors) 8 $fieldDescriptor.modifier $fieldDescriptor.qualifiedTypeName $fieldDescriptor.fieldName; 5 9 #end 6 10 7 #foreach($methodDescriptor in $classDescriptor.methodDescriptors) 8 $methodDescriptor.modifier $methodDescriptor.typeName {$methodDescriptor.methodName}() {} 11 #foreach($methodDescriptor in $typeDescriptor.methodDescriptors) 12 #if($methodDescriptor.description) /** 13 * $methodDescriptor.description 14 */ 9 15 #end 10 } 16 $methodDescriptor.modifier $methodDescriptor.qualifiedTypeName ${methodDescriptor.methodName}(#foreach($parameterDescriptor in $methodDescriptor.parameterDescriptors)#if($velocityCount>1), #end$parameterDescriptor.qualifiedTypeName $parameterDescriptor.parameterName#end); 17 #end 18 } 11 19 } trunk/out/templates/cs/enum.vm
r5 r6 1 namespace $ classDescriptor.nameSpace {2 public enum $classDescriptor.typeName { 3 #foreach($fieldDescriptor in $classDescriptor.fieldDescriptors)#if($velocityCounter>1),#end 4 $fieldDescriptor.fieldName 1 namespace $typeDescriptor.nameSpace { 2 #if($typeDescriptor.description) /** 3 * $typeDescriptor.description 4 */ 5 5 #end 6 } 6 public enum $typeDescriptor.typeName {#foreach($fieldDescriptor in $typeDescriptor.fieldDescriptors)#if($velocityCount>1), #end 7 8 $fieldDescriptor.fieldName#end 9 10 } 7 11 } trunk/out/templates/cs/interface.vm
r5 r6 1 namespace $ classDescriptor.nameSpace {2 public interface $classDescriptor.typeName { 3 #foreach($methodDescriptor in $classDescriptor.methodDescriptors) 4 $methodDescriptor.modifier $methodDescriptor.typeName ${methodDescriptor.methodName}() {} 1 namespace $typeDescriptor.nameSpace { 2 #if($typeDescriptor.description) /** 3 * $typeDescriptor.description 4 */ 5 5 #end 6 } 6 public interface $typeDescriptor.typeName#foreach($interface in $typeDescriptor.interfaces)#if($velocityCount == 1) : #{else}, #end$interface#end { 7 #foreach($methodDescriptor in $typeDescriptor.methodDescriptors) 8 #if($methodDescriptor.description) /** 9 * $methodDescriptor.description 10 */ 11 #end 12 $methodDescriptor.modifier $methodDescriptor.qualifiedTypeName ${methodDescriptor.methodName}(#foreach($parameterDescriptor in $methodDescriptor.parameterDescriptors)#if($velocityCount>1), #end$parameterDescriptor.qualifiedTypeName $parameterDescriptor.parameterName#end); 13 #end 14 } 7 15 } trunk/src/org/fluffnstuff/asdoclet/AsDoclet.java
r5 r6 10 10 import org.fluffnstuff.asdoclet.map.ClassTypeMap; 11 11 import org.fluffnstuff.asdoclet.map.TypeMap; 12 import org.fluffnstuff.asdoclet.util.EnumUtil; 12 13 13 14 public class AsDoclet { … … 17 18 private static final String PARAM_MAP = "-map"; 18 19 private static final String PARAM_ANNOTATION_MAP = "-annotationmap"; 19 20 private static final ClassTypeMap typeMap = new ClassTypeMap();21 private static final TypeMap annotationMap = new TypeMap();22 20 23 21 public static boolean start(RootDoc root) throws Exception { … … 41 39 String generator = null; 42 40 41 ClassTypeMap typeMap = new ClassTypeMap(); 42 TypeMap annotationMap = new TypeMap(); 43 43 44 for (String[] opt : options) { 44 45 if (opt[0].equals(PARAM_DESTINATION)) destination = opt[1]; … … 56 57 57 58 if ("actionscript".equals(generator)) { 58 return new AsGenerator(destination, namespace );59 return new AsGenerator(destination, namespace, typeMap, annotationMap); 59 60 } else if ("cs".equals(generator)) { 60 return new VelocityGenerator(destination, namespace, "cs" );61 return new VelocityGenerator(destination, namespace, "cs", typeMap, annotationMap); 61 62 } 62 63 return null; … … 67 68 68 69 if (classDoc.isInterface()) { 69 handler = new InterfaceHandler(generator , typeMap, annotationMap);70 } else if ( typeMap.isEnum(classDoc.qualifiedTypeName())) {71 handler = new EnumHandler(generator , typeMap, annotationMap);70 handler = new InterfaceHandler(generator); 71 } else if (EnumUtil.isEnum(classDoc.qualifiedTypeName())) { 72 handler = new EnumHandler(generator); 72 73 } else { 73 handler = new ClassHandler(generator , typeMap, annotationMap);74 handler = new ClassHandler(generator); 74 75 } 75 76 trunk/src/org/fluffnstuff/asdoclet/generator/AsGenerator.java
r5 r6 2 2 3 3 import org.fluffnstuff.asdoclet.handler.Constants; 4 import org.fluffnstuff.asdoclet.map.TypeMap; 4 5 import uk.co.badgersinfoil.metaas.ActionScriptFactory; 5 6 import uk.co.badgersinfoil.metaas.ActionScriptProject; … … 28 29 private ASField field; 29 30 30 public AsGenerator(String destination, String namespace) { 31 private TypeMap typeMap; 32 private TypeMap annotationMap; 33 34 public AsGenerator(String destination, String namespace, TypeMap typeMap, TypeMap annotationMap) { 35 this.typeMap = typeMap; 36 this.annotationMap = annotationMap; 37 31 38 project = factory.newEmptyASProject(destination); 39 40 initTypeMap(); 41 } 42 43 private void initTypeMap() { 44 typeMap.setEnumType("String"); 45 46 typeMap.addTypeMapping("boolean", "Boolean"); 47 typeMap.addTypeMapping("byte", "Number"); 48 typeMap.addTypeMapping("double", "Number"); 49 typeMap.addTypeMapping("float", "Number"); 50 typeMap.addTypeMapping("long", "Number"); 51 typeMap.addTypeMapping("short", "Number"); 52 53 // those need to be 'Object's since 'Number's cannot be null 54 typeMap.addTypeMapping("java.lang.Boolean", "Object"); 55 typeMap.addTypeMapping("java.lang.Byte", "Object"); 56 typeMap.addTypeMapping("java.lang.Double", "Object"); 57 typeMap.addTypeMapping("java.lang.Float", "Object"); 58 typeMap.addTypeMapping("java.lang.Integer", "Object"); 59 typeMap.addTypeMapping("java.lang.Long", "Object"); 60 typeMap.addTypeMapping("java.lang.Number", "Object"); 61 typeMap.addTypeMapping("java.lang.Short", "Object"); 62 63 typeMap.addTypeMapping("java.lang.String", "String"); 64 65 typeMap.addTypeMapping("java.util.Collection", "Array"); 66 typeMap.addTypeMapping("java.util.Date", "Date"); 67 typeMap.addTypeMapping("java.util.List", "Array"); 68 typeMap.addTypeMapping("java.util.Map", "Array"); 69 typeMap.addTypeMapping("java.util.Set", "Array"); 32 70 } 33 71 … … 159 197 } 160 198 199 public String getAnnotation(String name, Collection<String> imports) { 200 return annotationMap.getType(name, false, imports); 201 } 202 161 203 public String getName() { 162 204 return "actionscript"; 205 } 206 207 public String getType(String name, boolean primitive, Collection<String> imports) { 208 return typeMap.getType(name, primitive, imports); 163 209 } 164 210 trunk/src/org/fluffnstuff/asdoclet/generator/Generator.java
r5 r6 38 38 void generate() throws Exception; 39 39 40 String getAnnotation(String name, Collection<String> imports); 41 40 42 String getName(); 43 44 String getType(String name, boolean primitive, Collection<String> imports); 41 45 42 46 void setFieldDescription(String description); trunk/src/org/fluffnstuff/asdoclet/generator/VelocityGenerator.java
r5 r6 7 7 import org.fluffnstuff.asdoclet.generator.velocity.*; 8 8 import org.fluffnstuff.asdoclet.handler.Constants; 9 import org.fluffnstuff.asdoclet.map.TypeMap; 9 10 10 11 import java.io.File; … … 27 28 private MethodDescriptor methodDescriptor; 28 29 private ParameterDescriptor parameterDescriptor; 29 30 public VelocityGenerator(String destination, String namespace, String language) throws Exception { 30 private TypeMap annotationMap; 31 private TypeMap typeMap; 32 33 public VelocityGenerator(String destination, String namespace, String language, TypeMap typeMap, TypeMap annotationMap) throws Exception { 31 34 this.destination = new File(destination); 32 35 this.namespace = namespace; 33 36 this.language = language; 37 this.typeMap = typeMap; 38 this.annotationMap = annotationMap; 34 39 35 40 Velocity.setProperty(Velocity.RESOURCE_LOADER, "class"); 36 41 Velocity.setProperty("class.resource.loader.class", "org.apache.velocity.runtime.resource.loader.ClasspathResourceLoader"); 37 42 Velocity.init(); 43 44 initTypeMap(); 45 } 46 47 private void initTypeMap() { 48 if ("cs".equals(language)) { 49 initCsTypeMap(); 50 } 51 } 52 53 private void initCsTypeMap() { 54 typeMap.addTypeMapping("boolean", "bool"); 55 56 typeMap.addTypeMapping("java.lang.Boolean", "bool?"); 57 typeMap.addTypeMapping("java.lang.Byte", "byte?"); 58 typeMap.addTypeMapping("java.lang.Double", "double?"); 59 typeMap.addTypeMapping("java.lang.Float", "float?"); 60 typeMap.addTypeMapping("java.lang.Integer", "int?"); 61 typeMap.addTypeMapping("java.lang.Long", "long?"); 62 typeMap.addTypeMapping("java.lang.Number", "long?"); 63 typeMap.addTypeMapping("java.lang.Short", "short?"); 64 typeMap.addTypeMapping("java.lang.Object", "object"); 65 typeMap.addTypeMapping("java.lang.String", "System.String"); 66 typeMap.addTypeMapping("java.lang.Exception", "System.Exception"); 67 68 typeMap.addTypeMapping("java.util.Date", "System.DateTime"); 69 typeMap.addTypeMapping("java.util.Collection", "System.Collections.ICollection"); 70 typeMap.addTypeMapping("java.util.List", "System.Collections.IList"); 71 typeMap.addTypeMapping("java.util.Map", "System.Collections.IDictionary"); 72 typeMap.addTypeMapping("java.util.Set", "System.Collections.ICollection"); 38 73 } 39 74 … … 143 178 144 179 VelocityContext context = new VelocityContext(); 145 String s = typeDescriptor.getTemplate();180 String s = descriptor.getTemplate(); 146 181 Template template = Velocity.getTemplate("templates/" + language + "/" + s); 147 182 148 context.put(" classDescriptor", descriptor);183 context.put("typeDescriptor", descriptor); 149 184 template.merge(context, writer); 150 185 writer.close(); … … 152 187 } 153 188 189 public String getAnnotation(String name, Collection<String> imports) { 190 return annotationMap.getType(name, false, imports); 191 } 192 154 193 public String getName() { 155 194 return language; 195 } 196 197 public String getType(String name, boolean primitive, Collection<String> imports) { 198 return typeMap.getType(name, primitive, imports); 156 199 } 157 200 trunk/src/org/fluffnstuff/asdoclet/handler/AbstractHandler.java
r4 r6 2 2 3 3 import com.sun.javadoc.ClassDoc; 4 import org.fluffnstuff.asdoclet.map.TypeMap;5 4 import org.fluffnstuff.asdoclet.generator.Generator; 6 5 … … 9 8 10 9 private final Generator generator; 11 private final TypeMap typeMap;12 private final TypeMap annotationMap;13 10 14 protected AbstractHandler(Generator generator , TypeMap typeMap, TypeMap annotationMap) {11 protected AbstractHandler(Generator generator) { 15 12 this.generator = generator; 16 this.typeMap = typeMap;17 this.annotationMap = annotationMap;18 }19 20 protected TypeMap getAnnotationMap() {21 return annotationMap;22 13 } 23 14 24 15 protected Generator getGenerator() { 25 16 return generator; 26 }27 28 protected TypeMap getTypeMap() {29 return typeMap;30 17 } 31 18 trunk/src/org/fluffnstuff/asdoclet/handler/ClassHandler.java
r5 r6 3 3 import com.sun.javadoc.*; 4 4 import org.fluffnstuff.asdoclet.generator.Generator; 5 import org.fluffnstuff.asdoclet.map.TypeMap;6 5 7 6 import java.beans.Introspector; … … 13 12 14 13 public class ClassHandler extends AbstractHandler { 15 public ClassHandler(Generator generator , TypeMap typeMap, TypeMap annotationMap) {16 super(generator , typeMap, annotationMap);14 public ClassHandler(Generator generator) { 15 super(generator); 17 16 } 18 17 … … 82 81 83 82 if (fieldType == null) { 84 fieldType = get TypeMap().getType(returnType.qualifiedTypeName(), returnType.isPrimitive(), imports);83 fieldType = getGenerator().getType(returnType.qualifiedTypeName(), returnType.isPrimitive(), imports); 85 84 } 86 85 } else { … … 95 94 for (AnnotationDesc annotationDesc : annotationDescs) { 96 95 AnnotationTypeDoc annotationTypeDoc = annotationDesc.annotationType(); 97 fieldType = get AnnotationMap().getType(annotationTypeDoc.qualifiedTypeName(), false, imports);96 fieldType = getGenerator().getAnnotation(annotationTypeDoc.qualifiedTypeName(), imports); 98 97 if (fieldType != null) break; 99 98 } … … 124 123 if (superClassDoc != null) { 125 124 String superClassName = superClassDoc.qualifiedTypeName(); 126 if (!Object.class.getName().equals(superClassName) && !ignore.contains(superClassName)) getGenerator().setSuperclass(superClassName); 125 if (!superClassName.equals(Object.class.getName())) { 126 superClassName = getGenerator().getType(superClassName, false, null); 127 if (!Object.class.getName().equals(superClassName) && !ignore.contains(superClassName)) getGenerator().setSuperclass(superClassName); 128 } 127 129 } 128 130 } trunk/src/org/fluffnstuff/asdoclet/handler/EnumHandler.java
r4 r6 4 4 import com.sun.javadoc.FieldDoc; 5 5 import org.fluffnstuff.asdoclet.generator.Generator; 6 import org.fluffnstuff.asdoclet.map.TypeMap;7 6 8 7 public class EnumHandler extends AbstractHandler { 9 public EnumHandler(Generator generator , TypeMap typeMap, TypeMap annotationMap) {10 super(generator , typeMap, annotationMap);8 public EnumHandler(Generator generator) { 9 super(generator); 11 10 } 12 11 trunk/src/org/fluffnstuff/asdoclet/handler/InterfaceHandler.java
r5 r6 5 5 import com.sun.javadoc.Parameter; 6 6 import org.fluffnstuff.asdoclet.generator.Generator; 7 import org.fluffnstuff.asdoclet.map.TypeMap;8 7 9 8 import java.util.Collection; … … 13 12 14 13 public class InterfaceHandler extends AbstractHandler { 15 public InterfaceHandler(Generator generator , TypeMap typeMap, TypeMap annotationMap) {16 super(generator , typeMap, annotationMap);14 public InterfaceHandler(Generator generator) { 15 super(generator); 17 16 } 18 17 … … 45 44 String baseType = TagParser.getStringCommand(Constants.COMMAND_PROXY_BASE_CLASS, commands); 46 45 47 String interfaceType = get TypeMap().getType(interfaceName, false, proxyImports);46 String interfaceType = getGenerator().getType(interfaceName, false, proxyImports); 48 47 getGenerator().beginProxy(proxyName, asyncReturnType, baseType, proxyImports, interfaceType); 49 48 } … … 72 71 for (ClassDoc interfaceDoc : classDoc.interfaces()) { 73 72 if (!commands.containsKey(Constants.COMMAND_IGNORE) || !commands.get(Constants.COMMAND_IGNORE).contains(interfaceDoc.qualifiedTypeName())) { 74 String interfaceClass = get TypeMap().getType(interfaceDoc.qualifiedTypeName(), interfaceDoc.isPrimitive(), null);73 String interfaceClass = getGenerator().getType(interfaceDoc.qualifiedTypeName(), false, null); 75 74 getGenerator().addInterface(interfaceClass); 76 75 … … 82 81 private void processMethods(ClassDoc classDoc, Map<String, String> commands, Collection<String> imports, String asyncReturnType) { 83 82 for (MethodDoc methodDoc : classDoc.methods()) { 84 String returnType = get TypeMap().getType(methodDoc.returnType().qualifiedTypeName(), methodDoc.returnType().isPrimitive(), null);83 String returnType = getGenerator().getType(methodDoc.returnType().qualifiedTypeName(), methodDoc.returnType().isPrimitive(), null); 85 84 processMethod(methodDoc, commands, imports, returnType, asyncReturnType); 86 85 } … … 105 104 106 105 for (Parameter parameter : methodDoc.parameters()) { 107 String type = get TypeMap().getType(parameter.type().qualifiedTypeName(), parameter.type().isPrimitive(), imports);106 String type = getGenerator().getType(parameter.type().qualifiedTypeName(), parameter.type().isPrimitive(), imports); 108 107 getGenerator().addParameter(type, parameter.name()); 109 108 } trunk/src/org/fluffnstuff/asdoclet/map/ClassTypeMap.java
r4 r6 4 4 5 5 public class ClassTypeMap extends TypeMap { 6 public ClassTypeMap() {7 typeMap.put("boolean", "Boolean");8 typeMap.put("byte", "Number");9 typeMap.put("double", "Number");10 typeMap.put("float", "Number");11 typeMap.put("long", "Number");12 typeMap.put("short", "Number");13 14 // those need to be 'Object's since 'Number's cannot be null15 typeMap.put("java.lang.Boolean", "Object");16 typeMap.put("java.lang.Byte", "Object");17 typeMap.put("java.lang.Double", "Object");18 typeMap.put("java.lang.Float", "Object");19 typeMap.put("java.lang.Integer", "Object");20 typeMap.put("java.lang.Long", "Object");21 typeMap.put("java.lang.Number", "Object");22 typeMap.put("java.lang.Short", "Object");23 24 typeMap.put("java.lang.String", "String");25 26 typeMap.put("java.util.Collection", "Array");27 typeMap.put("java.util.Date", "Date");28 typeMap.put("java.util.List", "Array");29 typeMap.put("java.util.Map", "Array");30 typeMap.put("java.util.Set", "Array");31 }32 33 6 @Override 34 7 public String getType(String typeName, boolean primitive, Collection<String> imports) { 35 String asType ;8 String asType = super.getType(typeName, primitive, imports); 36 9 37 if (isEnum(typeName)) { 38 asType = "String"; 39 } else { 40 asType = super.getType(typeName, primitive, imports); 41 42 if (asType == null) { 43 if (imports != null && !primitive) imports.add(typeName); 44 asType = typeName; 45 } 10 if (asType == null) { 11 if (imports != null && !primitive) imports.add(typeName); 12 asType = typeName; 46 13 } 47 14 48 15 return asType; 49 16 } 50 51 public boolean isEnum(String typeName) {52 boolean isEnum = false;53 try {54 Class<?> typeClass = Class.forName(typeName);55 isEnum = typeClass.isEnum();56 } catch (ClassNotFoundException e) {57 // ignore58 }59 return isEnum;60 }61 17 } trunk/src/org/fluffnstuff/asdoclet/map/TypeMap.java
r4 r6 1 1 package org.fluffnstuff.asdoclet.map; 2 3 import org.fluffnstuff.asdoclet.util.EnumUtil; 2 4 3 5 import java.util.Collection; … … 7 9 public class TypeMap { 8 10 protected final Map<String, String> typeMap = new HashMap<String, String>(); 11 private String enumType; 12 13 public void setEnumType(String enumType) { 14 this.enumType = enumType; 15 } 9 16 10 17 public void addTypeMapping(String javaType, String asType) { 11 typeMap.put(javaType, asType);18 if (!typeMap.containsKey(javaType)) typeMap.put(javaType, asType); 12 19 } 13 20 … … 15 22 String asType = null; 16 23 17 if (typeMap.containsKey(typeName)) { 24 if (enumType != null && EnumUtil.isEnum(typeName)) { 25 asType = enumType; 26 } else if (typeMap.containsKey(typeName)) { 18 27 asType = typeMap.get(typeName); 19 28 }