Include field type parameters in the generated AS to force their linkage.

git-svn-id: svn+ssh://src.earth.threerings.net/narya/trunk@6696 542714f4-19e9-0310-aa3c-eee0fc999fb1
This commit is contained in:
Bruno Garcia
2011-08-26 04:54:07 +00:00
parent c32b1baa41
commit e1560a1298
3 changed files with 54 additions and 5 deletions
@@ -274,6 +274,32 @@ public class ActionScriptUtils
return false;
}
/**
* Returns the primitive (unboxed) counterpart of a class, or the same class if it isn't a boxed
* type.
*/
public static Class<?> toPrimitiveType (Class<?> cclass)
{
if (Boolean.class == cclass) {
return Boolean.TYPE;
} else if (Character.class == cclass) {
return Character.TYPE;
} else if (Byte.class == cclass) {
return Byte.TYPE;
} else if (Short.class == cclass) {
return Short.TYPE;
} else if (Integer.class == cclass) {
return Integer.TYPE;
} else if (Long.class == cclass) {
return Long.TYPE;
} else if (Float.class == cclass) {
return Float.TYPE;
} else if (Double.class == cclass) {
return Double.TYPE;
}
return cclass;
}
/** Returns if the given class is an implementation of Map that doesn't know about Streaming */
protected static boolean isNaiveMap (Class<?> type)
{
@@ -24,6 +24,8 @@ package com.threerings.presents.tools;
import java.io.File;
import java.lang.reflect.Field;
import java.lang.reflect.Modifier;
import java.lang.reflect.ParameterizedType;
import java.lang.reflect.Type;
import java.util.List;
import java.util.Map;
import java.util.Set;
@@ -165,12 +167,14 @@ public class GenActionScriptStreamableTask extends GenTask
public final String name;
public final String capitalName;
public final String simpleType;
public final String parameterTypes;
public final String reader;
public final String writer;
public final String dobjectField;
public boolean dset;
public boolean array;
public boolean oidList;
public boolean hasTypeParameters;
public ASField (Field f, ImportSet imports)
{
@@ -179,6 +183,25 @@ public class GenActionScriptStreamableTask extends GenTask
dobjectField = StringUtil.unStudlyName(name).toUpperCase();
simpleType = ActionScriptUtils.addImportAndGetShortType(f.getType(), true, imports);
List<String> parameters = Lists.newLinkedList();
Type genType = f.getGenericType();
if (genType instanceof ParameterizedType) {
for (Type param : ((ParameterizedType) genType).getActualTypeArguments()) {
if (param instanceof Class) {
// Convert any box classes to primitives to avoid having to import them
Class<?> primitive = ActionScriptUtils.toPrimitiveType((Class<?>) param);
parameters.add(ActionScriptUtils.addImportAndGetShortType(
primitive, false, imports));
}
}
}
if (!parameters.isEmpty()) {
parameterTypes = Joiner.on(", ").join(parameters);
hasTypeParameters = true;
} else {
parameterTypes = "";
}
// Lists and Maps use their Streamers directly
if (List.class.isAssignableFrom(f.getType())) {
imports.add("com.threerings.io.streamers.ArrayStreamer");
@@ -188,7 +211,6 @@ public class GenActionScriptStreamableTask extends GenTask
imports.add("com.threerings.io.streamers.SetStreamer");
} else if (DSet.class.isAssignableFrom(f.getType())) {
dset = true;
imports.add("com.threerings.presents.dobj.DSet_Entry"); // Used for signals
} else if (OidList.class.isAssignableFrom(f.getType())) {
oidList = true;
}
@@ -19,16 +19,17 @@ public class {{classname}} {{^extends.isEmpty}}extends {{extends}}
// GENERATED STREAMING START
{{#pubFields}}
public var {{name}} :{{simpleType}};
public var {{name}} :{{simpleType}};{{#hasTypeParameters}} /* of */ {{parameterTypes}};{{/hasTypeParameters}}
{{/pubFields}}
{{#dobject}}
{{#pubFields}}
public var {{name}}Changed :Signal = new Signal({{simpleType}}, {{simpleType}});
{{#dset}}
public var {{name}}EntryAdded :Signal = new Signal(DSet_Entry);
public var {{name}}EntryRemoved :Signal = new Signal(DSet_Entry);
public var {{name}}EntryUpdated :Signal = new Signal(DSet_Entry, DSet_Entry);
public var {{name}}EntryAdded :Signal = new Signal({{parameterTypes}});
public var {{name}}EntryRemoved :Signal = new Signal({{parameterTypes}});
public var {{name}}EntryUpdated :Signal = new Signal({{parameterTypes}}, {{parameterTypes}});
{{/dset}}
{{#array}}
public var {{name}}ElementUpdated :Signal = new Signal(int, Object, Object);