Search in sources :

Example 6 with ClassReader

use of jodd.asm5.ClassReader in project tomee by apache.

the class AnnotationFinder method readClassDef.

private void readClassDef(String className, final ClassVisitor visitor) {
    classes++;
    if (!className.endsWith(".class")) {
        className = className.replace('.', '/') + ".class";
    }
    try {
        final URL resource = classLoader.getResource(className);
        if (resource != null) {
            InputStream in = resource.openStream();
            in = new BufferedInputStream(in);
            try {
                final ClassReader classReader = new ClassReader(in);
                classReader.accept(visitor, ASM_FLAGS);
            } finally {
                in.close();
            }
        } else {
            new Exception("Could not load " + className).printStackTrace();
        }
    } catch (final IOException e) {
        e.printStackTrace();
    }
}
Also used : BufferedInputStream(java.io.BufferedInputStream) BufferedInputStream(java.io.BufferedInputStream) JarInputStream(java.util.jar.JarInputStream) InputStream(java.io.InputStream) ClassReader(org.apache.xbean.asm5.ClassReader) IOException(java.io.IOException) URL(java.net.URL) URISyntaxException(java.net.URISyntaxException) IOException(java.io.IOException)

Example 7 with ClassReader

use of jodd.asm5.ClassReader in project tomee by apache.

the class DynamicSubclass method copyMethodAnnotations.

private static void copyMethodAnnotations(final Class<?> classToProxy, final Map<String, MethodVisitor> visitors) throws ProxyGenerationException {
    // Move all the annotations onto the newly implemented methods
    // Ensures CDI and JAX-RS and JAX-WS still work
    Class clazz = classToProxy;
    while (clazz != null && !clazz.equals(Object.class)) {
        try {
            final ClassReader classReader = new ClassReader(readClassFile(clazz));
            final ClassVisitor copyMethodAnnotations = new CopyMethodAnnotations(visitors);
            classReader.accept(copyMethodAnnotations, ClassReader.SKIP_CODE);
        } catch (final IOException e) {
            throw new ProxyGenerationException(e);
        }
        clazz = clazz.getSuperclass();
    }
}
Also used : ProxyGenerationException(org.apache.openejb.util.proxy.ProxyGenerationException) ClassReader(org.apache.xbean.asm5.ClassReader) ClassVisitor(org.apache.xbean.asm5.ClassVisitor) IOException(java.io.IOException)

Example 8 with ClassReader

use of jodd.asm5.ClassReader in project tomee by apache.

the class ValidationKeysAuditorTest method file.

private static void file(final File file, final KeysAnnotationVisitor visitor) {
    try {
        final InputStream in = IO.read(file);
        try {
            final ClassReader classReader = new ClassReader(in);
            classReader.accept(visitor, ClassWriter.COMPUTE_FRAMES);
        } finally {
            IO.close(in);
        }
    } catch (final IOException e) {
        e.printStackTrace();
    }
}
Also used : InputStream(java.io.InputStream) ClassReader(org.apache.xbean.asm5.ClassReader) IOException(java.io.IOException)

Example 9 with ClassReader

use of jodd.asm5.ClassReader in project tomee by apache.

the class JpaTest method addNewField.

public static byte[] addNewField(final byte[] origBytes) {
    final ClassWriter classWriter = new ClassWriter(ClassWriter.COMPUTE_FRAMES);
    final FieldAdderClassVisitor visitor = new FieldAdderClassVisitor(classWriter);
    final ClassReader classReader = new ClassReader(origBytes);
    classReader.accept(visitor, 0);
    return classWriter.toByteArray();
}
Also used : ClassReader(org.apache.xbean.asm5.ClassReader) ClassWriter(org.apache.xbean.asm5.ClassWriter)

Example 10 with ClassReader

use of jodd.asm5.ClassReader in project tomee by apache.

the class TempClassLoader method isEnum.

/**
 * Fast-parse the given class bytecode to determine if it is an
 * enum class.
 */
private static boolean isEnum(final byte[] bytes) {
    final IsEnumVisitor isEnumVisitor = new IsEnumVisitor();
    final ClassReader classReader = new ClassReader(bytes);
    classReader.accept(isEnumVisitor, ClassReader.SKIP_DEBUG);
    return isEnumVisitor.isEnum;
}
Also used : ClassReader(org.apache.xbean.asm5.ClassReader)

Aggregations

ClassReader (org.apache.xbean.asm5.ClassReader)11 IOException (java.io.IOException)9 InputStream (java.io.InputStream)7 ClassReader (jodd.asm5.ClassReader)4 URL (java.net.URL)2 JarEntry (java.util.jar.JarEntry)2 JarFile (java.util.jar.JarFile)2 ProxyGenerationException (org.apache.openejb.util.proxy.ProxyGenerationException)2 ClassVisitor (org.apache.xbean.asm5.ClassVisitor)2 Test (org.junit.Test)2 SoftReference (com.intellij.reference.SoftReference)1 BufferedInputStream (java.io.BufferedInputStream)1 Reference (java.lang.ref.Reference)1 WeakReference (java.lang.ref.WeakReference)1 Constructor (java.lang.reflect.Constructor)1 Method (java.lang.reflect.Method)1 URISyntaxException (java.net.URISyntaxException)1 ArrayList (java.util.ArrayList)1 HashSet (java.util.HashSet)1 JarInputStream (java.util.jar.JarInputStream)1