Search in sources :

Example 1 with SimpleVerifier

use of org.apache.tapestry5.internal.plastic.asm.tree.analysis.SimpleVerifier in project tapestry-5 by apache.

the class CheckClassAdapter method verify.

/**
 * Checks the given class.
 *
 * @param classReader the class to be checked.
 * @param loader a <code>ClassLoader</code> which will be used to load referenced classes. May be
 *     {@literal null}.
 * @param printResults whether to print the results of the bytecode verification.
 * @param printWriter where the results (or the stack trace in case of error) must be printed.
 */
public static void verify(final ClassReader classReader, final ClassLoader loader, final boolean printResults, final PrintWriter printWriter) {
    ClassNode classNode = new ClassNode();
    classReader.accept(new CheckClassAdapter(/*latest*/
    Opcodes.ASM10_EXPERIMENTAL, classNode, false) {
    }, ClassReader.SKIP_DEBUG);
    Type syperType = classNode.superName == null ? null : Type.getObjectType(classNode.superName);
    List<MethodNode> methods = classNode.methods;
    List<Type> interfaces = new ArrayList<>();
    for (String interfaceName : classNode.interfaces) {
        interfaces.add(Type.getObjectType(interfaceName));
    }
    for (MethodNode method : methods) {
        SimpleVerifier verifier = new SimpleVerifier(Type.getObjectType(classNode.name), syperType, interfaces, (classNode.access & Opcodes.ACC_INTERFACE) != 0);
        Analyzer<BasicValue> analyzer = new Analyzer<>(verifier);
        if (loader != null) {
            verifier.setClassLoader(loader);
        }
        try {
            analyzer.analyze(classNode.name, method);
        } catch (AnalyzerException e) {
            e.printStackTrace(printWriter);
        }
        if (printResults) {
            printAnalyzerResult(method, analyzer, printWriter);
        }
    }
    printWriter.flush();
}
Also used : ClassNode(org.apache.tapestry5.internal.plastic.asm.tree.ClassNode) AnalyzerException(org.apache.tapestry5.internal.plastic.asm.tree.analysis.AnalyzerException) SimpleVerifier(org.apache.tapestry5.internal.plastic.asm.tree.analysis.SimpleVerifier) ArrayList(java.util.ArrayList) Analyzer(org.apache.tapestry5.internal.plastic.asm.tree.analysis.Analyzer) BasicValue(org.apache.tapestry5.internal.plastic.asm.tree.analysis.BasicValue) Type(org.apache.tapestry5.internal.plastic.asm.Type) MethodNode(org.apache.tapestry5.internal.plastic.asm.tree.MethodNode)

Aggregations

ArrayList (java.util.ArrayList)1 Type (org.apache.tapestry5.internal.plastic.asm.Type)1 ClassNode (org.apache.tapestry5.internal.plastic.asm.tree.ClassNode)1 MethodNode (org.apache.tapestry5.internal.plastic.asm.tree.MethodNode)1 Analyzer (org.apache.tapestry5.internal.plastic.asm.tree.analysis.Analyzer)1 AnalyzerException (org.apache.tapestry5.internal.plastic.asm.tree.analysis.AnalyzerException)1 BasicValue (org.apache.tapestry5.internal.plastic.asm.tree.analysis.BasicValue)1 SimpleVerifier (org.apache.tapestry5.internal.plastic.asm.tree.analysis.SimpleVerifier)1