Trail:

Changeset 6

Show
Ignore:
Timestamp:
07/17/08 16:52:03 (4 years ago)
Author:
harald
Message:

--

Files:

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; }; 
     1namespace $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; 
    59#end 
    610 
    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                 */ 
    915#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        } 
    1119} 
  • 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 
     1namespace $typeDescriptor.nameSpace { 
     2#if($typeDescriptor.description)        /** 
     3         * $typeDescriptor.description 
     4         */ 
    55#end 
    6     } 
     6        public enum $typeDescriptor.typeName {#foreach($fieldDescriptor in $typeDescriptor.fieldDescriptors)#if($velocityCount>1), #end 
     7 
     8                $fieldDescriptor.fieldName#end 
     9 
     10        } 
    711} 
  • 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}() {} 
     1namespace $typeDescriptor.nameSpace { 
     2#if($typeDescriptor.description)        /** 
     3         * $typeDescriptor.description 
     4         */ 
    55#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        } 
    715} 
  • trunk/src/org/fluffnstuff/asdoclet/AsDoclet.java

    r5 r6  
    1010import org.fluffnstuff.asdoclet.map.ClassTypeMap; 
    1111import org.fluffnstuff.asdoclet.map.TypeMap; 
     12import org.fluffnstuff.asdoclet.util.EnumUtil; 
    1213 
    1314public class AsDoclet { 
     
    1718    private static final String PARAM_MAP = "-map"; 
    1819    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(); 
    2220 
    2321    public static boolean start(RootDoc root) throws Exception { 
     
    4139        String generator = null; 
    4240 
     41        ClassTypeMap typeMap = new ClassTypeMap(); 
     42        TypeMap annotationMap = new TypeMap(); 
     43 
    4344        for (String[] opt : options) { 
    4445            if (opt[0].equals(PARAM_DESTINATION)) destination = opt[1]; 
     
    5657 
    5758        if ("actionscript".equals(generator)) { 
    58             return new AsGenerator(destination, namespace); 
     59            return new AsGenerator(destination, namespace, typeMap, annotationMap); 
    5960        } else if ("cs".equals(generator)) { 
    60             return new VelocityGenerator(destination, namespace, "cs"); 
     61            return new VelocityGenerator(destination, namespace, "cs", typeMap, annotationMap); 
    6162        } 
    6263        return null; 
     
    6768 
    6869        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); 
    7273        } else { 
    73             handler = new ClassHandler(generator, typeMap, annotationMap); 
     74            handler = new ClassHandler(generator); 
    7475        } 
    7576 
  • trunk/src/org/fluffnstuff/asdoclet/generator/AsGenerator.java

    r5 r6  
    22 
    33import org.fluffnstuff.asdoclet.handler.Constants; 
     4import org.fluffnstuff.asdoclet.map.TypeMap; 
    45import uk.co.badgersinfoil.metaas.ActionScriptFactory; 
    56import uk.co.badgersinfoil.metaas.ActionScriptProject; 
     
    2829    private ASField field; 
    2930 
    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 
    3138        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"); 
    3270    } 
    3371 
     
    159197    } 
    160198 
     199    public String getAnnotation(String name, Collection<String> imports) { 
     200        return annotationMap.getType(name, false, imports); 
     201    } 
     202 
    161203    public String getName() { 
    162204        return "actionscript"; 
     205    } 
     206 
     207    public String getType(String name, boolean primitive, Collection<String> imports) { 
     208        return typeMap.getType(name, primitive, imports); 
    163209    } 
    164210 
  • trunk/src/org/fluffnstuff/asdoclet/generator/Generator.java

    r5 r6  
    3838    void generate() throws Exception; 
    3939 
     40    String getAnnotation(String name, Collection<String> imports); 
     41 
    4042    String getName(); 
     43 
     44    String getType(String name, boolean primitive, Collection<String> imports); 
    4145 
    4246    void setFieldDescription(String description); 
  • trunk/src/org/fluffnstuff/asdoclet/generator/VelocityGenerator.java

    r5 r6  
    77import org.fluffnstuff.asdoclet.generator.velocity.*; 
    88import org.fluffnstuff.asdoclet.handler.Constants; 
     9import org.fluffnstuff.asdoclet.map.TypeMap; 
    910 
    1011import java.io.File; 
     
    2728    private MethodDescriptor methodDescriptor; 
    2829    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 { 
    3134        this.destination = new File(destination); 
    3235        this.namespace = namespace; 
    3336        this.language = language; 
     37        this.typeMap = typeMap; 
     38        this.annotationMap = annotationMap; 
    3439 
    3540        Velocity.setProperty(Velocity.RESOURCE_LOADER, "class"); 
    3641        Velocity.setProperty("class.resource.loader.class", "org.apache.velocity.runtime.resource.loader.ClasspathResourceLoader"); 
    3742        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"); 
    3873    } 
    3974 
     
    143178 
    144179            VelocityContext context = new VelocityContext(); 
    145             String s = typeDescriptor.getTemplate(); 
     180            String s = descriptor.getTemplate(); 
    146181            Template template = Velocity.getTemplate("templates/" + language + "/" + s); 
    147182 
    148             context.put("classDescriptor", descriptor); 
     183            context.put("typeDescriptor", descriptor); 
    149184            template.merge(context, writer); 
    150185            writer.close(); 
     
    152187    } 
    153188 
     189    public String getAnnotation(String name, Collection<String> imports) { 
     190        return annotationMap.getType(name, false, imports); 
     191    } 
     192 
    154193    public String getName() { 
    155194        return language; 
     195    } 
     196 
     197    public String getType(String name, boolean primitive, Collection<String> imports) { 
     198        return typeMap.getType(name, primitive, imports); 
    156199    } 
    157200 
  • trunk/src/org/fluffnstuff/asdoclet/handler/AbstractHandler.java

    r4 r6  
    22 
    33import com.sun.javadoc.ClassDoc; 
    4 import org.fluffnstuff.asdoclet.map.TypeMap; 
    54import org.fluffnstuff.asdoclet.generator.Generator; 
    65 
     
    98 
    109    private final Generator generator; 
    11     private final TypeMap typeMap; 
    12     private final TypeMap annotationMap; 
    1310 
    14     protected AbstractHandler(Generator generator, TypeMap typeMap, TypeMap annotationMap) { 
     11    protected AbstractHandler(Generator generator) { 
    1512        this.generator = generator; 
    16         this.typeMap = typeMap; 
    17         this.annotationMap = annotationMap; 
    18     } 
    19  
    20     protected TypeMap getAnnotationMap() { 
    21         return annotationMap; 
    2213    } 
    2314 
    2415    protected Generator getGenerator() { 
    2516        return generator; 
    26     } 
    27  
    28     protected TypeMap getTypeMap() { 
    29         return typeMap; 
    3017    } 
    3118 
  • trunk/src/org/fluffnstuff/asdoclet/handler/ClassHandler.java

    r5 r6  
    33import com.sun.javadoc.*; 
    44import org.fluffnstuff.asdoclet.generator.Generator; 
    5 import org.fluffnstuff.asdoclet.map.TypeMap; 
    65 
    76import java.beans.Introspector; 
     
    1312 
    1413public 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); 
    1716    } 
    1817 
     
    8281 
    8382            if (fieldType == null) { 
    84                 fieldType = getTypeMap().getType(returnType.qualifiedTypeName(), returnType.isPrimitive(), imports); 
     83                fieldType = getGenerator().getType(returnType.qualifiedTypeName(), returnType.isPrimitive(), imports); 
    8584            } 
    8685        } else { 
     
    9594        for (AnnotationDesc annotationDesc : annotationDescs) { 
    9695            AnnotationTypeDoc annotationTypeDoc = annotationDesc.annotationType(); 
    97             fieldType = getAnnotationMap().getType(annotationTypeDoc.qualifiedTypeName(), false, imports); 
     96            fieldType = getGenerator().getAnnotation(annotationTypeDoc.qualifiedTypeName(), imports); 
    9897            if (fieldType != null) break; 
    9998        } 
     
    124123        if (superClassDoc != null) { 
    125124            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            } 
    127129        } 
    128130    } 
  • trunk/src/org/fluffnstuff/asdoclet/handler/EnumHandler.java

    r4 r6  
    44import com.sun.javadoc.FieldDoc; 
    55import org.fluffnstuff.asdoclet.generator.Generator; 
    6 import org.fluffnstuff.asdoclet.map.TypeMap; 
    76 
    87public 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); 
    1110    } 
    1211 
  • trunk/src/org/fluffnstuff/asdoclet/handler/InterfaceHandler.java

    r5 r6  
    55import com.sun.javadoc.Parameter; 
    66import org.fluffnstuff.asdoclet.generator.Generator; 
    7 import org.fluffnstuff.asdoclet.map.TypeMap; 
    87 
    98import java.util.Collection; 
     
    1312 
    1413public 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); 
    1716    } 
    1817 
     
    4544            String baseType = TagParser.getStringCommand(Constants.COMMAND_PROXY_BASE_CLASS, commands); 
    4645 
    47             String interfaceType = getTypeMap().getType(interfaceName, false, proxyImports); 
     46            String interfaceType = getGenerator().getType(interfaceName, false, proxyImports); 
    4847            getGenerator().beginProxy(proxyName, asyncReturnType, baseType, proxyImports, interfaceType); 
    4948        } 
     
    7271        for (ClassDoc interfaceDoc : classDoc.interfaces()) { 
    7372            if (!commands.containsKey(Constants.COMMAND_IGNORE) || !commands.get(Constants.COMMAND_IGNORE).contains(interfaceDoc.qualifiedTypeName())) { 
    74                 String interfaceClass = getTypeMap().getType(interfaceDoc.qualifiedTypeName(), interfaceDoc.isPrimitive(), null); 
     73                String interfaceClass = getGenerator().getType(interfaceDoc.qualifiedTypeName(), false, null); 
    7574                getGenerator().addInterface(interfaceClass); 
    7675 
     
    8281    private void processMethods(ClassDoc classDoc, Map<String, String> commands, Collection<String> imports, String asyncReturnType) { 
    8382        for (MethodDoc methodDoc : classDoc.methods()) { 
    84             String returnType = getTypeMap().getType(methodDoc.returnType().qualifiedTypeName(), methodDoc.returnType().isPrimitive(), null); 
     83            String returnType = getGenerator().getType(methodDoc.returnType().qualifiedTypeName(), methodDoc.returnType().isPrimitive(), null); 
    8584            processMethod(methodDoc, commands, imports, returnType, asyncReturnType); 
    8685        } 
     
    105104 
    106105            for (Parameter parameter : methodDoc.parameters()) { 
    107                 String type = getTypeMap().getType(parameter.type().qualifiedTypeName(), parameter.type().isPrimitive(), imports); 
     106                String type = getGenerator().getType(parameter.type().qualifiedTypeName(), parameter.type().isPrimitive(), imports); 
    108107                getGenerator().addParameter(type, parameter.name()); 
    109108            } 
  • trunk/src/org/fluffnstuff/asdoclet/map/ClassTypeMap.java

    r4 r6  
    44 
    55public 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 null 
    15         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  
    336    @Override 
    347    public String getType(String typeName, boolean primitive, Collection<String> imports) { 
    35         String asType
     8        String asType = super.getType(typeName, primitive, imports)
    369 
    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; 
    4613        } 
    4714 
    4815        return asType; 
    4916    } 
    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             // ignore 
    58         } 
    59         return isEnum; 
    60     } 
    6117} 
  • trunk/src/org/fluffnstuff/asdoclet/map/TypeMap.java

    r4 r6  
    11package org.fluffnstuff.asdoclet.map; 
     2 
     3import org.fluffnstuff.asdoclet.util.EnumUtil; 
    24 
    35import java.util.Collection; 
     
    79public class TypeMap { 
    810    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    } 
    916 
    1017    public void addTypeMapping(String javaType, String asType) { 
    11         typeMap.put(javaType, asType); 
     18        if (!typeMap.containsKey(javaType)) typeMap.put(javaType, asType); 
    1219    } 
    1320 
     
    1522        String asType = null; 
    1623 
    17         if (typeMap.containsKey(typeName)) { 
     24        if (enumType != null && EnumUtil.isEnum(typeName)) { 
     25            asType = enumType; 
     26        } else if (typeMap.containsKey(typeName)) { 
    1827            asType = typeMap.get(typeName); 
    1928        }