diff options
author | Andrew John Hughes <gnu_andrew@member.fsf.org> | 2011-09-09 05:44:20 +0000 |
---|---|---|
committer | Andrew John Hughes <gnu_andrew@member.fsf.org> | 2011-09-09 05:44:20 +0000 |
commit | f3961f046edcdf6fca9897c2a3c0bb406d693ec3 (patch) | |
tree | 68c58cc9aa8a32316e1db020d40e154c83a9c685 /tools | |
parent | 90d84296530e154dd079db544606ffdf9bc1d158 (diff) | |
download | classpath-f3961f046edcdf6fca9897c2a3c0bb406d693ec3.tar.gz |
PR classpath/45526: Produce header files for any inner classes found.
2011-09-09 Andrew John Hughes <ahughes@redhat.com>
PR classpath/45526: Produce header files for
any inner classes found.
* tools/gnu/classpath/tools/javah/Main.java:
(parsed): Set of class names that have been parsed.
(writeHeader(Map,Printer)): Take a general Map
rather than a specific HashMap.
(parseClasses(Iterator<Object>)): Factor out
the parsing of class files into a separate
method so it can be called recursively for
inner classes.
(getClass(String)): Remove redundant cast.
Diffstat (limited to 'tools')
-rw-r--r-- | tools/gnu/classpath/tools/javah/Main.java | 87 |
1 files changed, 55 insertions, 32 deletions
diff --git a/tools/gnu/classpath/tools/javah/Main.java b/tools/gnu/classpath/tools/javah/Main.java index bec04f00d..894a5c4d2 100644 --- a/tools/gnu/classpath/tools/javah/Main.java +++ b/tools/gnu/classpath/tools/javah/Main.java @@ -58,9 +58,11 @@ import java.util.Arrays; import java.util.HashMap; import java.util.HashSet; import java.util.Iterator; +import java.util.Set; import java.util.Map; import org.objectweb.asm.ClassReader; +import org.objectweb.asm.tree.InnerClassNode; public class Main { @@ -101,6 +103,9 @@ public class Main // Map class names to lists of Text objects. HashMap<String,ArrayList<Text>> textMap = new HashMap<String,ArrayList<Text>>(); + // Set of classes which have been parsed + Set<String> parsed = new HashSet<String>(); + void readCommandFile(String textFileName) throws OptionException { FileInputStream fis; @@ -317,7 +322,7 @@ public class Main return result; } - private void writeHeaders(HashMap<File,ClassWrapper> klasses, Printer printer) + private void writeHeaders(Map<File,ClassWrapper> klasses, Printer printer) throws IOException { Iterator<Map.Entry<File,ClassWrapper>> i = klasses.entrySet().iterator(); @@ -332,6 +337,53 @@ public class Main } } + private Map<File,ClassWrapper> parseClasses(Iterator<Object> inputs) + throws IOException + { + Map<File,ClassWrapper> results = new HashMap<File,ClassWrapper>(); + while (inputs.hasNext()) + { + // Let user specify either kind of class name or a + // file name. + Object item = inputs.next(); + ClassWrapper klass; + File filename; + if (item instanceof File) + { + // Load class from file. + if (verbose) + System.err.println("[reading file " + item + "]"); + klass = getClass((File) item); + filename = new File(klass.name); + } + else + { + // Load class given the class name. + String className = ((String) item).replace('.', '/'); + if (verbose) + System.err.println("[reading class " + className + "]"); + // Use the name the user specified, even if it is + // different from the ultimate class name. + filename = new File(className); + klass = getClass(className); + } + results.put(filename, klass); + parsed.add(item.toString()); + + // Check to see if there are inner classes to also parse + Iterator<?> innerClasses = klass.innerClasses.iterator(); + HashSet<Object> innerNames = new HashSet<Object>(); + while (innerClasses.hasNext()) + { + String innerName = ((InnerClassNode) innerClasses.next()).name; + if (!parsed.contains(innerName)) + innerNames.add(innerName); + } + results.putAll(parseClasses(innerNames.iterator())); + } + return results; + } + protected void postParse(String[] names) { // Nothing here. @@ -385,36 +437,7 @@ public class Main } } - 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 - // file name. - Object item = i.next(); - ClassWrapper klass; - File filename; - if (item instanceof File) - { - // Load class from file. - if (verbose) - System.err.println("[reading file " + item + "]"); - klass = getClass((File) item); - filename = new File(klass.name); - } - else - { - // Load class given the class name. - String className = ((String) item).replace('.', '/'); - if (verbose) - System.err.println("[reading class " + className + "]"); - // Use the name the user specified, even if it is - // different from the ultimate class name. - filename = new File(className); - klass = getClass(className); - } - results.put(filename, klass); - } + Map<File, ClassWrapper> results = parseClasses(klasses.iterator()); writeHeaders(results, printer); } @@ -457,7 +480,7 @@ public class Main ClassWrapper result = readClass(is); classMap.put(name, result); } - return (ClassWrapper) classMap.get(name); + return classMap.get(name); } public static void main(String[] args) throws IOException |