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:
@@ -84,7 +84,7 @@ public class GenReceiverTask extends InvocationTask
|
|||||||
!Modifier.isAbstract(m.getModifiers())) {
|
!Modifier.isAbstract(m.getModifiers())) {
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
methods.add(new ServiceMethod(receiver, m, imports));
|
methods.add(new ServiceMethod(receiver, m, imports, null));
|
||||||
}
|
}
|
||||||
methods.sort();
|
methods.sort();
|
||||||
|
|
||||||
|
|||||||
@@ -45,7 +45,8 @@ public class GenServiceTask extends InvocationTask
|
|||||||
new ComparableArrayList<ServiceMethod>();
|
new ComparableArrayList<ServiceMethod>();
|
||||||
|
|
||||||
public ServiceListener (Class service, Class listener,
|
public ServiceListener (Class service, Class listener,
|
||||||
HashMap<String,Boolean> imports)
|
HashMap<String,Boolean> imports,
|
||||||
|
HashMap<String,Boolean> rawimports)
|
||||||
{
|
{
|
||||||
this.listener = listener;
|
this.listener = listener;
|
||||||
Method[] methdecls = listener.getDeclaredMethods();
|
Method[] methdecls = listener.getDeclaredMethods();
|
||||||
@@ -56,7 +57,7 @@ public class GenServiceTask extends InvocationTask
|
|||||||
!Modifier.isAbstract(m.getModifiers())) {
|
!Modifier.isAbstract(m.getModifiers())) {
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
methods.add(new ServiceMethod(service, m, imports));
|
methods.add(new ServiceMethod(service, m, imports, rawimports));
|
||||||
}
|
}
|
||||||
methods.sort();
|
methods.sort();
|
||||||
}
|
}
|
||||||
@@ -126,6 +127,7 @@ public class GenServiceTask extends InvocationTask
|
|||||||
}
|
}
|
||||||
|
|
||||||
HashMap<String,Boolean> imports = new HashMap<String,Boolean>();
|
HashMap<String,Boolean> imports = new HashMap<String,Boolean>();
|
||||||
|
HashMap<String,Boolean> rawimports = new HashMap<String,Boolean>();
|
||||||
ComparableArrayList<ServiceMethod> methods =
|
ComparableArrayList<ServiceMethod> methods =
|
||||||
new ComparableArrayList<ServiceMethod>();
|
new ComparableArrayList<ServiceMethod>();
|
||||||
ComparableArrayList<ServiceListener> listeners =
|
ComparableArrayList<ServiceListener> listeners =
|
||||||
@@ -133,6 +135,7 @@ public class GenServiceTask extends InvocationTask
|
|||||||
|
|
||||||
// we need to import the service itself
|
// we need to import the service itself
|
||||||
imports.put(importify(service.getName()), Boolean.TRUE);
|
imports.put(importify(service.getName()), Boolean.TRUE);
|
||||||
|
rawimports.put(service.getName(), Boolean.TRUE);
|
||||||
|
|
||||||
// look through and locate our service methods, also locating any
|
// look through and locate our service methods, also locating any
|
||||||
// custom InvocationListener derivations along the way
|
// custom InvocationListener derivations along the way
|
||||||
@@ -151,16 +154,16 @@ public class GenServiceTask extends InvocationTask
|
|||||||
GenUtil.simpleName(
|
GenUtil.simpleName(
|
||||||
args[aa], null).startsWith(sname + ".")) {
|
args[aa], null).startsWith(sname + ".")) {
|
||||||
checkedAdd(listeners, new ServiceListener(
|
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();
|
listeners.sort();
|
||||||
methods.sort();
|
methods.sort();
|
||||||
|
|
||||||
generateMarshaller(source, sname, spackage, methods, listeners,
|
generateMarshaller(source, sname, spackage, methods, listeners,
|
||||||
imports.keySet());
|
imports.keySet(), rawimports.keySet());
|
||||||
generateDispatcher(source, sname, spackage, methods,
|
generateDispatcher(source, sname, spackage, methods,
|
||||||
imports.keySet());
|
imports.keySet());
|
||||||
if (!_providerless.contains(sname)) {
|
if (!_providerless.contains(sname)) {
|
||||||
@@ -171,7 +174,8 @@ public class GenServiceTask extends InvocationTask
|
|||||||
|
|
||||||
protected void generateMarshaller (
|
protected void generateMarshaller (
|
||||||
File source, String sname, String spackage, List methods,
|
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 name = StringUtil.replace(sname, "Service", "");
|
||||||
String mname = StringUtil.replace(sname, "Service", "Marshaller");
|
String mname = StringUtil.replace(sname, "Service", "Marshaller");
|
||||||
@@ -213,15 +217,22 @@ public class GenServiceTask extends InvocationTask
|
|||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
// add imports for our inner listener interfaces; because they are not
|
// convert the raw imports into ActionScript versions (inner-classes
|
||||||
// real inner interfaces, we have to import them in addition to the
|
// become Foo_Bar)
|
||||||
// services that (in Java) contained them
|
Collection<String> asimports = new ArrayList<String>();
|
||||||
for (ServiceListener listener : listeners) {
|
for (String impy : rawimports) {
|
||||||
checkedAdd(implist, listener.listener.getName().replace("$", "_"));
|
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();
|
implist.sort();
|
||||||
|
ctx.put("imports", implist);
|
||||||
|
|
||||||
// now generate ActionScript versions of our marshaller
|
// now generate ActionScript versions of our marshaller
|
||||||
try {
|
try {
|
||||||
@@ -238,7 +249,6 @@ public class GenServiceTask extends InvocationTask
|
|||||||
|
|
||||||
// now generate ActionScript versions of our listener marshallers
|
// now generate ActionScript versions of our listener marshallers
|
||||||
// because those have to be in separate files
|
// because those have to be in separate files
|
||||||
Class imlm = InvocationMarshaller.ListenerMarshaller.class;
|
|
||||||
for (ServiceListener listener : listeners) {
|
for (ServiceListener listener : listeners) {
|
||||||
// recreate our imports with just what we need here
|
// recreate our imports with just what we need here
|
||||||
implist = new ComparableArrayList<String>();
|
implist = new ComparableArrayList<String>();
|
||||||
@@ -267,9 +277,10 @@ public class GenServiceTask extends InvocationTask
|
|||||||
// then make some changes to the context and generate ActionScript
|
// then make some changes to the context and generate ActionScript
|
||||||
// versions of the service interface itself
|
// versions of the service interface itself
|
||||||
implist = new ComparableArrayList<String>();
|
implist = new ComparableArrayList<String>();
|
||||||
implist.addAll(imports);
|
implist.addAll(asimports);
|
||||||
checkedAdd(implist, Client.class.getName());
|
checkedAdd(implist, Client.class.getName());
|
||||||
checkedAdd(implist, InvocationService.class.getName());
|
checkedAdd(implist, InvocationService.class.getName());
|
||||||
|
Class isil = InvocationService.InvocationListener.class;
|
||||||
checkedAdd(implist, isil.getName().replace("$", "_"));
|
checkedAdd(implist, isil.getName().replace("$", "_"));
|
||||||
implist.sort();
|
implist.sort();
|
||||||
ctx.put("imports", implist);
|
ctx.put("imports", implist);
|
||||||
@@ -292,7 +303,7 @@ public class GenServiceTask extends InvocationTask
|
|||||||
for (ServiceListener listener : listeners) {
|
for (ServiceListener listener : listeners) {
|
||||||
// recreate our imports with just what we need here
|
// recreate our imports with just what we need here
|
||||||
implist = new ComparableArrayList<String>();
|
implist = new ComparableArrayList<String>();
|
||||||
implist.addAll(imports);
|
implist.addAll(asimports);
|
||||||
checkedAdd(implist, isil.getName().replace("$", "_"));
|
checkedAdd(implist, isil.getName().replace("$", "_"));
|
||||||
String lname = listener.listener.getName();
|
String lname = listener.listener.getName();
|
||||||
checkedAdd(implist, lname.replace("$", "_"));
|
checkedAdd(implist, lname.replace("$", "_"));
|
||||||
|
|||||||
@@ -60,13 +60,19 @@ public abstract class InvocationTask extends Task
|
|||||||
if (name.equals("InvocationService.InvocationListener")) {
|
if (name.equals("InvocationService.InvocationListener")) {
|
||||||
return "ListenerMarshaller";
|
return "ListenerMarshaller";
|
||||||
}
|
}
|
||||||
name = StringUtil.replace(name, "Service", "Marshaller");
|
name = name.replace("Service", "Marshaller");
|
||||||
return StringUtil.replace(name, "Listener", "Marshaller");
|
return name.replace("Listener", "Marshaller");
|
||||||
}
|
}
|
||||||
|
|
||||||
public String getActionScriptMarshaller ()
|
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>();
|
new ArrayList<ListenerArgument>();
|
||||||
|
|
||||||
public ServiceMethod (Class<?> service, Method method,
|
public ServiceMethod (Class<?> service, Method method,
|
||||||
HashMap<String,Boolean> imports)
|
HashMap<String,Boolean> imports,
|
||||||
|
HashMap<String,Boolean> rawimports)
|
||||||
{
|
{
|
||||||
this.method = method;
|
this.method = method;
|
||||||
|
|
||||||
@@ -98,15 +105,22 @@ public abstract class InvocationTask extends Task
|
|||||||
listenerArgs.add(new ListenerArgument(ii, arg));
|
listenerArgs.add(new ListenerArgument(ii, arg));
|
||||||
}
|
}
|
||||||
|
|
||||||
// if it's not primitive, global or in our package, we
|
// if it's primitive or global we don't need an import
|
||||||
// should add an import statement for it
|
|
||||||
if (arg.isPrimitive() ||
|
if (arg.isPrimitive() ||
|
||||||
arg.getName().startsWith("java.lang") ||
|
arg.getName().startsWith("java.lang")) {
|
||||||
ObjectUtil.equals(
|
|
||||||
arg.getPackage(), service.getPackage())) {
|
|
||||||
continue;
|
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
|
// if it's a listener and not one of the special
|
||||||
// InvocationService listeners, we need to import its
|
// 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, "Service", "Marshaller");
|
||||||
mname = StringUtil.replace(mname, "Listener", "Marshaller");
|
mname = StringUtil.replace(mname, "Listener", "Marshaller");
|
||||||
mname = StringUtil.replace(mname, ".client.", ".data.");
|
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);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user