Search in sources :

Example 1 with DebuggingClassWriter

use of org.powermock.api.mockito.repackaged.cglib.core.DebuggingClassWriter in project powermock by powermock.

the class AbstractClassLoader method loadClass.

public Class loadClass(String name) throws ClassNotFoundException {
    Class loaded = findLoadedClass(name);
    if (loaded != null) {
        if (loaded.getClassLoader() == this) {
            return loaded;
        }
    //else reload with this class loader
    }
    if (!filter.accept(name)) {
        return super.loadClass(name);
    }
    ClassReader r;
    try {
        java.io.InputStream is = classPath.getResourceAsStream(name.replace('.', '/') + ".class");
        if (is == null) {
            throw new ClassNotFoundException(name);
        }
        try {
            r = new ClassReader(is);
        } finally {
            is.close();
        }
    } catch (IOException e) {
        throw new ClassNotFoundException(name + ":" + e.getMessage());
    }
    try {
        ClassWriter w = new DebuggingClassWriter(ClassWriter.COMPUTE_MAXS);
        getGenerator(r).generateClass(w);
        byte[] b = w.toByteArray();
        Class c = super.defineClass(name, b, 0, b.length, DOMAIN);
        postProcess(c);
        return c;
    } catch (RuntimeException e) {
        throw e;
    } catch (Exception e) {
        throw new CodeGenerationException(e);
    }
}
Also used : DebuggingClassWriter(org.powermock.api.mockito.repackaged.cglib.core.DebuggingClassWriter) CodeGenerationException(org.powermock.api.mockito.repackaged.cglib.core.CodeGenerationException) ClassReader(org.powermock.api.mockito.repackaged.asm.ClassReader) IOException(java.io.IOException) ClassWriter(org.powermock.api.mockito.repackaged.asm.ClassWriter) DebuggingClassWriter(org.powermock.api.mockito.repackaged.cglib.core.DebuggingClassWriter) CodeGenerationException(org.powermock.api.mockito.repackaged.cglib.core.CodeGenerationException) IOException(java.io.IOException)

Aggregations

IOException (java.io.IOException)1 ClassReader (org.powermock.api.mockito.repackaged.asm.ClassReader)1 ClassWriter (org.powermock.api.mockito.repackaged.asm.ClassWriter)1 CodeGenerationException (org.powermock.api.mockito.repackaged.cglib.core.CodeGenerationException)1 DebuggingClassWriter (org.powermock.api.mockito.repackaged.cglib.core.DebuggingClassWriter)1