FileDocCategorySizeDatePackage
Queries.javaAPI DocAndroid 5.1 API8110Thu Mar 12 22:18:30 GMT 2015com.android.hit

Queries

public class Queries extends Object

Fields Summary
private static final String
DEFAULT_PACKAGE
Constructors Summary
Methods Summary
public static java.util.MapallClasses(State state)


    /*
     * Produce a collection of all classes, broken down by package.
     * The keys of the resultant map iterate in sorted package order.
     * The values of the map are the classes defined in each package.
     */
          
        return classes(state, null);
    
public static Instance[]allInstancesOf(State state, java.lang.String baseClassName)

        ClassObj theClass = state.findClass(baseClassName);

        if (theClass == null) {
            throw new IllegalArgumentException("Class not found: "
                + baseClassName);
        }

        ArrayList<ClassObj> classList = new ArrayList<ClassObj>();

        classList.add(theClass);
        classList.addAll(traverseSubclasses(theClass));

        ArrayList<Instance> instanceList = new ArrayList<Instance>();

        for (ClassObj someClass: classList) {
            instanceList.addAll(someClass.mInstances);
        }

        Instance[] result = new Instance[instanceList.size()];

        instanceList.toArray(result);

        return result;
    
public static java.util.Mapclasses(State state, java.lang.String[] excludedPrefixes)

        TreeMap<String, Set<ClassObj>> result =
        new TreeMap<String, Set<ClassObj>>();

        Set<ClassObj> classes = new TreeSet<ClassObj>();

        //  Build a set of all classes across all heaps
        for (Heap heap: state.mHeaps.values()) {
            classes.addAll(heap.mClassesById.values());
        }

        //  Filter it if needed
        if (excludedPrefixes != null) {
            final int N = excludedPrefixes.length;
            Iterator<ClassObj> iter = classes.iterator();

            while (iter.hasNext()) {
                ClassObj theClass = iter.next();
                String classPath = theClass.toString();

                for (int i = 0; i < N; i++) {
                    if (classPath.startsWith(excludedPrefixes[i])) {
                        iter.remove();
                        break;
                    }
                }
            }
        }

        //  Now that we have a final list of classes, group them by package
        for (ClassObj theClass: classes) {
            String packageName = DEFAULT_PACKAGE;
            int lastDot = theClass.mClassName.lastIndexOf('.");

            if (lastDot != -1) {
                packageName = theClass.mClassName.substring(0, lastDot);
            }

            Set<ClassObj> classSet = result.get(packageName);

            if (classSet == null) {
                classSet = new TreeSet<ClassObj>();
                result.put(packageName, classSet);
            }

            classSet.add(theClass);
        }

        return result;
    
public static ClassObjfindClass(State state, java.lang.String name)

        return state.findClass(name);
    
public static InstancefindObject(State state, java.lang.String id)

        long id2 = Long.parseLong(id, 16);

        return state.findReference(id2);
    
public static java.util.CollectiongetRoots(State state)

        HashSet<RootObj> result = new HashSet<RootObj>();

        for (Heap heap: state.mHeaps.values()) {
            result.addAll(heap.mRoots);
        }

        return result;
    
public static Instance[]instancesOf(State state, java.lang.String baseClassName)

         ClassObj theClass = state.findClass(baseClassName);

         if (theClass == null) {
             throw new IllegalArgumentException("Class not found: "
                + baseClassName);
         }

         Instance[] instances = new Instance[theClass.mInstances.size()];

         return theClass.mInstances.toArray(instances);
     
public static final Instance[]newInstances(State older, State newer)

        ArrayList<Instance> resultList = new ArrayList<Instance>();

        for (Heap newHeap: newer.mHeaps.values()) {
            Heap oldHeap = older.getHeap(newHeap.mName);

            if (oldHeap == null) {
                continue;
            }

            for (Instance instance: newHeap.mInstances.values()) {
                Instance oldInstance = oldHeap.getInstance(instance.mId);

                /*
                 * If this instance wasn't in the old heap, or was there,
                 * but that ID was for an obj of a different type, then we have
                 * a newly allocated object and we should report it in the
                 * results.
                 */
                if ((oldInstance == null)
                        || (instance.mClassId != oldInstance.mClassId)) {
                    resultList.add(instance);
                }
            }
        }

        Instance[] resultArray = new Instance[resultList.size()];

        return resultList.toArray(resultArray);
    
private static java.util.ArrayListtraverseSubclasses(ClassObj base)

        ArrayList<ClassObj> result = new ArrayList<ClassObj>();

        for (ClassObj subclass: base.mSubclasses) {
            result.add(subclass);
            result.addAll(traverseSubclasses(subclass));
        }

        return result;