Trail:

Changeset 5

Show
Ignore:
Timestamp:
07/17/08 11:05:19 (4 years ago)
Author:
harald
Message:

--

Files:

Legend:

Unmodified
Added
Removed
Modified
Copied
Moved
  • trunk

    • Property svn:ignore changed from
      out
      *.iml
      *.iws
      *.jar
      to
      *.iml
      *.iws
      *.jar
      test
  • trunk/out/templates

    • Property svn:mergeinfo set
  • trunk/out/templates/cs/class.vm

    r4 r5  
    11namespace $classDescriptor.nameSpace { 
    2     public class $classDescriptor.className { 
     2    public class $classDescriptor.typeName { 
    33#foreach($fieldDescriptor in $classDescriptor.fieldDescriptors) 
    4         $fieldDescriptor.modifier $fieldDescriptor.typeName $methodDescriptor.fieldName { set; get; }; 
     4        $fieldDescriptor.modifier $fieldDescriptor.typeName $fieldDescriptor.fieldName { set; get; }; 
    55#end 
    66 
  • trunk/out/templates/cs/enum.vm

    • Property svn:mergeinfo set
    r4 r5  
    11namespace $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 
    95#end 
    106    } 
  • trunk/src/org/fluffnstuff/asdoclet/AsDoclet.java

    r4 r5  
    1313public class AsDoclet { 
    1414    private static final String PARAM_DESTINATION = "-d"; 
     15    private static final String PARAM_NAMESPACE = "-namespace"; 
     16    private static final String PARAM_GENERATOR = "-generator"; 
    1517    private static final String PARAM_MAP = "-map"; 
    1618    private static final String PARAM_ANNOTATION_MAP = "-annotationmap"; 
     
    2022 
    2123    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()); 
    2725 
    2826        for (ClassDoc classDoc : root.classes()) { 
    29             if (TagParser.hasClassTags(classDoc)) { 
     27            if (TagParser.hasClassTags(generator, classDoc)) { 
    3028                Handler handler = createHandler(generator, classDoc); 
    3129                handler.process(classDoc); 
     
    3836    } 
    3937 
    40     private static String readOptions(String[][] options)
     38    private static Generator readOptions(String[][] options) throws Exception
    4139        String destination = "."; 
     40        String namespace = null; 
     41        String generator = null; 
    4242 
    4343        for (String[] opt : options) { 
    4444            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]; 
    4547            if (opt[0].equals(PARAM_MAP)) { 
    4648                String[] strings = opt[1].split(":"); 
     
    5355        } 
    5456 
    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; 
    5663    } 
    5764 
     
    7481 
    7582        if (PARAM_DESTINATION.equals(option)) length = 2; 
     83        if (PARAM_NAMESPACE.equals(option)) length = 2; 
     84        if (PARAM_GENERATOR.equals(option)) length = 2; 
    7685        if (PARAM_MAP.equals(option)) length = 2; 
    7786        if (PARAM_ANNOTATION_MAP.equals(option)) length = 2; 
  • trunk/src/org/fluffnstuff/asdoclet/generator/AsGenerator.java

    r4 r5  
    2828    private ASField field; 
    2929 
    30     public AsGenerator(String destination) { 
     30    public AsGenerator(String destination, String namespace) { 
    3131        project = factory.newEmptyASProject(destination); 
    3232    } 
    3333 
    3434// --------------------- Interface Generator --------------------- 
    35  
    36     public void addAnnotation(String tag) { 
    37         type.newMetaTag(tag); 
    38     } 
    3935 
    4036    public void addConstant(String name, String value) { 
     
    6561    } 
    6662 
     63    public void addTypeAnnotation(String tag) { 
     64        type.newMetaTag(tag); 
     65    } 
     66 
    6767    public void beginClass(String name) { 
    6868        newClass(name, false); 
     
    159159    } 
    160160 
     161    public String getName() { 
     162        return "actionscript"; 
     163    } 
     164 
    161165    public void setFieldDescription(String description) { 
    162166        field.setDescription(description); 
  • trunk/src/org/fluffnstuff/asdoclet/generator/Generator.java

    r4 r5  
    44 
    55public interface Generator { 
    6     void addAnnotation(String tag); 
    7  
    86    void addConstant(String name, String value); 
    97 
     
    1513 
    1614    void addParameter(String type, String name); 
     15 
     16    void addTypeAnnotation(String tag); 
    1717 
    1818    void beginClass(String name); 
     
    3838    void generate() throws Exception; 
    3939 
     40    String getName(); 
     41 
    4042    void setFieldDescription(String description); 
    4143 
  • trunk/src/org/fluffnstuff/asdoclet/generator/VelocityGenerator.java

    r4 r5  
    11package org.fluffnstuff.asdoclet.generator; 
    22 
     3import org.apache.commons.lang.NotImplementedException; 
    34import org.apache.velocity.Template; 
    45import org.apache.velocity.VelocityContext; 
    56import org.apache.velocity.app.Velocity; 
    67import org.fluffnstuff.asdoclet.generator.velocity.*; 
     8import org.fluffnstuff.asdoclet.handler.Constants; 
    79 
    810import java.io.File; 
     
    1315 
    1416public 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; 
    1622 
    1723    private TypeDescriptor typeDescriptor; 
     24    private ClassDescriptor proxyTypeDescriptor; 
     25 
     26    private FieldDescriptor fieldDescriptor; 
    1827    private MethodDescriptor methodDescriptor; 
    1928    private ParameterDescriptor parameterDescriptor; 
    20     private FieldDescriptor fieldDescriptor; 
    21     private File destination; 
    2229 
    23     public VelocityGenerator(String destination) throws Exception { 
     30    public VelocityGenerator(String destination, String namespace, String language) throws Exception { 
    2431        this.destination = new File(destination); 
     32        this.namespace = namespace; 
     33        this.language = language; 
    2534 
    2635        Velocity.setProperty(Velocity.RESOURCE_LOADER, "class"); 
     
    3140// --------------------- Interface Generator --------------------- 
    3241 
    33     public void addAnnotation(String tag) { 
    34         //To change body of implemented methods use File | Settings | File Templates. 
    35     } 
    36  
    3742    public void addConstant(String name, String value) { 
    38         //To change body of implemented methods use File | Settings | File Templates. 
     43        throw new NotImplementedException(); 
    3944    } 
    4045 
    4146    public void addEnumField(String name) { 
    42         //To change body of implemented methods use File | Settings | File Templates. 
     47        addField(0, null, name); 
    4348    } 
    4449 
     
    4954 
    5055    public void addInterface(String name) { 
    51         //To change body of implemented methods use File | Settings | File Templates. 
     56        typeDescriptor.addInterface(name); 
    5257    } 
    5358 
     
    5762    } 
    5863 
     64    public void addTypeAnnotation(String annotation) { 
     65        typeDescriptor.addAnnotation(annotation); 
     66    } 
     67 
    5968    public void beginClass(String name) { 
    60         typeDescriptor = new ClassDescriptor(name); 
    61         classes.add(typeDescriptor); 
     69        beginType(new ClassDescriptor(name)); 
    6270    } 
    6371 
    6472    public void beginEnum(String name) { 
    65         //To change body of implemented methods use File | Settings | File Templates. 
     73        beginType(new EnumDescriptor(name)); 
    6674    } 
    6775 
    6876    public void beginInterface(String name) { 
    69         //To change body of implemented methods use File | Settings | File Templates. 
     77        beginType(new InterfaceDescriptor(name)); 
    7078    } 
    7179 
     
    7684 
    7785    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"); 
    79111    } 
    80112 
     
    83115 
    84116    public void endEnum() { 
    85         //To change body of implemented methods use File | Settings | File Templates. 
    86117    } 
    87118 
    88119    public void endInterface(Collection<String> imports) { 
    89         //To change body of implemented methods use File | Settings | File Templates. 
    90120    } 
    91121 
     
    94124 
    95125    public void endProxy(Collection<String> proxyImports) { 
    96         //To change body of implemented methods use File | Settings | File Templates. 
    97126    } 
    98127 
    99128    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(); 
    102131 
    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            } 
    104136 
    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; 
    108156    } 
    109157 
    110158    public void setFieldDescription(String description) { 
    111         //To change body of implemented methods use File | Settings | File Templates. 
     159        fieldDescriptor.setDescription(description); 
    112160    } 
    113161 
    114162    public void setMethodDescription(String description) { 
    115         //To change body of implemented methods use File | Settings | File Templates. 
     163        methodDescriptor.setDescription(description); 
    116164    } 
    117165 
    118166    public void setSuperclass(String name) { 
    119         //To change body of implemented methods use File | Settings | File Templates. 
     167        ((ClassDescriptor) typeDescriptor).setSuperclass(name); 
    120168    } 
    121169 
    122170    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); 
    124177    } 
    125178} 
  • trunk/src/org/fluffnstuff/asdoclet/generator/velocity/ClassDescriptor.java

    r4 r5  
    22 
    33public class ClassDescriptor extends TypeDescriptor { 
     4    private String superClass; 
     5 
    46    public ClassDescriptor(String className) { 
    57        super(className); 
    68    } 
     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    } 
    721} 
  • trunk/src/org/fluffnstuff/asdoclet/generator/velocity/Descriptor.java

    r4 r5  
    33import org.apache.commons.lang.ClassUtils; 
    44 
     5import java.util.ArrayList; 
     6import java.util.Collection; 
     7 
    58public class Descriptor { 
    69    private String typeName; 
     10    private String description; 
     11    private Collection<String> annotations = new ArrayList<String>(); 
    712 
    813    public Descriptor(String typeName) { 
    914        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); 
    1031    } 
    1132 
  • trunk/src/org/fluffnstuff/asdoclet/generator/velocity/TypeDescriptor.java

    r4 r5  
    44import java.util.Collection; 
    55 
    6 public class TypeDescriptor extends Descriptor { 
     6public abstract class TypeDescriptor extends Descriptor { 
    77    private Collection<MethodDescriptor> methodDescriptors = new ArrayList<MethodDescriptor>(); 
    88    private Collection<FieldDescriptor> fieldDescriptors = new ArrayList<FieldDescriptor>(); 
     9    private Collection<String> interfaces = new ArrayList<String>(); 
    910 
    1011    public TypeDescriptor(String typeName) { 
     
    1415    public Collection<FieldDescriptor> getFieldDescriptors() { 
    1516        return fieldDescriptors; 
     17    } 
     18 
     19    public Collection<String> getInterfaces() { 
     20        return interfaces; 
    1621    } 
    1722 
     
    2429    } 
    2530 
     31    public void addInterface(String interfaceName) { 
     32        interfaces.add(interfaceName); 
     33    } 
     34 
    2635    public void addMethodDescriptor(MethodDescriptor methodDescriptor) { 
    2736        methodDescriptors.add(methodDescriptor); 
    2837    } 
     38 
     39    public abstract String getTemplate(); 
    2940} 
  • trunk/src/org/fluffnstuff/asdoclet/handler/ClassHandler.java

    r4 r5  
    2121    public void process(ClassDoc classDoc) { 
    2222        Collection<String> imports = new TreeSet<String>(); 
    23         Map<String, String> commands = TagParser.processClassTags(classDoc); 
     23        Map<String, String> commands = TagParser.processClassTags(getGenerator(), classDoc); 
    2424 
    2525        boolean bindable = TagParser.getBooleanCommand(Constants.COMMAND_BINDABLE, commands); 
     
    2828        getGenerator().beginClass(classDoc.qualifiedTypeName()); 
    2929 
    30         if (bindable) getGenerator().addAnnotation("Bindable"); 
    31         getGenerator().addAnnotation("RemoteClass(alias=\"" + classDoc.qualifiedTypeName() + "\")"); 
     30        if (bindable) getGenerator().addTypeAnnotation("Bindable"); 
     31        getGenerator().addTypeAnnotation("RemoteClass(alias=\"" + classDoc.qualifiedTypeName() + "\")"); 
    3232 
    3333        processSuperClass(classDoc, ignore); 
     
    4141        for (MethodDoc methodDoc : classDoc.methods()) { 
    4242            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); 
    4444 
    4545            boolean ignoreProperty = TagParser.getBooleanCommand(Constants.COMMAND_IGNORE, commands); 
  • trunk/src/org/fluffnstuff/asdoclet/handler/Constants.java

    r4 r5  
    22 
    33final 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"; 
    77 
    88    public static final String COMMAND_ASYNC = "async"; 
  • trunk/src/org/fluffnstuff/asdoclet/handler/InterfaceHandler.java

    r4 r5  
    44import com.sun.javadoc.MethodDoc; 
    55import com.sun.javadoc.Parameter; 
     6import org.fluffnstuff.asdoclet.generator.Generator; 
    67import org.fluffnstuff.asdoclet.map.TypeMap; 
    7 import org.fluffnstuff.asdoclet.generator.Generator; 
    88 
    99import java.util.Collection; 
     
    2727 
    2828        if (parentCommands != null) commands.putAll(parentCommands); 
    29         commands.putAll(TagParser.processClassTags(classDoc)); 
     29        commands.putAll(TagParser.processClassTags(getGenerator(), classDoc)); 
    3030 
    3131        Collection<String> imports = new TreeSet<String>(); 
     
    6363 
    6464        if (parentCommands != null) commands.putAll(parentCommands); 
    65         commands.putAll(TagParser.processClassTags(classDoc)); 
     65        commands.putAll(TagParser.processClassTags(getGenerator(), classDoc)); 
    6666 
    6767        processInterfaces(classDoc, commands, asyncReturnType, proxyImports, imports); 
     
    9090        Map<String, String> methodCommands = new HashMap<String, String>(commands); 
    9191 
    92         TagParser.processTags(methodDoc.tags(Constants.TAG_ACTIONSCRIPT_METHOD), methodCommands); 
     92        TagParser.processTags(methodDoc.tags(getGenerator().getName() + Constants.TAG_METHOD), methodCommands); 
    9393 
    9494        boolean async = TagParser.getBooleanCommand(Constants.COMMAND_ASYNC, methodCommands); 
  • trunk/src/org/fluffnstuff/asdoclet/handler/TagParser.java

    r2 r5  
    33import com.sun.javadoc.ClassDoc; 
    44import com.sun.javadoc.Tag; 
     5import org.fluffnstuff.asdoclet.generator.Generator; 
    56 
    67import java.util.HashMap; 
     
    2829    } 
    2930 
    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); 
    3233        return tags.length > 0; 
    3334    } 
    3435 
    35     public static Map<String, String> processClassTags(ClassDoc classDoc) { 
     36    public static Map<String, String> processClassTags(Generator generator, ClassDoc classDoc) { 
    3637        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); 
    4041        return commands; 
    4142    }