diff --git a/src/java/com/threerings/presents/tools/ActionScriptSource.java b/src/java/com/threerings/presents/tools/ActionScriptSource.java index f4111ce1d..4fefd9b31 100644 --- a/src/java/com/threerings/presents/tools/ActionScriptSource.java +++ b/src/java/com/threerings/presents/tools/ActionScriptSource.java @@ -54,6 +54,7 @@ public class ActionScriptSource public String comment = ""; public String definition; public String body = ""; + public boolean noreplace = false; public Member (String name, String definition) { this.name = name; @@ -753,12 +754,8 @@ public class ActionScriptSource } // update the definition and comment with the ActionScript - // versions (unless it's readObject or writeObject in which - // case we want always to use the generated versions) - if (!funcName.equals("readObject") && - !funcName.equals("writeObject")) { - curmem.definition = line.trim(); - } + // versions + curmem.definition = line.trim(); String ncomment = accum.toString(); if (!StringUtil.isBlank(ncomment)) { curmem.setComment(ncomment); @@ -800,7 +797,10 @@ public class ActionScriptSource if (seenOpenBrace && braceCount == 0) { // update the method body of our currently matched member if (curmem != null) { - curmem.body = accum.toString(); + // don't overwrite the auto-generated methods + if (!curmem.noreplace) { + curmem.body = accum.toString(); + } curmem = null; } else { System.err.println( diff --git a/src/java/com/threerings/presents/tools/GenActionScriptTask.java b/src/java/com/threerings/presents/tools/GenActionScriptTask.java index 1629bede1..9d726912f 100644 --- a/src/java/com/threerings/presents/tools/GenActionScriptTask.java +++ b/src/java/com/threerings/presents/tools/GenActionScriptTask.java @@ -195,6 +195,7 @@ public class GenActionScriptTask extends Task ActionScriptSource.Member member; member = new ActionScriptSource.Member( "readObject", (needSuper ? "override " : "") + READ_SIG); + member.noreplace = true; member.comment = " // from interface Streamable\n"; StringBuilder body = new StringBuilder(" {\n"); if (needSuper) { @@ -207,7 +208,7 @@ public class GenActionScriptTask extends Task } body.append(" "); body.append(field.getName()).append(" = "); - body.append(toReadObject(field.getType().getName())); + body.append(toReadObject(field.getType())); body.append(";\n"); added++; } @@ -218,6 +219,7 @@ public class GenActionScriptTask extends Task member = new ActionScriptSource.Member( "writeObject", (needSuper ? "override " : "") + WRITE_SIG); + member.noreplace = true; member.comment = " // from interface Streamable\n"; body = new StringBuilder(" {\n"); if (needSuper) { @@ -267,30 +269,35 @@ public class GenActionScriptTask extends Task return !Modifier.isStatic(mods) && !Modifier.isTransient(mods); } - protected String toReadObject (String type) + protected String toReadObject (Class type) { - if (type.equals("java.lang.String")) { + if (type.equals(String.class)) { return "(ins.readField(String) as String)"; - } else if (type.equals("java.lang.Integer")) { - type = ActionScriptSource.toSimpleName(type); - return "(ins.readField(" + type + ") as " + type + ").value"; + } else if (type.equals(Integer.class) || + type.equals(Short.class) || + type.equals(Byte.class)) { + String name = ActionScriptSource.toSimpleName(type.getName()); + return "(ins.readField(" + name + ") as " + name + ").value"; - } else if (type.equals("byte")) { + } else if (type.equals(Byte.TYPE)) { return "ins.readByte()"; - } else if (type.equals("short")) { + } else if (type.equals(Short.TYPE)) { return "ins.readShort()"; - } else if (type.equals("int")) { + } else if (type.equals(Integer.TYPE)) { return "ins.readInt()"; - } else if (type.equals("long")) { + } else if (type.equals(Long.TYPE)) { return "new Long(ins.readInt(), ins.readInt())"; + } else if (type.isArray()) { + return "(ins.readObject() as TypedArray)"; + } else { - type = ActionScriptSource.toSimpleName(type); - return "(ins.readObject() as " + type + ")"; + return "(ins.readObject() as " + + ActionScriptSource.toSimpleName(type.getName()) + ")"; } }