FileDocCategorySizeDatePackage
StubGenerator.javaAPI DocAndroid 1.5 API3681Wed May 06 22:41:10 BST 2009com.android.mkstubs

StubGenerator

public 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)}.

Fields Summary
Constructors Summary
Methods Summary
java.lang.StringclassNameToEntryPath(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");
    
voidcreateJar(java.io.FileOutputStream outStream, java.util.Map all)
Writes the JAR file.

param
outStream The file output stream were to write the JAR.
param
all The map of all classes to output.
throws
IOException if an I/O error has occurred

        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 voidgenerateStubbedJar(java.io.File destJar, java.util.Map classes, Filter filter)
Generate source for the stubbed classes, mostly for debug purposes.

throws
IOException


        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();