StubGeneratorpublic class StubGenerator extends Object Given a set of already filtered classes, this filters out all private members,
stubs the remaining classes and then generates a Jar out of them.
This is an helper extracted for convenience. Callers just need to use
{@link #generateStubbedJar(File, Map, Filter)}. |
Methods Summary |
---|
java.lang.String | classNameToEntryPath(java.lang.String className)Utility method that converts a fully qualified java name into a JAR entry path
e.g. for the input "android.view.View" it returns "android/view/View.class"
return className.replaceAll("\\.", "/").concat(".class");
| void | createJar(java.io.FileOutputStream outStream, java.util.Map all)Writes the JAR file.
JarOutputStream jar = new JarOutputStream(outStream);
for (Entry<String, byte[]> entry : all.entrySet()) {
String name = entry.getKey();
JarEntry jar_entry = new JarEntry(name);
jar.putNextEntry(jar_entry);
jar.write(entry.getValue());
jar.closeEntry();
}
jar.flush();
jar.close();
| public void | generateStubbedJar(java.io.File destJar, java.util.Map classes, Filter filter)Generate source for the stubbed classes, mostly for debug purposes.
TreeMap<String, byte[]> all = new TreeMap<String, byte[]>();
for (Entry<String, ClassReader> entry : classes.entrySet()) {
ClassReader cr = entry.getValue();
byte[] b = visitClassStubber(cr, filter);
String name = classNameToEntryPath(cr.getClassName());
all.put(name, b);
}
createJar(new FileOutputStream(destJar), all);
System.out.println(String.format("Wrote %s", destJar.getPath()));
| byte[] | visitClassStubber(org.objectweb.asm.ClassReader cr, Filter filter)
System.out.println("Stub " + cr.getClassName());
// Rewrite the new class from scratch, without reusing the constant pool from the
// original class reader.
ClassWriter cw = new ClassWriter(ClassWriter.COMPUTE_MAXS);
ClassVisitor stubWriter = new ClassStubber(cw);
ClassVisitor classFilter = new FilterClassAdapter(stubWriter, filter);
cr.accept(classFilter, 0 /*flags*/);
return cw.toByteArray();
|
|