Search in sources :

Example 21 with JavaFileObject

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

the class DeepLinkProcessorTest method uppercasePackage.

@Test
public void uppercasePackage() {
    JavaFileObject activityWithUppercasePackage = JavaFileObjects.forSourceString("SampleActivity", "package com.Example;" + "import com.airbnb.deeplinkdispatch.DeepLink;\n" + "import com.airbnb.deeplinkdispatch.DeepLinkHandler;\n\n" + "import com.Example.SampleModule;\n\n" + "@DeepLink(\"airbnb://example.com/deepLink\")" + "@DeepLinkHandler({ SampleModule.class })\n" + "public class SampleActivity {\n" + "}");
    JavaFileObject module = JavaFileObjects.forSourceString("SampleModule", "package com.Example;" + "import com.airbnb.deeplinkdispatch.DeepLinkModule;\n\n" + "@DeepLinkModule\n" + "public class SampleModule {\n" + "}");
    assertAbout(javaSources()).that(Arrays.asList(module, activityWithUppercasePackage)).processedWith(new DeepLinkProcessor()).compilesWithoutError().and().generatesSources(JavaFileObjects.forSourceString("/SOURCE_OUTPUT.com.Example.SampleModuleLoader", "package com.Example;\n" + "\n" + "import com.airbnb.deeplinkdispatch.DeepLinkEntry;\n" + "import com.airbnb.deeplinkdispatch.Parser;\n" + "import java.lang.Override;\n" + "import java.lang.String;\n" + "import java.util.Arrays;\n" + "import java.util.Collections;\n" + "import java.util.List;\n" + "\n" + "public final class SampleModuleLoader implements Parser {\n" + "  public static final List<DeepLinkEntry> REGISTRY = " + "Collections.unmodifiableList(Arrays.asList(" + "new DeepLinkEntry(\"airbnb://example.com/deepLink\", DeepLinkEntry.Type" + ".CLASS, SampleActivity.class, null)));\n" + "\n" + "  @Override" + "  public DeepLinkEntry parseUri(String uri) {\n" + "    for (DeepLinkEntry entry : REGISTRY) {\n" + "      if (entry.matches(uri)) {\n" + "        return entry;\n" + "      }\n" + "    }\n" + "    return null;\n" + "  }\n" + "}"));
}
Also used : JavaFileObject(javax.tools.JavaFileObject) Test(org.junit.Test)

Example 22 with JavaFileObject

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

the class DeepLinkProcessorTest method testProcessor.

@Test
public void testProcessor() {
    JavaFileObject sampleActivity = JavaFileObjects.forSourceString("SampleActivity", "package com.example;" + "import com.airbnb.deeplinkdispatch.DeepLink;\n" + "import com.airbnb.deeplinkdispatch.DeepLinkHandler;\n\n" + "import com.example.SampleModule;\n\n" + "@DeepLink(\"airbnb://example.com/deepLink\")\n" + "@DeepLinkHandler({ SampleModule.class })\n" + "public class SampleActivity {\n" + "}");
    JavaFileObject module = JavaFileObjects.forSourceString("SampleModule", "package com.example;" + "import com.airbnb.deeplinkdispatch.DeepLinkModule;\n\n" + "@DeepLinkModule\n" + "public class SampleModule {\n" + "}");
    assertAbout(javaSources()).that(Arrays.asList(module, sampleActivity)).processedWith(new DeepLinkProcessor()).compilesWithoutError().and().generatesSources(JavaFileObjects.forResource("DeepLinkDelegate.java"), JavaFileObjects.forSourceString("/SOURCE_OUTPUT.com.example.SampleModuleLoader", "package com.example;\n" + "\n" + "import com.airbnb.deeplinkdispatch.DeepLinkEntry;\n" + "import com.airbnb.deeplinkdispatch.Parser;\n" + "import java.lang.Override;\n" + "import java.lang.String;\n" + "import java.util.Arrays;\n" + "import java.util.Collections;\n" + "import java.util.List;\n" + "\n" + "public final class SampleModuleLoader implements Parser {\n" + "  public static final List<DeepLinkEntry> REGISTRY = " + "Collections.unmodifiableList(Arrays.asList(" + "new DeepLinkEntry(\"airbnb://example.com/deepLink\", DeepLinkEntry.Type" + ".CLASS, SampleActivity.class, null)));\n" + "\n" + "  @Override" + "  public DeepLinkEntry parseUri(String uri) {\n" + "    for (DeepLinkEntry entry : REGISTRY) {\n" + "      if (entry.matches(uri)) {\n" + "        return entry;\n" + "      }\n" + "    }\n" + "    return null;\n" + "  }\n" + "}"));
}
Also used : JavaFileObject(javax.tools.JavaFileObject) Test(org.junit.Test)

Example 23 with JavaFileObject

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

the class DeepLinkProcessorTest method testProcessorWithEmptyCustomPrefixFail.

@Test
public void testProcessorWithEmptyCustomPrefixFail() {
    JavaFileObject emptyPrefixLink = JavaFileObjects.forSourceString("MyDeepLink", "package com.example;\n" + "import com.airbnb.deeplinkdispatch.DeepLinkSpec;\n" + "@DeepLinkSpec(prefix = { \"http://\", \"\" })\n" + "public @interface MyDeepLink {\n" + "    String[] value();\n" + "}");
    assertAbout(javaSources()).that(Arrays.asList(emptyPrefixLink, SIMPLE_DEEPLINK_ACTIVITY, SIMPLE_DEEPLINK_MODULE)).processedWith(new DeepLinkProcessor()).failsToCompile().withErrorContaining("Prefix property cannot have null or empty strings");
}
Also used : JavaFileObject(javax.tools.JavaFileObject) Test(org.junit.Test)

Example 24 with JavaFileObject

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

the class EpoxyProcessorTest method testModelThatDoesNotExtendEpoxyModelFails.

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

Example 25 with JavaFileObject

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

the class EpoxyProcessorTest method testGeneratedDefaultMethodWithLayoutSpecifiedInParent.

@Test
public void testGeneratedDefaultMethodWithLayoutSpecifiedInParent() {
    JavaFileObject model = JavaFileObjects.forResource("GenerateDefaultLayoutMethodParentLayout.java");
    JavaFileObject generatedNoLayoutModel = JavaFileObjects.forResource("GenerateDefaultLayoutMethodParentLayout$NoLayout_.java");
    JavaFileObject generatedWithLayoutModel = JavaFileObjects.forResource("GenerateDefaultLayoutMethodParentLayout$WithLayout_.java");
    assert_().about(javaSource()).that(model).processedWith(new EpoxyProcessor()).compilesWithoutError().and().generatesSources(generatedNoLayoutModel, generatedWithLayoutModel);
}
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