use of org.objectweb.asm.ClassReader in project cglib by cglib.
the class DebuggingClassWriter method toByteArray.
public byte[] toByteArray() {
return (byte[]) java.security.AccessController.doPrivileged(new java.security.PrivilegedAction() {
public Object run() {
byte[] b = ((ClassWriter) DebuggingClassWriter.super.cv).toByteArray();
if (debugLocation != null) {
String dirs = className.replace('.', File.separatorChar);
try {
new File(debugLocation + File.separatorChar + dirs).getParentFile().mkdirs();
File file = new File(new File(debugLocation), dirs + ".class");
OutputStream out = new BufferedOutputStream(new FileOutputStream(file));
try {
out.write(b);
} finally {
out.close();
}
if (traceCtor != null) {
file = new File(new File(debugLocation), dirs + ".asm");
out = new BufferedOutputStream(new FileOutputStream(file));
try {
ClassReader cr = new ClassReader(b);
PrintWriter pw = new PrintWriter(new OutputStreamWriter(out));
ClassVisitor tcv = (ClassVisitor) traceCtor.newInstance(new Object[] { null, pw });
cr.accept(tcv, 0);
pw.flush();
} finally {
out.close();
}
}
} catch (Exception e) {
throw new CodeGenerationException(e);
}
}
return b;
}
});
}
use of org.objectweb.asm.ClassReader in project cglib by cglib.
the class BridgeMethodResolver method resolveAll.
/**
* Finds all bridge methods that are being called with invokespecial &
* returns them.
*/
public Map resolveAll() {
Map resolved = new HashMap();
for (Iterator entryIter = declToBridge.entrySet().iterator(); entryIter.hasNext(); ) {
Map.Entry entry = (Map.Entry) entryIter.next();
Class owner = (Class) entry.getKey();
Set bridges = (Set) entry.getValue();
try {
new ClassReader(classLoader.getResourceAsStream(owner.getName().replace('.', '/') + ".class")).accept(new BridgedFinder(bridges, resolved), ClassReader.SKIP_FRAMES | ClassReader.SKIP_DEBUG);
} catch (IOException ignored) {
}
}
return resolved;
}
use of org.objectweb.asm.ClassReader in project cglib by cglib.
the class AbstractClassLoader method loadClass.
public Class loadClass(String name) throws ClassNotFoundException {
Class loaded = findLoadedClass(name);
if (loaded != null) {
if (loaded.getClassLoader() == this) {
return loaded;
}
//else reload with this class loader
}
if (!filter.accept(name)) {
return super.loadClass(name);
}
ClassReader r;
try {
java.io.InputStream is = classPath.getResourceAsStream(name.replace('.', '/') + ".class");
if (is == null) {
throw new ClassNotFoundException(name);
}
try {
r = new ClassReader(is);
} finally {
is.close();
}
} catch (IOException e) {
throw new ClassNotFoundException(name + ":" + e.getMessage());
}
try {
DebuggingClassWriter w = new DebuggingClassWriter(ClassWriter.COMPUTE_FRAMES);
getGenerator(r).generateClass(w);
byte[] b = w.toByteArray();
Class c = super.defineClass(name, b, 0, b.length, DOMAIN);
postProcess(c);
return c;
} catch (RuntimeException e) {
throw e;
} catch (Error e) {
throw e;
} catch (Exception e) {
throw new CodeGenerationException(e);
}
}
use of org.objectweb.asm.ClassReader 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.ClassReader in project buck by facebook.
the class FirstOrderTest method loadClassNode.
private static ClassNode loadClassNode(Class<?> input) {
try {
ClassReader reader = new ClassReader(input.getName());
ClassNode node = new ClassNode(Opcodes.ASM4);
reader.accept(node, ClassReader.SKIP_DEBUG | ClassReader.SKIP_FRAMES);
return node;
} catch (IOException e) {
throw new RuntimeException(e);
}
}
Aggregations