Changeset 4
- Timestamp:
- 07/16/08 17:44:24 (4 years ago)
- Files:
-
- trunk/asdoclet.ipr (modified) (1 diff)
- trunk/lib/velocity-dep.jar (added)
- trunk/src/org/fluffnstuff/asdoclet/AsDoclet.java (modified) (3 diffs)
- trunk/src/org/fluffnstuff/asdoclet/generator (added)
- trunk/src/org/fluffnstuff/asdoclet/generator/AsGenerator.java (added)
- trunk/src/org/fluffnstuff/asdoclet/generator/Generator.java (added)
- trunk/src/org/fluffnstuff/asdoclet/generator/VelocityGenerator.java (added)
- trunk/src/org/fluffnstuff/asdoclet/generator/velocity (added)
- trunk/src/org/fluffnstuff/asdoclet/generator/velocity/ClassDescriptor.java (added)
- trunk/src/org/fluffnstuff/asdoclet/generator/velocity/Descriptor.java (added)
- trunk/src/org/fluffnstuff/asdoclet/generator/velocity/FieldDescriptor.java (added)
- trunk/src/org/fluffnstuff/asdoclet/generator/velocity/MethodDescriptor.java (added)
- trunk/src/org/fluffnstuff/asdoclet/generator/velocity/ParameterDescriptor.java (added)
- trunk/src/org/fluffnstuff/asdoclet/generator/velocity/TypeDescriptor.java (added)
- trunk/src/org/fluffnstuff/asdoclet/handler/AbstractHandler.java (modified) (2 diffs)
- trunk/src/org/fluffnstuff/asdoclet/handler/ClassHandler.java (modified) (5 diffs)
- trunk/src/org/fluffnstuff/asdoclet/handler/Constants.java (modified) (2 diffs)
- trunk/src/org/fluffnstuff/asdoclet/handler/EnumHandler.java (modified) (2 diffs)
- trunk/src/org/fluffnstuff/asdoclet/handler/InterfaceHandler.java (modified) (6 diffs)
- trunk/src/org/fluffnstuff/asdoclet/map (added)
- trunk/src/org/fluffnstuff/asdoclet/map/ClassTypeMap.java (moved) (moved from trunk/src/org/fluffnstuff/asdoclet/AsClassTypeMap.java) (1 diff)
- trunk/src/org/fluffnstuff/asdoclet/map/TypeMap.java (moved) (moved from trunk/src/org/fluffnstuff/asdoclet/AsTypeMap.java) (2 diffs)
- trunk/templates (added)
- trunk/templates/cs (added)
- trunk/templates/cs/class.vm (added)
Legend:
- Unmodified
- Added
- Removed
- Modified
- Copied
- Moved
trunk/asdoclet.ipr
r2 r4 331 331 <component name="copyright"> 332 332 <Base> 333 <setting name="state" value=" 1" />333 <setting name="state" value="2" /> 334 334 </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) &#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) &#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) &#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) &#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) &#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) &#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) &#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" /> 349 475 <option name="keyword" value="Copyright" /> 350 476 <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) &#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) &#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) &#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) &#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) &#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) &#36;today.year, Your Corporation. All Rights Reserved." />475 <option name="keyword" value="Copyright" />476 <option name="fileTypeOverride" value="2" />477 477 <option name="relativeBefore" value="true" /> 478 478 <option name="addBlankAfter" value="true" /> trunk/src/org/fluffnstuff/asdoclet/AsDoclet.java
r2 r4 4 4 import com.sun.javadoc.DocErrorReporter; 5 5 import com.sun.javadoc.RootDoc; 6 import org.fluffnstuff.asdoclet.generator.AsGenerator; 7 import org.fluffnstuff.asdoclet.generator.Generator; 8 import org.fluffnstuff.asdoclet.generator.VelocityGenerator; 6 9 import org.fluffnstuff.asdoclet.handler.*; 7 import uk.co.badgersinfoil.metaas.ActionScriptFactory; 8 import uk.co.badgersinfoil.metaas.ActionScriptProject; 9 10 import java.io.IOException; 10 import org.fluffnstuff.asdoclet.map.ClassTypeMap; 11 import org.fluffnstuff.asdoclet.map.TypeMap; 11 12 12 13 public class AsDoclet { … … 15 16 private static final String PARAM_ANNOTATION_MAP = "-annotationmap"; 16 17 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(); 19 20 20 public static boolean start(RootDoc root) throws IOException {21 public static boolean start(RootDoc root) throws Exception { 21 22 String destination = readOptions(root.options()); 22 23 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); 25 27 26 28 for (ClassDoc classDoc : root.classes()) { 27 29 if (TagParser.hasClassTags(classDoc)) { 28 Handler handler = createHandler( project, classDoc);30 Handler handler = createHandler(generator, classDoc); 29 31 handler.process(classDoc); 30 32 } 31 33 } 32 34 33 project.performAutoImport(); 34 project.writeAll(); 35 generator.generate(); 35 36 36 37 return true; … … 55 56 } 56 57 57 private static Handler createHandler( ActionScriptProject project, ClassDoc classDoc) {58 private static Handler createHandler(Generator generator, ClassDoc classDoc) { 58 59 Handler handler; 59 60 60 61 if (classDoc.isInterface()) { 61 handler = new InterfaceHandler( project, typeMap, annotationMap);62 handler = new InterfaceHandler(generator, typeMap, annotationMap); 62 63 } else if (typeMap.isEnum(classDoc.qualifiedTypeName())) { 63 handler = new EnumHandler( project, typeMap, annotationMap);64 handler = new EnumHandler(generator, typeMap, annotationMap); 64 65 } else { 65 handler = new ClassHandler( project, typeMap, annotationMap);66 handler = new ClassHandler(generator, typeMap, annotationMap); 66 67 } 67 68 trunk/src/org/fluffnstuff/asdoclet/handler/AbstractHandler.java
r2 r4 2 2 3 3 import 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; 4 import org.fluffnstuff.asdoclet.map.TypeMap; 5 import org.fluffnstuff.asdoclet.generator.Generator; 10 6 11 7 public abstract class AbstractHandler implements Handler { 12 8 private static final String COMMENT_PREFIX = "\t * "; 13 9 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; 17 13 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; 20 16 this.typeMap = typeMap; 21 17 this.annotationMap = annotationMap; 22 18 } 23 19 24 protected AsTypeMap getAnnotationMap() {20 protected TypeMap getAnnotationMap() { 25 21 return annotationMap; 26 22 } 27 23 28 protected ActionScriptProject getProject() {29 return project;24 protected Generator getGenerator() { 25 return generator; 30 26 } 31 27 32 protected AsTypeMap getTypeMap() {28 protected TypeMap getTypeMap() { 33 29 return typeMap; 34 30 } 35 31 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) { 44 33 StringBuilder description = new StringBuilder(); 45 34 String comment = classDoc.commentText(); … … 55 44 description.append(COMMENT_PREFIX).append("Do not edit."); 56 45 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()); 65 47 } 66 48 } trunk/src/org/fluffnstuff/asdoclet/handler/ClassHandler.java
r3 r4 2 2 3 3 import 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; 4 import org.fluffnstuff.asdoclet.generator.Generator; 5 import org.fluffnstuff.asdoclet.map.TypeMap; 10 6 11 7 import java.beans.Introspector; 8 import java.lang.reflect.Modifier; 12 9 import java.util.Collection; 13 10 import java.util.HashMap; … … 16 13 17 14 public 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); 20 17 } 21 18 … … 29 26 String ignore = TagParser.getStringCommand(Constants.COMMAND_IGNORE, "", commands); 30 27 31 ASCompilationUnit unit = getProject().newClass(classDoc.qualifiedTypeName()); 32 ASClassType type = (ASClassType) unit.getType(); 28 getGenerator().beginClass(classDoc.qualifiedTypeName()); 33 29 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() + "\")"); 36 32 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); 41 38 } 42 39 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) { 44 41 for (MethodDoc methodDoc : classDoc.methods()) { 45 42 Map<String, String> methodCommands = new HashMap<String, String>(commands); … … 52 49 if (propertyName != null) { 53 50 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); 55 52 56 processFieldComment(methodDoc , field);53 processFieldComment(methodDoc); 57 54 } 58 55 } … … 116 113 } 117 114 118 private void processFieldComment(MethodDoc methodDoc , ASField field) {115 private void processFieldComment(MethodDoc methodDoc) { 119 116 StringBuilder description = new StringBuilder(); 120 117 String comment = methodDoc.commentText(); 121 118 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()); 123 120 } 124 121 125 private void processSuperClass(ClassDoc classDoc, String ignore , ASClassType type) {122 private void processSuperClass(ClassDoc classDoc, String ignore) { 126 123 ClassDoc superClassDoc = classDoc.superclass(); 127 124 if (superClassDoc != null) { 128 125 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); 130 127 } 131 128 } trunk/src/org/fluffnstuff/asdoclet/handler/Constants.java
r2 r4 1 1 package org.fluffnstuff.asdoclet.handler; 2 2 3 final class Constants {3 final public class Constants { 4 4 public static final String TAG_ACTIONSCRIPT_CLASS = "actionscript.class"; 5 5 public static final String TAG_ACTIONSCRIPT_METHOD = "actionscript.method"; … … 14 14 15 15 public static final String COMMAND_BINDABLE = "bindable"; 16 public static final String COMMAND_HANDLER = "handler";17 16 public static final String COMMAND_IGNORE = "ignore"; 18 17 public static final String COMMAND_TYPE = "type"; trunk/src/org/fluffnstuff/asdoclet/handler/EnumHandler.java
r2 r4 3 3 import com.sun.javadoc.ClassDoc; 4 4 import 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; 5 import org.fluffnstuff.asdoclet.generator.Generator; 6 import org.fluffnstuff.asdoclet.map.TypeMap; 9 7 10 8 public 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); 13 11 } 14 12 … … 16 14 17 15 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); 21 18 22 processClassComment(classDoc, type);19 for (FieldDoc fieldDoc : classDoc.fields()) getGenerator().addEnumField(fieldDoc.name()); 23 20 24 for (FieldDoc fieldDoc : classDoc.fields()) createConst(type, fieldDoc.name(), fieldDoc.name());21 getGenerator().endEnum(); 25 22 } 26 23 } trunk/src/org/fluffnstuff/asdoclet/handler/InterfaceHandler.java
r2 r4 4 4 import com.sun.javadoc.MethodDoc; 5 5 import 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.*; 6 import org.fluffnstuff.asdoclet.map.TypeMap; 7 import org.fluffnstuff.asdoclet.generator.Generator; 10 8 11 import java.beans.Introspector;12 import java.text.MessageFormat;13 9 import java.util.Collection; 14 10 import java.util.HashMap; … … 17 13 18 14 public 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); 21 17 } 22 18 … … 24 20 25 21 public void process(ClassDoc classDoc) { 26 processInterface(classDoc, null , null, null, null, true, null);22 processInterface(classDoc, null); 27 23 } 28 24 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) { 55 26 Map<String, String> commands = new HashMap<String, String>(); 56 27 … … 58 29 commands.putAll(TagParser.processClassTags(classDoc)); 59 30 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>(); 63 33 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); 67 36 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(); 75 38 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); 78 49 } 79 50 80 if (create) { 81 unit = getProject().newInterface(interfaceName); 82 type = unit.getType(); 51 processInterfaceInternal(classDoc, asyncReturnType, parentCommands, proxyImports, imports); 83 52 84 processClassComment(classDoc, type); 85 } 53 getGenerator().endInterface(imports); 86 54 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) { 93 56 proxyImports.addAll(imports); 94 processImports(proxyUnit,proxyImports);57 getGenerator().endProxy(proxyImports); 95 58 } 96 59 } 97 60 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>(); 100 63 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)); 104 66 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); 132 69 } 133 70 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 } 137 79 } 138 80 } 139 81 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) { 141 90 Map<String, String> methodCommands = new HashMap<String, String>(commands); 142 91 … … 144 93 145 94 boolean async = TagParser.getBooleanCommand(Constants.COMMAND_ASYNC, methodCommands); 146 boolean handler = TagParser.getBooleanCommand(Constants.COMMAND_HANDLER, methodCommands);147 95 boolean ignore = TagParser.getBooleanCommand(Constants.COMMAND_IGNORE, methodCommands); 148 96 149 97 if (!ignore) { 150 98 if (async) { 151 if (!Constants.TYPE_VOID.equals( returnType)) imports.add(returnType);99 if (!Constants.TYPE_VOID.equals(asyncReturnType)) imports.add(asyncReturnType); 152 100 } else { 153 Type retType = methodDoc.returnType(); 154 returnType = getTypeMap().getType(retType.qualifiedTypeName(), retType.isPrimitive(), imports); 101 asyncReturnType = returnType; 155 102 } 156 103 157 String methodName = methodDoc.name(); 158 ASMethod method = null; 159 ASMethod proxyMethod = null; 104 getGenerator().beginMethod(0, asyncReturnType, methodDoc.name()); 160 105 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()); 168 109 } 169 110 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(); 174 112 175 if (method != null) processMethodComment(methodDoc, method);113 processMethodComment(methodDoc); 176 114 } 177 115 } 178 116 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) { 219 118 StringBuilder description = new StringBuilder(); 220 119 String comment = methodDoc.commentText(); … … 223 122 if (comment != null) description.append(comment.trim()); 224 123 225 if (description.length() > 0) method.setDescription(description.toString());124 if (description.length() > 0) getGenerator().setMethodDescription(description.toString()); 226 125 } 227 126 } trunk/src/org/fluffnstuff/asdoclet/map/ClassTypeMap.java
r2 r4 1 package org.fluffnstuff.asdoclet ;1 package org.fluffnstuff.asdoclet.map; 2 2 3 3 import java.util.Collection; 4 4 5 public class AsClassTypeMap extends AsTypeMap {6 public AsClassTypeMap() {5 public class ClassTypeMap extends TypeMap { 6 public ClassTypeMap() { 7 7 typeMap.put("boolean", "Boolean"); 8 8 typeMap.put("byte", "Number"); trunk/src/org/fluffnstuff/asdoclet/map/TypeMap.java
r2 r4 1 package org.fluffnstuff.asdoclet ;1 package org.fluffnstuff.asdoclet.map; 2 2 3 3 import java.util.Collection; … … 5 5 import java.util.Map; 6 6 7 public class AsTypeMap {7 public class TypeMap { 8 8 protected final Map<String, String> typeMap = new HashMap<String, String>(); 9 9