Narya.abc work - get rid of unused imports in generated service targets:

* ServiceMethod import options:
  - Made argument type imports ignore first N args (0 for old behavior)
  - Made marshaller listener imports optional
* Added InvocationTask._verbose and several dumps of current imports to help 
  track down future superfluous imports
* Made the import of ServiceListener method arguments' types optional
* Wrapped up most of processService code into protected inner class 
  ServiceDescription and made configurable:
  - Optional import of the types of the first arguments of the service methods
  - Optinoal import of the types of listener method arguments
* Changed generate methods to take the service class and construct their own
  local ServiceDescription configured for their target
* Removed global import of service class and do it explicitly where required
  (via method addServiceImport)
* Made some imports conditional
  - InvocationResponseEvent for mashallers only if service has some listeners
  - InvocationException for providers only if service has some methods with 
    listener arguments
* Removed unused variables and imports


git-svn-id: svn+ssh://src.earth.threerings.net/narya/trunk@5036 542714f4-19e9-0310-aa3c-eee0fc999fb1
This commit is contained in:
Jamie Doornbos
2008-05-05 22:53:31 +00:00
parent c4af1d257c
commit bf501313f1
3 changed files with 177 additions and 103 deletions
@@ -30,7 +30,6 @@ import java.lang.reflect.Type;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.Iterator;
import java.util.List;
import org.apache.commons.io.FileUtils;
@@ -46,7 +45,6 @@ import org.apache.tools.ant.util.ClasspathUtils;
import org.apache.velocity.app.VelocityEngine;
import com.samskivert.util.ObjectUtil;
import com.samskivert.util.SortableArrayList;
import com.samskivert.util.StringUtil;
import com.samskivert.velocity.VelocityUtil;
@@ -94,7 +92,8 @@ public abstract class InvocationTask extends Task
}
}
/** Used to keep track of invocation service methods. */
/** Used to keep track of invocation service methods (or listener
* methods). */
public class ServiceMethod implements Comparable<ServiceMethod>
{
public Method method;
@@ -104,14 +103,16 @@ public abstract class InvocationTask extends Task
public ServiceMethod (Class<?> service, Method method,
HashMap<String,Boolean> imports,
HashMap<String,Boolean> rawimports)
HashMap<String,Boolean> rawimports,
int ignoreArguments,
boolean importMarshallerListeners)
{
this.method = method;
// we need to look through our arguments and note any needed
// imports in the supplied table
Class<?>[] args = method.getParameterTypes();
for (int ii = 0; ii < args.length; ii++) {
for (int ii = ignoreArguments; ii < args.length; ii++) {
Class<?> arg = args[ii];
while (arg.isArray()) {
arg = arg.getComponentType();
@@ -144,7 +145,8 @@ public abstract class InvocationTask extends Task
// InvocationService listeners, we need to import its
// marshaller as well
String sname = GenUtil.simpleName(arg, null);
if (_ilistener.isAssignableFrom(arg)) {
if (importMarshallerListeners &&
_ilistener.isAssignableFrom(arg)) {
String mname = arg.getName();
mname = StringUtil.replace(mname, "Service", "Marshaller");
mname = StringUtil.replace(mname, "Listener", "Marshaller");
@@ -265,7 +267,6 @@ public abstract class InvocationTask extends Task
{
StringBuilder buf = new StringBuilder();
Class<?>[] args = method.getParameterTypes();
Type[] ptypes = method.getGenericParameterTypes();
for (int ii = (listenerMode ? 0 : 1); ii < args.length; ii++) {
if (buf.length() > 0) {
buf.append(", ");
@@ -327,6 +328,14 @@ public abstract class InvocationTask extends Task
}
}
/**
* Configures to output extra information when generating code.
*/
public void setVerbose (boolean verbose)
{
_verbose = verbose;
}
/** Configures our classpath which we'll use to load service classes. */
public void setClasspathref (Reference pathref)
{
@@ -432,6 +441,9 @@ public abstract class InvocationTask extends Task
/** A header to put on all generated source files. */
protected String _header;
/** Show extra output if set. */
protected boolean _verbose;
/** Used to do our own classpath business. */
protected ClassLoader _cloader;