Added support for switching Java fields to a different type in their
ActionScript counterparts. git-svn-id: svn+ssh://src.earth.threerings.net/narya/trunk@4801 542714f4-19e9-0310-aa3c-eee0fc999fb1
This commit is contained in:
@@ -24,6 +24,7 @@ package com.threerings.crowd.chat.data;
|
|||||||
import com.samskivert.util.StringUtil;
|
import com.samskivert.util.StringUtil;
|
||||||
|
|
||||||
import com.threerings.io.Streamable;
|
import com.threerings.io.Streamable;
|
||||||
|
import com.threerings.util.ActionScript;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* The abstract base class of all the client-side ChatMessage objects.
|
* The abstract base class of all the client-side ChatMessage objects.
|
||||||
@@ -42,6 +43,7 @@ public abstract class ChatMessage
|
|||||||
public transient String localtype;
|
public transient String localtype;
|
||||||
|
|
||||||
/** The client time that this message was created. */
|
/** The client time that this message was created. */
|
||||||
|
@ActionScript(type="int")
|
||||||
public transient long timestamp;
|
public transient long timestamp;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|||||||
@@ -40,8 +40,8 @@ import com.samskivert.util.StringUtil;
|
|||||||
import com.threerings.util.ActionScript;
|
import com.threerings.util.ActionScript;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Primitively parses an ActionScriptSource file, allows the addition and
|
* Primitively parses an ActionScriptSource file, allows the addition and replacement of class
|
||||||
* replacement of class members and handles writing out the file again.
|
* members and handles writing out the file again.
|
||||||
*/
|
*/
|
||||||
public class ActionScriptSource
|
public class ActionScriptSource
|
||||||
{
|
{
|
||||||
@@ -62,8 +62,7 @@ public class ActionScriptSource
|
|||||||
}
|
}
|
||||||
|
|
||||||
public void setInitialValue (String initValue) {
|
public void setInitialValue (String initValue) {
|
||||||
// if we're a typed array and we're being set to "new Something[0]"
|
// if we're a typed array and we're being set to "new Something[0]" then convert that
|
||||||
// then convert that
|
|
||||||
if (definition.indexOf("TypedArray") != -1) {
|
if (definition.indexOf("TypedArray") != -1) {
|
||||||
Matcher m = ARRAYINIT.matcher(initValue);
|
Matcher m = ARRAYINIT.matcher(initValue);
|
||||||
if (m.matches()) {
|
if (m.matches()) {
|
||||||
@@ -76,8 +75,7 @@ public class ActionScriptSource
|
|||||||
initValue = initValue.replaceAll("\\}", "]");
|
initValue = initValue.replaceAll("\\}", "]");
|
||||||
|
|
||||||
// stick the initial value before the semicolon
|
// stick the initial value before the semicolon
|
||||||
definition = definition.substring(0, definition.length()-1) +
|
definition = definition.substring(0, definition.length()-1) + " = " + initValue + ";";
|
||||||
" = " + initValue + ";";
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public void setComment (String comment) {
|
public void setComment (String comment) {
|
||||||
@@ -145,11 +143,10 @@ public class ActionScriptSource
|
|||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Creates and returns a declaration for a field equivalent to the supplied
|
* Creates and returns a declaration for a field equivalent to the supplied Java field in
|
||||||
* Java field in ActionScript.
|
* ActionScript.
|
||||||
*/
|
*/
|
||||||
public static String createActionScriptDeclaration (
|
public static String createActionScriptDeclaration (String name, Field field, ActionScript asa)
|
||||||
String name, Field field)
|
|
||||||
{
|
{
|
||||||
int mods = field.getModifiers();
|
int mods = field.getModifiers();
|
||||||
StringBuilder builder = new StringBuilder();
|
StringBuilder builder = new StringBuilder();
|
||||||
@@ -175,16 +172,18 @@ public class ActionScriptSource
|
|||||||
builder.append(name).append(" :");
|
builder.append(name).append(" :");
|
||||||
|
|
||||||
// now convert the type to an ActionScript type
|
// now convert the type to an ActionScript type
|
||||||
builder.append(toActionScriptType(field.getType(),
|
if (asa != null && !StringUtil.isBlank(asa.type())) {
|
||||||
!Modifier.isStatic(mods)));
|
builder.append(asa.type());
|
||||||
|
} else {
|
||||||
|
builder.append(toActionScriptType(field.getType(), !Modifier.isStatic(mods)));
|
||||||
|
}
|
||||||
|
|
||||||
builder.append(";");
|
builder.append(";");
|
||||||
|
|
||||||
return builder.toString();
|
return builder.toString();
|
||||||
}
|
}
|
||||||
|
|
||||||
public static String createActionScriptDeclaration (
|
public static String createActionScriptDeclaration (Constructor ctor, boolean needsNoArg)
|
||||||
Constructor ctor, boolean needsNoArg)
|
|
||||||
{
|
{
|
||||||
int mods = ctor.getModifiers();
|
int mods = ctor.getModifiers();
|
||||||
StringBuilder builder = new StringBuilder();
|
StringBuilder builder = new StringBuilder();
|
||||||
@@ -221,8 +220,7 @@ public class ActionScriptSource
|
|||||||
return builder.toString();
|
return builder.toString();
|
||||||
}
|
}
|
||||||
|
|
||||||
public static String createActionScriptDeclaration (
|
public static String createActionScriptDeclaration (String name, Method method)
|
||||||
String name, Method method)
|
|
||||||
{
|
{
|
||||||
int mods = method.getModifiers();
|
int mods = method.getModifiers();
|
||||||
StringBuilder builder = new StringBuilder();
|
StringBuilder builder = new StringBuilder();
|
||||||
@@ -324,8 +322,7 @@ public class ActionScriptSource
|
|||||||
int mods = field.getModifiers();
|
int mods = field.getModifiers();
|
||||||
ArrayList<Member> list;
|
ArrayList<Member> list;
|
||||||
if (Modifier.isStatic(mods)) {
|
if (Modifier.isStatic(mods)) {
|
||||||
list = Modifier.isPublic(mods) ?
|
list = Modifier.isPublic(mods) ? publicConstants : protectedConstants;
|
||||||
publicConstants : protectedConstants;
|
|
||||||
} else {
|
} else {
|
||||||
list = Modifier.isPublic(mods) ? publicFields : protectedFields;
|
list = Modifier.isPublic(mods) ? publicFields : protectedFields;
|
||||||
}
|
}
|
||||||
@@ -339,7 +336,7 @@ public class ActionScriptSource
|
|||||||
name = asa.name();
|
name = asa.name();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
String decl = createActionScriptDeclaration(name, field);
|
String decl = createActionScriptDeclaration(name, field, asa);
|
||||||
list.add(new Member(name, decl));
|
list.add(new Member(name, decl));
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -363,11 +360,9 @@ public class ActionScriptSource
|
|||||||
if (mainctor != null) {
|
if (mainctor != null) {
|
||||||
int mods = mainctor.getModifiers();
|
int mods = mainctor.getModifiers();
|
||||||
ArrayList<Member> list;
|
ArrayList<Member> list;
|
||||||
list = Modifier.isPublic(mods) ?
|
list = Modifier.isPublic(mods) ? publicConstructors : protectedConstructors;
|
||||||
publicConstructors : protectedConstructors;
|
Member mem = new Member(toSimpleName(mainctor.getName()),
|
||||||
Member mem = new Member(
|
createActionScriptDeclaration(mainctor, needsNoArg));
|
||||||
toSimpleName(mainctor.getName()),
|
|
||||||
createActionScriptDeclaration(mainctor, needsNoArg));
|
|
||||||
mem.body = " {\n TODO: IMPLEMENT ME\n }\n";
|
mem.body = " {\n TODO: IMPLEMENT ME\n }\n";
|
||||||
list.add(mem);
|
list.add(mem);
|
||||||
}
|
}
|
||||||
@@ -494,6 +489,20 @@ public class ActionScriptSource
|
|||||||
String comment = accum.toString();
|
String comment = accum.toString();
|
||||||
accum.setLength(0);
|
accum.setLength(0);
|
||||||
|
|
||||||
|
// strip out any @ActionScript annotation
|
||||||
|
if (comment.indexOf("@ActionScript") != -1) {
|
||||||
|
StringBuilder combuf = new StringBuilder();
|
||||||
|
for (String cline : StringUtil.split(comment, "\n")) {
|
||||||
|
if (cline.indexOf("@ActionScript") == -1) {
|
||||||
|
if (combuf.length() > 0) {
|
||||||
|
combuf.append("\n");
|
||||||
|
}
|
||||||
|
combuf.append(cline);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
comment = combuf.toString();
|
||||||
|
}
|
||||||
|
|
||||||
// set the comment on the specified field
|
// set the comment on the specified field
|
||||||
Member mem = updateComment(publicConstants, name, comment);
|
Member mem = updateComment(publicConstants, name, comment);
|
||||||
if (mem == null) {
|
if (mem == null) {
|
||||||
@@ -573,7 +582,7 @@ public class ActionScriptSource
|
|||||||
if (comment.indexOf("@ActionScript") != -1) {
|
if (comment.indexOf("@ActionScript") != -1) {
|
||||||
StringBuilder combuf = new StringBuilder();
|
StringBuilder combuf = new StringBuilder();
|
||||||
for (String cline : StringUtil.split(comment, "\n")) {
|
for (String cline : StringUtil.split(comment, "\n")) {
|
||||||
if ((m = JANNOTATION.matcher(cline)).matches()) {
|
if ((m = METHOD_ANNOTATION.matcher(cline)).matches()) {
|
||||||
name = m.group(1);
|
name = m.group(1);
|
||||||
} else {
|
} else {
|
||||||
if (combuf.length() > 0) {
|
if (combuf.length() > 0) {
|
||||||
@@ -966,8 +975,7 @@ public class ActionScriptSource
|
|||||||
return builder.toString();
|
return builder.toString();
|
||||||
}
|
}
|
||||||
|
|
||||||
protected String slurpUntil (BufferedReader reader, String text, String token,
|
protected String slurpUntil (BufferedReader reader, String text, String token, boolean stripNL)
|
||||||
boolean stripNewlines)
|
|
||||||
throws IOException
|
throws IOException
|
||||||
{
|
{
|
||||||
int braces = countChars(text, '{') - countChars(text, '}');
|
int braces = countChars(text, '{') - countChars(text, '}');
|
||||||
@@ -980,7 +988,7 @@ public class ActionScriptSource
|
|||||||
"Too many close braces? [text=" + text + ", line=" + line + "].");
|
"Too many close braces? [text=" + text + ", line=" + line + "].");
|
||||||
}
|
}
|
||||||
line = line.replaceAll("\\s+$", "");
|
line = line.replaceAll("\\s+$", "");
|
||||||
if (!stripNewlines) {
|
if (!stripNL) {
|
||||||
text += "\n";
|
text += "\n";
|
||||||
}
|
}
|
||||||
text += line;
|
text += line;
|
||||||
@@ -1025,7 +1033,7 @@ public class ActionScriptSource
|
|||||||
protected static Pattern JMETHOD = Pattern.compile(
|
protected static Pattern JMETHOD = Pattern.compile(
|
||||||
"\\s+(?:public|protected|private).* ([a-zA-Z]\\w*) \\(.*");
|
"\\s+(?:public|protected|private).* ([a-zA-Z]\\w*) \\(.*");
|
||||||
|
|
||||||
protected static Pattern JANNOTATION = Pattern.compile(
|
protected static Pattern METHOD_ANNOTATION = Pattern.compile(
|
||||||
".*@ActionScript\\(name=\"(\\w+)\"\\).*");
|
".*@ActionScript\\(name=\"(\\w+)\"\\).*");
|
||||||
|
|
||||||
protected static Pattern ASFIELD = Pattern.compile(
|
protected static Pattern ASFIELD = Pattern.compile(
|
||||||
|
|||||||
@@ -35,14 +35,20 @@ import java.lang.annotation.ElementType;
|
|||||||
public @interface ActionScript
|
public @interface ActionScript
|
||||||
{
|
{
|
||||||
/**
|
/**
|
||||||
* Indicates whether this field, method or class should be omitted from the
|
* Indicates whether this field, method or class should be omitted from the ActionScript
|
||||||
* ActionScript translation.
|
* translation.
|
||||||
*/
|
*/
|
||||||
boolean omit () default false;
|
boolean omit () default false;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Indicates a custom name to be used for the ActionScript version of this
|
* Indicates a custom name to be used for the ActionScript version of this field, method or
|
||||||
* field, method or class.
|
* class.
|
||||||
*/
|
*/
|
||||||
String name () default "";
|
String name () default "";
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Indicates a custom type to be used for the ActionScript version of this field. Ignored if
|
||||||
|
* used on a method or class.
|
||||||
|
*/
|
||||||
|
String type () default "";
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user