More jockeying:
- handle // @Override // blah style comments - deal with fields that are assigned to anonymous inner classes (actually anything with braces, which would also include array literals). git-svn-id: svn+ssh://src.earth.threerings.net/narya/trunk@4667 542714f4-19e9-0310-aa3c-eee0fc999fb1
This commit is contained in:
@@ -82,7 +82,11 @@ public class ActionScriptSource
|
|||||||
|
|
||||||
public void setComment (String comment) {
|
public void setComment (String comment) {
|
||||||
if (comment.indexOf("@Override") != -1) {
|
if (comment.indexOf("@Override") != -1) {
|
||||||
comment = comment.replaceAll("@Override\\s?", "");
|
if (comment.trim().startsWith("//")) {
|
||||||
|
// handle // @Override // comment
|
||||||
|
comment = comment.replaceFirst("// ?", "");
|
||||||
|
}
|
||||||
|
comment = comment.replaceAll("@Override ?", "");
|
||||||
definition = "override " + definition;
|
definition = "override " + definition;
|
||||||
}
|
}
|
||||||
// trim blank lines from start
|
// trim blank lines from start
|
||||||
@@ -307,11 +311,14 @@ public class ActionScriptSource
|
|||||||
// note our implemented interfaces
|
// note our implemented interfaces
|
||||||
ArrayList<String> ifaces = new ArrayList<String>();
|
ArrayList<String> ifaces = new ArrayList<String>();
|
||||||
for (Class iclass : jclass.getInterfaces()) {
|
for (Class iclass : jclass.getInterfaces()) {
|
||||||
// we cannot use the FooCodes interface pattern in ActionScript so we just have to nix
|
// we cannot use the FooCodes interface pattern in ActionScript so we just nix it
|
||||||
// it
|
|
||||||
if (iclass.getName().endsWith("Codes")) {
|
if (iclass.getName().endsWith("Codes")) {
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
|
// we also nix Serializable and IsSerializable (hackity hack)
|
||||||
|
if (iclass.getName().endsWith("Serializable")) {
|
||||||
|
continue;
|
||||||
|
}
|
||||||
ifaces.add(toSimpleName(iclass.getName()));
|
ifaces.add(toSimpleName(iclass.getName()));
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -470,15 +477,13 @@ public class ActionScriptSource
|
|||||||
case CLASSBODY:
|
case CLASSBODY:
|
||||||
// see if we match a field declaration
|
// see if we match a field declaration
|
||||||
if ((m = JFIELD.matcher(line)).matches()) {
|
if ((m = JFIELD.matcher(line)).matches()) {
|
||||||
// if this line does not end on a semicolon, keep sucking
|
// if this line does not end on a semicolon, keep reading until it does
|
||||||
// up lines until it does
|
|
||||||
if (line.indexOf(";") == -1) {
|
if (line.indexOf(";") == -1) {
|
||||||
line = line + slurpUntil(bin, ";", true);
|
line = slurpUntil(bin, line, ";", true);
|
||||||
// now rematch it all on one line
|
// now rematch it all on one line
|
||||||
m = JFIELD.matcher(line);
|
m = JFIELD.matcher(line);
|
||||||
if (!m.matches()) {
|
if (!m.matches()) {
|
||||||
System.err.println(
|
System.err.println("J: Pants, no longer match field: " + line);
|
||||||
"J: Pants, no longer match field: " + line);
|
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -499,10 +504,7 @@ public class ActionScriptSource
|
|||||||
mem = updateComment(protectedConstants, name, comment);
|
mem = updateComment(protectedConstants, name, comment);
|
||||||
}
|
}
|
||||||
if (mem == null) {
|
if (mem == null) {
|
||||||
System.err.println("J: Matched field for which we " +
|
continue; // it was omitted, so skip it
|
||||||
"have no bytecode version: " + name +
|
|
||||||
": " + line);
|
|
||||||
continue;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// extract and clean up any default value
|
// extract and clean up any default value
|
||||||
@@ -520,15 +522,13 @@ public class ActionScriptSource
|
|||||||
|
|
||||||
// see if we match a constructor declaration
|
// see if we match a constructor declaration
|
||||||
} else if ((m = JCONSTRUCTOR.matcher(line)).matches()) {
|
} else if ((m = JCONSTRUCTOR.matcher(line)).matches()) {
|
||||||
// if this line does not contain a close paren, keep
|
// if this line does not contain a close paren, keep reading until it does
|
||||||
// sucking up lines until it does
|
|
||||||
if (line.indexOf(")") == -1) {
|
if (line.indexOf(")") == -1) {
|
||||||
line = line + slurpUntil(bin, ")", true);
|
line = slurpUntil(bin, line, ")", true);
|
||||||
// now rematch it all on one line
|
// now rematch it all on one line
|
||||||
m = JCONSTRUCTOR.matcher(line);
|
m = JCONSTRUCTOR.matcher(line);
|
||||||
if (!m.matches()) {
|
if (!m.matches()) {
|
||||||
System.err.println(
|
System.err.println("J: Pants, no longer match ctor: " + line);
|
||||||
"J: Pants, no longer match ctor: " + line);
|
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -551,10 +551,9 @@ public class ActionScriptSource
|
|||||||
|
|
||||||
// see if we match a method declaration
|
// see if we match a method declaration
|
||||||
} else if ((m = JMETHOD.matcher(line)).matches()) {
|
} else if ((m = JMETHOD.matcher(line)).matches()) {
|
||||||
// if this line does not contain a close paren, keep
|
// if this line does not contain a close paren, keep reading until it does
|
||||||
// sucking up lines until it does
|
|
||||||
if (line.indexOf(")") == -1) {
|
if (line.indexOf(")") == -1) {
|
||||||
line = line + slurpUntil(bin, ")", true);
|
line = slurpUntil(bin, line, ")", true);
|
||||||
// now rematch it all on one line
|
// now rematch it all on one line
|
||||||
m = JMETHOD.matcher(line);
|
m = JMETHOD.matcher(line);
|
||||||
if (!m.matches()) {
|
if (!m.matches()) {
|
||||||
@@ -706,7 +705,7 @@ public class ActionScriptSource
|
|||||||
// if this line does not contain a semicolon, keep sucking
|
// if this line does not contain a semicolon, keep sucking
|
||||||
// up lines until it does
|
// up lines until it does
|
||||||
if (line.indexOf(";") == -1) {
|
if (line.indexOf(";") == -1) {
|
||||||
line = line + "\n" + slurpUntil(bin, ";", false);
|
line = slurpUntil(bin, line, ";", false);
|
||||||
}
|
}
|
||||||
|
|
||||||
String fieldName = m.group(1);
|
String fieldName = m.group(1);
|
||||||
@@ -721,7 +720,7 @@ public class ActionScriptSource
|
|||||||
// if this line does not contain a close paren, keep
|
// if this line does not contain a close paren, keep
|
||||||
// sucking up lines until it does
|
// sucking up lines until it does
|
||||||
if (line.indexOf(")") == -1) {
|
if (line.indexOf(")") == -1) {
|
||||||
line = line + "\n" + slurpUntil(bin, ")", false);
|
line = slurpUntil(bin, line, ")", false);
|
||||||
}
|
}
|
||||||
|
|
||||||
// look up the public constructor
|
// look up the public constructor
|
||||||
@@ -747,7 +746,7 @@ public class ActionScriptSource
|
|||||||
// if this line does not contain a close paren, keep
|
// if this line does not contain a close paren, keep
|
||||||
// sucking up lines until it does
|
// sucking up lines until it does
|
||||||
if (line.indexOf(")") == -1) {
|
if (line.indexOf(")") == -1) {
|
||||||
line = line + "\n" + slurpUntil(bin, ")", false);
|
line = slurpUntil(bin, line, ")", false);
|
||||||
}
|
}
|
||||||
|
|
||||||
ArrayList<Member> list = publicMethods;
|
ArrayList<Member> list = publicMethods;
|
||||||
@@ -968,24 +967,40 @@ public class ActionScriptSource
|
|||||||
return builder.toString();
|
return builder.toString();
|
||||||
}
|
}
|
||||||
|
|
||||||
protected String slurpUntil (BufferedReader reader, String token,
|
protected String slurpUntil (BufferedReader reader, String text, String token,
|
||||||
boolean stripNewlines)
|
boolean stripNewlines)
|
||||||
throws IOException
|
throws IOException
|
||||||
{
|
{
|
||||||
String text = "", line;
|
int braces = countChars(text, '{') - countChars(text, '}');
|
||||||
|
String line;
|
||||||
while ((line = reader.readLine()) != null) {
|
while ((line = reader.readLine()) != null) {
|
||||||
|
braces += countChars(line, '{');
|
||||||
|
braces -= countChars(line, '}');
|
||||||
|
if (braces < 0) {
|
||||||
|
System.err.println(
|
||||||
|
"Too many close braces? [text=" + text + ", line=" + line + "].");
|
||||||
|
}
|
||||||
line = line.replaceAll("\\s+$", "");
|
line = line.replaceAll("\\s+$", "");
|
||||||
text += line;
|
|
||||||
if (!stripNewlines) {
|
if (!stripNewlines) {
|
||||||
text += "\n";
|
text += "\n";
|
||||||
}
|
}
|
||||||
if (line.indexOf(token) != -1) {
|
text += line;
|
||||||
|
if (braces <= 0 && line.indexOf(token) != -1) {
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
return text;
|
return text;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
protected int countChars (String text, char target)
|
||||||
|
{
|
||||||
|
int idx = -1, count = 0;
|
||||||
|
while ((idx = text.indexOf(target, idx+1)) != -1) {
|
||||||
|
count++;
|
||||||
|
}
|
||||||
|
return count;
|
||||||
|
}
|
||||||
|
|
||||||
protected boolean writeBlank (boolean writtenAnything, PrintWriter writer)
|
protected boolean writeBlank (boolean writtenAnything, PrintWriter writer)
|
||||||
{
|
{
|
||||||
if (writtenAnything) {
|
if (writtenAnything) {
|
||||||
|
|||||||
Reference in New Issue
Block a user