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 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.ClassReader in project semantic-versioning by jeluard.
the class ClassInheritanceTest method addClassInfo.
private void addClassInfo(Map<String, ClassInfo> classMap, Class klass, JarDiff jd) throws Exception {
ClassInfo classInfo = jd.loadClassInfo(new ClassReader(klass.getName()));
classMap.put(classInfo.getName(), classInfo);
}
Aggregations