FileDocCategorySizeDatePackage
ClassReferenceListBuilder.javaAPI DocAndroid 5.1 API5064Thu Mar 12 22:18:30 GMT 2015com.android.multidex

ClassReferenceListBuilder

public class ClassReferenceListBuilder extends Object
Tool to find direct class references to other classes.

Fields Summary
private static final String
CLASS_EXTENSION
private Path
path
private Set
classNames
Constructors Summary
public ClassReferenceListBuilder(Path path)


       
        this.path = path;
    
Methods Summary
private voidaddClassWithHierachy(java.lang.String classBinaryName)

        if (classNames.contains(classBinaryName)) {
            return;
        }

        try {
            DirectClassFile classFile = path.getClass(classBinaryName + CLASS_EXTENSION);
            classNames.add(classBinaryName);
            CstType superClass = classFile.getSuperclass();
            if (superClass != null) {
                addClassWithHierachy(superClass.getClassType().getClassName());
            }

            TypeList interfaceList = classFile.getInterfaces();
            int interfaceNumber = interfaceList.size();
            for (int i = 0; i < interfaceNumber; i++) {
                addClassWithHierachy(interfaceList.getType(i).getClassName());
            }
        } catch (FileNotFoundException e) {
            // Ignore: The referenced type is not in the path it must be part of the libraries.
        }
    
private voidaddDependencies(com.android.dx.rop.cst.ConstantPool pool)

        for (Constant constant : pool.getEntries()) {
            if (constant instanceof CstType) {
                Type type = ((CstType) constant).getClassType();
                String descriptor = type.getDescriptor();
                if (descriptor.endsWith(";")) {
                    int lastBrace = descriptor.lastIndexOf('[");
                    if (lastBrace < 0) {
                        addClassWithHierachy(descriptor.substring(1, descriptor.length()-1));
                    } else {
                        assert descriptor.length() > lastBrace + 3
                        && descriptor.charAt(lastBrace + 1) == 'L";
                        addClassWithHierachy(descriptor.substring(lastBrace + 2,
                                descriptor.length() - 1));
                    }
                }
            }
        }
    
public voidaddRoots(java.util.zip.ZipFile jarOfRoots)

param
jarOfRoots Archive containing the class files resulting of the tracing, typically this is the result of running ProGuard.


        // keep roots
        for (Enumeration<? extends ZipEntry> entries = jarOfRoots.entries();
                entries.hasMoreElements();) {
            ZipEntry entry = entries.nextElement();
            String name = entry.getName();
            if (name.endsWith(CLASS_EXTENSION)) {
                classNames.add(name.substring(0, name.length() - CLASS_EXTENSION.length()));
            }
        }

        // keep direct references of roots (+ direct references hierarchy)
        for (Enumeration<? extends ZipEntry> entries = jarOfRoots.entries();
                entries.hasMoreElements();) {
            ZipEntry entry = entries.nextElement();
            String name = entry.getName();
            if (name.endsWith(CLASS_EXTENSION)) {
                DirectClassFile classFile;
                try {
                    classFile = path.getClass(name);
                } catch (FileNotFoundException e) {
                    throw new IOException("Class " + name +
                            " is missing form original class path " + path, e);
                }

                addDependencies(classFile.getConstantPool());
            }
        }
    
java.util.SetgetClassNames()

        return classNames;
    
public static voidmain(java.lang.String[] args)
Kept for compatibility with the gradle integration, this method just forwards to {@link MainDexListBuilder#main(String[])}.

deprecated
use {@link MainDexListBuilder#main(String[])} instead.

        MainDexListBuilder.main(args);