Search in sources :

Example 1 with ClassReader

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();
}
Also used : ClassReader(net.bytebuddy.jar.asm.ClassReader) ClassWriter(net.bytebuddy.jar.asm.ClassWriter)

Example 2 with ClassReader

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);
    }
}
Also used : InputStream(java.io.InputStream) ClassReader(net.bytebuddy.jar.asm.ClassReader) UncheckedIOException(java.io.UncheckedIOException) IOException(java.io.IOException) UncheckedIOException(java.io.UncheckedIOException) URL(java.net.URL)

Example 3 with ClassReader

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;
}
Also used : InputStream(java.io.InputStream) ClassReader(net.bytebuddy.jar.asm.ClassReader) URL(java.net.URL) IOException(java.io.IOException)

Aggregations

ClassReader (net.bytebuddy.jar.asm.ClassReader)3 IOException (java.io.IOException)2 InputStream (java.io.InputStream)2 URL (java.net.URL)2 UncheckedIOException (java.io.UncheckedIOException)1 ClassWriter (net.bytebuddy.jar.asm.ClassWriter)1