use of net.bytebuddy.jar.asm.ClassReader in project powermock by powermock.
the class DefinalizingClassTransformer method transform.
public byte[] transform(ClassLoader loader, String className, Class<?> classBeingRedefined, ProtectionDomain protectionDomain, byte[] classfileBuffer) {
if (loader == null || shouldIgnore(className)) {
return null;
}
final ClassReader reader = new ClassReader(classfileBuffer);
final ClassWriter writer = new ClassWriter(NO_FLAGS_OR_OPTIONS);
reader.accept(new DefinalizingClassVisitor(writer), NO_FLAGS_OR_OPTIONS);
return writer.toByteArray();
}
use of net.bytebuddy.jar.asm.ClassReader in project flow by vaadin.
the class FrontendAnnotatedClassVisitor method visitClass.
/**
* Visit recursively a class to find annotations.
*
* @param name
* the class name
* @param visitor
* the visitor to use
* @throws UncheckedIOException
* when the class name is not found
*/
public void visitClass(String name, ClassVisitor visitor) {
if (name == null) {
return;
}
try {
URL url = finder.getResource(name.replace(".", "/") + ".class");
try (InputStream is = url.openStream()) {
ClassReader cr = new ClassReader(is);
cr.accept(visitor, 0);
}
} catch (IOException e) {
throw new UncheckedIOException(e);
}
}
use of net.bytebuddy.jar.asm.ClassReader in project flow by vaadin.
the class FrontendDependencies method visitClass.
/**
* Recursive method for visiting class names using bytecode inspection.
*
* @param className
* @param endPoint
* @return
* @throws IOException
*/
private EndPointData visitClass(String className, EndPointData endPoint, boolean themeScope) throws IOException {
// sorting, #5729)
if (!isVisitable(className) || (!themeScope && endPoint.getClasses().contains(className))) {
return endPoint;
}
endPoint.getClasses().add(className);
URL url = getUrl(className);
if (url == null) {
return endPoint;
}
FrontendClassVisitor visitor = new FrontendClassVisitor(className, endPoint, themeScope);
try (InputStream is = url.openStream()) {
ClassReader cr = new ClassReader(is);
cr.accept(visitor, ClassReader.EXPAND_FRAMES);
} catch (Exception e) {
log().error("Visiting class {} failed with {}.\nThis might be a broken class in the project.", className, e.getMessage());
throw e;
}
// all classes visited by the scanner, used for performance (#5933)
visited.add(className);
for (String clazz : visitor.getChildren()) {
// chunks, this will need to be considered.
if (!visited.contains(clazz)) {
visitClass(clazz, endPoint, themeScope);
}
}
return endPoint;
}
Aggregations