Search in sources :

Example 1 with ClassReader

use of org.apache.xbean.asm5.ClassReader in project jodd by oblac.

the class TargetClassInfoReader method visitEnd.

/**
	 * Stores signatures for all super public methods not already overridden by target class.
	 * All this methods will be accepted for proxyfication.
	 */
@Override
public void visitEnd() {
    // prepare class annotations
    if (classAnnotations != null) {
        annotations = classAnnotations.toArray(new AnnotationInfo[classAnnotations.size()]);
        classAnnotations = null;
    }
    List<String> superList = new ArrayList<>();
    Set<String> allInterfaces = new HashSet<>();
    if (nextInterfaces != null) {
        allInterfaces.addAll(nextInterfaces);
    }
    // check all public super methods that are not overridden in superclass
    while (nextSupername != null) {
        InputStream inputStream = null;
        ClassReader cr = null;
        try {
            inputStream = ClassLoaderUtil.getClassAsStream(nextSupername, classLoader);
            cr = new ClassReader(inputStream);
        } catch (IOException ioex) {
            throw new ProxettaException("Unable to inspect super class: " + nextSupername, ioex);
        } finally {
            StreamUtil.close(inputStream);
        }
        superList.add(nextSupername);
        // remember the super class reader
        superClassReaders.add(cr);
        cr.accept(new SuperClassVisitor(), 0);
        if (cr.getInterfaces() != null) {
            Collections.addAll(allInterfaces, cr.getInterfaces());
        }
    }
    superClasses = superList.toArray(new String[superList.size()]);
    // check all interface methods that are not overridden in super-interface
    for (String next : allInterfaces) {
        InputStream inputStream = null;
        ClassReader cr = null;
        try {
            inputStream = ClassLoaderUtil.getClassAsStream(next, classLoader);
            cr = new ClassReader(inputStream);
        } catch (IOException ioex) {
            throw new ProxettaException("Unable to inspect super interface: " + next, ioex);
        } finally {
            StreamUtil.close(inputStream);
        }
        // remember the super class reader
        superClassReaders.add(cr);
        cr.accept(new SuperClassVisitor(), 0);
    }
}
Also used : ProxettaException(jodd.proxetta.ProxettaException) InputStream(java.io.InputStream) ArrayList(java.util.ArrayList) ClassReader(jodd.asm5.ClassReader) IOException(java.io.IOException) AnnotationInfo(jodd.proxetta.AnnotationInfo) HashSet(java.util.HashSet)

Example 2 with ClassReader

use of org.apache.xbean.asm5.ClassReader in project jodd by oblac.

the class ProxettaBuilder method process.

/**
	 * Reads the target and creates destination class.
	 */
protected void process() {
    if (targetInputStream == null) {
        throw new ProxettaException("Target missing");
    }
    // create class reader
    ClassReader classReader;
    try {
        classReader = new ClassReader(targetInputStream);
    } catch (IOException ioex) {
        throw new ProxettaException("Error reading class input stream", ioex);
    }
    // reads information
    TargetClassInfoReader targetClassInfoReader = new TargetClassInfoReader(proxetta.getClassLoader());
    classReader.accept(targetClassInfoReader, 0);
    this.destClassWriter = new ClassWriter(ClassWriter.COMPUTE_MAXS | ClassWriter.COMPUTE_FRAMES);
    // create proxy
    if (log.isDebugEnabled()) {
        log.debug("processing: " + classReader.getClassName());
    }
    WorkData wd = process(classReader, targetClassInfoReader);
    // store important data
    proxyApplied = wd.proxyApplied;
    proxyClassName = wd.thisReference.replace('/', '.');
}
Also used : TargetClassInfoReader(jodd.proxetta.asm.TargetClassInfoReader) ClassReader(jodd.asm5.ClassReader) IOException(java.io.IOException) WorkData(jodd.proxetta.asm.WorkData) ClassWriter(jodd.asm5.ClassWriter)

Example 3 with ClassReader

use of org.apache.xbean.asm5.ClassReader in project tomee by apache.

the class PersistenceContextAnnFactory method addAnnotations.

public void addAnnotations(final Class c) throws OpenEJBException {
    if (!useAsm) {
        return;
    }
    if (processed.contains(c.getName())) {
        return;
    }
    try {
        final URL u = c.getResource("/" + c.getName().replace('.', '/') + ".class");
        final ClassReader r = new ClassReader(IO.read(u));
        r.accept(new PersistenceContextReader(contexts), ClassReader.SKIP_DEBUG);
    } catch (final IOException e) {
        throw new OpenEJBException("Unable to read class " + c.getName());
    }
    processed.add(c.getName());
}
Also used : OpenEJBException(org.apache.openejb.OpenEJBException) ClassReader(org.apache.xbean.asm5.ClassReader) IOException(java.io.IOException) URL(java.net.URL)

Example 4 with ClassReader

use of org.apache.xbean.asm5.ClassReader in project tomee by apache.

the class TempClassLoader method isAnnotationClass.

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

Example 5 with ClassReader

use of org.apache.xbean.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)

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