Trail:

Changeset 4

Show
Ignore:
Timestamp:
07/16/08 17:44:24 (4 years ago)
Author:
harald
Message:
  • Separate generator from doclet
  • Add velocity generator in parallel to the as generator
Files:

Legend:

Unmodified
Added
Removed
Modified
Copied
Moved
  • trunk/asdoclet.ipr

    r2 r4  
    331331  <component name="copyright"> 
    332332    <Base> 
    333       <setting name="state" value="1" /> 
     333      <setting name="state" value="2" /> 
    334334    </Base> 
    335     <LanguageOptions name="$TEMPLATE$"> 
    336       <option name="templateOptions"> 
    337         <value> 
    338           <option name="block" value="true" /> 
    339           <option name="separateBefore" value="false" /> 
    340           <option name="separateAfter" value="false" /> 
    341           <option name="prefixLines" value="true" /> 
    342           <option name="lenBefore" value="80" /> 
    343           <option name="lenAfter" value="80" /> 
    344           <option name="box" value="false" /> 
    345           <option name="filler" value=" " /> 
    346         </value> 
    347       </option> 
    348       <option name="notice" value="Copyright (c) &amp;#36;today.year, Modern-Families. All Rights Reserved." /> 
     335    <LanguageOptions name="HTML"> 
     336      <option name="templateOptions"> 
     337        <value> 
     338          <option name="block" value="true" /> 
     339          <option name="separateBefore" value="false" /> 
     340          <option name="separateAfter" value="false" /> 
     341          <option name="prefixLines" value="true" /> 
     342          <option name="lenBefore" value="80" /> 
     343          <option name="lenAfter" value="80" /> 
     344          <option name="box" value="false" /> 
     345          <option name="filler" value=" " /> 
     346        </value> 
     347      </option> 
     348      <option name="notice" value="Copyright (c) &amp;#36;today.year, Your Corporation. All Rights Reserved." /> 
     349      <option name="keyword" value="Copyright" /> 
     350      <option name="fileTypeOverride" value="2" /> 
     351      <option name="relativeBefore" value="true" /> 
     352      <option name="addBlankAfter" value="true" /> 
     353      <option name="fileLocation" value="1" /> 
     354      <option name="useAlternate" value="false" /> 
     355    </LanguageOptions> 
     356    <LanguageOptions name="JAVA"> 
     357      <option name="templateOptions"> 
     358        <value> 
     359          <option name="block" value="true" /> 
     360          <option name="separateBefore" value="false" /> 
     361          <option name="separateAfter" value="false" /> 
     362          <option name="prefixLines" value="true" /> 
     363          <option name="lenBefore" value="80" /> 
     364          <option name="lenAfter" value="80" /> 
     365          <option name="box" value="false" /> 
     366          <option name="filler" value=" " /> 
     367        </value> 
     368      </option> 
     369      <option name="notice" value="Copyright (c) &amp;#36;today.year, Your Corporation. All Rights Reserved." /> 
     370      <option name="keyword" value="Copyright" /> 
     371      <option name="fileTypeOverride" value="2" /> 
     372      <option name="relativeBefore" value="true" /> 
     373      <option name="addBlankAfter" value="true" /> 
     374      <option name="fileLocation" value="1" /> 
     375      <option name="useAlternate" value="false" /> 
     376    </LanguageOptions> 
     377    <LanguageOptions name="JSP"> 
     378      <option name="templateOptions"> 
     379        <value> 
     380          <option name="block" value="true" /> 
     381          <option name="separateBefore" value="false" /> 
     382          <option name="separateAfter" value="false" /> 
     383          <option name="prefixLines" value="true" /> 
     384          <option name="lenBefore" value="80" /> 
     385          <option name="lenAfter" value="80" /> 
     386          <option name="box" value="false" /> 
     387          <option name="filler" value=" " /> 
     388        </value> 
     389      </option> 
     390      <option name="notice" value="Copyright (c) &amp;#36;today.year, Your Corporation. All Rights Reserved." /> 
     391      <option name="keyword" value="Copyright" /> 
     392      <option name="fileTypeOverride" value="2" /> 
     393      <option name="relativeBefore" value="true" /> 
     394      <option name="addBlankAfter" value="true" /> 
     395      <option name="fileLocation" value="1" /> 
     396      <option name="useAlternate" value="false" /> 
     397    </LanguageOptions> 
     398    <LanguageOptions name="JavaScript"> 
     399      <option name="templateOptions"> 
     400        <value> 
     401          <option name="block" value="true" /> 
     402          <option name="separateBefore" value="false" /> 
     403          <option name="separateAfter" value="false" /> 
     404          <option name="prefixLines" value="true" /> 
     405          <option name="lenBefore" value="80" /> 
     406          <option name="lenAfter" value="80" /> 
     407          <option name="box" value="false" /> 
     408          <option name="filler" value=" " /> 
     409        </value> 
     410      </option> 
     411      <option name="notice" value="Copyright (c) &amp;#36;today.year, Your Corporation. All Rights Reserved." /> 
     412      <option name="keyword" value="Copyright" /> 
     413      <option name="fileTypeOverride" value="2" /> 
     414      <option name="relativeBefore" value="true" /> 
     415      <option name="addBlankAfter" value="true" /> 
     416      <option name="fileLocation" value="1" /> 
     417      <option name="useAlternate" value="false" /> 
     418    </LanguageOptions> 
     419    <LanguageOptions name="Properties"> 
     420      <option name="templateOptions"> 
     421        <value> 
     422          <option name="block" value="true" /> 
     423          <option name="separateBefore" value="false" /> 
     424          <option name="separateAfter" value="false" /> 
     425          <option name="prefixLines" value="true" /> 
     426          <option name="lenBefore" value="80" /> 
     427          <option name="lenAfter" value="80" /> 
     428          <option name="box" value="false" /> 
     429          <option name="filler" value=" " /> 
     430        </value> 
     431      </option> 
     432      <option name="notice" value="Copyright (c) &amp;#36;today.year, Your Corporation. All Rights Reserved." /> 
     433      <option name="keyword" value="Copyright" /> 
     434      <option name="fileTypeOverride" value="2" /> 
     435      <option name="relativeBefore" value="true" /> 
     436      <option name="addBlankAfter" value="true" /> 
     437      <option name="fileLocation" value="1" /> 
     438      <option name="useAlternate" value="false" /> 
     439    </LanguageOptions> 
     440    <LanguageOptions name="XML"> 
     441      <option name="templateOptions"> 
     442        <value> 
     443          <option name="block" value="true" /> 
     444          <option name="separateBefore" value="false" /> 
     445          <option name="separateAfter" value="false" /> 
     446          <option name="prefixLines" value="true" /> 
     447          <option name="lenBefore" value="80" /> 
     448          <option name="lenAfter" value="80" /> 
     449          <option name="box" value="false" /> 
     450          <option name="filler" value=" " /> 
     451        </value> 
     452      </option> 
     453      <option name="notice" value="Copyright (c) &amp;#36;today.year, Your Corporation. All Rights Reserved." /> 
     454      <option name="keyword" value="Copyright" /> 
     455      <option name="fileTypeOverride" value="2" /> 
     456      <option name="relativeBefore" value="true" /> 
     457      <option name="addBlankAfter" value="true" /> 
     458      <option name="fileLocation" value="1" /> 
     459      <option name="useAlternate" value="false" /> 
     460    </LanguageOptions> 
     461    <LanguageOptions name="__TEMPLATE__"> 
     462      <option name="templateOptions"> 
     463        <value> 
     464          <option name="block" value="true" /> 
     465          <option name="separateBefore" value="false" /> 
     466          <option name="separateAfter" value="false" /> 
     467          <option name="prefixLines" value="true" /> 
     468          <option name="lenBefore" value="80" /> 
     469          <option name="lenAfter" value="80" /> 
     470          <option name="box" value="false" /> 
     471          <option name="filler" value=" " /> 
     472        </value> 
     473      </option> 
     474      <option name="notice" value="asdf" /> 
    349475      <option name="keyword" value="Copyright" /> 
    350476      <option name="fileTypeOverride" value="4" /> 
    351       <option name="relativeBefore" value="true" /> 
    352       <option name="addBlankAfter" value="true" /> 
    353       <option name="fileLocation" value="1" /> 
    354       <option name="useAlternate" value="false" /> 
    355     </LanguageOptions> 
    356     <LanguageOptions name="HTML"> 
    357       <option name="templateOptions"> 
    358         <value> 
    359           <option name="block" value="true" /> 
    360           <option name="separateBefore" value="false" /> 
    361           <option name="separateAfter" value="false" /> 
    362           <option name="prefixLines" value="true" /> 
    363           <option name="lenBefore" value="80" /> 
    364           <option name="lenAfter" value="80" /> 
    365           <option name="box" value="false" /> 
    366           <option name="filler" value=" " /> 
    367         </value> 
    368       </option> 
    369       <option name="notice" value="Copyright (c) &amp;#36;today.year, Your Corporation. All Rights Reserved." /> 
    370       <option name="keyword" value="Copyright" /> 
    371       <option name="fileTypeOverride" value="2" /> 
    372       <option name="relativeBefore" value="true" /> 
    373       <option name="addBlankAfter" value="true" /> 
    374       <option name="fileLocation" value="1" /> 
    375       <option name="useAlternate" value="false" /> 
    376     </LanguageOptions> 
    377     <LanguageOptions name="JAVA"> 
    378       <option name="templateOptions"> 
    379         <value> 
    380           <option name="block" value="true" /> 
    381           <option name="separateBefore" value="false" /> 
    382           <option name="separateAfter" value="false" /> 
    383           <option name="prefixLines" value="true" /> 
    384           <option name="lenBefore" value="80" /> 
    385           <option name="lenAfter" value="80" /> 
    386           <option name="box" value="false" /> 
    387           <option name="filler" value=" " /> 
    388         </value> 
    389       </option> 
    390       <option name="notice" value="Copyright (c) &amp;#36;today.year, Your Corporation. All Rights Reserved." /> 
    391       <option name="keyword" value="Copyright" /> 
    392       <option name="fileTypeOverride" value="2" /> 
    393       <option name="relativeBefore" value="true" /> 
    394       <option name="addBlankAfter" value="true" /> 
    395       <option name="fileLocation" value="1" /> 
    396       <option name="useAlternate" value="false" /> 
    397     </LanguageOptions> 
    398     <LanguageOptions name="JSP"> 
    399       <option name="templateOptions"> 
    400         <value> 
    401           <option name="block" value="true" /> 
    402           <option name="separateBefore" value="false" /> 
    403           <option name="separateAfter" value="false" /> 
    404           <option name="prefixLines" value="true" /> 
    405           <option name="lenBefore" value="80" /> 
    406           <option name="lenAfter" value="80" /> 
    407           <option name="box" value="false" /> 
    408           <option name="filler" value=" " /> 
    409         </value> 
    410       </option> 
    411       <option name="notice" value="Copyright (c) &amp;#36;today.year, Your Corporation. All Rights Reserved." /> 
    412       <option name="keyword" value="Copyright" /> 
    413       <option name="fileTypeOverride" value="2" /> 
    414       <option name="relativeBefore" value="true" /> 
    415       <option name="addBlankAfter" value="true" /> 
    416       <option name="fileLocation" value="1" /> 
    417       <option name="useAlternate" value="false" /> 
    418     </LanguageOptions> 
    419     <LanguageOptions name="JavaScript"> 
    420       <option name="templateOptions"> 
    421         <value> 
    422           <option name="block" value="true" /> 
    423           <option name="separateBefore" value="false" /> 
    424           <option name="separateAfter" value="false" /> 
    425           <option name="prefixLines" value="true" /> 
    426           <option name="lenBefore" value="80" /> 
    427           <option name="lenAfter" value="80" /> 
    428           <option name="box" value="false" /> 
    429           <option name="filler" value=" " /> 
    430         </value> 
    431       </option> 
    432       <option name="notice" value="Copyright (c) &amp;#36;today.year, Your Corporation. All Rights Reserved." /> 
    433       <option name="keyword" value="Copyright" /> 
    434       <option name="fileTypeOverride" value="2" /> 
    435       <option name="relativeBefore" value="true" /> 
    436       <option name="addBlankAfter" value="true" /> 
    437       <option name="fileLocation" value="1" /> 
    438       <option name="useAlternate" value="false" /> 
    439     </LanguageOptions> 
    440     <LanguageOptions name="Properties"> 
    441       <option name="templateOptions"> 
    442         <value> 
    443           <option name="block" value="true" /> 
    444           <option name="separateBefore" value="false" /> 
    445           <option name="separateAfter" value="false" /> 
    446           <option name="prefixLines" value="true" /> 
    447           <option name="lenBefore" value="80" /> 
    448           <option name="lenAfter" value="80" /> 
    449           <option name="box" value="false" /> 
    450           <option name="filler" value=" " /> 
    451         </value> 
    452       </option> 
    453       <option name="notice" value="Copyright (c) &amp;#36;today.year, Your Corporation. All Rights Reserved." /> 
    454       <option name="keyword" value="Copyright" /> 
    455       <option name="fileTypeOverride" value="2" /> 
    456       <option name="relativeBefore" value="true" /> 
    457       <option name="addBlankAfter" value="true" /> 
    458       <option name="fileLocation" value="1" /> 
    459       <option name="useAlternate" value="false" /> 
    460     </LanguageOptions> 
    461     <LanguageOptions name="XML"> 
    462       <option name="templateOptions"> 
    463         <value> 
    464           <option name="block" value="true" /> 
    465           <option name="separateBefore" value="false" /> 
    466           <option name="separateAfter" value="false" /> 
    467           <option name="prefixLines" value="true" /> 
    468           <option name="lenBefore" value="80" /> 
    469           <option name="lenAfter" value="80" /> 
    470           <option name="box" value="false" /> 
    471           <option name="filler" value=" " /> 
    472         </value> 
    473       </option> 
    474       <option name="notice" value="Copyright (c) &amp;#36;today.year, Your Corporation. All Rights Reserved." /> 
    475       <option name="keyword" value="Copyright" /> 
    476       <option name="fileTypeOverride" value="2" /> 
    477477      <option name="relativeBefore" value="true" /> 
    478478      <option name="addBlankAfter" value="true" /> 
  • trunk/src/org/fluffnstuff/asdoclet/AsDoclet.java

    r2 r4  
    44import com.sun.javadoc.DocErrorReporter; 
    55import com.sun.javadoc.RootDoc; 
     6import org.fluffnstuff.asdoclet.generator.AsGenerator; 
     7import org.fluffnstuff.asdoclet.generator.Generator; 
     8import org.fluffnstuff.asdoclet.generator.VelocityGenerator; 
    69import org.fluffnstuff.asdoclet.handler.*; 
    7 import uk.co.badgersinfoil.metaas.ActionScriptFactory; 
    8 import uk.co.badgersinfoil.metaas.ActionScriptProject; 
    9  
    10 import java.io.IOException; 
     10import org.fluffnstuff.asdoclet.map.ClassTypeMap; 
     11import org.fluffnstuff.asdoclet.map.TypeMap; 
    1112 
    1213public class AsDoclet { 
     
    1516    private static final String PARAM_ANNOTATION_MAP = "-annotationmap"; 
    1617 
    17     private static final AsClassTypeMap typeMap = new AsClassTypeMap(); 
    18     private static final AsTypeMap annotationMap = new AsTypeMap(); 
     18    private static final ClassTypeMap typeMap = new ClassTypeMap(); 
     19    private static final TypeMap annotationMap = new TypeMap(); 
    1920 
    20     public static boolean start(RootDoc root) throws IOException { 
     21    public static boolean start(RootDoc root) throws Exception { 
    2122        String destination = readOptions(root.options()); 
    2223 
    23         ActionScriptFactory factory = new ActionScriptFactory(); 
    24         ActionScriptProject project = factory.newEmptyASProject(destination); 
     24        // todo configurable generator 
     25//        Generator generator = new AsGenerator(destination); 
     26        Generator generator = new VelocityGenerator(destination); 
    2527 
    2628        for (ClassDoc classDoc : root.classes()) { 
    2729            if (TagParser.hasClassTags(classDoc)) { 
    28                 Handler handler = createHandler(project, classDoc); 
     30                Handler handler = createHandler(generator, classDoc); 
    2931                handler.process(classDoc); 
    3032            } 
    3133        } 
    3234 
    33         project.performAutoImport(); 
    34         project.writeAll(); 
     35        generator.generate(); 
    3536 
    3637        return true; 
     
    5556    } 
    5657 
    57     private static Handler createHandler(ActionScriptProject project, ClassDoc classDoc) { 
     58    private static Handler createHandler(Generator generator, ClassDoc classDoc) { 
    5859        Handler handler; 
    5960 
    6061        if (classDoc.isInterface()) { 
    61             handler = new InterfaceHandler(project, typeMap, annotationMap); 
     62            handler = new InterfaceHandler(generator, typeMap, annotationMap); 
    6263        } else if (typeMap.isEnum(classDoc.qualifiedTypeName())) { 
    63             handler = new EnumHandler(project, typeMap, annotationMap); 
     64            handler = new EnumHandler(generator, typeMap, annotationMap); 
    6465        } else { 
    65             handler = new ClassHandler(project, typeMap, annotationMap); 
     66            handler = new ClassHandler(generator, typeMap, annotationMap); 
    6667        } 
    6768 
  • trunk/src/org/fluffnstuff/asdoclet/handler/AbstractHandler.java

    r2 r4  
    22 
    33import com.sun.javadoc.ClassDoc; 
    4 import org.fluffnstuff.asdoclet.AsTypeMap; 
    5 import uk.co.badgersinfoil.metaas.ActionScriptProject; 
    6 import uk.co.badgersinfoil.metaas.dom.*; 
    7  
    8 import java.text.MessageFormat; 
    9 import java.util.Collection; 
     4import org.fluffnstuff.asdoclet.map.TypeMap; 
     5import org.fluffnstuff.asdoclet.generator.Generator; 
    106 
    117public abstract class AbstractHandler implements Handler { 
    128    private static final String COMMENT_PREFIX = "\t * "; 
    139 
    14     private final ActionScriptProject project
    15     private final AsTypeMap typeMap; 
    16     private final AsTypeMap annotationMap; 
     10    private final Generator generator
     11    private final TypeMap typeMap; 
     12    private final TypeMap annotationMap; 
    1713 
    18     protected AbstractHandler(ActionScriptProject project, AsTypeMap typeMap, AsTypeMap annotationMap) { 
    19         this.project = project
     14    protected AbstractHandler(Generator generator, TypeMap typeMap, TypeMap annotationMap) { 
     15        this.generator = generator
    2016        this.typeMap = typeMap; 
    2117        this.annotationMap = annotationMap; 
    2218    } 
    2319 
    24     protected AsTypeMap getAnnotationMap() { 
     20    protected TypeMap getAnnotationMap() { 
    2521        return annotationMap; 
    2622    } 
    2723 
    28     protected ActionScriptProject getProject() { 
    29         return project
     24    protected Generator getGenerator() { 
     25        return generator
    3026    } 
    3127 
    32     protected AsTypeMap getTypeMap() { 
     28    protected TypeMap getTypeMap() { 
    3329        return typeMap; 
    3430    } 
    3531 
    36     protected void createConst(ASClassType eventType, String name, String value) { 
    37         ASField field = eventType.newField(name, Visibility.PUBLIC, "String"); 
    38         field.setInitializer(MessageFormat.format("\"{0}\"", value)); 
    39         field.setStatic(true); 
    40         field.setConst(true); 
    41     } 
    42  
    43     protected void processClassComment(ClassDoc classDoc, ASType type) { 
     32    protected void processClassComment(ClassDoc classDoc) { 
    4433        StringBuilder description = new StringBuilder(); 
    4534        String comment = classDoc.commentText(); 
     
    5544        description.append(COMMENT_PREFIX).append("Do not edit."); 
    5645 
    57         if (description.length() > 0) type.setDescription(description.toString()); 
    58     } 
    59  
    60     protected void processImports(ASCompilationUnit unit, Collection<String> imports) { 
    61         ASPackage packge = unit.getPackage(); 
    62         for (String imp : imports) { 
    63             packge.addImport(imp); 
    64         } 
     46        if (description.length() > 0) getGenerator().setTypeDescription(description.toString()); 
    6547    } 
    6648} 
  • trunk/src/org/fluffnstuff/asdoclet/handler/ClassHandler.java

    r3 r4  
    22 
    33import com.sun.javadoc.*; 
    4 import org.fluffnstuff.asdoclet.AsTypeMap; 
    5 import uk.co.badgersinfoil.metaas.ActionScriptProject; 
    6 import uk.co.badgersinfoil.metaas.dom.ASClassType; 
    7 import uk.co.badgersinfoil.metaas.dom.ASCompilationUnit; 
    8 import uk.co.badgersinfoil.metaas.dom.ASField; 
    9 import uk.co.badgersinfoil.metaas.dom.Visibility; 
     4import org.fluffnstuff.asdoclet.generator.Generator; 
     5import org.fluffnstuff.asdoclet.map.TypeMap; 
    106 
    117import java.beans.Introspector; 
     8import java.lang.reflect.Modifier; 
    129import java.util.Collection; 
    1310import java.util.HashMap; 
     
    1613 
    1714public class ClassHandler extends AbstractHandler { 
    18     public ClassHandler(ActionScriptProject project, AsTypeMap typeMap, AsTypeMap annotationMap) { 
    19         super(project, typeMap, annotationMap); 
     15    public ClassHandler(Generator generator, TypeMap typeMap, TypeMap annotationMap) { 
     16        super(generator, typeMap, annotationMap); 
    2017    } 
    2118 
     
    2926        String ignore = TagParser.getStringCommand(Constants.COMMAND_IGNORE, "", commands); 
    3027 
    31         ASCompilationUnit unit = getProject().newClass(classDoc.qualifiedTypeName()); 
    32         ASClassType type = (ASClassType) unit.getType(); 
     28        getGenerator().beginClass(classDoc.qualifiedTypeName()); 
    3329 
    34         if (bindable) type.newMetaTag("Bindable"); 
    35         type.newMetaTag("RemoteClass(alias=\"" + classDoc.qualifiedTypeName() + "\")"); 
     30        if (bindable) getGenerator().addAnnotation("Bindable"); 
     31        getGenerator().addAnnotation("RemoteClass(alias=\"" + classDoc.qualifiedTypeName() + "\")"); 
    3632 
    37         processSuperClass(classDoc, ignore, type); 
    38         processClassComment(classDoc, type); 
    39         processBeanProperties(classDoc, imports, commands, type); 
    40         processImports(unit, imports); 
     33        processSuperClass(classDoc, ignore); 
     34        processClassComment(classDoc); 
     35        processBeanProperties(classDoc, imports, commands); 
     36 
     37        getGenerator().endClass(imports); 
    4138    } 
    4239 
    43     private void processBeanProperties(ClassDoc classDoc, Collection<String> imports, Map<String, String> commands, ASClassType type) { 
     40    private void processBeanProperties(ClassDoc classDoc, Collection<String> imports, Map<String, String> commands) { 
    4441        for (MethodDoc methodDoc : classDoc.methods()) { 
    4542            Map<String, String> methodCommands = new HashMap<String, String>(commands); 
     
    5249                if (propertyName != null) { 
    5350                    String fieldType = getFieldType(methodDoc, findField(classDoc, propertyName), imports, methodCommands); 
    54                     ASField field = type.newField(propertyName, Visibility.PUBLIC, fieldType); 
     51                    getGenerator().addField(Modifier.PUBLIC, fieldType, propertyName); 
    5552 
    56                     processFieldComment(methodDoc, field); 
     53                    processFieldComment(methodDoc); 
    5754                } 
    5855            } 
     
    116113    } 
    117114 
    118     private void processFieldComment(MethodDoc methodDoc, ASField field) { 
     115    private void processFieldComment(MethodDoc methodDoc) { 
    119116        StringBuilder description = new StringBuilder(); 
    120117        String comment = methodDoc.commentText(); 
    121118        if (comment != null) description.append(comment.trim()); 
    122         if (description.length() > 0) field.setDescription(description.toString()); 
     119        if (description.length() > 0) getGenerator().setFieldDescription(description.toString()); 
    123120    } 
    124121 
    125     private void processSuperClass(ClassDoc classDoc, String ignore, ASClassType type) { 
     122    private void processSuperClass(ClassDoc classDoc, String ignore) { 
    126123        ClassDoc superClassDoc = classDoc.superclass(); 
    127124        if (superClassDoc != null) { 
    128125            String superClassName = superClassDoc.qualifiedTypeName(); 
    129             if (!Object.class.getName().equals(superClassName) && !ignore.contains(superClassName)) type.setSuperclass(superClassName); 
     126            if (!Object.class.getName().equals(superClassName) && !ignore.contains(superClassName)) getGenerator().setSuperclass(superClassName); 
    130127        } 
    131128    } 
  • trunk/src/org/fluffnstuff/asdoclet/handler/Constants.java

    r2 r4  
    11package org.fluffnstuff.asdoclet.handler; 
    22 
    3 final class Constants { 
     3final public class Constants { 
    44    public static final String TAG_ACTIONSCRIPT_CLASS = "actionscript.class"; 
    55    public static final String TAG_ACTIONSCRIPT_METHOD = "actionscript.method"; 
     
    1414 
    1515    public static final String COMMAND_BINDABLE = "bindable"; 
    16     public static final String COMMAND_HANDLER = "handler"; 
    1716    public static final String COMMAND_IGNORE = "ignore"; 
    1817    public static final String COMMAND_TYPE = "type"; 
  • trunk/src/org/fluffnstuff/asdoclet/handler/EnumHandler.java

    r2 r4  
    33import com.sun.javadoc.ClassDoc; 
    44import com.sun.javadoc.FieldDoc; 
    5 import org.fluffnstuff.asdoclet.AsTypeMap; 
    6 import uk.co.badgersinfoil.metaas.ActionScriptProject; 
    7 import uk.co.badgersinfoil.metaas.dom.ASClassType; 
    8 import uk.co.badgersinfoil.metaas.dom.ASCompilationUnit; 
     5import org.fluffnstuff.asdoclet.generator.Generator; 
     6import org.fluffnstuff.asdoclet.map.TypeMap; 
    97 
    108public class EnumHandler extends AbstractHandler { 
    11     public EnumHandler(ActionScriptProject project, AsTypeMap typeMap, AsTypeMap annotationMap) { 
    12         super(project, typeMap, annotationMap); 
     9    public EnumHandler(Generator generator, TypeMap typeMap, TypeMap annotationMap) { 
     10        super(generator, typeMap, annotationMap); 
    1311    } 
    1412 
     
    1614 
    1715    public void process(ClassDoc classDoc) { 
    18         ASCompilationUnit unit = getProject().newClass(classDoc.qualifiedTypeName()); 
    19         ASClassType type = (ASClassType) unit.getType(); 
    20         type.setFinal(true); 
     16        getGenerator().beginEnum(classDoc.qualifiedTypeName()); 
     17        processClassComment(classDoc); 
    2118 
    22         processClassComment(classDoc, type); 
     19        for (FieldDoc fieldDoc : classDoc.fields()) getGenerator().addEnumField(fieldDoc.name()); 
    2320 
    24         for (FieldDoc fieldDoc : classDoc.fields()) createConst(type, fieldDoc.name(), fieldDoc.name()); 
     21        getGenerator().endEnum(); 
    2522    } 
    2623} 
  • trunk/src/org/fluffnstuff/asdoclet/handler/InterfaceHandler.java

    r2 r4  
    44import com.sun.javadoc.MethodDoc; 
    55import com.sun.javadoc.Parameter; 
    6 import com.sun.javadoc.Type; 
    7 import org.fluffnstuff.asdoclet.AsTypeMap; 
    8 import uk.co.badgersinfoil.metaas.ActionScriptProject; 
    9 import uk.co.badgersinfoil.metaas.dom.*; 
     6import org.fluffnstuff.asdoclet.map.TypeMap; 
     7import org.fluffnstuff.asdoclet.generator.Generator; 
    108 
    11 import java.beans.Introspector; 
    12 import java.text.MessageFormat; 
    139import java.util.Collection; 
    1410import java.util.HashMap; 
     
    1713 
    1814public class InterfaceHandler extends AbstractHandler { 
    19     public InterfaceHandler(ActionScriptProject project, AsTypeMap typeMap, AsTypeMap annotationMap) { 
    20         super(project, typeMap, annotationMap); 
     15    public InterfaceHandler(Generator generator, TypeMap typeMap, TypeMap annotationMap) { 
     16        super(generator, typeMap, annotationMap); 
    2117    } 
    2218 
     
    2420 
    2521    public void process(ClassDoc classDoc) { 
    26         processInterface(classDoc, null, null, null, null, true, null); 
     22        processInterface(classDoc, null); 
    2723    } 
    2824 
    29     private void processInterfaces(ClassDoc classDoc, ASType type, Map<String, String> commands, ASClassType eventType, ASClassType proxyType, Collection<String> proxyImports, String returnType) { 
    30         for (ClassDoc interfaceDoc : classDoc.interfaces()) { 
    31             if (!commands.containsKey(Constants.COMMAND_IGNORE) || !commands.get(Constants.COMMAND_IGNORE).contains(interfaceDoc.qualifiedTypeName())) { 
    32                 processParent(classDoc, interfaceDoc, type); 
    33                 processInterface(interfaceDoc, eventType, proxyType, proxyImports, returnType, false, commands); 
    34             } 
    35         } 
    36     } 
    37  
    38     private void processParent(ClassDoc classDoc, ClassDoc interfaceDoc, ASType type) { 
    39         String interfaceClass = getTypeMap().getType(interfaceDoc.qualifiedTypeName(), interfaceDoc.isPrimitive(), null); 
    40  
    41         if (type != null) { 
    42             if (classDoc.isInterface()) { 
    43                 ASInterfaceType interfaceType = (ASInterfaceType) type; 
    44                 interfaceType.addSuperInterface(interfaceClass); 
    45             } else { 
    46                 ASClassType classType = (ASClassType) type; 
    47                 classType.addImplementedInterface(interfaceClass); 
    48             } 
    49         } 
    50     } 
    51  
    52     private void processInterface(ClassDoc classDoc, ASClassType eventType, ASClassType proxyType, Collection<String> proxyImports, String returnType, boolean create, Map<String, String> parentCommands) { 
    53         Collection<String> imports = new TreeSet<String>(); 
    54         String interfaceName = classDoc.qualifiedTypeName(); 
     25    private void processInterface(ClassDoc classDoc, Map<String, String> parentCommands) { 
    5526        Map<String, String> commands = new HashMap<String, String>(); 
    5627 
     
    5829        commands.putAll(TagParser.processClassTags(classDoc)); 
    5930 
    60         ASCompilationUnit proxyUnit = null; 
    61         ASCompilationUnit unit = null; 
    62         ASType type = null; 
     31        Collection<String> imports = new TreeSet<String>(); 
     32        Collection<String> proxyImports = new TreeSet<String>(); 
    6333 
    64         if (proxyType == null) { 
    65             boolean proxy = TagParser.getBooleanCommand(Constants.COMMAND_PROXY, commands); 
    66             returnType = TagParser.getStringCommand(Constants.COMMAND_ASYNC_RETURN_TYPE, Constants.TYPE_VOID, commands); 
     34        boolean proxy = TagParser.getBooleanCommand(Constants.COMMAND_PROXY, commands); 
     35        String asyncReturnType = TagParser.getStringCommand(Constants.COMMAND_ASYNC_RETURN_TYPE, Constants.TYPE_VOID, commands); 
    6736 
    68             if (proxy) { 
    69                 String proxyName = TagParser.getStringCommand(Constants.COMMAND_PROXY_NAME, interfaceName + "Proxy", commands); 
    70                 ASCompilationUnit eventUnit = getProject().newClass(proxyName + "Events"); 
    71                 proxyUnit = getProject().newClass(proxyName); 
    72                 eventType = (ASClassType) eventUnit.getType(); 
    73                 proxyType = (ASClassType) proxyUnit.getType(); 
    74                 proxyImports = new TreeSet<String>(); 
     37        String interfaceName = classDoc.qualifiedTypeName(); 
    7538 
    76                 createProxy(interfaceName, commands, proxyType, proxyImports, returnType); 
    77             } 
     39        getGenerator().beginInterface(interfaceName); 
     40 
     41        processClassComment(classDoc); 
     42 
     43        if (proxy) { 
     44            String proxyName = TagParser.getStringCommand(Constants.COMMAND_PROXY_NAME, interfaceName + "Proxy", commands); 
     45            String baseType = TagParser.getStringCommand(Constants.COMMAND_PROXY_BASE_CLASS, commands); 
     46 
     47            String interfaceType = getTypeMap().getType(interfaceName, false, proxyImports); 
     48            getGenerator().beginProxy(proxyName, asyncReturnType, baseType, proxyImports, interfaceType); 
    7849        } 
    7950 
    80         if (create) { 
    81             unit = getProject().newInterface(interfaceName); 
    82             type = unit.getType(); 
     51        processInterfaceInternal(classDoc, asyncReturnType, parentCommands, proxyImports, imports); 
    8352 
    84             processClassComment(classDoc, type); 
    85         } 
     53        getGenerator().endInterface(imports); 
    8654 
    87         processInterfaces(classDoc, type, commands, eventType, proxyType, proxyImports, returnType); 
    88         processMethods(classDoc, type, commands, imports, eventType, proxyType, proxyImports, returnType); 
    89  
    90         if (create) processImports(unit, imports); 
    91  
    92         if (proxyUnit != null) { 
     55        if (proxy) { 
    9356            proxyImports.addAll(imports); 
    94             processImports(proxyUnit, proxyImports); 
     57            getGenerator().endProxy(proxyImports); 
    9558        } 
    9659    } 
    9760 
    98     private void createProxy(String interfaceName, Map<String, String> commands, ASClassType proxyType, Collection<String> proxyImports, String returnType) { 
    99         String baseType = TagParser.getStringCommand(Constants.COMMAND_PROXY_BASE_CLASS, commands); 
     61    private void processInterfaceInternal(ClassDoc classDoc, String asyncReturnType, Map<String, String> parentCommands, Collection<String> proxyImports, Collection<String> imports) { 
     62        Map<String, String> commands = new HashMap<String, String>(); 
    10063 
    101         proxyImports.add("mx.logging.ILogger"); 
    102         proxyImports.add("mx.logging.Log"); 
    103         proxyImports.add("mx.logging.LogEventLevel"); 
     64        if (parentCommands != null) commands.putAll(parentCommands); 
     65        commands.putAll(TagParser.processClassTags(classDoc)); 
    10466 
    105         proxyType.addImplementedInterface(getTypeMap().getType(interfaceName, false, proxyImports)); 
    106         proxyType.newField("logLevel", Visibility.PRIVATE, "Number"); 
    107         proxyType.newField("log", Visibility.PRIVATE, "ILogger"); 
    108  
    109         ASMethod ctor = proxyType.newMethod(proxyType.getName(), Visibility.PUBLIC, null); 
    110         ASArg arg = ctor.addParam("logLevel", "Number"); 
    111         arg.setDefault("LogEventLevel.INFO"); 
    112  
    113         ctor.addStmt("log = Log.getLogger(\"" + proxyType.getName() + "\");"); 
    114         ctor.addStmt("this.logLevel=logLevel;"); 
    115  
    116         if (baseType != null) { 
    117             proxyType.setSuperclass(baseType); 
    118             proxyImports.add(baseType); 
    119         } 
    120  
    121         if (!Constants.TYPE_VOID.equals(returnType)) proxyImports.add(returnType); 
    122         ASMethod callMethod = proxyType.newMethod(Constants.METHOD_CALL, Visibility.PROTECTED, returnType); 
    123         callMethod.addParam("name", "String"); 
    124         callMethod.addParam("...args", null); 
    125         callMethod.addStmt("throw new Error(\"Not Implemented\");"); 
    126  
    127         ASMethod resultMethod = proxyType.newMethod(Constants.METHOD_ON_RESULT, Visibility.PROTECTED, Constants.TYPE_VOID); 
    128         resultMethod.addParam("result", "Object"); 
    129  
    130         ASMethod statusMethod = proxyType.newMethod(Constants.METHOD_ON_STATUS, Visibility.PROTECTED, Constants.TYPE_VOID); 
    131         statusMethod.addParam("status", "Object"); 
     67        processInterfaces(classDoc, commands, asyncReturnType, proxyImports, imports); 
     68        processMethods(classDoc, commands, imports, asyncReturnType); 
    13269    } 
    13370 
    134     private void processMethods(ClassDoc classDoc, ASType type, Map<String, String> commands, Collection<String> imports, ASClassType eventType, ASClassType proxyType, Collection<String> proxyImports, String returnType) { 
    135         for (MethodDoc methodDoc : classDoc.methods()) { 
    136             processMethod(methodDoc, type, commands, imports, eventType, proxyType, proxyImports, returnType); 
     71    private void processInterfaces(ClassDoc classDoc, Map<String, String> commands, String asyncReturnType, Collection<String> proxyImports, Collection<String> imports) { 
     72        for (ClassDoc interfaceDoc : classDoc.interfaces()) { 
     73            if (!commands.containsKey(Constants.COMMAND_IGNORE) || !commands.get(Constants.COMMAND_IGNORE).contains(interfaceDoc.qualifiedTypeName())) { 
     74                String interfaceClass = getTypeMap().getType(interfaceDoc.qualifiedTypeName(), interfaceDoc.isPrimitive(), null); 
     75                getGenerator().addInterface(interfaceClass); 
     76 
     77                processInterfaceInternal(interfaceDoc, asyncReturnType, commands, proxyImports, imports); 
     78            } 
    13779        } 
    13880    } 
    13981 
    140     private void processMethod(MethodDoc methodDoc, ASType type, Map<String, String> commands, Collection<String> imports, ASClassType eventType, ASClassType proxyType, Collection<String> proxyImports, String returnType) { 
     82    private void processMethods(ClassDoc classDoc, Map<String, String> commands, Collection<String> imports, String asyncReturnType) { 
     83        for (MethodDoc methodDoc : classDoc.methods()) { 
     84            String returnType = getTypeMap().getType(methodDoc.returnType().qualifiedTypeName(), methodDoc.returnType().isPrimitive(), null); 
     85            processMethod(methodDoc, commands, imports, returnType, asyncReturnType); 
     86        } 
     87    } 
     88 
     89    private void processMethod(MethodDoc methodDoc, Map<String, String> commands, Collection<String> imports, String returnType, String asyncReturnType) { 
    14190        Map<String, String> methodCommands = new HashMap<String, String>(commands); 
    14291 
     
    14493 
    14594        boolean async = TagParser.getBooleanCommand(Constants.COMMAND_ASYNC, methodCommands); 
    146         boolean handler = TagParser.getBooleanCommand(Constants.COMMAND_HANDLER, methodCommands); 
    14795        boolean ignore = TagParser.getBooleanCommand(Constants.COMMAND_IGNORE, methodCommands); 
    14896 
    14997        if (!ignore) { 
    15098            if (async) { 
    151                 if (!Constants.TYPE_VOID.equals(returnType)) imports.add(returnType); 
     99                if (!Constants.TYPE_VOID.equals(asyncReturnType)) imports.add(asyncReturnType); 
    152100            } else { 
    153                 Type retType = methodDoc.returnType(); 
    154                 returnType = getTypeMap().getType(retType.qualifiedTypeName(), retType.isPrimitive(), imports); 
     101                asyncReturnType = returnType; 
    155102            } 
    156103 
    157             String methodName = methodDoc.name(); 
    158             ASMethod method = null; 
    159             ASMethod proxyMethod = null; 
     104            getGenerator().beginMethod(0, asyncReturnType, methodDoc.name()); 
    160105 
    161             if (type != null) method = type.newMethod(methodName, Visibility.DEFAULT, returnType); 
    162  
    163             if (proxyType != null) { 
    164                 String proxyMethodName = firstToUpper(methodName); 
    165                 createConst(eventType, proxyMethodName, methodName); 
    166                 proxyMethod = proxyType.newMethod(methodName, Visibility.PUBLIC, returnType); 
    167                 if (async) createAsyncHandler(methodDoc, eventType, proxyMethod, proxyMethodName, proxyType, proxyImports, handler); 
     106            for (Parameter parameter : methodDoc.parameters()) { 
     107                String type = getTypeMap().getType(parameter.type().qualifiedTypeName(), parameter.type().isPrimitive(), imports); 
     108                getGenerator().addParameter(type, parameter.name()); 
    168109            } 
    169110 
    170             for (Parameter parameter : methodDoc.parameters()) { 
    171                 if (method != null) method.addParam(parameter.name(), getTypeMap().getType(parameter.type().qualifiedTypeName(), parameter.type().isPrimitive(), imports)); 
    172                 if (proxyMethod != null) proxyMethod.addParam(parameter.name(), getTypeMap().getType(parameter.type().qualifiedTypeName(), parameter.type().isPrimitive(), imports)); 
    173             } 
     111            if (async) getGenerator().endMethod(); 
    174112 
    175             if (method != null) processMethodComment(methodDoc, method); 
     113            processMethodComment(methodDoc); 
    176114        } 
    177115    } 
    178116 
    179     private String firstToUpper(String methodName) { 
    180         return methodName.length() > 1 ? methodName.substring(0, 1).toUpperCase() + methodName.substring(1) : methodName.toUpperCase(); 
    181     } 
    182  
    183     private void createAsyncHandler(MethodDoc methodDoc, ASClassType eventType, ASMethod proxyMethod, String proxyMethodName, ASClassType proxyType, Collection<String> proxyImports, boolean handler) { 
    184         String event = eventType.getName() + '.' + proxyMethodName; 
    185         StringBuilder args = new StringBuilder(); 
    186         for (Parameter parameter : methodDoc.parameters()) { 
    187             args.append(", ").append(parameter.name()); 
    188         } 
    189  
    190         proxyMethod.addStmt(MessageFormat.format("log.log(logLevel, \"{0}\");", proxyMethodName)); 
    191         proxyMethod.addStmt(MessageFormat.format("return {0}({1}{2});", Constants.METHOD_CALL, event, args)); 
    192  
    193         if (handler) createHandler(methodDoc, event, proxyMethodName, proxyType, proxyImports); 
    194     } 
    195  
    196     private void createHandler(MethodDoc methodDoc, String event, String proxyMethodName, ASClassType proxyType, Collection<String> proxyImports) { 
    197         String resultMethodName = "on" + proxyMethodName + "Result"; 
    198         String statusMethodName = "on" + proxyMethodName + "Status"; 
    199  
    200         ASMethod proxyOnResult = proxyType.newMethod(resultMethodName, Visibility.PROTECTED, Constants.TYPE_VOID); 
    201         proxyOnResult.addStmt(MessageFormat.format("log.log(logLevel, \"{0}\");", resultMethodName)); 
    202  
    203         String returnTypeName = methodDoc.returnType().qualifiedTypeName(); 
    204         if (Constants.TYPE_VOID.equals(returnTypeName)) { 
    205             proxyOnResult.addStmt(MessageFormat.format("{0}({1}, null);", Constants.METHOD_ON_RESULT, event)); 
    206         } else { 
    207             String resultParam = Introspector.decapitalize(returnTypeName); 
    208             proxyOnResult.addParam(resultParam, getTypeMap().getType(returnTypeName, methodDoc.returnType().isPrimitive(), proxyImports)); 
    209             proxyOnResult.addStmt(MessageFormat.format("{0}({1}, {2});", Constants.METHOD_ON_RESULT, event, resultParam)); 
    210         } 
    211  
    212         ASMethod proxyOnStatus = proxyType.newMethod(statusMethodName, Visibility.PROTECTED, Constants.TYPE_VOID); 
    213         proxyOnStatus.addParam("status", "Object"); 
    214         proxyOnStatus.addStmt(MessageFormat.format("log.log(logLevel, \"{0}\");", statusMethodName)); 
    215         proxyOnStatus.addStmt(MessageFormat.format("{0}({1}, status);", Constants.METHOD_ON_STATUS, event)); 
    216     } 
    217  
    218     private void processMethodComment(MethodDoc methodDoc, ASMethod method) { 
     117    private void processMethodComment(MethodDoc methodDoc) { 
    219118        StringBuilder description = new StringBuilder(); 
    220119        String comment = methodDoc.commentText(); 
     
    223122        if (comment != null) description.append(comment.trim()); 
    224123 
    225         if (description.length() > 0) method.setDescription(description.toString()); 
     124        if (description.length() > 0) getGenerator().setMethodDescription(description.toString()); 
    226125    } 
    227126} 
  • trunk/src/org/fluffnstuff/asdoclet/map/ClassTypeMap.java

    r2 r4  
    1 package org.fluffnstuff.asdoclet
     1package org.fluffnstuff.asdoclet.map
    22 
    33import java.util.Collection; 
    44 
    5 public class AsClassTypeMap extends AsTypeMap { 
    6     public AsClassTypeMap() { 
     5public class ClassTypeMap extends TypeMap { 
     6    public ClassTypeMap() { 
    77        typeMap.put("boolean", "Boolean"); 
    88        typeMap.put("byte", "Number"); 
  • trunk/src/org/fluffnstuff/asdoclet/map/TypeMap.java

    r2 r4  
    1 package org.fluffnstuff.asdoclet
     1package org.fluffnstuff.asdoclet.map
    22 
    33import java.util.Collection; 
     
    55import java.util.Map; 
    66 
    7 public class AsTypeMap { 
     7public class TypeMap { 
    88    protected final Map<String, String> typeMap = new HashMap<String, String>(); 
    99