Generate receivers and decoders for actionscript
git-svn-id: svn+ssh://src.earth.threerings.net/narya/trunk@6507 542714f4-19e9-0310-aa3c-eee0fc999fb1
This commit is contained in:
@@ -569,7 +569,6 @@ public abstract class PeerManager
|
||||
final DObjectAddress remote, final ResultListener<Integer> listener)
|
||||
{
|
||||
if (remote.nodeName.equals(_nodeName)) {
|
||||
System.out.println("Found locally!");
|
||||
_omgr.postRunnable(new Runnable() {
|
||||
public void run () {
|
||||
listener.requestCompleted(remote.oid);
|
||||
|
||||
@@ -29,12 +29,14 @@ import java.util.List;
|
||||
|
||||
import java.io.File;
|
||||
|
||||
import com.google.common.base.Preconditions;
|
||||
import com.google.common.collect.Iterators;
|
||||
|
||||
import com.samskivert.util.ComparableArrayList;
|
||||
import com.samskivert.util.StringUtil;
|
||||
|
||||
import com.threerings.presents.client.InvocationDecoder;
|
||||
import com.threerings.presents.client.InvocationReceiver;
|
||||
import com.threerings.presents.data.ClientObject;
|
||||
import com.threerings.presents.server.InvocationSender;
|
||||
|
||||
@@ -43,6 +45,14 @@ import com.threerings.presents.server.InvocationSender;
|
||||
*/
|
||||
public class GenReceiverTask extends InvocationTask
|
||||
{
|
||||
/**
|
||||
* Configures the path to our ActionScript source files.
|
||||
*/
|
||||
public void setAsroot (File asroot)
|
||||
{
|
||||
_asroot = asroot;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void processClass (File source, Class<?> receiver)
|
||||
throws Exception
|
||||
@@ -57,11 +67,8 @@ public class GenReceiverTask extends InvocationTask
|
||||
}
|
||||
|
||||
// verify that the receiver class name is as we expect it to be
|
||||
if (!rname.endsWith("Receiver")) {
|
||||
System.err.println("Cannot process '" + rname + "':");
|
||||
System.err.println("Receiver classes must be named SomethingReceiver.");
|
||||
return;
|
||||
}
|
||||
Preconditions.checkArgument(rname.endsWith("Receiver"), "Cannot process '%s'. " +
|
||||
"Receiver classes must be named SomethingReceiver.", rname);
|
||||
|
||||
ImportSet imports = new ImportSet();
|
||||
ComparableArrayList<ServiceMethod> methods = new ComparableArrayList<ServiceMethod>();
|
||||
@@ -142,8 +149,33 @@ public class GenReceiverTask extends InvocationTask
|
||||
"package", rpackage,
|
||||
"methods", methods,
|
||||
"imports", implist);
|
||||
if (_asroot == null) {
|
||||
return;
|
||||
}
|
||||
// generate an ActionScript decoder
|
||||
String sppath = rpackage.replace('.', File.separatorChar);
|
||||
String aspath = _asroot + File.separator + sppath + File.separator + name + "Decoder.as";
|
||||
writeTemplate(AS_DECODER_TMPL, aspath,
|
||||
"name", name,
|
||||
"receiver_code", rcode,
|
||||
"package", rpackage,
|
||||
"methods", methods,
|
||||
"imports", implist);
|
||||
|
||||
// ... and an ActionScript receiver
|
||||
aspath = _asroot + File.separator + sppath + File.separator + rname + ".as";
|
||||
implist.remove(InvocationDecoder.class.getName());
|
||||
checkedAdd(implist, InvocationReceiver.class.getName());
|
||||
writeTemplate(AS_RECEIVER_TMPL, aspath,
|
||||
"name", name,
|
||||
"package", rpackage,
|
||||
"methods", methods,
|
||||
"imports", implist);
|
||||
}
|
||||
|
||||
/** The path to our ActionScript source files. */
|
||||
protected File _asroot;
|
||||
|
||||
/** Specifies the path to the sender template. */
|
||||
protected static final String SENDER_TMPL =
|
||||
"com/threerings/presents/tools/sender.tmpl";
|
||||
@@ -151,4 +183,12 @@ public class GenReceiverTask extends InvocationTask
|
||||
/** Specifies the path to the decoder template. */
|
||||
protected static final String DECODER_TMPL =
|
||||
"com/threerings/presents/tools/decoder.tmpl";
|
||||
|
||||
/** Specifies the path to the decoder template. */
|
||||
protected static final String AS_DECODER_TMPL =
|
||||
"com/threerings/presents/tools/decoder_as.tmpl";
|
||||
|
||||
/** Specifies the path to the decoder template. */
|
||||
protected static final String AS_RECEIVER_TMPL =
|
||||
"com/threerings/presents/tools/receiver_as.tmpl";
|
||||
}
|
||||
|
||||
@@ -47,7 +47,7 @@ public class GenUtil extends com.samskivert.util.GenUtil
|
||||
|
||||
/** 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|enum)\\s+(\\S+)(\\W|$)");
|
||||
Pattern.compile("^\\s*public\\s+(?:abstract\\s+)?(@?interface|class|enum)\\s+([\\w$]+)");
|
||||
|
||||
/**
|
||||
* Returns the name of the supplied class as it would appear in ActionScript code using the
|
||||
|
||||
@@ -44,7 +44,7 @@ import com.samskivert.util.StringUtil;
|
||||
* <p>A few methods also use a "pattern" string parameter that is used to match a class name.
|
||||
* This is a dumbed down regular expression (to avoid many \.) where "*" means .* and no other
|
||||
* characters have special meaning. The pattern is also implicitly enclosed with ^$ so that the
|
||||
* pattern must match the class name in its entirity. Callers will mostly use this to specify a
|
||||
* pattern must match the class name in its entirety. Callers will mostly use this to specify a
|
||||
* prefix like "something*" or a suffix like "*something".
|
||||
*/
|
||||
public class ImportSet
|
||||
|
||||
Reference in New Issue
Block a user