Search in sources :

Example 46 with JavaFileObject

use of javax.tools.JavaFileObject in project epoxy by airbnb.

the class ConfigTest method testConfigRequireHashCodeIterableFails.

@Test
public void testConfigRequireHashCodeIterableFails() {
    JavaFileObject model = forResource("ModelRequiresHashCodeIterableFails.java");
    assert_().about(javaSources()).that(asList(CONFIG_CLASS_REQUIRE_HASH, model)).processedWith(new EpoxyProcessor()).failsToCompile().withErrorContaining("Type in Iterable does not implement hashCode");
}
Also used : JavaFileObject(javax.tools.JavaFileObject) Test(org.junit.Test)

Example 47 with JavaFileObject

use of javax.tools.JavaFileObject in project epoxy by airbnb.

the class EpoxyProcessorTest method testModelWithFinalClassFails.

@Test
public void testModelWithFinalClassFails() {
    JavaFileObject model = JavaFileObjects.forResource("ModelWithFinalClass.java");
    assert_().about(javaSource()).that(model).processedWith(new EpoxyProcessor()).failsToCompile();
}
Also used : JavaFileObject(javax.tools.JavaFileObject) Test(org.junit.Test)

Example 48 with JavaFileObject

use of javax.tools.JavaFileObject in project immutables by immutables.

the class Processor method generateTemplateType.

private void generateTemplateType(TypeElement templateType) throws IOException, Exception {
    SwissArmyKnife knife = new SwissArmyKnife(processingEnv, templateType);
    String string = readTemplateResource(templateType, knife);
    Unit unit = parseUnit(string);
    Unit resolved = transformUnit(knife, unit);
    TemplateWriter writingTransformer = new TemplateWriter(knife, templateType, GeneratedTypes.getSimpleName(templateType));
    CharSequence template = writingTransformer.toCharSequence(resolved);
    JavaFileObject templateFile = knife.environment.getFiler().createSourceFile(GeneratedTypes.getQualifiedName(knife.elements, templateType), templateType);
    try (Writer writer = templateFile.openWriter()) {
        writer.append(template);
    }
}
Also used : JavaFileObject(javax.tools.JavaFileObject) Unit(org.immutables.generator.processor.ImmutableTrees.Unit) Writer(java.io.Writer)

Example 49 with JavaFileObject

use of javax.tools.JavaFileObject in project jsonschema2pojo by joelittlejohn.

the class CompilerWarningIT method checkWarnings.

@Test
public void checkWarnings() {
    schemaRule.generate(schema, "com.example", config);
    schemaRule.compile(compiler, new NullWriter(), new ArrayList<File>(), config);
    List<Diagnostic<? extends JavaFileObject>> warnings = warnings(schemaRule.getDiagnostics());
    assertThat(warnings, matcher);
}
Also used : JavaFileObject(javax.tools.JavaFileObject) Diagnostic(javax.tools.Diagnostic) File(java.io.File) NullWriter(org.apache.commons.io.output.NullWriter) Test(org.junit.Test)

Example 50 with JavaFileObject

use of javax.tools.JavaFileObject in project jsonschema2pojo by joelittlejohn.

the class Jsonschema2PojoRule method apply.

@Override
public Statement apply(final Statement base, final Description description) {
    return new Statement() {

        @Override
        public void evaluate() throws Throwable {
            active = true;
            diagnostics = new ArrayList<Diagnostic<? extends JavaFileObject>>();
            boolean captureDiagnosticsStart = captureDiagnostics;
            try {
                File testRoot = methodNameDir(classNameDir(rootDirectory(), description.getClassName()), description.getMethodName());
                generateDir = new File(testRoot, "generate");
                compileDir = new File(testRoot, "compile");
                base.evaluate();
            } finally {
                generateDir = null;
                compileDir = null;
                classLoader = null;
                sourceDirInitialized = false;
                classesDirInitialized = false;
                captureDiagnostics = captureDiagnosticsStart;
                diagnostics = null;
                active = false;
            }
        }
    };
}
Also used : JavaFileObject(javax.tools.JavaFileObject) Statement(org.junit.runners.model.Statement) Diagnostic(javax.tools.Diagnostic) File(java.io.File)

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