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:
Michael Bayne
2007-04-18 01:28:10 +00:00
parent cefe7f0788
commit 17b9162881
3 changed files with 55 additions and 60 deletions
@@ -307,8 +307,8 @@ public class ActionScriptSource
// note our implemented interfaces
ArrayList<String> ifaces = new ArrayList<String>();
for (Class iclass : jclass.getInterfaces()) {
// we cannot use the FooCodes interface pattern in ActionScript so
// we just have to nix it
// we cannot use the FooCodes interface pattern in ActionScript so we just have to nix
// it
if (iclass.getName().endsWith("Codes")) {
continue;
}
@@ -339,9 +339,9 @@ public class ActionScriptSource
list.add(new Member(name, decl));
}
// ActionScript only supports one constructor so we find the one with
// the most arguments and we make a note whether or not we need a no
// argument constructor which we create using default arguments
// ActionScript only supports one constructor so we find the one with the most arguments
// and we make a note whether or not we need a no argument constructor which we create
// using default arguments
Constructor<?> mainctor = null;
boolean needsNoArg = false;
for (Constructor<?> ctor : jclass.getConstructors()) {
@@ -537,9 +537,12 @@ public class ActionScriptSource
String comment = accum.toString();
accum.setLength(0);
// set the comment on the specified method
updateComment(publicConstructors, name, comment);
updateComment(protectedConstructors, name, comment);
// the only annotation that makes sense on a constructor is "omit"
if (comment.indexOf("@ActionScript") == -1) {
// set the comment on the specified method
updateComment(publicConstructors, name, comment);
updateComment(protectedConstructors, name, comment);
}
// switch to METHODBODY to absorb the method
braceCount = (line.indexOf("{") == -1) ? 0 : 1;
@@ -565,8 +568,7 @@ public class ActionScriptSource
String comment = accum.toString();
accum.setLength(0);
// look through the comment for an @ActionScript
// annotation; oh the hackery
// look through the comment for an @ActionScript annotation; oh the hackery
if (comment.indexOf("@ActionScript") != -1) {
StringBuilder combuf = new StringBuilder();
for (String cline : StringUtil.split(comment, "\n")) {
@@ -601,12 +603,11 @@ public class ActionScriptSource
tline.startsWith("*")) {
accum.append(line).append("\n");
} else if (tline.equals("}")) {
} else if (line.startsWith("}")) {
mode = Mode.POSTCLASS;
} else {
System.err.println("J: Non-comment encountered " +
"between members: " + line);
System.err.println("J: Non-comment encountered between members: " + line);
}
}
break;
@@ -793,8 +794,7 @@ public class ActionScriptSource
mode = Mode.POSTCLASS;
} else {
System.err.println("AS: Non-comment encountered " +
"between members: " + line);
System.err.println("AS: Non-comment encountered between members: " + line);
}
}
break;
@@ -52,19 +52,19 @@ import com.samskivert.util.StringUtil;
import com.samskivert.velocity.VelocityUtil;
import com.threerings.io.Streamable;
import com.threerings.util.ActionScript;
import com.threerings.presents.data.InvocationMarshaller;
import com.threerings.presents.dobj.DObject;
/**
* Generates ActionScript versions of {@link Streamable} classes and provides
* routines used by the {@link GenDObjectTask} to create ActionScript versions
* of distributed objects.
* Generates ActionScript versions of {@link Streamable} classes and provides routines used by the
* {@link GenDObjectTask} to create ActionScript versions of distributed objects.
*/
public class GenActionScriptTask extends Task
{
/**
* Adds a nested &lt;fileset&gt; element which enumerates streamable source
* files.
* Adds a nested &lt;fileset&gt; element which enumerates streamable source files.
*/
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
* generated source files.
* Configures us with a header file that we'll prepend to all generated source files.
*/
public void setHeader (File header)
{
try {
_header = IOUtils.toString(new FileReader(header));
} catch (IOException ioe) {
System.err.println("Unabled to load header '" + header + ": " +
ioe.getMessage());
System.err.println("Unabled to load header '" + header + ": " + ioe.getMessage());
}
}
@@ -126,24 +124,19 @@ public class GenActionScriptTask extends Task
try {
name = GenUtil.readClassName(source);
} catch (Exception e) {
System.err.println(
"Failed to parse " + source + ": " + e.getMessage());
System.err.println("Failed to parse " + source + ": " + e.getMessage());
return;
}
try {
// in order for annotations to work, this task and all the classes
// it uses must be loaded from the same class loader as the classes
// on which we are going to introspect; this is non-ideal but
// unavoidable
// in order for annotations to work, this task and all the classes it uses must be
// loaded from the same class loader as the classes on which we are going to
// introspect; this is non-ideal but unavoidable
processClass(source, getClass().getClassLoader().loadClass(name));
} catch (ClassNotFoundException cnfe) {
System.err.println(
"Failed to load " + name + ".\n" +
"Missing class: " + cnfe.getMessage());
System.err.println(
"Be sure to set the 'classpathref' attribute to a classpath\n" +
"that contains your projects invocation service classes.");
System.err.println("Failed to load " + name + ".\nMissing class: " + cnfe.getMessage());
System.err.println("Be sure to set the 'classpathref' attribute to a classpath\n" +
"that contains your projects invocation service classes.");
} catch (Exception e) {
e.printStackTrace(System.err);
}
@@ -152,11 +145,11 @@ public class GenActionScriptTask extends Task
/**
* Processes a resolved Streamable class instance.
*/
protected void processClass (File source, Class sclass)
protected void processClass (File source, Class<?> sclass)
throws IOException
{
// make sure we implement Streamable but don't extend DObject or
// InvocationMarshaller and that we're a class not an interface
// make sure we implement Streamable but don't extend DObject or InvocationMarshaller and
// that we're a class not an interface
if (!Streamable.class.isAssignableFrom(sclass) ||
DObject.class.isAssignableFrom(sclass) ||
InvocationMarshaller.class.isAssignableFrom(sclass) ||
@@ -165,6 +158,13 @@ public class GenActionScriptTask extends Task
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
String path = sclass.getPackage().getName();
path = path.replace(".", File.separator);
@@ -42,19 +42,15 @@ import com.samskivert.util.StringUtil;
public class GenUtil extends com.samskivert.util.GenUtil
{
/** A regular expression for matching the package declaration. */
public static final Pattern PACKAGE_PATTERN =
Pattern.compile("^\\s*package\\s+(\\S+)\\W");
public static final Pattern PACKAGE_PATTERN = Pattern.compile("^\\s*package\\s+(\\S+)\\W");
/** A regular expression for matching the class or interface
* declaration. */
/** A regular expression for matching the class or interface declaration. */
public static final Pattern NAME_PATTERN =
Pattern.compile("^\\s*public\\s+(?:abstract\\s+)?" +
"(interface|class)\\s+(\\S+)(\\W|$)");
Pattern.compile("^\\s*public\\s+(?:abstract\\s+)?(interface|class|enum)\\s+(\\S+)(\\W|$)");
/**
* Returns the name of the supplied class as it would appear in
* ActionScript code using the class (no package prefix, arrays specified
* as Array<code>Array</code>).
* Returns the name of the supplied class as it would appear in ActionScript code using the
* class (no package prefix, arrays specified as Array<code>Array</code>).
*/
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
* an <code>Integer</code> object.
* "Boxes" the supplied argument, ie. turning an <code>int</code> into an <code>Integer</code>
* object.
*/
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>
* object into an <code>int</code>.
* "Unboxes" the supplied argument, ie. turning an <code>Integer</code> object into an
* <code>int</code>.
*/
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
* an <code>Integer</code> object.
* "Boxes" the supplied argument, ie. turning an <code>int</code> into an <code>Integer</code>
* object.
*/
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>
* object into an <code>int</code>.
* "Unboxes" the supplied argument, ie. turning an <code>Integer</code> object into an
* <code>int</code>.
*/
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
* needs such treatment.
* Potentially clones the supplied argument if it is the type that needs such treatment.
*/
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
* or interface name and returns a fully qualified class name.
* Reads in the supplied source file and locates the package and class or interface name and
* returns a fully qualified class name.
*/
public static String readClassName (File source)
throws IOException