Changeset 5
- Timestamp:
- 07/17/08 11:05:19 (4 years ago)
- Files:
-
- trunk (modified) (1 prop)
- trunk/out (added)
- trunk/out/templates (moved) (moved from trunk/templates) (1 prop)
- trunk/out/templates/cs/class.vm (modified) (1 diff)
- trunk/out/templates/cs/enum.vm (copied) (copied from trunk/templates/cs/class.vm) (1 diff, 1 prop)
- trunk/out/templates/cs/interface.vm (added)
- 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) (3 diffs)
- trunk/src/org/fluffnstuff/asdoclet/generator/VelocityGenerator.java (modified) (8 diffs)
- trunk/src/org/fluffnstuff/asdoclet/generator/velocity/ClassDescriptor.java (modified) (1 diff)
- trunk/src/org/fluffnstuff/asdoclet/generator/velocity/Descriptor.java (modified) (1 diff)
- trunk/src/org/fluffnstuff/asdoclet/generator/velocity/EnumDescriptor.java (added)
- trunk/src/org/fluffnstuff/asdoclet/generator/velocity/InterfaceDescriptor.java (added)
- trunk/src/org/fluffnstuff/asdoclet/generator/velocity/TypeDescriptor.java (modified) (3 diffs)
- trunk/src/org/fluffnstuff/asdoclet/handler/ClassHandler.java (modified) (3 diffs)
- trunk/src/org/fluffnstuff/asdoclet/handler/Constants.java (modified) (1 diff)
- trunk/src/org/fluffnstuff/asdoclet/handler/InterfaceHandler.java (modified) (4 diffs)
- trunk/src/org/fluffnstuff/asdoclet/handler/TagParser.java (modified) (2 diffs)
Legend:
- Unmodified
- Added
- Removed
- Modified
- Copied
- Moved
trunk
- Property svn:ignore changed from
out
*.iml
*.iws
*.jar
to
*.iml
*.iws
*.jar
test
- Property svn:ignore changed from
trunk/out/templates
- Property svn:mergeinfo set
trunk/out/templates/cs/class.vm
r4 r5 1 1 namespace $classDescriptor.nameSpace { 2 public class $classDescriptor. className {2 public class $classDescriptor.typeName { 3 3 #foreach($fieldDescriptor in $classDescriptor.fieldDescriptors) 4 $fieldDescriptor.modifier $fieldDescriptor.typeName $ methodDescriptor.fieldName { set; get; };4 $fieldDescriptor.modifier $fieldDescriptor.typeName $fieldDescriptor.fieldName { set; get; }; 5 5 #end 6 6 trunk/out/templates/cs/enum.vm
- Property svn:mergeinfo set
r4 r5 1 1 namespace $classDescriptor.nameSpace { 2 public class $classDescriptor.className { 3 #foreach($fieldDescriptor in $classDescriptor.fieldDescriptors) 4 $fieldDescriptor.modifier $fieldDescriptor.typeName $methodDescriptor.fieldName { set; get; }; 5 #end 6 7 #foreach($methodDescriptor in $classDescriptor.methodDescriptors) 8 $methodDescriptor.modifier $methodDescriptor.typeName {$methodDescriptor.methodName}() {} 2 public enum $classDescriptor.typeName { 3 #foreach($fieldDescriptor in $classDescriptor.fieldDescriptors)#if($velocityCounter>1),#end 4 $fieldDescriptor.fieldName 9 5 #end 10 6 } trunk/src/org/fluffnstuff/asdoclet/AsDoclet.java
r4 r5 13 13 public class AsDoclet { 14 14 private static final String PARAM_DESTINATION = "-d"; 15 private static final String PARAM_NAMESPACE = "-namespace"; 16 private static final String PARAM_GENERATOR = "-generator"; 15 17 private static final String PARAM_MAP = "-map"; 16 18 private static final String PARAM_ANNOTATION_MAP = "-annotationmap"; … … 20 22 21 23 public static boolean start(RootDoc root) throws Exception { 22 String destination = readOptions(root.options()); 23 24 // todo configurable generator 25 // Generator generator = new AsGenerator(destination); 26 Generator generator = new VelocityGenerator(destination); 24 Generator generator = readOptions(root.options()); 27 25 28 26 for (ClassDoc classDoc : root.classes()) { 29 if (TagParser.hasClassTags( classDoc)) {27 if (TagParser.hasClassTags(generator, classDoc)) { 30 28 Handler handler = createHandler(generator, classDoc); 31 29 handler.process(classDoc); … … 38 36 } 39 37 40 private static String readOptions(String[][] options){38 private static Generator readOptions(String[][] options) throws Exception { 41 39 String destination = "."; 40 String namespace = null; 41 String generator = null; 42 42 43 43 for (String[] opt : options) { 44 44 if (opt[0].equals(PARAM_DESTINATION)) destination = opt[1]; 45 if (opt[0].equals(PARAM_NAMESPACE)) namespace = opt[1]; 46 if (opt[0].equals(PARAM_GENERATOR)) generator = opt[1]; 45 47 if (opt[0].equals(PARAM_MAP)) { 46 48 String[] strings = opt[1].split(":"); … … 53 55 } 54 56 55 return destination; 57 if ("actionscript".equals(generator)) { 58 return new AsGenerator(destination, namespace); 59 } else if ("cs".equals(generator)) { 60 return new VelocityGenerator(destination, namespace, "cs"); 61 } 62 return null; 56 63 } 57 64 … … 74 81 75 82 if (PARAM_DESTINATION.equals(option)) length = 2; 83 if (PARAM_NAMESPACE.equals(option)) length = 2; 84 if (PARAM_GENERATOR.equals(option)) length = 2; 76 85 if (PARAM_MAP.equals(option)) length = 2; 77 86 if (PARAM_ANNOTATION_MAP.equals(option)) length = 2; trunk/src/org/fluffnstuff/asdoclet/generator/AsGenerator.java
r4 r5 28 28 private ASField field; 29 29 30 public AsGenerator(String destination ) {30 public AsGenerator(String destination, String namespace) { 31 31 project = factory.newEmptyASProject(destination); 32 32 } 33 33 34 34 // --------------------- Interface Generator --------------------- 35 36 public void addAnnotation(String tag) {37 type.newMetaTag(tag);38 }39 35 40 36 public void addConstant(String name, String value) { … … 65 61 } 66 62 63 public void addTypeAnnotation(String tag) { 64 type.newMetaTag(tag); 65 } 66 67 67 public void beginClass(String name) { 68 68 newClass(name, false); … … 159 159 } 160 160 161 public String getName() { 162 return "actionscript"; 163 } 164 161 165 public void setFieldDescription(String description) { 162 166 field.setDescription(description); trunk/src/org/fluffnstuff/asdoclet/generator/Generator.java
r4 r5 4 4 5 5 public interface Generator { 6 void addAnnotation(String tag);7 8 6 void addConstant(String name, String value); 9 7 … … 15 13 16 14 void addParameter(String type, String name); 15 16 void addTypeAnnotation(String tag); 17 17 18 18 void beginClass(String name); … … 38 38 void generate() throws Exception; 39 39 40 String getName(); 41 40 42 void setFieldDescription(String description); 41 43 trunk/src/org/fluffnstuff/asdoclet/generator/VelocityGenerator.java
r4 r5 1 1 package org.fluffnstuff.asdoclet.generator; 2 2 3 import org.apache.commons.lang.NotImplementedException; 3 4 import org.apache.velocity.Template; 4 5 import org.apache.velocity.VelocityContext; 5 6 import org.apache.velocity.app.Velocity; 6 7 import org.fluffnstuff.asdoclet.generator.velocity.*; 8 import org.fluffnstuff.asdoclet.handler.Constants; 7 9 8 10 import java.io.File; … … 13 15 14 16 public class VelocityGenerator implements Generator { 15 private Collection<TypeDescriptor> classes = new ArrayList<TypeDescriptor>(); 17 private Collection<TypeDescriptor> typeDescriptors = new ArrayList<TypeDescriptor>(); 18 19 private File destination; 20 private String language; 21 private String namespace; 16 22 17 23 private TypeDescriptor typeDescriptor; 24 private ClassDescriptor proxyTypeDescriptor; 25 26 private FieldDescriptor fieldDescriptor; 18 27 private MethodDescriptor methodDescriptor; 19 28 private ParameterDescriptor parameterDescriptor; 20 private FieldDescriptor fieldDescriptor;21 private File destination;22 29 23 public VelocityGenerator(String destination ) throws Exception {30 public VelocityGenerator(String destination, String namespace, String language) throws Exception { 24 31 this.destination = new File(destination); 32 this.namespace = namespace; 33 this.language = language; 25 34 26 35 Velocity.setProperty(Velocity.RESOURCE_LOADER, "class"); … … 31 40 // --------------------- Interface Generator --------------------- 32 41 33 public void addAnnotation(String tag) {34 //To change body of implemented methods use File | Settings | File Templates.35 }36 37 42 public void addConstant(String name, String value) { 38 //To change body of implemented methods use File | Settings | File Templates.43 throw new NotImplementedException(); 39 44 } 40 45 41 46 public void addEnumField(String name) { 42 //To change body of implemented methods use File | Settings | File Templates.47 addField(0, null, name); 43 48 } 44 49 … … 49 54 50 55 public void addInterface(String name) { 51 //To change body of implemented methods use File | Settings | File Templates.56 typeDescriptor.addInterface(name); 52 57 } 53 58 … … 57 62 } 58 63 64 public void addTypeAnnotation(String annotation) { 65 typeDescriptor.addAnnotation(annotation); 66 } 67 59 68 public void beginClass(String name) { 60 typeDescriptor = new ClassDescriptor(name); 61 classes.add(typeDescriptor); 69 beginType(new ClassDescriptor(name)); 62 70 } 63 71 64 72 public void beginEnum(String name) { 65 //To change body of implemented methods use File | Settings | File Templates.73 beginType(new EnumDescriptor(name)); 66 74 } 67 75 68 76 public void beginInterface(String name) { 69 //To change body of implemented methods use File | Settings | File Templates.77 beginType(new InterfaceDescriptor(name)); 70 78 } 71 79 … … 76 84 77 85 public void beginProxy(String proxyName, String returnType, String baseType, Collection<String> proxyImports, String interfaceType) { 78 //To change body of implemented methods use File | Settings | File Templates. 86 // ASCompilationUnit eventUnit = project.newClass(proxyName + "Events"); 87 // eventType = (ASClassType) eventUnit.getType(); 88 89 proxyTypeDescriptor = new ClassDescriptor(proxyName); 90 proxyTypeDescriptor.addInterface(interfaceType); 91 92 if (baseType != null) { 93 proxyTypeDescriptor.setSuperclass(baseType); 94 proxyImports.add(baseType); 95 } 96 97 typeDescriptors.add(proxyTypeDescriptor); 98 99 if (!Constants.TYPE_VOID.equals(returnType)) proxyImports.add(returnType); 100 101 // ASMethod callMethod = proxyType.newMethod(Constants.METHOD_CALL, Visibility.PROTECTED, returnType); 102 // callMethod.addParam("name", "String"); 103 // callMethod.addParam("...args", null); 104 // callMethod.addStmt("throw new Error(\"Not Implemented\");"); 105 106 // ASMethod resultMethod = proxyType.newMethod(Constants.METHOD_ON_RESULT, Visibility.PROTECTED, Constants.TYPE_VOID); 107 // resultMethod.addParam("result", "Object"); 108 109 // ASMethod statusMethod = proxyType.newMethod(Constants.METHOD_ON_STATUS, Visibility.PROTECTED, Constants.TYPE_VOID); 110 // statusMethod.addParam("status", "Object"); 79 111 } 80 112 … … 83 115 84 116 public void endEnum() { 85 //To change body of implemented methods use File | Settings | File Templates.86 117 } 87 118 88 119 public void endInterface(Collection<String> imports) { 89 //To change body of implemented methods use File | Settings | File Templates.90 120 } 91 121 … … 94 124 95 125 public void endProxy(Collection<String> proxyImports) { 96 //To change body of implemented methods use File | Settings | File Templates.97 126 } 98 127 99 128 public void generate() throws Exception { 100 VelocityContext context = new VelocityContext();101 context.put("classDescriptor", typeDescriptor);129 for (TypeDescriptor descriptor : typeDescriptors) { 130 String ns = descriptor.getNameSpace(); 102 131 103 Template template = Velocity.getTemplate("templates/cs/class.vm"); 132 if (ns.indexOf(namespace) == 0) { 133 ns = ns.substring(namespace.length()); 134 if (ns.startsWith(".")) ns = ns.substring(1); 135 } 104 136 105 Writer writer = new FileWriter(new File(this.destination, "test.cs")); 106 template.merge(context, writer); 107 writer.close(); 137 String folderName = ns.replace('.', '\\'); 138 139 File folder = new File(this.destination, folderName); 140 folder.mkdirs(); 141 142 Writer writer = new FileWriter(new File(folder, descriptor.getTypeName() + ".cs")); 143 144 VelocityContext context = new VelocityContext(); 145 String s = typeDescriptor.getTemplate(); 146 Template template = Velocity.getTemplate("templates/" + language + "/" + s); 147 148 context.put("classDescriptor", descriptor); 149 template.merge(context, writer); 150 writer.close(); 151 } 152 } 153 154 public String getName() { 155 return language; 108 156 } 109 157 110 158 public void setFieldDescription(String description) { 111 //To change body of implemented methods use File | Settings | File Templates.159 fieldDescriptor.setDescription(description); 112 160 } 113 161 114 162 public void setMethodDescription(String description) { 115 //To change body of implemented methods use File | Settings | File Templates.163 methodDescriptor.setDescription(description); 116 164 } 117 165 118 166 public void setSuperclass(String name) { 119 //To change body of implemented methods use File | Settings | File Templates.167 ((ClassDescriptor) typeDescriptor).setSuperclass(name); 120 168 } 121 169 122 170 public void setTypeDescription(String description) { 123 //To change body of implemented methods use File | Settings | File Templates. 171 typeDescriptor.setDescription(description); 172 } 173 174 private void beginType(TypeDescriptor typeDescriptor) { 175 this.typeDescriptor = typeDescriptor; 176 typeDescriptors.add(typeDescriptor); 124 177 } 125 178 } trunk/src/org/fluffnstuff/asdoclet/generator/velocity/ClassDescriptor.java
r4 r5 2 2 3 3 public class ClassDescriptor extends TypeDescriptor { 4 private String superClass; 5 4 6 public ClassDescriptor(String className) { 5 7 super(className); 6 8 } 9 10 public String getSuperClass() { 11 return superClass; 12 } 13 14 public String getTemplate() { 15 return "class.vm"; 16 } 17 18 public void setSuperclass(String superClass) { 19 this.superClass = superClass; 20 } 7 21 } trunk/src/org/fluffnstuff/asdoclet/generator/velocity/Descriptor.java
r4 r5 3 3 import org.apache.commons.lang.ClassUtils; 4 4 5 import java.util.ArrayList; 6 import java.util.Collection; 7 5 8 public class Descriptor { 6 9 private String typeName; 10 private String description; 11 private Collection<String> annotations = new ArrayList<String>(); 7 12 8 13 public Descriptor(String typeName) { 9 14 this.typeName = typeName; 15 } 16 17 public Collection<String> getAnnotations() { 18 return annotations; 19 } 20 21 public String getDescription() { 22 return description; 23 } 24 25 public void setDescription(String description) { 26 this.description = description; 27 } 28 29 public void addAnnotation(String annotation) { 30 annotations.add(annotation); 10 31 } 11 32 trunk/src/org/fluffnstuff/asdoclet/generator/velocity/TypeDescriptor.java
r4 r5 4 4 import java.util.Collection; 5 5 6 public class TypeDescriptor extends Descriptor {6 public abstract class TypeDescriptor extends Descriptor { 7 7 private Collection<MethodDescriptor> methodDescriptors = new ArrayList<MethodDescriptor>(); 8 8 private Collection<FieldDescriptor> fieldDescriptors = new ArrayList<FieldDescriptor>(); 9 private Collection<String> interfaces = new ArrayList<String>(); 9 10 10 11 public TypeDescriptor(String typeName) { … … 14 15 public Collection<FieldDescriptor> getFieldDescriptors() { 15 16 return fieldDescriptors; 17 } 18 19 public Collection<String> getInterfaces() { 20 return interfaces; 16 21 } 17 22 … … 24 29 } 25 30 31 public void addInterface(String interfaceName) { 32 interfaces.add(interfaceName); 33 } 34 26 35 public void addMethodDescriptor(MethodDescriptor methodDescriptor) { 27 36 methodDescriptors.add(methodDescriptor); 28 37 } 38 39 public abstract String getTemplate(); 29 40 } trunk/src/org/fluffnstuff/asdoclet/handler/ClassHandler.java
r4 r5 21 21 public void process(ClassDoc classDoc) { 22 22 Collection<String> imports = new TreeSet<String>(); 23 Map<String, String> commands = TagParser.processClassTags( classDoc);23 Map<String, String> commands = TagParser.processClassTags(getGenerator(), classDoc); 24 24 25 25 boolean bindable = TagParser.getBooleanCommand(Constants.COMMAND_BINDABLE, commands); … … 28 28 getGenerator().beginClass(classDoc.qualifiedTypeName()); 29 29 30 if (bindable) getGenerator().add Annotation("Bindable");31 getGenerator().add Annotation("RemoteClass(alias=\"" + classDoc.qualifiedTypeName() + "\")");30 if (bindable) getGenerator().addTypeAnnotation("Bindable"); 31 getGenerator().addTypeAnnotation("RemoteClass(alias=\"" + classDoc.qualifiedTypeName() + "\")"); 32 32 33 33 processSuperClass(classDoc, ignore); … … 41 41 for (MethodDoc methodDoc : classDoc.methods()) { 42 42 Map<String, String> methodCommands = new HashMap<String, String>(commands); 43 TagParser.processTags(methodDoc.tags( Constants.TAG_ACTIONSCRIPT_PROPERTY), methodCommands);43 TagParser.processTags(methodDoc.tags(getGenerator().getName() + Constants.TAG_PROPERTY), methodCommands); 44 44 45 45 boolean ignoreProperty = TagParser.getBooleanCommand(Constants.COMMAND_IGNORE, commands); trunk/src/org/fluffnstuff/asdoclet/handler/Constants.java
r4 r5 2 2 3 3 final public class Constants { 4 public static final String TAG_ ACTIONSCRIPT_CLASS = "actionscript.class";5 public static final String TAG_ ACTIONSCRIPT_METHOD = "actionscript.method";6 public static final String TAG_ ACTIONSCRIPT_PROPERTY = "actionscript.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 8 public static final String COMMAND_ASYNC = "async"; trunk/src/org/fluffnstuff/asdoclet/handler/InterfaceHandler.java
r4 r5 4 4 import com.sun.javadoc.MethodDoc; 5 5 import com.sun.javadoc.Parameter; 6 import org.fluffnstuff.asdoclet.generator.Generator; 6 7 import org.fluffnstuff.asdoclet.map.TypeMap; 7 import org.fluffnstuff.asdoclet.generator.Generator;8 8 9 9 import java.util.Collection; … … 27 27 28 28 if (parentCommands != null) commands.putAll(parentCommands); 29 commands.putAll(TagParser.processClassTags( classDoc));29 commands.putAll(TagParser.processClassTags(getGenerator(), classDoc)); 30 30 31 31 Collection<String> imports = new TreeSet<String>(); … … 63 63 64 64 if (parentCommands != null) commands.putAll(parentCommands); 65 commands.putAll(TagParser.processClassTags( classDoc));65 commands.putAll(TagParser.processClassTags(getGenerator(), classDoc)); 66 66 67 67 processInterfaces(classDoc, commands, asyncReturnType, proxyImports, imports); … … 90 90 Map<String, String> methodCommands = new HashMap<String, String>(commands); 91 91 92 TagParser.processTags(methodDoc.tags( Constants.TAG_ACTIONSCRIPT_METHOD), methodCommands);92 TagParser.processTags(methodDoc.tags(getGenerator().getName() + Constants.TAG_METHOD), methodCommands); 93 93 94 94 boolean async = TagParser.getBooleanCommand(Constants.COMMAND_ASYNC, methodCommands); trunk/src/org/fluffnstuff/asdoclet/handler/TagParser.java
r2 r5 3 3 import com.sun.javadoc.ClassDoc; 4 4 import com.sun.javadoc.Tag; 5 import org.fluffnstuff.asdoclet.generator.Generator; 5 6 6 7 import java.util.HashMap; … … 28 29 } 29 30 30 public static boolean hasClassTags( ClassDoc classDoc) {31 Tag[] tags = classDoc.tags( Constants.TAG_ACTIONSCRIPT_CLASS);31 public static boolean hasClassTags(Generator generator, ClassDoc classDoc) { 32 Tag[] tags = classDoc.tags(generator.getName() + Constants.TAG_CLASS); 32 33 return tags.length > 0; 33 34 } 34 35 35 public static Map<String, String> processClassTags( ClassDoc classDoc) {36 public static Map<String, String> processClassTags(Generator generator, ClassDoc classDoc) { 36 37 Map<String, String> commands = new HashMap<String, String>(); 37 processTags(classDoc.tags( Constants.TAG_ACTIONSCRIPT_CLASS), commands);38 processTags(classDoc.tags( Constants.TAG_ACTIONSCRIPT_METHOD), commands);39 processTags(classDoc.tags( Constants.TAG_ACTIONSCRIPT_PROPERTY), commands);38 processTags(classDoc.tags(generator.getName() + Constants.TAG_CLASS), commands); 39 processTags(classDoc.tags(generator.getName() + Constants.TAG_METHOD), commands); 40 processTags(classDoc.tags(generator.getName() + Constants.TAG_PROPERTY), commands); 40 41 return commands; 41 42 }