Widened, honor @ActionScript(omit=true) on classes and constructors, sort of
handle inner class declarations, emphasis on sort of. git-svn-id: svn+ssh://src.earth.threerings.net/narya/trunk@4666 542714f4-19e9-0310-aa3c-eee0fc999fb1
This commit is contained in:
@@ -307,8 +307,8 @@ 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 cannot use the FooCodes interface pattern in ActionScript so we just have to nix
|
||||||
// we just have to nix it
|
// it
|
||||||
if (iclass.getName().endsWith("Codes")) {
|
if (iclass.getName().endsWith("Codes")) {
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
@@ -339,9 +339,9 @@ public class ActionScriptSource
|
|||||||
list.add(new Member(name, decl));
|
list.add(new Member(name, decl));
|
||||||
}
|
}
|
||||||
|
|
||||||
// ActionScript only supports one constructor so we find the one with
|
// ActionScript only supports one constructor so we find the one with the most arguments
|
||||||
// the most arguments and we make a note whether or not we need a no
|
// and we make a note whether or not we need a no argument constructor which we create
|
||||||
// argument constructor which we create using default arguments
|
// using default arguments
|
||||||
Constructor<?> mainctor = null;
|
Constructor<?> mainctor = null;
|
||||||
boolean needsNoArg = false;
|
boolean needsNoArg = false;
|
||||||
for (Constructor<?> ctor : jclass.getConstructors()) {
|
for (Constructor<?> ctor : jclass.getConstructors()) {
|
||||||
@@ -537,9 +537,12 @@ public class ActionScriptSource
|
|||||||
String comment = accum.toString();
|
String comment = accum.toString();
|
||||||
accum.setLength(0);
|
accum.setLength(0);
|
||||||
|
|
||||||
// set the comment on the specified method
|
// the only annotation that makes sense on a constructor is "omit"
|
||||||
updateComment(publicConstructors, name, comment);
|
if (comment.indexOf("@ActionScript") == -1) {
|
||||||
updateComment(protectedConstructors, name, comment);
|
// set the comment on the specified method
|
||||||
|
updateComment(publicConstructors, name, comment);
|
||||||
|
updateComment(protectedConstructors, name, comment);
|
||||||
|
}
|
||||||
|
|
||||||
// switch to METHODBODY to absorb the method
|
// switch to METHODBODY to absorb the method
|
||||||
braceCount = (line.indexOf("{") == -1) ? 0 : 1;
|
braceCount = (line.indexOf("{") == -1) ? 0 : 1;
|
||||||
@@ -565,8 +568,7 @@ public class ActionScriptSource
|
|||||||
String comment = accum.toString();
|
String comment = accum.toString();
|
||||||
accum.setLength(0);
|
accum.setLength(0);
|
||||||
|
|
||||||
// look through the comment for an @ActionScript
|
// look through the comment for an @ActionScript annotation; oh the hackery
|
||||||
// annotation; oh the hackery
|
|
||||||
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")) {
|
||||||
@@ -601,12 +603,11 @@ public class ActionScriptSource
|
|||||||
tline.startsWith("*")) {
|
tline.startsWith("*")) {
|
||||||
accum.append(line).append("\n");
|
accum.append(line).append("\n");
|
||||||
|
|
||||||
} else if (tline.equals("}")) {
|
} else if (line.startsWith("}")) {
|
||||||
mode = Mode.POSTCLASS;
|
mode = Mode.POSTCLASS;
|
||||||
|
|
||||||
} else {
|
} else {
|
||||||
System.err.println("J: Non-comment encountered " +
|
System.err.println("J: Non-comment encountered between members: " + line);
|
||||||
"between members: " + line);
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
break;
|
break;
|
||||||
@@ -793,8 +794,7 @@ public class ActionScriptSource
|
|||||||
mode = Mode.POSTCLASS;
|
mode = Mode.POSTCLASS;
|
||||||
|
|
||||||
} else {
|
} else {
|
||||||
System.err.println("AS: Non-comment encountered " +
|
System.err.println("AS: Non-comment encountered between members: " + line);
|
||||||
"between members: " + line);
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
break;
|
break;
|
||||||
|
|||||||
@@ -52,19 +52,19 @@ import com.samskivert.util.StringUtil;
|
|||||||
import com.samskivert.velocity.VelocityUtil;
|
import com.samskivert.velocity.VelocityUtil;
|
||||||
|
|
||||||
import com.threerings.io.Streamable;
|
import com.threerings.io.Streamable;
|
||||||
|
import com.threerings.util.ActionScript;
|
||||||
|
|
||||||
import com.threerings.presents.data.InvocationMarshaller;
|
import com.threerings.presents.data.InvocationMarshaller;
|
||||||
import com.threerings.presents.dobj.DObject;
|
import com.threerings.presents.dobj.DObject;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Generates ActionScript versions of {@link Streamable} classes and provides
|
* Generates ActionScript versions of {@link Streamable} classes and provides routines used by the
|
||||||
* routines used by the {@link GenDObjectTask} to create ActionScript versions
|
* {@link GenDObjectTask} to create ActionScript versions of distributed objects.
|
||||||
* of distributed objects.
|
|
||||||
*/
|
*/
|
||||||
public class GenActionScriptTask extends Task
|
public class GenActionScriptTask extends Task
|
||||||
{
|
{
|
||||||
/**
|
/**
|
||||||
* Adds a nested <fileset> element which enumerates streamable source
|
* Adds a nested <fileset> element which enumerates streamable source files.
|
||||||
* files.
|
|
||||||
*/
|
*/
|
||||||
public void addFileset (FileSet set)
|
public void addFileset (FileSet set)
|
||||||
{
|
{
|
||||||
@@ -80,16 +80,14 @@ public class GenActionScriptTask extends Task
|
|||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Configures us with a header file that we'll prepend to all
|
* Configures us with a header file that we'll prepend to all generated source files.
|
||||||
* generated source files.
|
|
||||||
*/
|
*/
|
||||||
public void setHeader (File header)
|
public void setHeader (File header)
|
||||||
{
|
{
|
||||||
try {
|
try {
|
||||||
_header = IOUtils.toString(new FileReader(header));
|
_header = IOUtils.toString(new FileReader(header));
|
||||||
} catch (IOException ioe) {
|
} catch (IOException ioe) {
|
||||||
System.err.println("Unabled to load header '" + header + ": " +
|
System.err.println("Unabled to load header '" + header + ": " + ioe.getMessage());
|
||||||
ioe.getMessage());
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -126,24 +124,19 @@ public class GenActionScriptTask extends Task
|
|||||||
try {
|
try {
|
||||||
name = GenUtil.readClassName(source);
|
name = GenUtil.readClassName(source);
|
||||||
} catch (Exception e) {
|
} catch (Exception e) {
|
||||||
System.err.println(
|
System.err.println("Failed to parse " + source + ": " + e.getMessage());
|
||||||
"Failed to parse " + source + ": " + e.getMessage());
|
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
try {
|
try {
|
||||||
// in order for annotations to work, this task and all the classes
|
// in order for annotations to work, this task and all the classes it uses must be
|
||||||
// it uses must be loaded from the same class loader as the classes
|
// loaded from the same class loader as the classes on which we are going to
|
||||||
// on which we are going to introspect; this is non-ideal but
|
// introspect; this is non-ideal but unavoidable
|
||||||
// unavoidable
|
|
||||||
processClass(source, getClass().getClassLoader().loadClass(name));
|
processClass(source, getClass().getClassLoader().loadClass(name));
|
||||||
} catch (ClassNotFoundException cnfe) {
|
} catch (ClassNotFoundException cnfe) {
|
||||||
System.err.println(
|
System.err.println("Failed to load " + name + ".\nMissing class: " + cnfe.getMessage());
|
||||||
"Failed to load " + name + ".\n" +
|
System.err.println("Be sure to set the 'classpathref' attribute to a classpath\n" +
|
||||||
"Missing class: " + cnfe.getMessage());
|
"that contains your projects invocation service classes.");
|
||||||
System.err.println(
|
|
||||||
"Be sure to set the 'classpathref' attribute to a classpath\n" +
|
|
||||||
"that contains your projects invocation service classes.");
|
|
||||||
} catch (Exception e) {
|
} catch (Exception e) {
|
||||||
e.printStackTrace(System.err);
|
e.printStackTrace(System.err);
|
||||||
}
|
}
|
||||||
@@ -152,11 +145,11 @@ public class GenActionScriptTask extends Task
|
|||||||
/**
|
/**
|
||||||
* Processes a resolved Streamable class instance.
|
* Processes a resolved Streamable class instance.
|
||||||
*/
|
*/
|
||||||
protected void processClass (File source, Class sclass)
|
protected void processClass (File source, Class<?> sclass)
|
||||||
throws IOException
|
throws IOException
|
||||||
{
|
{
|
||||||
// make sure we implement Streamable but don't extend DObject or
|
// make sure we implement Streamable but don't extend DObject or InvocationMarshaller and
|
||||||
// InvocationMarshaller and that we're a class not an interface
|
// that we're a class not an interface
|
||||||
if (!Streamable.class.isAssignableFrom(sclass) ||
|
if (!Streamable.class.isAssignableFrom(sclass) ||
|
||||||
DObject.class.isAssignableFrom(sclass) ||
|
DObject.class.isAssignableFrom(sclass) ||
|
||||||
InvocationMarshaller.class.isAssignableFrom(sclass) ||
|
InvocationMarshaller.class.isAssignableFrom(sclass) ||
|
||||||
@@ -165,6 +158,13 @@ public class GenActionScriptTask extends Task
|
|||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// if we have an ActionScript(omit=true) annotation, skip this class
|
||||||
|
ActionScript asa = sclass.getAnnotation(ActionScript.class);
|
||||||
|
if (asa != null && asa.omit()) {
|
||||||
|
// System.err.println("Skipping " + sclass.getName() + "...");
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
// determine the path to the corresponding action script source file
|
// determine the path to the corresponding action script source file
|
||||||
String path = sclass.getPackage().getName();
|
String path = sclass.getPackage().getName();
|
||||||
path = path.replace(".", File.separator);
|
path = path.replace(".", File.separator);
|
||||||
|
|||||||
@@ -42,19 +42,15 @@ import com.samskivert.util.StringUtil;
|
|||||||
public class GenUtil extends com.samskivert.util.GenUtil
|
public class GenUtil extends com.samskivert.util.GenUtil
|
||||||
{
|
{
|
||||||
/** A regular expression for matching the package declaration. */
|
/** A regular expression for matching the package declaration. */
|
||||||
public static final Pattern PACKAGE_PATTERN =
|
public static final Pattern PACKAGE_PATTERN = Pattern.compile("^\\s*package\\s+(\\S+)\\W");
|
||||||
Pattern.compile("^\\s*package\\s+(\\S+)\\W");
|
|
||||||
|
|
||||||
/** A regular expression for matching the class or interface
|
/** A regular expression for matching the class or interface declaration. */
|
||||||
* declaration. */
|
|
||||||
public static final Pattern NAME_PATTERN =
|
public static final Pattern NAME_PATTERN =
|
||||||
Pattern.compile("^\\s*public\\s+(?:abstract\\s+)?" +
|
Pattern.compile("^\\s*public\\s+(?:abstract\\s+)?(interface|class|enum)\\s+(\\S+)(\\W|$)");
|
||||||
"(interface|class)\\s+(\\S+)(\\W|$)");
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Returns the name of the supplied class as it would appear in
|
* Returns the name of the supplied class as it would appear in ActionScript code using the
|
||||||
* ActionScript code using the class (no package prefix, arrays specified
|
* class (no package prefix, arrays specified as Array<code>Array</code>).
|
||||||
* as Array<code>Array</code>).
|
|
||||||
*/
|
*/
|
||||||
public static String simpleASName (Class<?> clazz)
|
public static String simpleASName (Class<?> clazz)
|
||||||
{
|
{
|
||||||
@@ -82,8 +78,8 @@ public class GenUtil extends com.samskivert.util.GenUtil
|
|||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* "Boxes" the supplied argument, ie. turning an <code>int</code> into
|
* "Boxes" the supplied argument, ie. turning an <code>int</code> into an <code>Integer</code>
|
||||||
* an <code>Integer</code> object.
|
* object.
|
||||||
*/
|
*/
|
||||||
public static String boxArgument (Class<?> clazz, String name)
|
public static String boxArgument (Class<?> clazz, String name)
|
||||||
{
|
{
|
||||||
@@ -109,8 +105,8 @@ public class GenUtil extends com.samskivert.util.GenUtil
|
|||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* "Unboxes" the supplied argument, ie. turning an <code>Integer</code>
|
* "Unboxes" the supplied argument, ie. turning an <code>Integer</code> object into an
|
||||||
* object into an <code>int</code>.
|
* <code>int</code>.
|
||||||
*/
|
*/
|
||||||
public static String unboxArgument (Class<?> clazz, Type type, String name)
|
public static String unboxArgument (Class<?> clazz, Type type, String name)
|
||||||
{
|
{
|
||||||
@@ -136,8 +132,8 @@ public class GenUtil extends com.samskivert.util.GenUtil
|
|||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* "Boxes" the supplied argument, ie. turning an <code>int</code> into
|
* "Boxes" the supplied argument, ie. turning an <code>int</code> into an <code>Integer</code>
|
||||||
* an <code>Integer</code> object.
|
* object.
|
||||||
*/
|
*/
|
||||||
public static String boxASArgument (Class<?> clazz, String name)
|
public static String boxASArgument (Class<?> clazz, String name)
|
||||||
{
|
{
|
||||||
@@ -163,8 +159,8 @@ public class GenUtil extends com.samskivert.util.GenUtil
|
|||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* "Unboxes" the supplied argument, ie. turning an <code>Integer</code>
|
* "Unboxes" the supplied argument, ie. turning an <code>Integer</code> object into an
|
||||||
* object into an <code>int</code>.
|
* <code>int</code>.
|
||||||
*/
|
*/
|
||||||
public static String unboxASArgument (Class<?> clazz, String name)
|
public static String unboxASArgument (Class<?> clazz, String name)
|
||||||
{
|
{
|
||||||
@@ -186,8 +182,7 @@ public class GenUtil extends com.samskivert.util.GenUtil
|
|||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Potentially clones the supplied argument if it is the type that
|
* Potentially clones the supplied argument if it is the type that needs such treatment.
|
||||||
* needs such treatment.
|
|
||||||
*/
|
*/
|
||||||
public static String cloneArgument (Class<?> dsclazz, Field f, String name)
|
public static String cloneArgument (Class<?> dsclazz, Field f, String name)
|
||||||
{
|
{
|
||||||
@@ -203,8 +198,8 @@ public class GenUtil extends com.samskivert.util.GenUtil
|
|||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Reads in the supplied source file and locates the package and class
|
* Reads in the supplied source file and locates the package and class or interface name and
|
||||||
* or interface name and returns a fully qualified class name.
|
* returns a fully qualified class name.
|
||||||
*/
|
*/
|
||||||
public static String readClassName (File source)
|
public static String readClassName (File source)
|
||||||
throws IOException
|
throws IOException
|
||||||
|
|||||||
Reference in New Issue
Block a user