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();
}
use of org.objectweb.asm.tree.ClassNode in project enumerable by hraberg.
the class LambdaExpressionTrees method findMethodNode.
@SuppressWarnings("unchecked")
static MethodNode findMethodNode(Method method) throws IOException {
String className = method.getDeclaringClass().getName();
ClassReader cr;
if (InMemoryCompiler.bytesByClassName.containsKey(className))
cr = new ClassReader(InMemoryCompiler.bytesByClassName.get(className));
else
cr = new ClassReader(className);
ClassNode cn = new ClassNode();
cr.accept(cn, 0);
String descriptor = getMethodDescriptor(method);
for (MethodNode mn : (List<MethodNode>) cn.methods) {
if (method.getName().equals(mn.name) && descriptor.equals(mn.desc))
return mn;
}
throw new IllegalStateException("Cannot find method which does exist");
}
use of org.objectweb.asm.tree.ClassNode in project MinecraftForge by MinecraftForge.
the class AccessTransformer method processJar.
private static void processJar(File inFile, File outFile, AccessTransformer[] transformers) throws IOException {
ZipInputStream inJar = null;
ZipOutputStream outJar = null;
try {
try {
inJar = new ZipInputStream(new BufferedInputStream(new FileInputStream(inFile)));
} catch (FileNotFoundException e) {
throw new FileNotFoundException("Could not open input file: " + e.getMessage());
}
try {
outJar = new ZipOutputStream(new BufferedOutputStream(new FileOutputStream(outFile)));
} catch (FileNotFoundException e) {
throw new FileNotFoundException("Could not open output file: " + e.getMessage());
}
ZipEntry entry;
while ((entry = inJar.getNextEntry()) != null) {
if (entry.isDirectory()) {
outJar.putNextEntry(entry);
continue;
}
byte[] data = new byte[4096];
ByteArrayOutputStream entryBuffer = new ByteArrayOutputStream();
int len;
do {
len = inJar.read(data);
if (len > 0) {
entryBuffer.write(data, 0, len);
}
} while (len != -1);
byte[] entryData = entryBuffer.toByteArray();
String entryName = entry.getName();
if (entryName.endsWith(".class") && !entryName.startsWith(".")) {
ClassNode cls = new ClassNode();
ClassReader rdr = new ClassReader(entryData);
rdr.accept(cls, 0);
String name = cls.name.replace('/', '.').replace('\\', '.');
for (AccessTransformer trans : transformers) {
entryData = trans.transform(name, name, entryData);
}
}
ZipEntry newEntry = new ZipEntry(entryName);
outJar.putNextEntry(newEntry);
outJar.write(entryData);
}
} finally {
IOUtils.closeQuietly(outJar);
IOUtils.closeQuietly(inJar);
}
}
use of org.objectweb.asm.tree.ClassNode in project MinecraftForge by MinecraftForge.
the class EventSubscriptionTransformer method transform.
@Override
public byte[] transform(String name, String transformedName, byte[] bytes) {
if (bytes == null || name.equals("net.minecraftforge.fml.common.eventhandler.Event") || name.startsWith("net.minecraft.") || name.indexOf('.') == -1) {
return bytes;
}
ClassReader cr = new ClassReader(bytes);
ClassNode classNode = new ClassNode();
cr.accept(classNode, 0);
try {
if (buildEvents(classNode)) {
ClassWriter cw = new ClassWriter(COMPUTE_FRAMES);
classNode.accept(cw);
return cw.toByteArray();
}
return bytes;
} catch (ClassNotFoundException ex) {
// Discard silently- it's just noise
} catch (Exception e) {
e.printStackTrace();
}
return bytes;
}
Aggregations