Search in sources :

Example 1 with ByteCodes

use of org.neo4j.codegen.ByteCodes in project neo4j by neo4j.

the class ByteCodeVerifier method check.

/**
     * Check the bytecode from one round of bytecode generation.
     *
     * @param classpathLoader
     *         the ClassLoader to use for loading classes from the classpath.
     * @param byteCodes
     *         the bytecodes generated in this round.
     * @throws CompilationFailureException
     *         if any issue is discovered in the verification.
     */
@Override
public void check(ClassLoader classpathLoader, Collection<ByteCodes> byteCodes) throws CompilationFailureException {
    List<ClassNode> classes = new ArrayList<>(byteCodes.size());
    List<Failure> failures = new ArrayList<>();
    // load (and verify) the structure of the generated classes
    for (ByteCodes byteCode : byteCodes) {
        try {
            classes.add(classNode(byteCode.bytes()));
        } catch (Exception e) {
            failures.add(new Failure(e, e.toString()));
        }
    }
    // we are not going to be able to verify their methods
    if (!failures.isEmpty()) {
        throw compilationFailure(failures);
    }
    // continue with verifying the methods of the classes
    AssignmentChecker check = new AssignmentChecker(classpathLoader, classes);
    for (ClassNode clazz : classes) {
        verify(check, clazz, failures);
    }
    if (!failures.isEmpty()) {
        throw compilationFailure(failures);
    }
}
Also used : ClassNode(org.objectweb.asm.tree.ClassNode) ArrayList(java.util.ArrayList) ByteCodes(org.neo4j.codegen.ByteCodes) AnalyzerException(org.objectweb.asm.tree.analysis.AnalyzerException) CompilationFailureException(org.neo4j.codegen.CompilationFailureException)

Aggregations

ArrayList (java.util.ArrayList)1 ByteCodes (org.neo4j.codegen.ByteCodes)1 CompilationFailureException (org.neo4j.codegen.CompilationFailureException)1 ClassNode (org.objectweb.asm.tree.ClassNode)1 AnalyzerException (org.objectweb.asm.tree.analysis.AnalyzerException)1