use of org.neo4j.codegen.CompilationFailureException in project neo4j by neo4j.
the class ByteCodeVerifier method compilationFailure.
private static CompilationFailureException compilationFailure(List<Failure> failures) {
List<Diagnostic<?>> diagnostics = new ArrayList<>(failures.size());
for (Failure failure : failures) {
diagnostics.add(new BytecodeDiagnostic(failure.message));
}
CompilationFailureException exception = new CompilationFailureException(diagnostics);
for (Failure failure : failures) {
exception.addSuppressed(failure.cause);
}
return exception;
}
use of org.neo4j.codegen.CompilationFailureException 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);
}
}
use of org.neo4j.codegen.CompilationFailureException in project neo4j by neo4j.
the class ByteCodeVerifierTest method shouldVerifyBytecode.
@Test
public void shouldVerifyBytecode() throws Throwable {
// given
CodeGenerator generator = generateCode(BYTECODE, VERIFY_GENERATED_BYTECODE);
ClassHandle handle;
try (ClassGenerator clazz = generator.generateClass(PACKAGE, "SimpleClass");
CodeBlock code = clazz.generateMethod(Integer.class, "box", param(int.class, "value"))) {
handle = clazz.handle();
code.returns(code.load("value"));
}
// when
try {
handle.loadClass();
fail("Should have thrown exception");
}// then
catch (CompilationFailureException expected) {
assertThat(expected.toString(), containsString("box(I)"));
}
}
Aggregations