Generate streaming code for Map

Is there a reason Map isn't Equalable?  java.util.Map requires an equals implementation, and it has
the same lack of guarantee of its values implementing equals.



git-svn-id: svn+ssh://src.earth.threerings.net/narya/trunk@6201 542714f4-19e9-0310-aa3c-eee0fc999fb1
This commit is contained in:
Charlie Groves
2010-10-15 08:42:39 +00:00
parent bcbeb03345
commit 13f43728ec
5 changed files with 69 additions and 19 deletions
@@ -24,9 +24,11 @@ package com.threerings.presents.tools;
import java.lang.reflect.Field;
import java.util.List;
import java.util.Map;
import java.util.Set;
import java.io.File;
import com.google.common.base.Charsets;
import com.google.common.base.Joiner;
import com.google.common.base.Preconditions;
@@ -96,9 +98,11 @@ public class GenActionScriptStreamableTask extends GenActionScriptTask
this.name = f.getName();
this.simpleType = addImportAndGetShortType(f.getType(), true, imports);
// Reading and writing Lists uses ArrayStreamer.INSTANCE directly
// Lists and Maps use their Streamers directly
if (List.class.isAssignableFrom(f.getType())) {
imports.add("com.threerings.io.streamers.ArrayStreamer");
} else if (Map.class.isAssignableFrom(f.getType())) {
imports.add("com.threerings.io.streamers.MapStreamer");
}
this.reader = toReadObject(f.getType());
this.writer = toWriteObject(f.getType(), name);
@@ -26,6 +26,7 @@ import java.lang.reflect.Modifier;
import java.util.ArrayList;
import java.util.List;
import java.util.Map;
import java.util.Set;
import java.io.BufferedWriter;
@@ -269,30 +270,24 @@ public class GenActionScriptTask extends GenTask
return "com.threerings.io.TypedArray";
}
return "Array";
}
if (Integer.TYPE.equals(type) ||
} else if (Map.class.isAssignableFrom(type)) {
return "com.threerings.util.Map";
} else if (Integer.TYPE.equals(type) ||
Byte.TYPE.equals(type) ||
Short.TYPE.equals(type) ||
Character.TYPE.equals(type)) {
return "int";
}
if (Float.TYPE.equals(type) ||
} else if (Float.TYPE.equals(type) ||
Double.TYPE.equals(type)) {
return "Number";
}
if (Long.TYPE.equals(type)) {
} else if (Long.TYPE.equals(type)) {
return "com.threerings.util.Long";
}
if (Boolean.TYPE.equals(type)) {
} else if (Boolean.TYPE.equals(type)) {
return "Boolean";
} else {
// inner classes are not supported by ActionScript so we _
return type.getName().replaceAll("\\$", "_");
}
// inner classes are not supported by ActionScript so we _
return type.getName().replaceAll("\\$", "_");
}
public static String toReadObject (Class<?> type)
@@ -331,6 +326,9 @@ public class GenActionScriptTask extends GenTask
} else if (type.equals(Double.TYPE)) {
return "readDouble()";
} else if (Map.class.isAssignableFrom(type)) {
return "readField(MapStreamer.INSTANCE)";
} else if (List.class.isAssignableFrom(type)) {
return "readField(ArrayStreamer.INSTANCE)";
@@ -391,6 +389,9 @@ public class GenActionScriptTask extends GenTask
} else if (List.class.isAssignableFrom(type)) {
return "writeField(" + name + ", ArrayStreamer.INSTANCE)";
} else if (Map.class.isAssignableFrom(type)) {
return "writeField(" + name + ", MapStreamer.INSTANCE)";
} else {
return "writeObject(" + name + ")";
}