Search in sources :

Example 51 with JavaFileObject

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();
}
Also used : JavaFileObject(javax.tools.JavaFileObject) IdentityHashMap(java.util.IdentityHashMap) JavaFileObject(javax.tools.JavaFileObject) IOException(java.io.IOException)

Example 52 with JavaFileObject

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);
}
Also used : JavaFileObject(javax.tools.JavaFileObject) Test(org.junit.Test)

Example 53 with JavaFileObject

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);
}
Also used : JavaFileObject(javax.tools.JavaFileObject) Test(org.junit.Test)

Example 54 with JavaFileObject

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);
}
Also used : JavaFileObject(javax.tools.JavaFileObject) UnsuccessfulCompilationClause(com.google.testing.compile.CompileTester.UnsuccessfulCompilationClause) Test(org.junit.Test)

Example 55 with JavaFileObject

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);
}
Also used : JavaFileObject(javax.tools.JavaFileObject) Test(org.junit.Test)

Aggregations

JavaFileObject (javax.tools.JavaFileObject)663 Test (org.junit.Test)473 ButterKnifeProcessor (butterknife.compiler.ButterKnifeProcessor)121 IOException (java.io.IOException)52 JavaCompiler (javax.tools.JavaCompiler)40 StorIOContentResolverProcessor (com.pushtorefresh.storio.contentresolver.annotations.processor.StorIOContentResolverProcessor)38 StorIOSQLiteProcessor (com.pushtorefresh.storio.sqlite.annotations.processor.StorIOSQLiteProcessor)35 File (java.io.File)32 Diagnostic (javax.tools.Diagnostic)30 DiagnosticCollector (javax.tools.DiagnosticCollector)28 SimpleJavaFileObject (javax.tools.SimpleJavaFileObject)25 StandardJavaFileManager (javax.tools.StandardJavaFileManager)25 ArrayList (java.util.ArrayList)24 TypeElement (javax.lang.model.element.TypeElement)21 Result (com.sun.tools.javac.main.Main.Result)20 Writer (java.io.Writer)17 PrintWriter (java.io.PrintWriter)16 CompilationTask (javax.tools.JavaCompiler.CompilationTask)14 JCTree (com.sun.tools.javac.tree.JCTree)10 StringWriter (java.io.StringWriter)10