use of org.objectweb.asm.tree.ClassNode in project buck by facebook.
the class ClassNodeListSupplierTest method testOneJar.
@Test
public void testOneJar() throws IOException {
File jar = new File(tmpDir.getRoot(), "primary.jar");
ZipOutputStream jarOut = new JarOutputStream(new FileOutputStream(jar));
jarOut.putNextEntry(new JarEntry("com/facebook/buck/android/ClassNodeListSupplierTest.class"));
writeClassBytes(ClassNodeListSupplierTest.class, jarOut);
jarOut.close();
Supplier<ImmutableList<ClassNode>> supplier = ClassNodeListSupplier.createMemoized(ImmutableList.of(jar.toPath()));
ImmutableList<ClassNode> classNodes = supplier.get();
assertEquals(1, classNodes.size());
assertEquals(Type.getType(ClassNodeListSupplierTest.class).getInternalName(), classNodes.get(0).name);
// Memoized should always return the same object
assertSame(classNodes, supplier.get());
}
use of org.objectweb.asm.tree.ClassNode in project buck by facebook.
the class FirstOrderHelper method addDependencies.
private ImmutableSet<String> addDependencies(Iterable<ClassNode> allClasses) {
for (ClassNode classNode : allClasses) {
FirstOrderVisitorContext context = new FirstOrderVisitorContext();
classNode.accept(context.classVisitor);
FirstOrderTypeInfo info = context.builder.build();
knownTypes.put(info.type, info);
}
for (Type type : scenarioTypes) {
addFirstOrderTypes(type);
}
return resultBuilder.build();
}
use of org.objectweb.asm.tree.ClassNode in project buck by facebook.
the class DxAnalysisMain method loadAllClasses.
private static ImmutableMap<String, ClassNode> loadAllClasses(String zipFileName) throws IOException {
ImmutableMap.Builder<String, ClassNode> allClassesBuilder = ImmutableMap.builder();
try (ZipFile inJar = new ZipFile(zipFileName)) {
for (ZipEntry entry : Collections.list(inJar.entries())) {
if (!entry.getName().endsWith(".class")) {
continue;
}
// Skip external libraries.
if (entry.getName().startsWith("junit/") || entry.getName().startsWith("org/junit/") || entry.getName().startsWith("com/google/common/")) {
continue;
}
byte[] rawClass = ByteStreams.toByteArray(inJar.getInputStream(entry));
ClassNode klass = new ClassNode();
new ClassReader(rawClass).accept(klass, ClassReader.EXPAND_FRAMES);
allClassesBuilder.put(klass.name, klass);
}
}
return allClassesBuilder.build();
}
use of org.objectweb.asm.tree.ClassNode in project buck by facebook.
the class MutabilityAnalyzer method markClassAsHavingMutableDescendents.
private void markClassAsHavingMutableDescendents(String className) {
if (classesWithMutableDescendents.contains(className)) {
return;
}
ClassNode klass = allClasses.get(className);
if (klass == null) {
return;
}
classesWithMutableDescendents.add(className);
madeProgress = true;
markClassAsHavingMutableDescendents(klass.superName);
for (String iface : klass.interfaces) {
markClassAsHavingMutableDescendents(iface);
}
}
use of org.objectweb.asm.tree.ClassNode in project buck by facebook.
the class StaticStateAnalyzer method go.
private void go() {
ImmutableSet.Builder<String> unsafeClassesBuilder = ImmutableSet.builder();
for (ClassNode klass : allClasses.values()) {
boolean classIsSafe = isClassSafe(klass);
if (!classIsSafe) {
unsafeClassesBuilder.add(klass.name);
}
}
unsafeClasses = unsafeClassesBuilder.build();
}
Aggregations