Various tweaks to get import ordering to match the ooo convention of putting java and javax imports first, then threerings imports.

* Add importGroups template variable, set to the two groups: one for java, one for threerings.
* Omit Client import the client-side generated code. This was removed some time ago.
* Omit the blanket int -> Integer replacement, this was only needed for the marshaller
* Add the as boxing imports when generating the marshaller (this gets the Integer import for int types in marshaller signatures)
* Change the templates to put space between each group of imports.

git-svn-id: svn+ssh://src.earth.threerings.net/narya/trunk@6677 542714f4-19e9-0310-aa3c-eee0fc999fb1
This commit is contained in:
Jamie Doornbos
2011-07-06 21:06:55 +00:00
parent 3d1f57c14e
commit 29f06663c6
10 changed files with 55 additions and 33 deletions
@@ -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");
@@ -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")));
}
/**
@@ -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();
@@ -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
@@ -1,9 +1,11 @@
package {{package}} {
{{#imports}}
{{#importGroups}}
{{#this}}
import {{this}};
{{/imports}}
{{/this}}
{{/importGroups}}
/**
* Provides the implementation of the <code>{{name}}Service</code> interface
* that marshalls the arguments and delivers the request to the provider
@@ -1,9 +1,11 @@
package {{package}} {
{{#imports}}
{{#importGroups}}
{{#this}}
import {{this}};
{{/imports}}
{{/this}}
{{/importGroups}}
/**
* Marshalls instances of the {{name}}Service_{{listener.listenerName}}Marshaller interface.
*/
@@ -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}.
*/
@@ -1,9 +1,11 @@
package {{package}} {
{{#imports}}
{{#importGroups}}
{{#this}}
import {{this}};
{{/imports}}
{{/this}}
{{/importGroups}}
/**
* An ActionScript version of the Java {{name}}Service interface.
*/
@@ -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.
*/
@@ -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.
*/