Changeset 82
- Timestamp:
- 10/23/09 12:06:13 (2 years ago)
- Files:
-
- trunk/src/org/fluffnstuff/asdoclet/generator/AsGenerator.java (modified) (5 diffs)
- trunk/src/org/fluffnstuff/asdoclet/generator/Generator.java (modified) (4 diffs)
- trunk/src/org/fluffnstuff/asdoclet/generator/VelocityGenerator.java (modified) (5 diffs)
- trunk/src/org/fluffnstuff/asdoclet/handler/InterfaceHandler.java (modified) (3 diffs)
- trunk/test/TestAsdoclet.java (modified) (1 diff)
- trunk/test/asdoclet/test/TestProxyInterface.java (modified) (2 diffs)
- trunk/test/asdoclet/test/TestProxyInterfaceBase.java (modified) (2 diffs)
- trunk/test/expectations/actionscript/asdoclet/test/TestProxyInterfaceBase.as (modified) (1 diff)
- trunk/test/expectations/actionscript/asdoclet/test/TestProxyInterfaceProxy.as (modified) (1 diff)
- trunk/test/expectations/cs/asdoclet/test/TestProxyInterface.cs (modified) (1 diff)
- trunk/test/expectations/cs/asdoclet/test/TestProxyInterfaceBase.cs (modified) (1 diff)
- trunk/test/expectations/cs/asdoclet/test/TestProxyInterfaceProxy.cs (modified) (1 diff)
Legend:
- Unmodified
- Added
- Removed
- Modified
- Copied
- Moved
trunk/src/org/fluffnstuff/asdoclet/generator/AsGenerator.java
r79 r82 23 23 import uk.co.badgersinfoil.metaas.dom.ASType; 24 24 import uk.co.badgersinfoil.metaas.dom.Visibility; 25 import com.sun.javadoc.ClassDoc; 25 26 26 27 public class AsGenerator implements Generator { … … 147 148 148 149 @Override 149 public void beginGetter(Type classType, Type methodType, int modifier, Type fieldType, String propertyName, String comment, boolean override) {150 fieldType = resolveTypeArguments(classType, methodType, fieldType);151 152 if (type instanceof ASClassType) {153 addField(classType, Modifier.PRIVATE, fieldType, "_" + propertyName, null, null);154 beginMethod(classType, Type.EMPTY, modifier, fieldType, "get " + propertyName, false, override);155 method.addStmt("return _" + propertyName + ";");156 } else {157 beginMethod(classType, Type.EMPTY, modifier, fieldType, "get " + propertyName, false, override);158 }159 160 setMethodDescription(comment);161 }162 163 @Override164 150 public void addInterface(Type name) { 165 151 if (type instanceof ASInterfaceType) { … … 181 167 182 168 addImport(type.getName()); 169 } 170 171 @Override 172 public void beginClass(Type classType) { 173 System.out.println("Creating ActionScript class " + classType); 174 175 newClass(classType, false); 176 addAnnotation(GeneratorUtils.getType("RemoteClass(alias=\"" + classType.getName() + "\")", this)); 177 } 178 179 @Override 180 public void beginEnum(Type name) { 181 System.out.println("Creating ActionScript enumeration " + name); 182 183 newClass(name, true); 184 } 185 186 @Override 187 public void beginGetter(Type classType, Type methodType, int modifier, Type fieldType, String propertyName, String comment, boolean override) { 188 fieldType = resolveTypeArguments(classType, methodType, fieldType); 189 190 if (type instanceof ASClassType) { 191 addField(classType, Modifier.PRIVATE, fieldType, "_" + propertyName, null, null); 192 beginMethod(classType, Type.EMPTY, modifier, fieldType, "get " + propertyName, false, override); 193 method.addStmt("return _" + propertyName + ";"); 194 } else { 195 beginMethod(classType, Type.EMPTY, modifier, fieldType, "get " + propertyName, false, override); 196 } 197 198 setMethodDescription(comment); 199 } 200 201 @Override 202 public void beginInterface(Type name) { 203 System.out.println("Creating ActionScript interface " + name); 204 205 unit = project.newInterface(name.getName()); 206 type = unit.getType(); 207 imports = new TreeSet<String>(); 208 } 209 210 @Override 211 public void beginMethod(Type classType, Type methodType, int modifier, Type returnType, String methodName, boolean asnyc, boolean override) { 212 returnType = resolveTypeArguments(classType, methodType, returnType); 213 214 if (unit != null) { 215 method = type.newMethod(methodName, getVisibility(modifier), returnType.getName()); 216 method.setOverride(override); 217 } 218 219 if (proxyUnit != null) { 220 String proxyMethodName = firstToUpper(methodName); 221 boolean hasField = false; 222 223 for (Object o : eventType.getFields()) { 224 ASField field = (ASField) o; 225 if (field.getName().equals(proxyMethodName)) { 226 hasField = true; 227 break; 228 } 229 } 230 231 if (!hasField) { 232 createConst(eventType, proxyMethodName, MessageFormat.format("\"{0}\"", methodName), "String", null); 233 proxyMethod = proxyType.newMethod(methodName, Visibility.PUBLIC, returnType.getName()); 234 } 235 } 236 237 addImport(returnType.getName()); 238 } 239 240 @Override 241 public void beginProxy(Type proxy, Type baseType, Type interfaceType) { 242 System.out.println("Creating ActionScript proxy " + proxy.getName()); 243 244 ASCompilationUnit eventUnit = project.newClass(proxy.getName() + "Events"); 245 proxyUnit = project.newClass(proxy.getName()); 246 247 eventType = (ASClassType) eventUnit.getType(); 248 proxyType = (ASClassType) proxyUnit.getType(); 249 250 proxyType.addImplementedInterface(interfaceType.getName()); 251 252 proxyImports = new TreeSet<String>(); 253 proxyImports.add(interfaceType.getName()); 254 255 if (baseType != Type.NULL) { 256 proxyType.setSuperclass(baseType.getName()); 257 proxyImports.add(baseType.getName()); 258 } 259 260 ASMethod callMethod = proxyType.newMethod(Constants.METHOD_CALL, Visibility.PROTECTED, "Object"); 261 callMethod.addParam("name", "String"); 262 callMethod.addParam("...args", null); 263 callMethod.addStmt("throw new Error(\"Not Implemented\");"); 264 265 ASMethod resultMethod = proxyType.newMethod(Constants.METHOD_ON_RESULT, Visibility.PROTECTED, Type.VOID.getName()); 266 resultMethod.addParam("result", "Object"); 267 268 ASMethod statusMethod = proxyType.newMethod(Constants.METHOD_ON_STATUS, Visibility.PROTECTED, Type.VOID.getName()); 269 statusMethod.addParam("status", "Object"); 183 270 } 184 271 … … 201 288 202 289 @Override 203 public void beginClass(Type classType) {204 System.out.println("Creating ActionScript class " + classType);205 206 newClass(classType, false);207 addAnnotation(GeneratorUtils.getType("RemoteClass(alias=\"" + classType.getName() + "\")", this));208 }209 210 @Override211 public void beginEnum(Type name) {212 System.out.println("Creating ActionScript enumeration " + name);213 214 newClass(name, true);215 }216 217 @Override218 public void beginInterface(Type name) {219 System.out.println("Creating ActionScript interface " + name);220 221 unit = project.newInterface(name.getName());222 type = unit.getType();223 imports = new TreeSet<String>();224 }225 226 @Override227 public void beginMethod(Type classType, Type methodType, int modifier, Type returnType, String methodName, boolean asnyc, boolean override) {228 returnType = resolveTypeArguments(classType, methodType, returnType);229 230 if (unit != null) {231 method = type.newMethod(methodName, getVisibility(modifier), returnType.getName());232 method.setOverride(override);233 }234 235 if (proxyUnit != null) {236 String proxyMethodName = firstToUpper(methodName);237 boolean hasField = false;238 239 for (Object o : eventType.getFields()) {240 ASField field = (ASField) o;241 if (field.getName().equals(proxyMethodName)) {242 hasField = true;243 break;244 }245 }246 247 if (!hasField) {248 createConst(eventType, proxyMethodName, MessageFormat.format("\"{0}\"", methodName), "String", null);249 proxyMethod = proxyType.newMethod(methodName, Visibility.PUBLIC, returnType.getName());250 }251 }252 253 addImport(returnType.getName());254 }255 256 @Override257 public void beginProxy(Type proxy, Type baseType, Type interfaceType) {258 System.out.println("Creating ActionScript proxy " + proxy.getName());259 260 ASCompilationUnit eventUnit = project.newClass(proxy.getName() + "Events");261 proxyUnit = project.newClass(proxy.getName());262 263 eventType = (ASClassType) eventUnit.getType();264 proxyType = (ASClassType) proxyUnit.getType();265 266 proxyType.addImplementedInterface(interfaceType.getName());267 268 proxyImports = new TreeSet<String>();269 proxyImports.add(interfaceType.getName());270 271 if (baseType != Type.NULL) {272 proxyType.setSuperclass(baseType.getName());273 proxyImports.add(baseType.getName());274 }275 276 ASMethod callMethod = proxyType.newMethod(Constants.METHOD_CALL, Visibility.PROTECTED, "Object");277 callMethod.addParam("name", "String");278 callMethod.addParam("...args", null);279 callMethod.addStmt("throw new Error(\"Not Implemented\");");280 281 ASMethod resultMethod = proxyType.newMethod(Constants.METHOD_ON_RESULT, Visibility.PROTECTED, Type.VOID.getName());282 resultMethod.addParam("result", "Object");283 284 ASMethod statusMethod = proxyType.newMethod(Constants.METHOD_ON_STATUS, Visibility.PROTECTED, Type.VOID.getName());285 statusMethod.addParam("status", "Object");286 }287 288 @Override289 290 public void endClass() { 290 291 end(); … … 381 382 public void setTypeDescription(String description) { 382 383 if (!StringUtils.isEmpty(description)) type.setDescription(description.trim()); 384 } 385 386 @Override 387 public boolean traverse(ClassDoc classDoc) { 388 return true; 383 389 } 384 390 trunk/src/org/fluffnstuff/asdoclet/generator/Generator.java
r71 r82 4 4 5 5 import org.fluffnstuff.asdoclet.map.TypeMap; 6 7 import com.sun.javadoc.ClassDoc; 6 8 7 9 public interface Generator { … … 16 18 void addField(Type classType, int modifier, Type fieldType, String fieldName, Object value, String comment); 17 19 18 void beginGetter(Type classType, Type methodType, int modifier, Type fieldType, String propertyName, String comment, boolean override);19 20 20 void addInterface(Type type); 21 21 22 22 void addParameter(Type classType, Type methodType, Type type, String name); 23 23 24 void beginSetter(Type classType, Type methodType, int modifier, Type fieldType, String propertyName, String comment, boolean override);25 26 24 void beginClass(Type type); 27 25 28 26 void beginEnum(Type type); 27 28 void beginGetter(Type classType, Type methodType, int modifier, Type fieldType, String propertyName, String comment, boolean override); 29 29 30 30 void beginInterface(Type type); … … 33 33 34 34 void beginProxy(Type type, Type baseType, Type interfaceType); 35 36 void beginSetter(Type classType, Type methodType, int modifier, Type fieldType, String propertyName, String comment, boolean override); 35 37 36 38 void endClass(); … … 71 73 72 74 void setTypeDescription(String description); 75 76 boolean traverse(ClassDoc classDoc); 73 77 } trunk/src/org/fluffnstuff/asdoclet/generator/VelocityGenerator.java
r81 r82 25 25 import org.fluffnstuff.asdoclet.map.TypeMap; 26 26 27 import com.sun.javadoc.ClassDoc; 28 27 29 public class VelocityGenerator implements Generator { 28 30 private static final String CSHARP = "cs"; … … 161 163 162 164 @Override 165 public void addInterface(Type name) { 166 typeDescriptor.addInterface(name); 167 } 168 169 @Override 170 public void addParameter(Type classType, Type methodType, Type type, String name) { 171 if (methodDescriptor != null) { 172 ParameterDescriptor parameterDescriptor = new ParameterDescriptor(type, name); 173 methodDescriptor.addParameterDescriptor(parameterDescriptor); 174 } 175 if (proxyMethodDescriptor != null) { 176 if (type.getTypeMap().containsKey(type.getName())) type = type.getTypeMap().get(type.getName()); 177 ParameterDescriptor parameterDescriptor = new ParameterDescriptor(type, name); 178 proxyMethodDescriptor.addParameterDescriptor(parameterDescriptor); 179 } 180 } 181 182 @Override 183 public void beginClass(Type type) { 184 beginType(new ClassDescriptor(type)); 185 } 186 187 @Override 188 public void beginEnum(Type type) { 189 beginType(new EnumDescriptor(type)); 190 } 191 192 @Override 163 193 public void beginGetter(Type classType, Type methodType, int modifier, Type returnType, String propertyName, String description, boolean override) { 164 194 propertyDescriptor = new PropertyDescriptor(modifier, returnType, methodType, propertyName); … … 174 204 175 205 @Override 176 public void addInterface(Type name) { 177 typeDescriptor.addInterface(name); 178 } 179 180 @Override 181 public void addParameter(Type classType, Type methodType, Type type, String name) { 182 if (methodDescriptor != null) { 183 ParameterDescriptor parameterDescriptor = new ParameterDescriptor(type, name); 184 methodDescriptor.addParameterDescriptor(parameterDescriptor); 185 } 186 if (proxyMethodDescriptor != null) { 187 if (type.getTypeMap().containsKey(type.getName())) type = type.getTypeMap().get(type.getName()); 188 ParameterDescriptor parameterDescriptor = new ParameterDescriptor(type, name); 189 proxyMethodDescriptor.addParameterDescriptor(parameterDescriptor); 190 } 206 public void beginInterface(Type type) { 207 beginType(new InterfaceDescriptor(type)); 208 } 209 210 @Override 211 public void beginMethod(Type classType, Type methodType, int modifier, Type returnType, String methodName, boolean asnyc, boolean override) { 212 if (typeDescriptor != null) { 213 methodDescriptor = new MethodDescriptor(modifier, returnType, methodType, methodName, asnyc); 214 methodDescriptor.setOverride(override); 215 typeDescriptor.addMethodDescriptor(methodDescriptor); 216 } 217 if (proxyTypeDescriptor != null) { 218 proxyMethodDescriptor = new MethodDescriptor(modifier, returnType, methodType, methodName, asnyc); 219 proxyTypeDescriptor.addMethodDescriptor(proxyMethodDescriptor); 220 } 221 } 222 223 @Override 224 public void beginProxy(Type proxy, Type baseType, Type interfaceType) { 225 proxyTypeDescriptor = new ProxyDescriptor(proxy); 226 proxyTypeDescriptor.addInterface(interfaceType); 227 228 if (baseType != Type.NULL) proxyTypeDescriptor.setSuperclass(baseType); 229 230 typeDescriptors.add(proxyTypeDescriptor); 191 231 } 192 232 … … 205 245 206 246 @Override 207 public void beginClass(Type type) {208 beginType(new ClassDescriptor(type));209 }210 211 @Override212 public void beginEnum(Type type) {213 beginType(new EnumDescriptor(type));214 }215 216 @Override217 public void beginInterface(Type type) {218 beginType(new InterfaceDescriptor(type));219 }220 221 @Override222 public void beginMethod(Type classType, Type methodType, int modifier, Type returnType, String methodName, boolean asnyc, boolean override) {223 if (typeDescriptor != null) {224 methodDescriptor = new MethodDescriptor(modifier, returnType, methodType, methodName, asnyc);225 methodDescriptor.setOverride(override);226 typeDescriptor.addMethodDescriptor(methodDescriptor);227 }228 if (proxyTypeDescriptor != null) {229 proxyMethodDescriptor = new MethodDescriptor(modifier, returnType, methodType, methodName, asnyc);230 proxyTypeDescriptor.addMethodDescriptor(proxyMethodDescriptor);231 }232 }233 234 @Override235 public void beginProxy(Type proxy, Type baseType, Type interfaceType) {236 proxyTypeDescriptor = new ProxyDescriptor(proxy);237 proxyTypeDescriptor.addInterface(interfaceType);238 239 if (baseType != Type.NULL) proxyTypeDescriptor.setSuperclass(baseType);240 241 typeDescriptors.add(proxyTypeDescriptor);242 }243 244 @Override245 247 public void endClass() { 246 248 typeDescriptor = null; … … 365 367 } 366 368 369 @Override 370 public boolean traverse(ClassDoc classDoc) { 371 return classDoc.isIncluded(); 372 } 373 367 374 private void beginType(TypeDescriptor typeDescriptor) { 368 375 this.typeDescriptor = typeDescriptor; trunk/src/org/fluffnstuff/asdoclet/handler/InterfaceHandler.java
r79 r82 3 3 import java.util.ArrayList; 4 4 import java.util.HashMap; 5 import java.util.HashSet; 5 6 import java.util.Iterator; 6 7 import java.util.Map; 7 8 import java.util.Set; 8 import java.util.HashSet;9 9 10 10 import org.fluffnstuff.asdoclet.generator.Generator; … … 155 155 ClassDoc classDoc = type.asClassDoc(); 156 156 157 // don't process interfaces that are not part of the source path 158 if (!getGenerator().traverse(classDoc)) continue; 159 157 160 org.fluffnstuff.asdoclet.generator.Type interfaceType = GeneratorUtils.getType(type, getGenerator(), ignore); 158 161 … … 178 181 179 182 boolean bean = TagParser.getBooleanCommand(Constants.COMMAND_BEAN, commands); 180 processMethods(classDoc, interface Type, bean, ignore, commands, typeMap);183 processMethods(classDoc, interfaceClass, bean, ignore, commands, typeMap); 181 184 182 185 traverseInterfaces(classDoc, ignore, commands); trunk/test/TestAsdoclet.java
r79 r82 3 3 public class TestAsdoclet { 4 4 public static void main(String[] args) { 5 Main.execute(new String[]{"-d", "test/results/cs", "-doclet", "org.fluffnstuff.asdoclet.AsDoclet", "-generator", " cs", "asdoclet.test", "test/asdoclet/test/TestProxyInterface.java"});5 Main.execute(new String[]{"-d", "test/results/cs", "-doclet", "org.fluffnstuff.asdoclet.AsDoclet", "-generator", "actionscript", "asdoclet.test", "test/asdoclet/test/TestProxyInterface.java"}); 6 6 } 7 7 } trunk/test/asdoclet/test/TestProxyInterface.java
r79 r82 1 1 package asdoclet.test; 2 3 import java.sql.Date; 2 4 3 5 /** … … 5 7 * @cs.class proxy=<code>true</code> 6 8 */ 7 public interface TestProxyInterface extends TestProxyInterfaceBase< Integer> {9 public interface TestProxyInterface extends TestProxyInterfaceBase<Date> { 8 10 } trunk/test/asdoclet/test/TestProxyInterfaceBase.java
r79 r82 1 1 package asdoclet.test; 2 3 import java.util.Date; 2 4 3 5 /** … … 5 7 * @cs.class 6 8 */ 7 public interface TestProxyInterfaceBase<T > extends TestProxyInterfaceGeneric {9 public interface TestProxyInterfaceBase<T extends Date> extends TestProxyInterfaceGeneric { 8 10 void foo(T bar); 9 11 } trunk/test/expectations/actionscript/asdoclet/test/TestProxyInterfaceBase.as
r79 r82 6 6 */ 7 7 public interface TestProxyInterfaceBase extends asdoclet.test.TestProxyInterfaceGeneric { 8 override function foo(bar: Object):void;8 override function foo(bar:Date):void; 9 9 } 10 10 } trunk/test/expectations/actionscript/asdoclet/test/TestProxyInterfaceProxy.as
r79 r82 10 10 protected function onStatus(status:Object):void { 11 11 } 12 public function foo(bar: Object):void {12 public function foo(bar:Date):void { 13 13 dispatchCall(TestProxyInterfaceProxyEvents.Foo, bar); 14 14 } trunk/test/expectations/cs/asdoclet/test/TestProxyInterface.cs
r79 r82 8 8 * </summary> 9 9 */ 10 public interface TestProxyInterface : asdoclet.test.TestProxyInterfaceBase< int?> {10 public interface TestProxyInterface : asdoclet.test.TestProxyInterfaceBase<java.sql.Date> { 11 11 } 12 12 } trunk/test/expectations/cs/asdoclet/test/TestProxyInterfaceBase.cs
r79 r82 8 8 * </summary> 9 9 */ 10 public interface TestProxyInterfaceBase<T> : asdoclet.test.TestProxyInterfaceGeneric {10 public interface TestProxyInterfaceBase<T> : asdoclet.test.TestProxyInterfaceGeneric where T : System.DateTime? { 11 11 void Foo(T bar); 12 12 } trunk/test/expectations/cs/asdoclet/test/TestProxyInterfaceProxy.cs
r81 r82 10 10 } 11 11 12 virtual public void Foo( int?bar) {12 virtual public void Foo(java.sql.Date bar) { 13 13 DispatchCall<object>("foo", bar); 14 14 }