diff --git a/src/main/java/com/threerings/presents/tools/ActionScriptUtils.java b/src/main/java/com/threerings/presents/tools/ActionScriptUtils.java index c107888fe..e3e194a32 100644 --- a/src/main/java/com/threerings/presents/tools/ActionScriptUtils.java +++ b/src/main/java/com/threerings/presents/tools/ActionScriptUtils.java @@ -230,7 +230,6 @@ public class ActionScriptUtils { // replace primitive types with OOO types (required for unboxing) imports.replace("byte", "com.threerings.util.Byte"); - imports.replace("int", "com.threerings.util.Integer"); imports.replace("boolean", "com.threerings.util.langBoolean"); imports.replace("[B", "flash.utils.ByteArray"); imports.replace("float", "com.threerings.util.Float"); diff --git a/src/main/java/com/threerings/presents/tools/GenServiceTask.java b/src/main/java/com/threerings/presents/tools/GenServiceTask.java index 5a4568059..47bdd7776 100644 --- a/src/main/java/com/threerings/presents/tools/GenServiceTask.java +++ b/src/main/java/com/threerings/presents/tools/GenServiceTask.java @@ -24,6 +24,7 @@ package com.threerings.presents.tools; import java.lang.reflect.Method; import java.lang.reflect.Modifier; +import java.util.Arrays; import java.util.Collections; import java.util.HashMap; import java.util.List; @@ -41,7 +42,6 @@ import com.samskivert.util.StringUtil; import com.threerings.util.ActionScript; -import com.threerings.presents.client.Client; import com.threerings.presents.client.InvocationService; import com.threerings.presents.data.ClientObject; import com.threerings.presents.data.InvocationMarshaller; @@ -247,6 +247,7 @@ public class GenServiceTask extends InvocationTask // import things marshaller will always need imports.add(sdesc.service); imports.add(InvocationMarshaller.class); + imports.add("javax.annotation.Generated"); // import classes contained in arrays imports.translateClassArrays(); @@ -275,7 +276,7 @@ public class GenServiceTask extends InvocationTask ctx.put("package", mpackage); ctx.put("methods", sdesc.methods); ctx.put("listeners", sdesc.listeners); - ctx.put("imports", imports.toList()); + ctx.put("importGroups", imports.toGroups(Arrays.asList("java", "com.threerings"))); // determine the path to our marshaller file String mpath = source.getPath(); @@ -296,7 +297,6 @@ public class GenServiceTask extends InvocationTask // add some things that marshallers just need imports.add(sdesc.service); - imports.add(Client.class); imports.add(InvocationMarshaller.class); // replace inner classes with action script equivalents @@ -317,13 +317,17 @@ public class GenServiceTask extends InvocationTask ".client.", ".data."); imports.popIn(); + for (ServiceMethod method : sdesc.methods) { + method.gatherASWrappedArgListImports(imports); + } + // convert java bases and primitives ActionScriptUtils.convertBaseClasses(imports); // remove imports in our own package imports.removeSamePackage(mpackage); - ctx.put("imports", imports.toList()); + ctx.put("importGroups", imports.toGroups()); // now generate ActionScript versions of our marshaller @@ -358,7 +362,7 @@ public class GenServiceTask extends InvocationTask // remove imports in our own package imports.removeSamePackage(mpackage); - ctx.put("imports", imports.toList()); + ctx.put("importGroups", imports.toGroups()); ctx.put("listener", listener); String aslpath = _asroot + File.separator + mppath + File.separator + mname + "_" + listener.getListenerName() + "Marshaller.as"; @@ -374,7 +378,6 @@ public class GenServiceTask extends InvocationTask imports = sdesc.imports.clone(); // add some things required by action script - imports.add(Client.class); imports.add(InvocationService.class); // change imports of Foo$Bar to Foo_Bar @@ -386,7 +389,7 @@ public class GenServiceTask extends InvocationTask // remove imports in our own package imports.removeSamePackage(sdesc.spackage); - ctx.put("imports", imports.toList()); + ctx.put("importGroups", imports.toGroups()); ctx.put("package", sdesc.spackage); // make sure our service directory exists @@ -418,7 +421,7 @@ public class GenServiceTask extends InvocationTask // remove imports in our own package imports.removeSamePackage(sdesc.spackage); - ctx.put("imports", imports.toList()); + ctx.put("importGroups", imports.toGroups()); ctx.put("listener", listener); String aslpath = _asroot + File.separator + sppath + File.separator + @@ -453,7 +456,6 @@ public class GenServiceTask extends InvocationTask // swap Client for ClientObject imports.add(ClientObject.class); - imports.remove(Client.class); // add some classes required for all dispatchers imports.add(InvocationDispatcher.class); @@ -506,11 +508,11 @@ public class GenServiceTask extends InvocationTask // swap Client for ClientObject imports.add(ClientObject.class); - imports.remove(Client.class); // import superclass and service imports.add(InvocationProvider.class); imports.add(sdesc.service); + imports.add("javax.annotation.Generated"); // any method that takes a listener may throw this if (sdesc.hasAnyListenerArgs()) { @@ -542,7 +544,7 @@ public class GenServiceTask extends InvocationTask "package", mpackage, "methods", sdesc.methods, "listeners", sdesc.listeners, - "imports", imports.toList()); + "importGroups", imports.toGroups(Arrays.asList("java", "com.threerings"))); } /** diff --git a/src/main/java/com/threerings/presents/tools/InvocationTask.java b/src/main/java/com/threerings/presents/tools/InvocationTask.java index 1c31a00fa..42c0fb999 100644 --- a/src/main/java/com/threerings/presents/tools/InvocationTask.java +++ b/src/main/java/com/threerings/presents/tools/InvocationTask.java @@ -87,10 +87,15 @@ public abstract class InvocationTask extends GenTask protected int _index; } - public ServiceMethod createAndGatherImports (Method method, ImportSet set) + /** + * Creates a new service method and adds its basic imports to a set. + * @param method the method to create + * @param imports will be filled with the types required by the method + */ + public ServiceMethod createAndGatherImports (Method method, ImportSet imports) { ServiceMethod sm = new ServiceMethod(method); - sm.gatherImports(set); + sm.gatherImports(imports); return sm; } @@ -103,7 +108,6 @@ public abstract class InvocationTask extends GenTask /** * Creates a new service method. * @param method the method to inspect - * @param imports will be filled with the types required by the method */ public ServiceMethod (Method method) { this.method = method; @@ -213,6 +217,13 @@ public abstract class InvocationTask extends GenTask return buf.toString(); } + public void gatherASWrappedArgListImports (ImportSet set) { + Class[] args = method.getParameterTypes(); + for (int ii = 0; ii < args.length; ii++) { + set.addAll(GenUtil.getASBoxImports(args[ii])); + } + } + public String getASWrappedArgList () { StringBuilder buf = new StringBuilder(); Class[] args = method.getParameterTypes(); diff --git a/src/main/resources/com/threerings/presents/tools/marshaller.tmpl b/src/main/resources/com/threerings/presents/tools/marshaller.tmpl index f5dea922f..8062464ff 100644 --- a/src/main/resources/com/threerings/presents/tools/marshaller.tmpl +++ b/src/main/resources/com/threerings/presents/tools/marshaller.tmpl @@ -1,11 +1,11 @@ package {{package}}; -import javax.annotation.Generated; - -{{#imports}} +{{#importGroups}} +{{#this}} import {{this}}; -{{/imports}} +{{/this}} +{{/importGroups}} /** * Provides the implementation of the {@link {{name}}Service} interface * that marshalls the arguments and delivers the request to the provider diff --git a/src/main/resources/com/threerings/presents/tools/marshaller_as.tmpl b/src/main/resources/com/threerings/presents/tools/marshaller_as.tmpl index 0a0571fe5..35f9b9b07 100644 --- a/src/main/resources/com/threerings/presents/tools/marshaller_as.tmpl +++ b/src/main/resources/com/threerings/presents/tools/marshaller_as.tmpl @@ -1,9 +1,11 @@ package {{package}} { -{{#imports}} +{{#importGroups}} +{{#this}} import {{this}}; -{{/imports}} +{{/this}} +{{/importGroups}} /** * Provides the implementation of the {{name}}Service interface * that marshalls the arguments and delivers the request to the provider diff --git a/src/main/resources/com/threerings/presents/tools/marshaller_listener_as.tmpl b/src/main/resources/com/threerings/presents/tools/marshaller_listener_as.tmpl index 992a76bff..3571c118d 100644 --- a/src/main/resources/com/threerings/presents/tools/marshaller_listener_as.tmpl +++ b/src/main/resources/com/threerings/presents/tools/marshaller_listener_as.tmpl @@ -1,9 +1,11 @@ package {{package}} { -{{#imports}} +{{#importGroups}} +{{#this}} import {{this}}; -{{/imports}} +{{/this}} +{{/importGroups}} /** * Marshalls instances of the {{name}}Service_{{listener.listenerName}}Marshaller interface. */ diff --git a/src/main/resources/com/threerings/presents/tools/provider.tmpl b/src/main/resources/com/threerings/presents/tools/provider.tmpl index 43ea18c5a..9b495f773 100644 --- a/src/main/resources/com/threerings/presents/tools/provider.tmpl +++ b/src/main/resources/com/threerings/presents/tools/provider.tmpl @@ -1,11 +1,11 @@ package {{package}}; -import javax.annotation.Generated; - -{{#imports}} +{{#importGroups}} +{{#this}} import {{this}}; -{{/imports}} +{{/this}} +{{/importGroups}} /** * Defines the server-side of the {@link {{name}}Service}. */ diff --git a/src/main/resources/com/threerings/presents/tools/service_as.tmpl b/src/main/resources/com/threerings/presents/tools/service_as.tmpl index b18a26da1..f3345ef90 100644 --- a/src/main/resources/com/threerings/presents/tools/service_as.tmpl +++ b/src/main/resources/com/threerings/presents/tools/service_as.tmpl @@ -1,9 +1,11 @@ package {{package}} { -{{#imports}} +{{#importGroups}} +{{#this}} import {{this}}; -{{/imports}} +{{/this}} +{{/importGroups}} /** * An ActionScript version of the Java {{name}}Service interface. */ diff --git a/src/main/resources/com/threerings/presents/tools/service_listener_adapter_as.tmpl b/src/main/resources/com/threerings/presents/tools/service_listener_adapter_as.tmpl index df3e0c346..29bbe6ace 100644 --- a/src/main/resources/com/threerings/presents/tools/service_listener_adapter_as.tmpl +++ b/src/main/resources/com/threerings/presents/tools/service_listener_adapter_as.tmpl @@ -1,9 +1,11 @@ package {{package}} { -{{#imports}} +{{#importGroups}} +{{#this}} import {{this}}; -{{/imports}} +{{/this}} +{{/importGroups}} /** * A functional adapter for the {{name}}Service_{{listener.listenerName}}Listener interface. */ diff --git a/src/main/resources/com/threerings/presents/tools/service_listener_as.tmpl b/src/main/resources/com/threerings/presents/tools/service_listener_as.tmpl index 394ab86bc..d9203a7ee 100644 --- a/src/main/resources/com/threerings/presents/tools/service_listener_as.tmpl +++ b/src/main/resources/com/threerings/presents/tools/service_listener_as.tmpl @@ -1,9 +1,11 @@ package {{package}} { -{{#imports}} +{{#importGroups}} +{{#this}} import {{this}}; -{{/imports}} +{{/this}} +{{/importGroups}} /** * An ActionScript version of the Java {{name}}Service_{{listener.listenerName}}Listener interface. */