- Properly parse out ActionScript member variables, and insert them back into the generated code
- Eclipse keeps rejiggering my imports git-svn-id: svn+ssh://src.earth.threerings.net/narya/trunk@6063 542714f4-19e9-0310-aa3c-eee0fc999fb1
This commit is contained in:
@@ -21,18 +21,20 @@
|
|||||||
|
|
||||||
package com.threerings.presents.tools;
|
package com.threerings.presents.tools;
|
||||||
|
|
||||||
|
import java.lang.reflect.Constructor;
|
||||||
|
import java.lang.reflect.Field;
|
||||||
|
import java.lang.reflect.Method;
|
||||||
|
import java.lang.reflect.Modifier;
|
||||||
|
|
||||||
|
import java.util.ArrayList;
|
||||||
|
import java.util.regex.Matcher;
|
||||||
|
import java.util.regex.Pattern;
|
||||||
|
|
||||||
import java.io.BufferedReader;
|
import java.io.BufferedReader;
|
||||||
import java.io.File;
|
import java.io.File;
|
||||||
import java.io.FileReader;
|
import java.io.FileReader;
|
||||||
import java.io.IOException;
|
import java.io.IOException;
|
||||||
import java.io.PrintWriter;
|
import java.io.PrintWriter;
|
||||||
import java.lang.reflect.Constructor;
|
|
||||||
import java.lang.reflect.Field;
|
|
||||||
import java.lang.reflect.Method;
|
|
||||||
import java.lang.reflect.Modifier;
|
|
||||||
import java.util.ArrayList;
|
|
||||||
import java.util.regex.Matcher;
|
|
||||||
import java.util.regex.Pattern;
|
|
||||||
|
|
||||||
import com.google.common.collect.Lists;
|
import com.google.common.collect.Lists;
|
||||||
|
|
||||||
@@ -40,6 +42,8 @@ import com.samskivert.util.StringUtil;
|
|||||||
|
|
||||||
import com.threerings.util.ActionScript;
|
import com.threerings.util.ActionScript;
|
||||||
|
|
||||||
|
import static com.threerings.NaryaLog.log;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Primitively parses an ActionScriptSource file, allows the addition and replacement of class
|
* Primitively parses an ActionScriptSource file, allows the addition and replacement of class
|
||||||
* members and handles writing out the file again.
|
* members and handles writing out the file again.
|
||||||
@@ -738,13 +742,28 @@ public class ActionScriptSource
|
|||||||
line = slurpUntil(bin, line, ";", false);
|
line = slurpUntil(bin, line, ";", false);
|
||||||
}
|
}
|
||||||
|
|
||||||
// String fieldName = m.group(1);
|
ArrayList<Member> list = publicFields;
|
||||||
|
boolean isProtected = (line.indexOf("protected ") != -1);
|
||||||
|
boolean isConst = (line.indexOf("const ") != -1);
|
||||||
|
list = isProtected ?
|
||||||
|
(isConst ? protectedConstants : protectedFields) :
|
||||||
|
(isConst ? publicConstants : publicFields);
|
||||||
|
|
||||||
|
// extract the name, replace the declaration
|
||||||
|
String fieldName = m.group(1);
|
||||||
|
//log.info("ASFIELD", "name", fieldName);
|
||||||
|
Member member = getMember(list, fieldName);
|
||||||
|
if (member == null) {
|
||||||
|
System.err.println(
|
||||||
|
"Have ActionScript field with no " +
|
||||||
|
"Java equivalent: " + fieldName);
|
||||||
|
member = new Member(fieldName, line.trim());
|
||||||
|
list.add(member);
|
||||||
|
}
|
||||||
|
|
||||||
// TODO: update the comment?
|
// TODO: update the comment?
|
||||||
accum.setLength(0);
|
accum.setLength(0);
|
||||||
|
|
||||||
// TODO: extract the name, replace that declaration
|
|
||||||
|
|
||||||
// see if we match a constructor declaration
|
// see if we match a constructor declaration
|
||||||
} else if (line.indexOf("public function " + className) != -1) {
|
} else if (line.indexOf("public function " + className) != -1) {
|
||||||
// if this line does not contain a close paren, keep reading until it does
|
// if this line does not contain a close paren, keep reading until it does
|
||||||
@@ -1037,6 +1056,17 @@ public class ActionScriptSource
|
|||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public static void main (String[] args)
|
||||||
|
{
|
||||||
|
test("public function asdf () :void");
|
||||||
|
test("public function get asdf () :void");
|
||||||
|
}
|
||||||
|
|
||||||
|
protected static void test (String test)
|
||||||
|
{
|
||||||
|
log.info("test", "string", test, "matches", ASFUNCTION.matcher(test).matches());
|
||||||
|
}
|
||||||
|
|
||||||
/** Denotes various phases of class file parsing. */
|
/** Denotes various phases of class file parsing. */
|
||||||
protected static enum Mode { PREAMBLE, IMPORTS, CLASSCOMMENT, CLASSDECL,
|
protected static enum Mode { PREAMBLE, IMPORTS, CLASSCOMMENT, CLASSDECL,
|
||||||
CLASSBODY, METHODBODY, POSTCLASS, POSTPKG }
|
CLASSBODY, METHODBODY, POSTCLASS, POSTPKG }
|
||||||
|
|||||||
Reference in New Issue
Block a user