summaryrefslogtreecommitdiff
path: root/tools/gnu/classpath/tools/rmic/ClassRmicCompiler.java
diff options
context:
space:
mode:
Diffstat (limited to 'tools/gnu/classpath/tools/rmic/ClassRmicCompiler.java')
-rw-r--r--tools/gnu/classpath/tools/rmic/ClassRmicCompiler.java126
1 files changed, 58 insertions, 68 deletions
diff --git a/tools/gnu/classpath/tools/rmic/ClassRmicCompiler.java b/tools/gnu/classpath/tools/rmic/ClassRmicCompiler.java
index 9ac103c75..790407bae 100644
--- a/tools/gnu/classpath/tools/rmic/ClassRmicCompiler.java
+++ b/tools/gnu/classpath/tools/rmic/ClassRmicCompiler.java
@@ -1,5 +1,5 @@
/* ClassRmicCompiler.java --
- Copyright (c) 1996, 1997, 1998, 1999, 2001, 2002, 2003, 2004, 2005
+ Copyright (c) 1996, 1997, 1998, 1999, 2001, 2002, 2003, 2004, 2005, 2012
Free Software Foundation, Inc.
This file is part of GNU Classpath.
@@ -76,26 +76,23 @@ public class ClassRmicCompiler
{
private String[] args;
private int next;
- private List errors = new ArrayList();
- private boolean keep = false;
+ private List<Exception> errors = new ArrayList<Exception>();
private boolean need11Stubs = true;
private boolean need12Stubs = true;
- private boolean compile = true;
private boolean verbose;
private boolean noWrite;
private String destination;
- private String classpath;
private ClassLoader loader;
private int errorCount = 0;
- private Class clazz;
+ private Class<?> clazz;
private String classname;
private String classInternalName;
private String fullclassname;
private MethodRef[] remotemethods;
private String stubname;
private String skelname;
- private List mRemoteInterfaces;
+ private List<Class<?>> mRemoteInterfaces;
/**
* @return true if run was successful
@@ -126,9 +123,9 @@ public class ClassRmicCompiler
}
if (errors.size() > 0)
{
- for (Iterator it = errors.iterator(); it.hasNext(); )
+ for (Iterator<Exception> it = errors.iterator(); it.hasNext(); )
{
- Exception ex = (Exception) it.next();
+ Exception ex = it.next();
logError(ex);
}
}
@@ -146,7 +143,7 @@ public class ClassRmicCompiler
remotemethods = null;
stubname = null;
skelname = null;
- mRemoteInterfaces = new ArrayList();
+ mRemoteInterfaces = new ArrayList<Class<?>>();
analyzeClass(cls);
generateStub();
@@ -175,7 +172,7 @@ public class ClassRmicCompiler
*/
public Exception getException()
{
- return errors.size() == 0 ? null : (Exception) errors.get(0);
+ return errors.size() == 0 ? null : errors.get(0);
}
private void findClass()
@@ -202,7 +199,7 @@ public class ClassRmicCompiler
}
}
- private static Type[] typeArray(Class[] cls)
+ private static Type[] typeArray(Class<?>[] cls)
{
Type[] t = new Type[cls.length];
for (int i = 0; i < cls.length; i++)
@@ -231,11 +228,11 @@ public class ClassRmicCompiler
private static final String forName = "class$";
- private static Object param(Method m, int argIndex)
+ private static List<Object> param(Method m, int argIndex)
{
- List l = new ArrayList();
+ List<Object> l = new ArrayList<Object>();
l.add(m);
- l.add(new Integer(argIndex));
+ l.add(Integer.valueOf(argIndex));
return l;
}
@@ -283,10 +280,10 @@ public class ClassRmicCompiler
cv.visitMaxs(-1, -1);
}
- private void generateClassConstant(MethodVisitor cv, Class cls) {
+ private void generateClassConstant(MethodVisitor cv, Class<?> cls) {
if (cls.isPrimitive())
{
- Class boxCls;
+ Class<?> boxCls;
if (cls.equals(Boolean.TYPE))
boxCls = Boolean.class;
else if (cls.equals(Character.TYPE))
@@ -321,7 +318,7 @@ public class ClassRmicCompiler
new Type[] { Type.getType(String.class) }));
}
- private void generateClassArray(MethodVisitor code, Class[] classes)
+ private void generateClassArray(MethodVisitor code, Class<?>[] classes)
{
code.visitLdcInsn(new Integer(classes.length));
code.visitTypeInsn(Opcodes.ANEWARRAY, typeArg(Class.class));
@@ -352,7 +349,7 @@ public class ClassRmicCompiler
desc.append(m.getName() + "(");
// signature
- Class[] sig = m.getParameterTypes();
+ Class<?>[] sig = m.getParameterTypes();
for (int j = 0; j < sig.length; j++)
{
desc.append(getPrettyName(sig[j]));
@@ -418,7 +415,6 @@ public class ClassRmicCompiler
throws IOException
{
stubname = fullclassname + "_Stub";
- String stubclassname = classname + "_Stub";
File file = new File((destination == null ? "." : destination)
+ File.separator
+ stubname.replace('.', File.separatorChar)
@@ -433,7 +429,7 @@ public class ClassRmicCompiler
Type.getType(RemoteStub.class).getInternalName();
String[] remoteInternalNames =
- internalNameArray((Class[]) mRemoteInterfaces.toArray(new Class[] {}));
+ internalNameArray(mRemoteInterfaces.toArray(new Class[mRemoteInterfaces.size()]));
stub.visit
(Opcodes.V1_2, Opcodes.ACC_PUBLIC + Opcodes.ACC_FINAL, classInternalName,
null, superInternalName, remoteInternalNames);
@@ -601,10 +597,10 @@ public class ClassRmicCompiler
for (int i = 0; i < remotemethods.length; i++)
{
Method m = remotemethods[i].meth;
- Class[] sig = m.getParameterTypes();
- Class returntype = m.getReturnType();
- Class[] except = sortExceptions
- ((Class[]) remotemethods[i].exceptions.toArray(new Class[0]));
+ Class<?>[] sig = m.getParameterTypes();
+ Class<?> returntype = m.getReturnType();
+ Class<?>[] except = sortExceptions
+ (remotemethods[i].exceptions.toArray(new Class<?>[remotemethods[i].exceptions.size()]));
MethodVisitor code = stub.visitMethod
(Opcodes.ACC_PUBLIC,
@@ -664,9 +660,8 @@ public class ClassRmicCompiler
for (int j = 0; j < sig.length; j++)
{
- int size = size(sig[j]);
int insn = loadOpcode(sig[j]);
- Class box = sig[j].isPrimitive() ? box(sig[j]) : null;
+ Class<?> box = sig[j].isPrimitive() ? box(sig[j]) : null;
code.visitVarInsn(Opcodes.ALOAD, var.get("argArray"));
code.visitLdcInsn(new Integer(j));
@@ -695,7 +690,7 @@ public class ClassRmicCompiler
}
// push remote operation opcode
- code.visitLdcInsn(new Long(remotemethods[i].hash));
+ code.visitLdcInsn(Long.valueOf(remotemethods[i].hash));
code.visitMethodInsn
(Opcodes.INVOKEINTERFACE,
Type.getInternalName(RemoteRef.class),
@@ -710,7 +705,7 @@ public class ClassRmicCompiler
if (! returntype.equals(Void.TYPE))
{
int retcode = returnOpcode(returntype);
- Class boxCls =
+ Class<?> boxCls =
returntype.isPrimitive() ? box(returntype) : null;
code.visitTypeInsn
(Opcodes.CHECKCAST, typeArg(boxCls == null ? returntype : boxCls));
@@ -797,7 +792,7 @@ public class ClassRmicCompiler
// get j'th arg to remote method
code.visitVarInsn(loadOpcode(sig[j]), var.get(param(m, j)));
- Class argCls =
+ Class<?> argCls =
sig[j].isPrimitive() ? sig[j] : Object.class;
// out.writeFoo
@@ -872,7 +867,7 @@ public class ClassRmicCompiler
Type.getMethodDescriptor
(Type.getType(ObjectInput.class), new Type[] {}));
- Class readCls =
+ Class<?> readCls =
returntype.isPrimitive() ? returntype : Object.class;
code.visitMethodInsn
(Opcodes.INVOKEINTERFACE,
@@ -936,8 +931,6 @@ public class ClassRmicCompiler
Type.getType(Exception.class) }));
code.visitInsn(Opcodes.ATHROW);
- Label endReturnTryCatch = new Label();
-
// catch IOException
code.visitTryCatchBlock
(beginReturnTryCatch, handler, handler,
@@ -1024,7 +1017,6 @@ public class ClassRmicCompiler
private void generateSkel() throws IOException
{
skelname = fullclassname + "_Skel";
- String skelclassname = classname + "_Skel";
File file = new File(destination == null ? "" : destination
+ File.separator
+ skelname.replace('.', File.separatorChar)
@@ -1119,7 +1111,7 @@ public class ClassRmicCompiler
{
// assign opnum if hash matches supplied hash
dispatch.visitVarInsn(Opcodes.LLOAD, var.get("hash"));
- dispatch.visitLdcInsn(new Long(remotemethods[i].hash));
+ dispatch.visitLdcInsn(Long.valueOf(remotemethods[i].hash));
Label notIt = new Label();
dispatch.visitInsn(Opcodes.LCMP);
dispatch.visitJumpInsn(Opcodes.IFNE, notIt);
@@ -1214,7 +1206,7 @@ public class ClassRmicCompiler
private void generateMethodSkel(MethodVisitor cv, Method m, Variables var)
{
- Class[] sig = m.getParameterTypes();
+ Class<?>[] sig = m.getParameterTypes();
Label readArgs = new Label();
cv.visitLabel(readArgs);
@@ -1235,7 +1227,7 @@ public class ClassRmicCompiler
// dup input stream
cv.visitVarInsn(Opcodes.ALOAD, var.get("objectinput"));
- Class readCls = sig[i].isPrimitive() ? sig[i] : Object.class;
+ Class<?> readCls = sig[i].isPrimitive() ? sig[i] : Object.class;
// in.readFoo()
cv.visitMethodInsn
@@ -1314,7 +1306,7 @@ public class ClassRmicCompiler
(Opcodes.INVOKEVIRTUAL, Type.getInternalName(clazz), m.getName(),
Type.getMethodDescriptor(m));
- Class returntype = m.getReturnType();
+ Class<?> returntype = m.getReturnType();
if (! returntype.equals(Void.TYPE))
{
cv.visitVarInsn
@@ -1338,7 +1330,7 @@ public class ClassRmicCompiler
{
// out.writeFoo(result)
cv.visitVarInsn(loadOpcode(returntype), var.deallocate("result"));
- Class writeCls = returntype.isPrimitive() ? returntype : Object.class;
+ Class<?> writeCls = returntype.isPrimitive() ? returntype : Object.class;
cv.visitMethodInsn
(Opcodes.INVOKEINTERFACE,
Type.getInternalName(ObjectOutput.class),
@@ -1370,7 +1362,7 @@ public class ClassRmicCompiler
Type.getInternalName(IOException.class));
}
- private static String typeArg(Class cls)
+ private static String typeArg(Class<?> cls)
{
if (cls.isArray())
return Type.getDescriptor(cls);
@@ -1378,7 +1370,7 @@ public class ClassRmicCompiler
return Type.getInternalName(cls);
}
- private static String readMethod(Class cls)
+ private static String readMethod(Class<?> cls)
{
if (cls.equals(Void.TYPE))
throw new IllegalArgumentException("can not read void");
@@ -1406,7 +1398,7 @@ public class ClassRmicCompiler
return method;
}
- private static String writeMethod(Class cls)
+ private static String writeMethod(Class<?> cls)
{
if (cls.equals(Void.TYPE))
throw new IllegalArgumentException("can not read void");
@@ -1434,7 +1426,7 @@ public class ClassRmicCompiler
return method;
}
- private static int returnOpcode(Class cls)
+ private static int returnOpcode(Class<?> cls)
{
int returncode;
if (cls.equals(Boolean.TYPE))
@@ -1461,7 +1453,7 @@ public class ClassRmicCompiler
return returncode;
}
- private static int loadOpcode(Class cls)
+ private static int loadOpcode(Class<?> cls)
{
if (cls.equals(Void.TYPE))
throw new IllegalArgumentException("can not load void");
@@ -1489,7 +1481,7 @@ public class ClassRmicCompiler
return loadcode;
}
- private static int storeOpcode(Class cls)
+ private static int storeOpcode(Class<?> cls)
{
if (cls.equals(Void.TYPE))
throw new IllegalArgumentException("can not load void");
@@ -1517,7 +1509,7 @@ public class ClassRmicCompiler
return storecode;
}
- private static String unboxMethod(Class primitive)
+ private static String unboxMethod(Class<?> primitive)
{
if (! primitive.isPrimitive())
throw new IllegalArgumentException("can not unbox nonprimitive");
@@ -1545,12 +1537,12 @@ public class ClassRmicCompiler
return method;
}
- public static Class box(Class cls)
+ public static Class<?> box(Class<?> cls)
{
if (! cls.isPrimitive())
throw new IllegalArgumentException("can only box primitive");
- Class box;
+ Class<?> box;
if (cls.equals(Boolean.TYPE))
box = Boolean.class;
else if (cls.equals(Byte.TYPE))
@@ -1573,7 +1565,7 @@ public class ClassRmicCompiler
return box;
}
- private static int size(Class cls) {
+ private static int size(Class<?> cls) {
if (cls.equals(Long.TYPE) || cls.equals(Double.TYPE))
return 2;
else
@@ -1583,7 +1575,7 @@ public class ClassRmicCompiler
/**
* Sort exceptions so the most general go last.
*/
- private Class[] sortExceptions(Class[] except)
+ private Class<?>[] sortExceptions(Class<?>[] except)
{
for (int i = 0; i < except.length; i++)
{
@@ -1591,7 +1583,7 @@ public class ClassRmicCompiler
{
if (except[i].isAssignableFrom(except[j]))
{
- Class tmp = except[i];
+ Class<?> tmp = except[i];
except[i] = except[j];
except[j] = tmp;
}
@@ -1605,14 +1597,12 @@ public class ClassRmicCompiler
boolean noWrite, boolean verbose, boolean force, String classpath,
String bootclasspath, String extdirs, String outputDirectory)
{
- this.keep = keep;
this.need11Stubs = need11Stubs;
this.need12Stubs = need12Stubs;
this.verbose = verbose;
this.noWrite = noWrite;
// Set up classpath.
- this.classpath = classpath;
StringTokenizer st =
new StringTokenizer(classpath, File.pathSeparator);
URL[] u = new URL[st.countTokens()];
@@ -1638,15 +1628,15 @@ public class ClassRmicCompiler
private void findRemoteMethods()
throws RMICException
{
- List rmeths = new ArrayList();
- for (Class cur = clazz; cur != null; cur = cur.getSuperclass())
+ List<Method> rmeths = new ArrayList<Method>();
+ for (Class<?> cur = clazz; cur != null; cur = cur.getSuperclass())
{
- Class[] interfaces = cur.getInterfaces();
+ Class<?>[] interfaces = cur.getInterfaces();
for (int i = 0; i < interfaces.length; i++)
{
if (java.rmi.Remote.class.isAssignableFrom(interfaces[i]))
{
- Class remoteInterface = interfaces[i];
+ Class<?> remoteInterface = interfaces[i];
if (verbose)
System.out.println
("[implements " + remoteInterface.getName() + "]");
@@ -1684,11 +1674,11 @@ public class ClassRmicCompiler
boolean[] skip = new boolean[rmeths.size()];
for (int i = 0; i < skip.length; i++)
skip[i] = false;
- List methrefs = new ArrayList();
+ List<MethodRef> methrefs = new ArrayList<MethodRef>();
for (int i = 0; i < rmeths.size(); i++)
{
if (skip[i]) continue;
- Method current = (Method) rmeths.get(i);
+ Method current = rmeths.get(i);
MethodRef ref = new MethodRef(current);
for (int j = i+1; j < rmeths.size(); j++)
{
@@ -1703,7 +1693,7 @@ public class ClassRmicCompiler
}
// Convert into a MethodRef array and sort them
- remotemethods = (MethodRef[])
+ remotemethods =
methrefs.toArray(new MethodRef[methrefs.size()]);
Arrays.sort(remotemethods);
}
@@ -1748,7 +1738,7 @@ public class ClassRmicCompiler
{
Method meth;
long hash;
- List exceptions;
+ List<Class<?>> exceptions;
private String sig;
MethodRef(Method m) {
@@ -1784,12 +1774,12 @@ public class ClassRmicCompiler
return true;
}
- private static List removeSubclasses(Class[] classes)
+ private static List<Class<?>> removeSubclasses(Class<?>[] classes)
{
- List list = new ArrayList();
+ List<Class<?>> list = new ArrayList<Class<?>>();
for (int i = 0; i < classes.length; i++)
{
- Class candidate = classes[i];
+ Class<?> candidate = classes[i];
boolean add = true;
for (int j = 0; j < classes.length; j++)
{
@@ -1806,17 +1796,17 @@ public class ClassRmicCompiler
public void intersectExceptions(Method m)
{
- List incoming = removeSubclasses(m.getExceptionTypes());
+ List<Class<?>> incoming = removeSubclasses(m.getExceptionTypes());
- List updated = new ArrayList();
+ List<Class<?>> updated = new ArrayList<Class<?>>();
for (int i = 0; i < exceptions.size(); i++)
{
- Class outer = (Class) exceptions.get(i);
+ Class<?> outer = exceptions.get(i);
boolean addOuter = false;
for (int j = 0; j < incoming.size(); j++)
{
- Class inner = (Class) incoming.get(j);
+ Class<?> inner = incoming.get(j);
if (inner.equals(outer) || inner.isAssignableFrom(outer))
addOuter = true;