use of javax.tools.JavaFileObject in project neo4j by neo4j.
the class CompilationFailureException method source.
private static String source(List<? extends Diagnostic<?>> diagnostics) {
Set<JavaFileObject> sources = null;
for (Diagnostic<?> diagnostic : diagnostics) {
Object source = diagnostic.getSource();
if (source instanceof JavaFileObject) {
JavaFileObject file = (JavaFileObject) source;
if (file.getKind() == JavaFileObject.Kind.SOURCE) {
if (sources == null) {
sources = Collections.newSetFromMap(new IdentityHashMap<JavaFileObject, Boolean>());
}
sources.add(file);
}
}
}
if (sources == null) {
return "";
}
StringBuilder result = new StringBuilder();
for (JavaFileObject source : sources) {
int pos = result.length();
result.append("\nSource file ").append(source.getName()).append(":\n");
try {
CharSequence content = source.getCharContent(true);
result.append(String.format("%4d: ", 1));
for (int line = 1, i = 0; i < content.length(); i++) {
char c = content.charAt(i);
result.append(c);
if (c == '\n') {
result.append(String.format("%4d: ", ++line));
}
}
} catch (IOException e) {
result.setLength(pos);
}
}
return result.toString();
}
use of javax.tools.JavaFileObject in project neo4j by neo4j.
the class ProcedureProcessorTest method fails_if_procedure_primitive_input_type_is_not_supported.
@Test
public void fails_if_procedure_primitive_input_type_is_not_supported() {
JavaFileObject sproc = JavaFileObjectUtils.INSTANCE.procedureSource("invalid/bad_proc_input_type/BadPrimitiveInputSproc.java");
assert_().about(javaSource()).that(sproc).processedWith(processor).failsToCompile().withErrorCount(1).withErrorContaining("Unsupported parameter type <short> of procedure|function BadPrimitiveInputSproc#doSomething").in(sproc).onLine(32);
}
use of javax.tools.JavaFileObject in project neo4j by neo4j.
the class ProcedureProcessorTest method does_not_emit_warnings_if_context_injected_field_types_are_unsupported_when_context_warnings_disabled.
@Test
public void does_not_emit_warnings_if_context_injected_field_types_are_unsupported_when_context_warnings_disabled() {
JavaFileObject sproc = JavaFileObjectUtils.INSTANCE.procedureSource("invalid/bad_context_field/BadContextTypeSproc.java");
assert_().about(javaSource()).that(sproc).withCompilerOptions("-AIgnoreContextWarnings").processedWith(processor).compilesWithoutError().withWarningCount(1);
}
use of javax.tools.JavaFileObject in project neo4j by neo4j.
the class ProcedureProcessorTest method fails_if_context_injected_fields_have_wrong_modifiers.
@Test
public void fails_if_context_injected_fields_have_wrong_modifiers() {
JavaFileObject sproc = JavaFileObjectUtils.INSTANCE.procedureSource("invalid/bad_context_field/BadContextSproc.java");
UnsuccessfulCompilationClause unsuccessfulCompilationClause = assert_().about(javaSource()).that(sproc).processedWith(processor).failsToCompile().withErrorCount(4);
unsuccessfulCompilationClause.withErrorContaining("@org.neo4j.procedure.Context usage error: field BadContextSproc#shouldBeNonStatic should be public, non-static and non-final").in(sproc).onLine(30);
unsuccessfulCompilationClause.withErrorContaining("@org.neo4j.procedure.Context usage error: field BadContextSproc#shouldBeNonFinal should be public, non-static and non-final").in(sproc).onLine(33);
unsuccessfulCompilationClause.withErrorContaining("@org.neo4j.procedure.Context usage error: field BadContextSproc#shouldBePublic should be public, non-static and non-final").in(sproc).onLine(37);
unsuccessfulCompilationClause.withErrorContaining("Field BadContextSproc#shouldBeStatic should be static").in(sproc).onLine(38);
}
use of javax.tools.JavaFileObject in project neo4j by neo4j.
the class ProcedureProcessorTest method fails_if_procedure_class_has_no_public_no_arg_constructor.
@Test
public void fails_if_procedure_class_has_no_public_no_arg_constructor() {
JavaFileObject procedure = JavaFileObjectUtils.INSTANCE.procedureSource("invalid/missing_constructor/MissingConstructorProcedure.java");
assert_().about(javaSource()).that(procedure).processedWith(processor).failsToCompile().withErrorCount(1).withErrorContaining("Procedure class org.neo4j.tooling.procedure.procedures.invalid.missing_constructor.MissingConstructorProcedure should contain a public no-arg constructor, none found.").in(procedure).onLine(24);
}
Aggregations