Search in sources :

Example 1 with DecompiledClassNode

use of org.codehaus.groovy.ast.decompiled.DecompiledClassNode in project groovy-core by groovy.

the class ClassNodeResolver method findDecompiled.

/**
     * Search for classes using ASM decompiler
     */
private LookupResult findDecompiled(String name, CompilationUnit compilationUnit, GroovyClassLoader loader) {
    ClassNode node = ClassHelper.make(name);
    if (node.isResolved()) {
        return new LookupResult(null, node);
    }
    DecompiledClassNode asmClass = null;
    String fileName = name.replace('.', '/') + ".class";
    URL resource = loader.getResource(fileName);
    if (resource != null) {
        try {
            asmClass = new DecompiledClassNode(AsmDecompiler.parseClass(resource), new AsmReferenceResolver(this, compilationUnit));
            if (!asmClass.getName().equals(name)) {
                // this may happen under Windows because getResource is case insensitive under that OS!
                asmClass = null;
            }
        } catch (IOException e) {
        // fall through and attempt other search strategies
        }
    }
    if (asmClass != null) {
        if (isFromAnotherClassLoader(loader, fileName)) {
            return tryAsScript(name, compilationUnit, asmClass);
        }
        return new LookupResult(null, asmClass);
    }
    return null;
}
Also used : ClassNode(org.codehaus.groovy.ast.ClassNode) DecompiledClassNode(org.codehaus.groovy.ast.decompiled.DecompiledClassNode) DecompiledClassNode(org.codehaus.groovy.ast.decompiled.DecompiledClassNode) AsmReferenceResolver(org.codehaus.groovy.ast.decompiled.AsmReferenceResolver) IOException(java.io.IOException) URL(java.net.URL)

Example 2 with DecompiledClassNode

use of org.codehaus.groovy.ast.decompiled.DecompiledClassNode in project groovy by apache.

the class ClassNodeResolver method findDecompiled.

/**
     * Search for classes using ASM decompiler
     */
private LookupResult findDecompiled(String name, CompilationUnit compilationUnit, GroovyClassLoader loader) {
    ClassNode node = ClassHelper.make(name);
    if (node.isResolved()) {
        return new LookupResult(null, node);
    }
    DecompiledClassNode asmClass = null;
    String fileName = name.replace('.', '/') + ".class";
    URL resource = loader.getResource(fileName);
    if (resource != null) {
        try {
            asmClass = new DecompiledClassNode(AsmDecompiler.parseClass(resource), new AsmReferenceResolver(this, compilationUnit));
            if (!asmClass.getName().equals(name)) {
                // this may happen under Windows because getResource is case insensitive under that OS!
                asmClass = null;
            }
        } catch (IOException e) {
        // fall through and attempt other search strategies
        }
    }
    if (asmClass != null) {
        if (isFromAnotherClassLoader(loader, fileName)) {
            return tryAsScript(name, compilationUnit, asmClass);
        }
        return new LookupResult(null, asmClass);
    }
    return null;
}
Also used : ClassNode(org.codehaus.groovy.ast.ClassNode) DecompiledClassNode(org.codehaus.groovy.ast.decompiled.DecompiledClassNode) DecompiledClassNode(org.codehaus.groovy.ast.decompiled.DecompiledClassNode) AsmReferenceResolver(org.codehaus.groovy.ast.decompiled.AsmReferenceResolver) IOException(java.io.IOException) URL(java.net.URL)

Aggregations

IOException (java.io.IOException)2 URL (java.net.URL)2 ClassNode (org.codehaus.groovy.ast.ClassNode)2 AsmReferenceResolver (org.codehaus.groovy.ast.decompiled.AsmReferenceResolver)2 DecompiledClassNode (org.codehaus.groovy.ast.decompiled.DecompiledClassNode)2