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:
@@ -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)
|
public static File createActionScriptPath (File actionScriptRoot, Class<?> sclass)
|
||||||
{
|
{
|
||||||
// determine the path to the corresponding action script source file
|
// determine the path to the corresponding action script source file
|
||||||
|
|||||||
@@ -81,7 +81,7 @@ public class GenReceiverTask extends InvocationTask
|
|||||||
!Modifier.isAbstract(m.getModifiers())) {
|
!Modifier.isAbstract(m.getModifiers())) {
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
methods.add(new ServiceMethod(m, imports));
|
methods.add(createAndGatherImports(m, imports));
|
||||||
}
|
}
|
||||||
methods.sort();
|
methods.sort();
|
||||||
|
|
||||||
|
|||||||
@@ -92,7 +92,7 @@ public class GenServiceTask extends InvocationTask
|
|||||||
System.out.println("Adding " + m + ", imports are " +
|
System.out.println("Adding " + m + ", imports are " +
|
||||||
StringUtil.toString(imports));
|
StringUtil.toString(imports));
|
||||||
}
|
}
|
||||||
methods.add(new ServiceMethod(m, imports));
|
methods.add(createAndGatherImports(m, imports));
|
||||||
if (_verbose) {
|
if (_verbose) {
|
||||||
System.out.println("Added " + m + ", imports are " +
|
System.out.println("Added " + m + ", imports are " +
|
||||||
StringUtil.toString(imports));
|
StringUtil.toString(imports));
|
||||||
@@ -302,14 +302,6 @@ public class GenServiceTask extends InvocationTask
|
|||||||
// replace inner classes with action script equivalents
|
// replace inner classes with action script equivalents
|
||||||
imports.translateInnerClasses();
|
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
|
// ye olde special case - any method that uses a default listener
|
||||||
// causes the need for the default listener marshaller
|
// causes the need for the default listener marshaller
|
||||||
imports.duplicateAndMunge("*.InvocationService_InvocationListener",
|
imports.duplicateAndMunge("*.InvocationService_InvocationListener",
|
||||||
@@ -325,19 +317,8 @@ public class GenServiceTask extends InvocationTask
|
|||||||
".client.", ".data.");
|
".client.", ".data.");
|
||||||
imports.popIn();
|
imports.popIn();
|
||||||
|
|
||||||
// convert java primitive types to ooo util types
|
// convert java bases and primitives
|
||||||
imports.replace(Integer.class, "com.threerings.util.Integer");
|
ActionScriptUtils.convertBaseClasses(imports);
|
||||||
|
|
||||||
// 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();
|
|
||||||
|
|
||||||
// remove imports in our own package
|
// remove imports in our own package
|
||||||
imports.removeSamePackage(mpackage);
|
imports.removeSamePackage(mpackage);
|
||||||
@@ -371,16 +352,8 @@ public class GenServiceTask extends InvocationTask
|
|||||||
// replace '$' with '_' for action script naming convention
|
// replace '$' with '_' for action script naming convention
|
||||||
imports.translateInnerClasses();
|
imports.translateInnerClasses();
|
||||||
|
|
||||||
// convert primitive java types to ooo util types
|
// convert java bases and primitives
|
||||||
imports.replace("long", "com.threerings.util.Long");
|
ActionScriptUtils.convertBaseClasses(imports);
|
||||||
|
|
||||||
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();
|
|
||||||
|
|
||||||
// remove imports in our own package
|
// remove imports in our own package
|
||||||
imports.removeSamePackage(mpackage);
|
imports.removeSamePackage(mpackage);
|
||||||
@@ -404,26 +377,12 @@ public class GenServiceTask extends InvocationTask
|
|||||||
imports.add(Client.class);
|
imports.add(Client.class);
|
||||||
imports.add(InvocationService.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
|
// change imports of Foo$Bar to Foo_Bar
|
||||||
imports.translateInnerClasses();
|
imports.translateInnerClasses();
|
||||||
|
|
||||||
|
// convert java bases and primitives
|
||||||
|
ActionScriptUtils.convertBaseClasses(imports);
|
||||||
|
|
||||||
// remove imports in our own package
|
// remove imports in our own package
|
||||||
imports.removeSamePackage(sdesc.spackage);
|
imports.removeSamePackage(sdesc.spackage);
|
||||||
|
|
||||||
@@ -454,16 +413,7 @@ public class GenServiceTask extends InvocationTask
|
|||||||
// change Foo$Bar to Foo_Bar
|
// change Foo$Bar to Foo_Bar
|
||||||
imports.translateInnerClasses();
|
imports.translateInnerClasses();
|
||||||
|
|
||||||
imports.replace("[B", "flash.utils.ByteArray");
|
ActionScriptUtils.convertBaseClasses(imports);
|
||||||
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();
|
|
||||||
|
|
||||||
// remove imports in our own package
|
// remove imports in our own package
|
||||||
imports.removeSamePackage(sdesc.spackage);
|
imports.removeSamePackage(sdesc.spackage);
|
||||||
@@ -644,7 +594,7 @@ public class GenServiceTask extends InvocationTask
|
|||||||
System.out.println("Adding " + m + ", imports are " +
|
System.out.println("Adding " + m + ", imports are " +
|
||||||
StringUtil.toString(imports));
|
StringUtil.toString(imports));
|
||||||
}
|
}
|
||||||
methods.add(new ServiceMethod(m, imports));
|
methods.add(createAndGatherImports(m, imports));
|
||||||
if (_verbose) {
|
if (_verbose) {
|
||||||
System.out.println("Added " + m + ", imports are " +
|
System.out.println("Added " + m + ", imports are " +
|
||||||
StringUtil.toString(imports));
|
StringUtil.toString(imports));
|
||||||
|
|||||||
@@ -87,6 +87,13 @@ public abstract class InvocationTask extends GenTask
|
|||||||
protected int _index;
|
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. */
|
/** Used to keep track of invocation service methods or listener methods. */
|
||||||
public class ServiceMethod implements Comparable<ServiceMethod>
|
public class ServiceMethod implements Comparable<ServiceMethod>
|
||||||
{
|
{
|
||||||
@@ -98,7 +105,7 @@ public abstract class InvocationTask extends GenTask
|
|||||||
* @param method the method to inspect
|
* @param method the method to inspect
|
||||||
* @param imports will be filled with the types required by the method
|
* @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;
|
this.method = method;
|
||||||
|
|
||||||
// if this method has listener arguments, we need to add listener argument info for them
|
// 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));
|
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
|
// we need to look through our arguments and note any needed imports in the supplied
|
||||||
// table
|
// table
|
||||||
for (Type type : method.getGenericParameterTypes()) {
|
for (Type type : method.getGenericParameterTypes()) {
|
||||||
|
|||||||
Reference in New Issue
Block a user