Consolidate actionscript import munging, add Map conversion.

git-svn-id: svn+ssh://src.earth.threerings.net/narya/trunk@6674 542714f4-19e9-0310-aa3c-eee0fc999fb1
This commit is contained in:
Jamie Doornbos
2011-07-06 17:55:20 +00:00
parent 455eb55d90
commit 23614ac71f
4 changed files with 51 additions and 62 deletions
@@ -223,6 +223,36 @@ public class ActionScriptUtils
}
}
/**
* Converts java types to their actionscript equivalents for ooo-style streaming.
*/
public static void convertBaseClasses (ImportSet imports)
{
// 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");
imports.replace("long", "com.threerings.util.Long");
if (imports.removeAll("[*") > 0) {
imports.add("com.threerings.io.TypedArray");
}
// convert java primitive boxes to their ooo counterparts
imports.replace(Integer.class, "com.threerings.util.Integer");
// convert some java.util types to their ooo counterparts
imports.replace(Map.class, "com.threerings.util.Map");
// get rid of java.lang stuff and any remaining primitives
imports.removeGlobals();
// get rid of remaining arrays
imports.removeArrays();
}
public static File createActionScriptPath (File actionScriptRoot, Class<?> sclass)
{
// determine the path to the corresponding action script source file
@@ -81,7 +81,7 @@ public class GenReceiverTask extends InvocationTask
!Modifier.isAbstract(m.getModifiers())) {
continue;
}
methods.add(new ServiceMethod(m, imports));
methods.add(createAndGatherImports(m, imports));
}
methods.sort();
@@ -92,7 +92,7 @@ public class GenServiceTask extends InvocationTask
System.out.println("Adding " + m + ", imports are " +
StringUtil.toString(imports));
}
methods.add(new ServiceMethod(m, imports));
methods.add(createAndGatherImports(m, imports));
if (_verbose) {
System.out.println("Added " + m + ", imports are " +
StringUtil.toString(imports));
@@ -302,14 +302,6 @@ public class GenServiceTask extends InvocationTask
// replace inner classes with action script equivalents
imports.translateInnerClasses();
// 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");
imports.replace("[I", "com.threerings.io.TypedArray");
// ye olde special case - any method that uses a default listener
// causes the need for the default listener marshaller
imports.duplicateAndMunge("*.InvocationService_InvocationListener",
@@ -325,19 +317,8 @@ public class GenServiceTask extends InvocationTask
".client.", ".data.");
imports.popIn();
// convert java primitive types to ooo util types
imports.replace(Integer.class, "com.threerings.util.Integer");
// get rid of java.lang stuff and any remaining primitives
imports.removeGlobals();
imports.replace("[B", "flash.utils.ByteArray");
if (imports.removeAll("[*") > 0) {
imports.add("com.threerings.io.TypedArray");
}
// get rid of remaining arrays
imports.removeArrays();
// convert java bases and primitives
ActionScriptUtils.convertBaseClasses(imports);
// remove imports in our own package
imports.removeSamePackage(mpackage);
@@ -371,16 +352,8 @@ public class GenServiceTask extends InvocationTask
// replace '$' with '_' for action script naming convention
imports.translateInnerClasses();
// convert primitive java types to ooo util types
imports.replace("long", "com.threerings.util.Long");
imports.replace("[B", "flash.utils.ByteArray");
if (imports.removeAll("[*") > 0) {
imports.add("com.threerings.io.TypedArray");
}
// get rid of remaining primitives and java.lang types
imports.removeGlobals();
// convert java bases and primitives
ActionScriptUtils.convertBaseClasses(imports);
// remove imports in our own package
imports.removeSamePackage(mpackage);
@@ -404,26 +377,12 @@ public class GenServiceTask extends InvocationTask
imports.add(Client.class);
imports.add(InvocationService.class);
// allow primitive types in service methods
imports.replace("[B", "flash.utils.ByteArray");
imports.replace("[I", "com.threerings.io.TypedArray");
// convert java primitive types to ooo util types
imports.replace("java.lang.Integer", "com.threerings.util.Integer");
if (imports.removeAll("[*") > 0) {
imports.add("com.threerings.io.TypedArray");
}
// get rid of primitives and java.lang classes
imports.removeGlobals();
// get rid of remaining arrays
imports.removeArrays();
// change imports of Foo$Bar to Foo_Bar
imports.translateInnerClasses();
// convert java bases and primitives
ActionScriptUtils.convertBaseClasses(imports);
// remove imports in our own package
imports.removeSamePackage(sdesc.spackage);
@@ -454,16 +413,7 @@ public class GenServiceTask extends InvocationTask
// change Foo$Bar to Foo_Bar
imports.translateInnerClasses();
imports.replace("[B", "flash.utils.ByteArray");
if (imports.removeAll("[*") > 0) {
imports.add("com.threerings.io.TypedArray");
}
// convert java primitive types to ooo util types
imports.replace("long", "com.threerings.util.Long");
// get rid of remaining primitives and java.lang types
imports.removeGlobals();
ActionScriptUtils.convertBaseClasses(imports);
// remove imports in our own package
imports.removeSamePackage(sdesc.spackage);
@@ -644,7 +594,7 @@ public class GenServiceTask extends InvocationTask
System.out.println("Adding " + m + ", imports are " +
StringUtil.toString(imports));
}
methods.add(new ServiceMethod(m, imports));
methods.add(createAndGatherImports(m, imports));
if (_verbose) {
System.out.println("Added " + m + ", imports are " +
StringUtil.toString(imports));
@@ -87,6 +87,13 @@ public abstract class InvocationTask extends GenTask
protected int _index;
}
public ServiceMethod createAndGatherImports (Method method, ImportSet set)
{
ServiceMethod sm = new ServiceMethod(method);
sm.gatherImports(set);
return sm;
}
/** Used to keep track of invocation service methods or listener methods. */
public class ServiceMethod implements Comparable<ServiceMethod>
{
@@ -98,7 +105,7 @@ public abstract class InvocationTask extends GenTask
* @param method the method to inspect
* @param imports will be filled with the types required by the method
*/
public ServiceMethod (Method method, ImportSet imports) {
public ServiceMethod (Method method) {
this.method = method;
// if this method has listener arguments, we need to add listener argument info for them
@@ -113,7 +120,9 @@ public abstract class InvocationTask extends GenTask
listenerArgs.add(new ListenerArgument(ii, arg));
}
}
}
public void gatherImports (ImportSet imports) {
// we need to look through our arguments and note any needed imports in the supplied
// table
for (Type type : method.getGenericParameterTypes()) {