diff --git a/src/java/com/threerings/presents/tools/GenServiceTask.java b/src/java/com/threerings/presents/tools/GenServiceTask.java index a89cf0d36..62439aa36 100644 --- a/src/java/com/threerings/presents/tools/GenServiceTask.java +++ b/src/java/com/threerings/presents/tools/GenServiceTask.java @@ -46,6 +46,12 @@ import com.threerings.presents.server.InvocationProvider; /** * An Ant task for generating invocation service marshalling and * unmarshalling classes. + * TODO: when generating the imports for exported action script files, there are just enough + * conversions of primitive types (e.g. float -> Number), array types (e.g. int[] -> TypedArray) + * and three rings utility types (e.g. float -> Float) to make the existing serivces work. It + * should be possible to create a complete list of these conversions so that future services + * can be generated without problems. + * TODO: when generating imports, remove imports of classes in the same pacakge. */ public class GenServiceTask extends InvocationTask { @@ -179,8 +185,11 @@ public class GenServiceTask extends InvocationTask // get rid of java.lang stuff and primitives imports.removeGlobals(); + // get rid of all arrays (they are automatic in java) + imports.removeArrays(); + // for each listener type, also import the corresponding marshaller - imports.duplicateAndMunge("Listener", + imports.duplicateAndMunge("*Listener", "Service", "Marshaller", "Listener", "Marshaller", ".client.", ".data."); @@ -233,16 +242,34 @@ public class GenServiceTask extends InvocationTask 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", + imports.duplicateAndMunge("*.InvocationService_InvocationListener", "InvocationService_InvocationListener", "InvocationMarshaller_ListenerMarshaller", ".client.", ".data."); + // any use of a listener requires the listener marshaller + imports.pushOut("*.InvocationService_InvocationListener"); + imports.duplicateAndMunge("*Listener", + "Service", "Marshaller", + "Listener", "Marshaller", + ".client.", ".data."); + imports.popIn(); + // get rid of java.lang stuff and any remaining primitives imports.removeGlobals(); + + if (imports.removeAll("[L*") > 0) { + imports.add("com.threerings.io.TypedArray"); + } + + // get rid of remaining arrays + imports.removeArrays(); ctx.put("imports", imports.toList()); @@ -312,9 +339,21 @@ public class GenServiceTask extends InvocationTask imports.add(Client.class); imports.add(InvocationService.class); + // allow primitive types in service methods + // TODO: are more primitive types needed? + imports.replace("[B", "flash.utils.ByteArray"); + imports.replace("[I", "com.threerings.io.TypedArray"); + + if (imports.removeAll("[L*") > 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(); @@ -405,6 +444,9 @@ public class GenServiceTask extends InvocationTask // get rid of primitives and java.lang types imports.removeGlobals(); + + // get rid of arrays + imports.removeArrays(); // import the Marshaller corresponding to the service imports.addMunged(sdesc.service, @@ -465,6 +507,9 @@ public class GenServiceTask extends InvocationTask // get rid of primitives and java.lang types imports.removeGlobals(); + // get rid of arrays + imports.removeArrays(); + // import Foo instead of Foo$Bar imports.swapInnerClassesForParents(); diff --git a/src/java/com/threerings/presents/tools/ImportSet.java b/src/java/com/threerings/presents/tools/ImportSet.java index 72dfa56bb..1ef6a4038 100644 --- a/src/java/com/threerings/presents/tools/ImportSet.java +++ b/src/java/com/threerings/presents/tools/ImportSet.java @@ -1,8 +1,10 @@ package com.threerings.presents.tools; +import java.util.ArrayList; import java.util.HashSet; import java.util.Iterator; import java.util.List; +import java.util.regex.Pattern; import com.samskivert.util.ComparableArrayList; import com.samskivert.util.StringUtil; @@ -15,6 +17,12 @@ import com.samskivert.util.StringUtil; * convenience for easily specifying multiple find/replace pairs. For example, to replace "Foo" * with "Bar" and "123" with "ABC", a function can be called with the 4 arguments "Foo", "Bar", * "123", "ABC" for the String... replace argument. + * + *
A few methods also use a "pattern" string parameter that is used to match a class name.
+ * This is a dumbed down regular expression (to avoid many \.) where "*" means .* and no other
+ * characters have special meaning. The pattern is also implicitly enclosed with ^$ so that the
+ * pattern must match the class name in its entirity. Callers will mostly use this to specify a
+ * prefix like "something*" or a suffix like "*something".
*/
public class ImportSet
{
@@ -33,7 +41,9 @@ public class ImportSet
*/
public void add (String name)
{
- _imports.add(name);
+ if (name != null) {
+ _imports.add(name);
+ }
}
/**
@@ -87,6 +97,14 @@ public class ImportSet
}
}
+ /**
+ * Gets rid of array imports.
+ */
+ public int removeArrays ()
+ {
+ return removeAll("[*");
+ }
+
/**
* Replaces inner class imports (those with a '$') with an import of the parent class.
*/
@@ -126,6 +144,40 @@ public class ImportSet
addAll(inner);
}
+ /**
+ * Temporarily remove one import matching the given pattern. The most recently pushed pattern
+ * can be re-added using popIn. If there is no match, a null value is pushed so
+ * that popIn can still be called.
+ * @param pattern to match
+ */
+ public void pushOut (String pattern)
+ {
+ Pattern pat = makePattern(pattern);
+ Iterator