From f4bc4a2680051baad67c2b954d10ac4f5a20a96a Mon Sep 17 00:00:00 2001 From: Tom Conkling Date: Sat, 1 May 2010 02:35:39 +0000 Subject: [PATCH] - 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 --- .../presents/tools/ActionScriptSource.java | 50 +++++++++++++++---- 1 file changed, 40 insertions(+), 10 deletions(-) diff --git a/src/java/com/threerings/presents/tools/ActionScriptSource.java b/src/java/com/threerings/presents/tools/ActionScriptSource.java index 631640f31..e4eb3c8ea 100644 --- a/src/java/com/threerings/presents/tools/ActionScriptSource.java +++ b/src/java/com/threerings/presents/tools/ActionScriptSource.java @@ -21,18 +21,20 @@ 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.File; import java.io.FileReader; import java.io.IOException; 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; @@ -40,6 +42,8 @@ import com.samskivert.util.StringUtil; import com.threerings.util.ActionScript; +import static com.threerings.NaryaLog.log; + /** * Primitively parses an ActionScriptSource file, allows the addition and replacement of class * members and handles writing out the file again. @@ -738,13 +742,28 @@ public class ActionScriptSource line = slurpUntil(bin, line, ";", false); } -// String fieldName = m.group(1); + ArrayList 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? accum.setLength(0); - // TODO: extract the name, replace that declaration - // see if we match a constructor declaration } else if (line.indexOf("public function " + className) != -1) { // if this line does not contain a close paren, keep reading until it does @@ -1037,6 +1056,17 @@ public class ActionScriptSource 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. */ protected static enum Mode { PREAMBLE, IMPORTS, CLASSCOMMENT, CLASSDECL, CLASSBODY, METHODBODY, POSTCLASS, POSTPKG }