More juicy auto-generating goodness.

git-svn-id: svn+ssh://src.earth.threerings.net/narya/trunk@4412 542714f4-19e9-0310-aa3c-eee0fc999fb1
This commit is contained in:
Michael Bayne
2006-10-05 02:01:34 +00:00
parent e292e04e65
commit c7dd56f845
2 changed files with 26 additions and 19 deletions
@@ -54,6 +54,7 @@ public class ActionScriptSource
public String comment = ""; public String comment = "";
public String definition; public String definition;
public String body = ""; public String body = "";
public boolean noreplace = false;
public Member (String name, String definition) { public Member (String name, String definition) {
this.name = name; this.name = name;
@@ -753,12 +754,8 @@ public class ActionScriptSource
} }
// update the definition and comment with the ActionScript // update the definition and comment with the ActionScript
// versions (unless it's readObject or writeObject in which // versions
// case we want always to use the generated versions) curmem.definition = line.trim();
if (!funcName.equals("readObject") &&
!funcName.equals("writeObject")) {
curmem.definition = line.trim();
}
String ncomment = accum.toString(); String ncomment = accum.toString();
if (!StringUtil.isBlank(ncomment)) { if (!StringUtil.isBlank(ncomment)) {
curmem.setComment(ncomment); curmem.setComment(ncomment);
@@ -800,7 +797,10 @@ public class ActionScriptSource
if (seenOpenBrace && braceCount == 0) { if (seenOpenBrace && braceCount == 0) {
// update the method body of our currently matched member // update the method body of our currently matched member
if (curmem != null) { if (curmem != null) {
curmem.body = accum.toString(); // don't overwrite the auto-generated methods
if (!curmem.noreplace) {
curmem.body = accum.toString();
}
curmem = null; curmem = null;
} else { } else {
System.err.println( System.err.println(
@@ -195,6 +195,7 @@ public class GenActionScriptTask extends Task
ActionScriptSource.Member member; ActionScriptSource.Member member;
member = new ActionScriptSource.Member( member = new ActionScriptSource.Member(
"readObject", (needSuper ? "override " : "") + READ_SIG); "readObject", (needSuper ? "override " : "") + READ_SIG);
member.noreplace = true;
member.comment = " // from interface Streamable\n"; member.comment = " // from interface Streamable\n";
StringBuilder body = new StringBuilder(" {\n"); StringBuilder body = new StringBuilder(" {\n");
if (needSuper) { if (needSuper) {
@@ -207,7 +208,7 @@ public class GenActionScriptTask extends Task
} }
body.append(" "); body.append(" ");
body.append(field.getName()).append(" = "); body.append(field.getName()).append(" = ");
body.append(toReadObject(field.getType().getName())); body.append(toReadObject(field.getType()));
body.append(";\n"); body.append(";\n");
added++; added++;
} }
@@ -218,6 +219,7 @@ public class GenActionScriptTask extends Task
member = new ActionScriptSource.Member( member = new ActionScriptSource.Member(
"writeObject", (needSuper ? "override " : "") + WRITE_SIG); "writeObject", (needSuper ? "override " : "") + WRITE_SIG);
member.noreplace = true;
member.comment = " // from interface Streamable\n"; member.comment = " // from interface Streamable\n";
body = new StringBuilder(" {\n"); body = new StringBuilder(" {\n");
if (needSuper) { if (needSuper) {
@@ -267,30 +269,35 @@ public class GenActionScriptTask extends Task
return !Modifier.isStatic(mods) && !Modifier.isTransient(mods); 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)"; return "(ins.readField(String) as String)";
} else if (type.equals("java.lang.Integer")) { } else if (type.equals(Integer.class) ||
type = ActionScriptSource.toSimpleName(type); type.equals(Short.class) ||
return "(ins.readField(" + type + ") as " + type + ").value"; 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()"; return "ins.readByte()";
} else if (type.equals("short")) { } else if (type.equals(Short.TYPE)) {
return "ins.readShort()"; return "ins.readShort()";
} else if (type.equals("int")) { } else if (type.equals(Integer.TYPE)) {
return "ins.readInt()"; return "ins.readInt()";
} else if (type.equals("long")) { } else if (type.equals(Long.TYPE)) {
return "new Long(ins.readInt(), ins.readInt())"; return "new Long(ins.readInt(), ins.readInt())";
} else if (type.isArray()) {
return "(ins.readObject() as TypedArray)";
} else { } else {
type = ActionScriptSource.toSimpleName(type); return "(ins.readObject() as " +
return "(ins.readObject() as " + type + ")"; ActionScriptSource.toSimpleName(type.getName()) + ")";
} }
} }