Search in sources :

Example 6 with net.sf.cglib.asm.$ClassReader

use of net.sf.cglib.asm.$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 7 with net.sf.cglib.asm.$ClassReader

use of net.sf.cglib.asm.$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 8 with net.sf.cglib.asm.$ClassReader

use of net.sf.cglib.asm.$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 9 with net.sf.cglib.asm.$ClassReader

use of net.sf.cglib.asm.$ClassReader in project geronimo-xbean by apache.

the class XbeanAsmParameterNameLoader method createClassReader.

private static ClassReader createClassReader(Class declaringClass) throws IOException {
    InputStream in = null;
    try {
        ClassLoader classLoader = declaringClass.getClassLoader();
        in = classLoader.getResourceAsStream(declaringClass.getName().replace('.', '/') + ".class");
        ClassReader reader = new ClassReader(in);
        return reader;
    } finally {
        if (in != null) {
            try {
                in.close();
            } catch (IOException ignored) {
            }
        }
    }
}
Also used : InputStream(java.io.InputStream) ClassReader(org.apache.xbean.asm6.ClassReader) IOException(java.io.IOException)

Example 10 with net.sf.cglib.asm.$ClassReader

use of net.sf.cglib.asm.$ClassReader in project apex-core by apache.

the class FastClassIndexReaderTest method testIndexReader.

@Test
public void testIndexReader() throws IOException {
    String javahome = System.getProperty("java.home");
    String jdkJar = javahome + "/lib/rt.jar";
    JarFile jar = new JarFile(jdkJar);
    java.util.Enumeration<JarEntry> entriesEnum = jar.entries();
    while (entriesEnum.hasMoreElements()) {
        JarEntry jarEntry = entriesEnum.nextElement();
        if (jarEntry.getName().endsWith("class")) {
            InputStream ins = jar.getInputStream(jarEntry);
            ClassReader classReader = new ClassReader(ins);
            ClassNodeType classN = new ClassNodeType();
            classReader.accept(classN, ClassReader.SKIP_CODE);
            CompactClassNode ccn = CompactUtil.compactClassNode(classN);
            ins.close();
            ins = jar.getInputStream(jarEntry);
            FastClassIndexReader fastClassIndexReader = new FastClassIndexReader(ins);
            Assert.assertEquals("The wrong class is " + classN.name, classN.name, fastClassIndexReader.getName());
            Assert.assertEquals("The wrong class is " + classN.name, classN.superName, fastClassIndexReader.getSuperName());
            Assert.assertEquals("The wrong class is " + classN.name, !ASMUtil.isAbstract(classN.access) && ASMUtil.isPublic(classN.access) && ccn.getDefaultConstructor() != null, fastClassIndexReader.isInstantiable());
            Assert.assertArrayEquals("The wrong class is " + classN.name, classN.interfaces.toArray(), fastClassIndexReader.getInterfaces());
        }
    }
}
Also used : InputStream(java.io.InputStream) ClassReader(org.apache.xbean.asm5.ClassReader) JarFile(java.util.jar.JarFile) JarEntry(java.util.jar.JarEntry) Test(org.junit.Test)

Aggregations

IOException (java.io.IOException)15 InputStream (java.io.InputStream)12 ClassReader (org.apache.xbean.asm5.ClassReader)11 ClassReader (org.apache.xbean.asm6.ClassReader)8 JarEntry (java.util.jar.JarEntry)5 ClassReader (jodd.asm5.ClassReader)4 File (java.io.File)3 FileInputStream (java.io.FileInputStream)3 FileOutputStream (java.io.FileOutputStream)3 ArrayList (java.util.ArrayList)3 HashMap (java.util.HashMap)3 List (java.util.List)3 Optional.ofNullable (java.util.Optional.ofNullable)3 JarOutputStream (java.util.jar.JarOutputStream)3 Stream (java.util.stream.Stream)3 EXPAND_FRAMES (org.apache.xbean.asm6.ClassReader.EXPAND_FRAMES)3 ClassWriter (org.apache.xbean.asm6.ClassWriter)3 COMPUTE_FRAMES (org.apache.xbean.asm6.ClassWriter.COMPUTE_FRAMES)3 ClassRemapper (org.apache.xbean.asm6.commons.ClassRemapper)3 Remapper (org.apache.xbean.asm6.commons.Remapper)3