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

AsmAnalyzer

public class AsmAnalyzer extends Object
Analyzes an input Jar to get all the relevant classes according to the given filter.

This is mostly a helper extracted for convenience. Callers will want to use {@link #parseInputJar(String)} followed by {@link #filter(Map, Filter)}.

Fields Summary
Constructors Summary
Methods Summary
static java.lang.StringclassReaderToAsmName(org.objectweb.asm.ClassReader classReader)
Utility that returns the fully qualified ASM class name for a ClassReader. E.g. it returns something like android/view/View.

        if (classReader == null) {
            return null;
        } else {
            return classReader.getClassName();
        }
    
voidfilter(java.util.Map classes, Filter filter)
Filters the set of classes. Removes all classes that should not be included in the filter or that should be excluded. This modifies the map in-place.

param
classes The in-out map of classes to examine and filter. The map is filtered in-place.
param
filter A filter describing which classes to include and which ones to exclude.


        Set<String> keys = classes.keySet();
        for(Iterator<String> it = keys.iterator(); it.hasNext(); ) {
            String key = it.next();

            // TODO: We *could* filter out all private classes here: classes.get(key).getAccess().
            
            // remove if we don't keep it
            if (!filter.accept(key)) {
                System.out.println("- Remove class " + key);
                it.remove();
            }
        }
    
java.util.MapparseInputJar(java.lang.String inputJarPath)
Parses a JAR file and returns a list of all classes founds using a map class name => ASM ClassReader. Class names are in the form "android.view.View".

        TreeMap<String, ClassReader> classes = new TreeMap<String, ClassReader>();

        ZipFile zip = new ZipFile(inputJarPath);
        Enumeration<? extends ZipEntry> entries = zip.entries();
        ZipEntry entry;
        while (entries.hasMoreElements()) {
            entry = entries.nextElement();
            if (entry.getName().endsWith(".class")) {
                ClassReader cr = new ClassReader(zip.getInputStream(entry));
                String className = classReaderToAsmName(cr);
                classes.put(className, cr);
            }
        }
        
        return classes;