This patch cleans up the gjavah source code so it
no longer produces a mass of warnings related to generics.
We're a little restricted in what we can do by the external
ASM library which is not yet using generics, either in
GNU Classpath or upstream.
ChangeLog:
2009-03-20 Andrew John Hughes <[email protected]>
* tools/gnu/classpath/tools/javah/ClassWrapper.java,
* tools/gnu/classpath/tools/javah/CniPrintStream.java,
* tools/gnu/classpath/tools/javah/CniStubPrinter.java,
* tools/gnu/classpath/tools/javah/GcjhMain.java,
* tools/gnu/classpath/tools/javah/JniIncludePrinter.java,
* tools/gnu/classpath/tools/javah/JniPrintStream.java,
* tools/gnu/classpath/tools/javah/JniStubPrinter.java,
* tools/gnu/classpath/tools/javah/Keywords.java,
* tools/gnu/classpath/tools/javah/Main.java,
* tools/gnu/classpath/tools/javah/MethodHelper.java,
* tools/gnu/classpath/tools/javah/PathOptionGroup.java:
Fix generic issues in gjavah.
--
Andrew :)
Red Hat Free Java Software Engineer
Index: tools/gnu/classpath/tools/javah/ClassWrapper.java
===================================================================
RCS file:
/sources/classpath/classpath/tools/gnu/classpath/tools/javah/ClassWrapper.java,v
retrieving revision 1.4
diff -u -r1.4 ClassWrapper.java
--- tools/gnu/classpath/tools/javah/ClassWrapper.java 2 Sep 2008 22:00:31
-0000 1.4
+++ tools/gnu/classpath/tools/javah/ClassWrapper.java 20 Mar 2009 12:27:14
-0000
@@ -58,21 +58,21 @@
ClassWrapper superClass;
- ArrayList interfaceClasses;
+ ArrayList<ClassWrapper> interfaceClasses;
// The virtual table for this class.
- ArrayList vtable;
+ ArrayList<MethodNode> vtable;
// A set of all the bridge method targets we've found.
- HashSet bridgeTargets;
+ HashSet<String> bridgeTargets;
// A set of all the method names in this class.
- HashSet methodNames = new HashSet();
+ HashSet<String> methodNames = new HashSet<String>();
// This maps a method name + descriptor, e.g. "method()V", to the
// name chosen for the method. This is used when computing the
// names of bridge method targets.
- HashMap methodNameMap = new HashMap();
+ HashMap<String,String> methodNameMap = new HashMap<String,String>();
public ClassWrapper(Main classpath)
{
@@ -81,7 +81,7 @@
public boolean hasNativeMethod()
{
- Iterator i = methods.iterator();
+ Iterator<?> i = methods.iterator();
while (i.hasNext())
{
MethodNode method = (MethodNode) i.next();
@@ -115,7 +115,7 @@
{
superClass = classpath.getClass(superName);
assert interfaceClasses == null;
- interfaceClasses = new ArrayList();
+ interfaceClasses = new ArrayList<ClassWrapper>();
for (int i = 0; i < interfaces.size(); ++i)
{
String ifname = (String) interfaces.get(i);
@@ -131,7 +131,7 @@
{
for (int i = vtable.size() - 1; i >= 0; --i)
{
- MethodNode base = (MethodNode) vtable.get(i);
+ MethodNode base = vtable.get(i);
if (MethodHelper.overrides(method, base))
return i;
}
@@ -140,7 +140,7 @@
private void addInterfaceMethods(ClassWrapper iface)
{
- Iterator i = iface.methods.iterator();
+ Iterator<?> i = iface.methods.iterator();
while (i.hasNext())
{
MethodNode im = (MethodNode) i.next();
@@ -159,7 +159,7 @@
{
if (base.interfaceClasses == null)
return;
- Iterator i = base.interfaceClasses.iterator();
+ Iterator<?> i = base.interfaceClasses.iterator();
while (i.hasNext())
{
ClassWrapper iface = (ClassWrapper) i.next();
@@ -169,7 +169,7 @@
private void addLocalMethods()
{
- Iterator i = methods.iterator();
+ Iterator<?> i = methods.iterator();
while (i.hasNext())
{
MethodNode meth = (MethodNode) i.next();
@@ -191,16 +191,16 @@
if (superClass != null)
{
superClass.makeVtable();
- vtable = new ArrayList(superClass.vtable);
- bridgeTargets = new HashSet(superClass.bridgeTargets);
- methodNameMap = new HashMap(superClass.methodNameMap);
+ vtable = new ArrayList<MethodNode>(superClass.vtable);
+ bridgeTargets = new HashSet<String>(superClass.bridgeTargets);
+ methodNameMap = new HashMap<String,String>(superClass.methodNameMap);
}
else
{
// Object.
- vtable = new ArrayList();
- bridgeTargets = new HashSet();
- methodNameMap = new HashMap();
+ vtable = new ArrayList<MethodNode>();
+ bridgeTargets = new HashSet<String>();
+ methodNameMap = new HashMap<String,String>();
}
addLocalMethods();
addInterfaces(this);
@@ -211,7 +211,7 @@
// methods by definition override a method from the superclass --
// and we have to consider the superclass' header as an
// unchangeable entity.
- Iterator i = methods.iterator();
+ Iterator<?> i = methods.iterator();
while (i.hasNext())
{
MethodNode m = (MethodNode) i.next();
@@ -234,7 +234,7 @@
private void printFields(CniPrintStream out)
{
- Iterator i = fields.iterator();
+ Iterator<?> i = fields.iterator();
ClassWrapper self = superClass;
while (i.hasNext())
{
@@ -251,7 +251,7 @@
// A given method is either static, overrides a super method, or
// is already in vtable order.
- Iterator i = methods.iterator();
+ Iterator<?> i = methods.iterator();
while (i.hasNext())
{
MethodNode m = (MethodNode) i.next();
@@ -266,15 +266,15 @@
}
}
- private void printTextList(PrintStream out, int what, ArrayList textList)
+ private void printTextList(PrintStream out, int what, ArrayList<Text>
textList)
{
if (textList == null)
return;
- Iterator i = textList.iterator();
+ Iterator<Text> i = textList.iterator();
boolean first = true;
while (i.hasNext())
{
- Text item = (Text) i.next();
+ Text item = i.next();
if (item.type == what)
{
if (first)
@@ -295,7 +295,7 @@
}
// This prints the body of a class to a CxxPrintStream.
- private void printContents(CniPrintStream out, ArrayList textList)
+ private void printContents(CniPrintStream out, ArrayList<Text> textList)
throws IOException
{
printTextList(out, Text.PREPEND, textList);
@@ -337,7 +337,7 @@
{
linkSupers();
- ArrayList textList = classpath.getClassTextList(name);
+ ArrayList<Text> textList = classpath.getClassTextList(name);
out.println("// DO NOT EDIT THIS FILE - it is machine generated -*- c++
-*-");
out.println();
Index: tools/gnu/classpath/tools/javah/CniPrintStream.java
===================================================================
RCS file:
/sources/classpath/classpath/tools/gnu/classpath/tools/javah/CniPrintStream.java,v
retrieving revision 1.2
diff -u -r1.2 CniPrintStream.java
--- tools/gnu/classpath/tools/javah/CniPrintStream.java 20 Oct 2006 22:37:06
-0000 1.2
+++ tools/gnu/classpath/tools/javah/CniPrintStream.java 20 Mar 2009 12:27:14
-0000
@@ -55,7 +55,7 @@
boolean sawArray;
// All the classes referenced by this header.
- HashSet allClasses = new HashSet();
+ HashSet<String> allClasses = new HashSet<String>();
String[] previousPackage = new String[0];
@@ -214,7 +214,7 @@
out.println();
}
- String[] classes = (String[]) allClasses.toArray(new String[0]);
+ String[] classes = allClasses.toArray(new String[0]);
Arrays.sort(classes);
boolean first = true;
Index: tools/gnu/classpath/tools/javah/CniStubPrinter.java
===================================================================
RCS file:
/sources/classpath/classpath/tools/gnu/classpath/tools/javah/CniStubPrinter.java,v
retrieving revision 1.3
diff -u -r1.3 CniStubPrinter.java
--- tools/gnu/classpath/tools/javah/CniStubPrinter.java 16 Mar 2007 22:42:43
-0000 1.3
+++ tools/gnu/classpath/tools/javah/CniStubPrinter.java 20 Mar 2009 12:27:14
-0000
@@ -103,7 +103,7 @@
out.println("#include <" + klass.name + ".h>");
out.println();
- Iterator i = klass.methods.iterator();
+ Iterator<?> i = klass.methods.iterator();
boolean first = true;
while (i.hasNext())
{
Index: tools/gnu/classpath/tools/javah/GcjhMain.java
===================================================================
RCS file:
/sources/classpath/classpath/tools/gnu/classpath/tools/javah/GcjhMain.java,v
retrieving revision 1.2
diff -u -r1.2 GcjhMain.java
--- tools/gnu/classpath/tools/javah/GcjhMain.java 5 Jun 2008 23:58:47
-0000 1.2
+++ tools/gnu/classpath/tools/javah/GcjhMain.java 20 Mar 2009 12:27:14
-0000
@@ -49,7 +49,7 @@
public class GcjhMain extends Main
{
- ArrayList commands = new ArrayList();
+ ArrayList<Text> commands = new ArrayList<Text>();
public GcjhMain()
{
Index: tools/gnu/classpath/tools/javah/JniIncludePrinter.java
===================================================================
RCS file:
/sources/classpath/classpath/tools/gnu/classpath/tools/javah/JniIncludePrinter.java,v
retrieving revision 1.8
diff -u -r1.8 JniIncludePrinter.java
--- tools/gnu/classpath/tools/javah/JniIncludePrinter.java 31 Jul 2007
16:15:53 -0000 1.8
+++ tools/gnu/classpath/tools/javah/JniIncludePrinter.java 20 Mar 2009
12:27:14 -0000
@@ -63,7 +63,7 @@
boolean wroteAny = false;
for (; klass != null; klass = klass.superClass)
{
- Iterator i = klass.fields.iterator();
+ Iterator<?> i = klass.fields.iterator();
while (i.hasNext())
{
FieldNode field = (FieldNode) i.next();
@@ -138,7 +138,7 @@
out.println("#endif");
out.println();
- Iterator i = klass.methods.iterator();
+ Iterator<?> i = klass.methods.iterator();
while (i.hasNext())
{
MethodNode method = (MethodNode) i.next();
Index: tools/gnu/classpath/tools/javah/JniPrintStream.java
===================================================================
RCS file:
/sources/classpath/classpath/tools/gnu/classpath/tools/javah/JniPrintStream.java,v
retrieving revision 1.1
diff -u -r1.1 JniPrintStream.java
--- tools/gnu/classpath/tools/javah/JniPrintStream.java 28 Jul 2006 15:22:29
-0000 1.1
+++ tools/gnu/classpath/tools/javah/JniPrintStream.java 20 Mar 2009 12:27:14
-0000
@@ -54,7 +54,7 @@
Main classpath;
// This is used to determine whether a method has an overload.
- HashMap methodNameMap = new HashMap();
+ HashMap<String,Integer> methodNameMap = new HashMap<String,Integer>();
public JniPrintStream(Main classpath, OutputStream out, ClassWrapper klass)
{
@@ -65,7 +65,7 @@
private void computeOverloads(ClassWrapper klass)
{
- Iterator i = klass.methods.iterator();
+ Iterator<?> i = klass.methods.iterator();
while (i.hasNext())
{
MethodNode method = (MethodNode) i.next();
@@ -73,11 +73,11 @@
continue;
if (methodNameMap.containsKey(method.name))
{
- Integer val = (Integer) methodNameMap.get(method.name);
- methodNameMap.put(method.name, new Integer(val.intValue() + 1));
+ Integer val = methodNameMap.get(method.name);
+ methodNameMap.put(method.name, Integer.valueOf(val.intValue() +
1));
}
else
- methodNameMap.put(method.name, new Integer(1));
+ methodNameMap.put(method.name, Integer.valueOf(1));
}
}
Index: tools/gnu/classpath/tools/javah/JniStubPrinter.java
===================================================================
RCS file:
/sources/classpath/classpath/tools/gnu/classpath/tools/javah/JniStubPrinter.java,v
retrieving revision 1.5
diff -u -r1.5 JniStubPrinter.java
--- tools/gnu/classpath/tools/javah/JniStubPrinter.java 16 Mar 2007 22:42:43
-0000 1.5
+++ tools/gnu/classpath/tools/javah/JniStubPrinter.java 20 Mar 2009 12:27:14
-0000
@@ -87,7 +87,7 @@
out.print(klass.name.replace('/', '_'));
out.println(".h>");
- Iterator i = klass.methods.iterator();
+ Iterator<?> i = klass.methods.iterator();
while (i.hasNext())
{
MethodNode method = (MethodNode) i.next();
Index: tools/gnu/classpath/tools/javah/Keywords.java
===================================================================
RCS file:
/sources/classpath/classpath/tools/gnu/classpath/tools/javah/Keywords.java,v
retrieving revision 1.1
diff -u -r1.1 Keywords.java
--- tools/gnu/classpath/tools/javah/Keywords.java 28 Jul 2006 15:22:29
-0000 1.1
+++ tools/gnu/classpath/tools/javah/Keywords.java 20 Mar 2009 12:27:14
-0000
@@ -65,10 +65,10 @@
"void", "volatile", "wchar_t",
"while", "xor", "xor_eq" };
- private static final HashSet keywords;
+ private static final HashSet<String> keywords;
static
{
- keywords = new HashSet();
+ keywords = new HashSet<String>();
for (int i = 0; i < words.length; ++i)
keywords.add(words[i]);
}
Index: tools/gnu/classpath/tools/javah/Main.java
===================================================================
RCS file:
/sources/classpath/classpath/tools/gnu/classpath/tools/javah/Main.java,v
retrieving revision 1.11
diff -u -r1.11 Main.java
--- tools/gnu/classpath/tools/javah/Main.java 5 Jun 2008 23:58:47 -0000
1.11
+++ tools/gnu/classpath/tools/javah/Main.java 20 Mar 2009 12:27:14 -0000
@@ -96,10 +96,10 @@
boolean force;
// Map class names to class wrappers.
- HashMap classMap = new HashMap();
+ HashMap<String,ClassWrapper> classMap = new HashMap<String,ClassWrapper>();
// Map class names to lists of Text objects.
- HashMap textMap = new HashMap();
+ HashMap<String,ArrayList<Text>> textMap = new
HashMap<String,ArrayList<Text>>();
void readCommandFile(String textFileName) throws OptionException
{
@@ -114,7 +114,7 @@
}
BufferedReader reader = new BufferedReader(new InputStreamReader(fis));
String currentClass = null;
- ArrayList currentValues = null;
+ ArrayList<Text> currentValues = null;
while (true)
{
String line;
@@ -142,7 +142,7 @@
textMap.put(currentClass, currentValues);
}
currentClass = value;
- currentValues = new ArrayList();
+ currentValues = new ArrayList<Text>();
continue;
}
if (currentClass == null)
@@ -165,7 +165,7 @@
}
}
- void scanDirectory(File dir, final HashSet results)
+ void scanDirectory(File dir, final HashSet<Object> results)
{
File[] files = dir.listFiles(new FileFilter()
{
@@ -317,15 +317,15 @@
return result;
}
- private void writeHeaders(HashMap klasses, Printer printer)
+ private void writeHeaders(HashMap<File,ClassWrapper> klasses, Printer
printer)
throws IOException
{
- Iterator i = klasses.entrySet().iterator();
+ Iterator<Map.Entry<File,ClassWrapper>> i = klasses.entrySet().iterator();
while (i.hasNext())
{
- Map.Entry e = (Map.Entry) i.next();
- File file = (File) e.getKey();
- ClassWrapper klass = (ClassWrapper) e.getValue();
+ Map.Entry<File,ClassWrapper> e = i.next();
+ File file = e.getKey();
+ ClassWrapper klass = e.getValue();
if (verbose)
System.err.println("[writing " + klass + " as " + file + "]");
printer.printClass(file, klass);
@@ -368,7 +368,7 @@
// First we load all of the files. That way if
// there are references between the files we will
// be loading the set that the user asked for.
- HashSet klasses = new HashSet();
+ HashSet<Object> klasses = new HashSet<Object>();
if (allDirectory != null)
scanDirectory(new File(allDirectory), klasses);
// Add the command-line arguments. We use the type of
@@ -385,8 +385,8 @@
}
}
- Iterator i = klasses.iterator();
- HashMap results = new HashMap();
+ Iterator<Object> i = klasses.iterator();
+ HashMap<File,ClassWrapper> results = new HashMap<File,ClassWrapper>();
while (i.hasNext())
{
// Let user specify either kind of class name or a
@@ -419,9 +419,9 @@
writeHeaders(results, printer);
}
- public ArrayList getClassTextList(String name)
+ public ArrayList<Text> getClassTextList(String name)
{
- return (ArrayList) textMap.get(name);
+ return textMap.get(name);
}
private ClassWrapper readClass(InputStream is) throws IOException
Index: tools/gnu/classpath/tools/javah/MethodHelper.java
===================================================================
RCS file:
/sources/classpath/classpath/tools/gnu/classpath/tools/javah/MethodHelper.java,v
retrieving revision 1.2
diff -u -r1.2 MethodHelper.java
--- tools/gnu/classpath/tools/javah/MethodHelper.java 19 Apr 2007 00:14:15
-0000 1.2
+++ tools/gnu/classpath/tools/javah/MethodHelper.java 20 Mar 2009 12:27:14
-0000
@@ -64,7 +64,7 @@
{
if ((meth.access & Opcodes.ACC_BRIDGE) == 0)
return null;
- Iterator i = meth.instructions.iterator();
+ Iterator<?> i = meth.instructions.iterator();
while (i.hasNext())
{
AbstractInsnNode insn = (AbstractInsnNode) i.next();
Index: tools/gnu/classpath/tools/javah/PathOptionGroup.java
===================================================================
RCS file:
/sources/classpath/classpath/tools/gnu/classpath/tools/javah/PathOptionGroup.java,v
retrieving revision 1.4
diff -u -r1.4 PathOptionGroup.java
--- tools/gnu/classpath/tools/javah/PathOptionGroup.java 7 Feb 2007
21:49:49 -0000 1.4
+++ tools/gnu/classpath/tools/javah/PathOptionGroup.java 20 Mar 2009
12:27:14 -0000
@@ -55,11 +55,11 @@
public class PathOptionGroup
extends OptionGroup
{
- ArrayList classpath = new ArrayList();
+ ArrayList<String> classpath = new ArrayList<String>();
- ArrayList bootclasspath = new ArrayList();
+ ArrayList<String> bootclasspath = new ArrayList<String>();
- void setPath(ArrayList list, String path)
+ void setPath(ArrayList<String> list, String path)
{
list.clear();
StringTokenizer st = new StringTokenizer(path, File.pathSeparator);
@@ -69,7 +69,7 @@
}
}
- void addExtDirs(ArrayList list, String path)
+ void addExtDirs(ArrayList<String> list, String path)
{
StringTokenizer tok = new StringTokenizer(path, File.pathSeparator);
while (tok.hasMoreTokens())
@@ -133,15 +133,15 @@
public URLClassLoader getLoader() throws MalformedURLException
{
- ArrayList urls = new ArrayList();
+ ArrayList<URL> urls = new ArrayList<URL>();
classpath.addAll(bootclasspath);
- Iterator i = classpath.iterator();
+ Iterator<String> i = classpath.iterator();
while (i.hasNext())
{
- String f = (String) i.next();
+ String f = i.next();
urls.add(new File(f).toURL());
}
- URL[] urlArray = (URL[]) urls.toArray(new URL[0]);
+ URL[] urlArray = urls.toArray(new URL[0]);
return new URLClassLoader(urlArray);
}
}