use of java.util.TreeMap in project android_frameworks_base by ParanoidAndroid.
the class DependencyFinder method findClassesDeps.
/**
* Finds all dependencies for all classes in keepClasses which are also
* listed in zipClasses. Returns a map of all the dependencies found.
*/
Map<String, Set<String>> findClassesDeps(Map<String, ClassReader> zipClasses) {
// The dependencies that we'll collect.
// It's a map Class name => uses class names.
Map<String, Set<String>> dependencyMap = new TreeMap<String, Set<String>>();
DependencyVisitor visitor = getVisitor();
int count = 0;
try {
for (Entry<String, ClassReader> entry : zipClasses.entrySet()) {
String name = entry.getKey();
TreeSet<String> set = new TreeSet<String>();
dependencyMap.put(name, set);
visitor.setDependencySet(set);
ClassReader cr = entry.getValue();
cr.accept(visitor, 0);
visitor.setDependencySet(null);
mLog.debugNoln("Visited %d classes\r", ++count);
}
} finally {
mLog.debugNoln("\n");
}
return dependencyMap;
}
use of java.util.TreeMap in project android_frameworks_base by ParanoidAndroid.
the class DependencyFinder method parseZip.
// ----------------
/**
* 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".
*/
Map<String, ClassReader> parseZip(List<String> jarPathList) throws IOException {
TreeMap<String, ClassReader> classes = new TreeMap<String, ClassReader>();
for (String jarPath : jarPathList) {
ZipFile zip = new ZipFile(jarPath);
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 = classReaderToClassName(cr);
classes.put(className, cr);
}
}
}
return classes;
}
use of java.util.TreeMap in project android_frameworks_base by ParanoidAndroid.
the class AsmAnalyzerTest method testFindGlobs.
@Test
public void testFindGlobs() throws IOException, LogAbortException {
Map<String, ClassReader> zipClasses = mAa.parseZip(mOsJarPath);
TreeMap<String, ClassReader> found = new TreeMap<String, ClassReader>();
// this matches classes, a package match returns nothing
found.clear();
mAa.findGlobs("mock_android.view", zipClasses, found);
assertArrayEquals(new String[] {}, found.keySet().toArray());
// a complex glob search. * is a search pattern that matches names, not dots
mAa.findGlobs("mock_android.*.*Group$*Layout*", zipClasses, found);
assertArrayEquals(new String[] { "mock_android.view.ViewGroup$LayoutParams", "mock_android.view.ViewGroup$MarginLayoutParams" }, found.keySet().toArray());
// a complex glob search. ** is a search pattern that matches names including dots
mAa.findGlobs("mock_android.**Group*", zipClasses, found);
assertArrayEquals(new String[] { "mock_android.view.ViewGroup", "mock_android.view.ViewGroup$LayoutParams", "mock_android.view.ViewGroup$MarginLayoutParams" }, found.keySet().toArray());
// matches a single class
found.clear();
mAa.findGlobs("mock_android.view.View", zipClasses, found);
assertArrayEquals(new String[] { "mock_android.view.View" }, found.keySet().toArray());
// matches everyting inside the given package but not sub-packages
found.clear();
mAa.findGlobs("mock_android.view.*", zipClasses, found);
assertArrayEquals(new String[] { "mock_android.view.View", "mock_android.view.ViewGroup", "mock_android.view.ViewGroup$LayoutParams", "mock_android.view.ViewGroup$MarginLayoutParams" }, found.keySet().toArray());
for (String key : found.keySet()) {
ClassReader value = found.get(key);
assertNotNull("No value for " + key, value);
assertEquals(key, AsmAnalyzer.classReaderToClassName(value));
}
}
use of java.util.TreeMap in project android_frameworks_base by ParanoidAndroid.
the class AsmAnalyzerTest method testFindClass.
@Test
public void testFindClass() throws IOException, LogAbortException {
Map<String, ClassReader> zipClasses = mAa.parseZip(mOsJarPath);
TreeMap<String, ClassReader> found = new TreeMap<String, ClassReader>();
ClassReader cr = mAa.findClass("mock_android.view.ViewGroup$LayoutParams", zipClasses, found);
assertNotNull(cr);
assertEquals("mock_android/view/ViewGroup$LayoutParams", cr.getClassName());
assertArrayEquals(new String[] { "mock_android.view.ViewGroup$LayoutParams" }, found.keySet().toArray());
assertArrayEquals(new ClassReader[] { cr }, found.values().toArray());
}
use of java.util.TreeMap in project android_frameworks_base by ParanoidAndroid.
the class AsmAnalyzerTest method testFindClassesDerivingFrom.
@Test
public void testFindClassesDerivingFrom() throws LogAbortException, IOException {
Map<String, ClassReader> zipClasses = mAa.parseZip(mOsJarPath);
TreeMap<String, ClassReader> found = new TreeMap<String, ClassReader>();
mAa.findClassesDerivingFrom("mock_android.view.View", zipClasses, found);
assertArrayEquals(new String[] { "mock_android.view.View", "mock_android.view.ViewGroup", "mock_android.widget.LinearLayout", "mock_android.widget.TableLayout" }, found.keySet().toArray());
for (String key : found.keySet()) {
ClassReader value = found.get(key);
assertNotNull("No value for " + key, value);
assertEquals(key, AsmAnalyzer.classReaderToClassName(value));
}
}
Aggregations