OMG, it like handles the annoying ActionScript not-so-inner classes.

git-svn-id: svn+ssh://src.earth.threerings.net/narya/trunk@4399 542714f4-19e9-0310-aa3c-eee0fc999fb1
This commit is contained in:
Michael Bayne
2006-10-04 18:53:36 +00:00
parent 20c0f0ff3d
commit 9da0e7a4f3
3 changed files with 58 additions and 28 deletions
@@ -84,7 +84,7 @@ public class GenReceiverTask extends InvocationTask
!Modifier.isAbstract(m.getModifiers())) {
continue;
}
methods.add(new ServiceMethod(receiver, m, imports));
methods.add(new ServiceMethod(receiver, m, imports, null));
}
methods.sort();
@@ -45,7 +45,8 @@ public class GenServiceTask extends InvocationTask
new ComparableArrayList<ServiceMethod>();
public ServiceListener (Class service, Class listener,
HashMap<String,Boolean> imports)
HashMap<String,Boolean> imports,
HashMap<String,Boolean> rawimports)
{
this.listener = listener;
Method[] methdecls = listener.getDeclaredMethods();
@@ -56,7 +57,7 @@ public class GenServiceTask extends InvocationTask
!Modifier.isAbstract(m.getModifiers())) {
continue;
}
methods.add(new ServiceMethod(service, m, imports));
methods.add(new ServiceMethod(service, m, imports, rawimports));
}
methods.sort();
}
@@ -126,6 +127,7 @@ public class GenServiceTask extends InvocationTask
}
HashMap<String,Boolean> imports = new HashMap<String,Boolean>();
HashMap<String,Boolean> rawimports = new HashMap<String,Boolean>();
ComparableArrayList<ServiceMethod> methods =
new ComparableArrayList<ServiceMethod>();
ComparableArrayList<ServiceListener> listeners =
@@ -133,6 +135,7 @@ public class GenServiceTask extends InvocationTask
// we need to import the service itself
imports.put(importify(service.getName()), Boolean.TRUE);
rawimports.put(service.getName(), Boolean.TRUE);
// look through and locate our service methods, also locating any
// custom InvocationListener derivations along the way
@@ -151,16 +154,16 @@ public class GenServiceTask extends InvocationTask
GenUtil.simpleName(
args[aa], null).startsWith(sname + ".")) {
checkedAdd(listeners, new ServiceListener(
service, args[aa], imports));
service, args[aa], imports, rawimports));
}
}
methods.add(new ServiceMethod(service, m, imports));
methods.add(new ServiceMethod(service, m, imports, rawimports));
}
listeners.sort();
methods.sort();
generateMarshaller(source, sname, spackage, methods, listeners,
imports.keySet());
imports.keySet(), rawimports.keySet());
generateDispatcher(source, sname, spackage, methods,
imports.keySet());
if (!_providerless.contains(sname)) {
@@ -171,7 +174,8 @@ public class GenServiceTask extends InvocationTask
protected void generateMarshaller (
File source, String sname, String spackage, List methods,
List<ServiceListener> listeners, Collection<String> imports)
List<ServiceListener> listeners, Collection<String> imports,
Collection<String> rawimports)
{
String name = StringUtil.replace(sname, "Service", "");
String mname = StringUtil.replace(sname, "Service", "Marshaller");
@@ -213,15 +217,22 @@ public class GenServiceTask extends InvocationTask
return;
}
// add imports for our inner listener interfaces; because they are not
// real inner interfaces, we have to import them in addition to the
// services that (in Java) contained them
for (ServiceListener listener : listeners) {
checkedAdd(implist, listener.listener.getName().replace("$", "_"));
// convert the raw imports into ActionScript versions (inner-classes
// become Foo_Bar)
Collection<String> asimports = new ArrayList<String>();
for (String impy : rawimports) {
asimports.add(impy.replace("$", "_"));
}
Class isil = InvocationService.InvocationListener.class;
checkedAdd(implist, isil.getName().replace("$", "_"));
// recreate our service imports using those
implist = new ComparableArrayList<String>();
implist.addAll(asimports);
checkedAdd(implist, Client.class.getName());
checkedAdd(implist, InvocationMarshaller.class.getName());
Class imlm = InvocationMarshaller.ListenerMarshaller.class;
checkedAdd(implist, imlm.getName().replace("$", "_"));
implist.sort();
ctx.put("imports", implist);
// now generate ActionScript versions of our marshaller
try {
@@ -238,7 +249,6 @@ public class GenServiceTask extends InvocationTask
// now generate ActionScript versions of our listener marshallers
// because those have to be in separate files
Class imlm = InvocationMarshaller.ListenerMarshaller.class;
for (ServiceListener listener : listeners) {
// recreate our imports with just what we need here
implist = new ComparableArrayList<String>();
@@ -267,9 +277,10 @@ public class GenServiceTask extends InvocationTask
// then make some changes to the context and generate ActionScript
// versions of the service interface itself
implist = new ComparableArrayList<String>();
implist.addAll(imports);
implist.addAll(asimports);
checkedAdd(implist, Client.class.getName());
checkedAdd(implist, InvocationService.class.getName());
Class isil = InvocationService.InvocationListener.class;
checkedAdd(implist, isil.getName().replace("$", "_"));
implist.sort();
ctx.put("imports", implist);
@@ -292,7 +303,7 @@ public class GenServiceTask extends InvocationTask
for (ServiceListener listener : listeners) {
// recreate our imports with just what we need here
implist = new ComparableArrayList<String>();
implist.addAll(imports);
implist.addAll(asimports);
checkedAdd(implist, isil.getName().replace("$", "_"));
String lname = listener.listener.getName();
checkedAdd(implist, lname.replace("$", "_"));
@@ -60,13 +60,19 @@ public abstract class InvocationTask extends Task
if (name.equals("InvocationService.InvocationListener")) {
return "ListenerMarshaller";
}
name = StringUtil.replace(name, "Service", "Marshaller");
return StringUtil.replace(name, "Listener", "Marshaller");
name = name.replace("Service", "Marshaller");
return name.replace("Listener", "Marshaller");
}
public String getActionScriptMarshaller ()
{
return getMarshaller().replace(".", "_");
// handle ye olde special case
String name = listener.getName();
if (name.endsWith("InvocationService$InvocationListener")) {
return "InvocationMarshaller_ListenerMarshaller";
} else {
return getMarshaller().replace(".", "_");
}
}
}
@@ -79,7 +85,8 @@ public abstract class InvocationTask extends Task
new ArrayList<ListenerArgument>();
public ServiceMethod (Class<?> service, Method method,
HashMap<String,Boolean> imports)
HashMap<String,Boolean> imports,
HashMap<String,Boolean> rawimports)
{
this.method = method;
@@ -98,15 +105,22 @@ public abstract class InvocationTask extends Task
listenerArgs.add(new ListenerArgument(ii, arg));
}
// if it's not primitive, global or in our package, we
// should add an import statement for it
// if it's primitive or global we don't need an import
if (arg.isPrimitive() ||
arg.getName().startsWith("java.lang") ||
ObjectUtil.equals(
arg.getPackage(), service.getPackage())) {
arg.getName().startsWith("java.lang")) {
continue;
}
imports.put(importify(arg.getName()), Boolean.TRUE);
// if it's in our same package, we don't need a normal import
// but we may need a raw import
boolean samepkg =
ObjectUtil.equals(arg.getPackage(), service.getPackage());
if (!samepkg) {
imports.put(importify(arg.getName()), Boolean.TRUE);
}
if (rawimports != null) {
rawimports.put(arg.getName(), Boolean.TRUE);
}
// if it's a listener and not one of the special
// InvocationService listeners, we need to import its
@@ -118,7 +132,12 @@ public abstract class InvocationTask extends Task
mname = StringUtil.replace(mname, "Service", "Marshaller");
mname = StringUtil.replace(mname, "Listener", "Marshaller");
mname = StringUtil.replace(mname, ".client.", ".data.");
imports.put(importify(mname), Boolean.TRUE);
if (!samepkg) {
imports.put(importify(mname), Boolean.TRUE);
}
if (rawimports != null) {
rawimports.put(mname, Boolean.TRUE);
}
}
}
}