Search in sources :

Example 16 with JavaFileObject

use of javax.tools.JavaFileObject in project buck by facebook.

the class JavaInMemoryFileManagerTest method testMultipleFilesInSamePackage.

@Test
public void testMultipleFilesInSamePackage() throws Exception {
    JavaFileObject fileObject1 = inMemoryFileManager.getJavaFileForOutput(StandardLocation.CLASS_OUTPUT, "jvm.java.JavaFileParser", JavaFileObject.Kind.CLASS, null);
    JavaFileObject fileObject2 = inMemoryFileManager.getJavaFileForOutput(StandardLocation.CLASS_OUTPUT, "jvm.java.JavaInMemoryFileManager", JavaFileObject.Kind.CLASS, null);
    fileObject1.openOutputStream().close();
    fileObject2.openOutputStream().close();
    List<ZipEntry> zipEntries = outputStream.getZipEntries();
    assertEquals(4, zipEntries.size());
    assertEquals("jvm/", zipEntries.get(0).getName());
    assertEquals("jvm/java/", zipEntries.get(1).getName());
    assertEquals("jvm/java/JavaFileParser.class", zipEntries.get(2).getName());
    assertEquals("jvm/java/JavaInMemoryFileManager.class", zipEntries.get(3).getName());
}
Also used : JavaFileObject(javax.tools.JavaFileObject) ZipEntry(java.util.zip.ZipEntry) Test(org.junit.Test)

Example 17 with JavaFileObject

use of javax.tools.JavaFileObject in project buck by facebook.

the class JavaInMemoryFileManagerTest method testIsNotSameFile.

@Test
public void testIsNotSameFile() throws Exception {
    JavaFileObject fileObject1 = inMemoryFileManager.getJavaFileForOutput(StandardLocation.CLASS_OUTPUT, "jvm.java.JavaFileParser", JavaFileObject.Kind.CLASS, null);
    JavaFileObject fileObject2 = inMemoryFileManager.getJavaFileForOutput(StandardLocation.CLASS_OUTPUT, "jvm.java.JavaInMemoryFileManager", JavaFileObject.Kind.CLASS, null);
    assertFalse(inMemoryFileManager.isSameFile(fileObject1, fileObject2));
}
Also used : JavaFileObject(javax.tools.JavaFileObject) Test(org.junit.Test)

Example 18 with JavaFileObject

use of javax.tools.JavaFileObject in project buck by facebook.

the class JavaInMemoryFileManagerTest method testWriteContent.

@Test
public void testWriteContent() throws Exception {
    JavaFileObject fileObject = inMemoryFileManager.getJavaFileForOutput(StandardLocation.CLASS_OUTPUT, "JavaFileParser", JavaFileObject.Kind.CLASS, null);
    OutputStream stream = fileObject.openOutputStream();
    stream.write("Hello World!".getBytes());
    stream.close();
    List<String> entries = outputStream.getEntriesContent();
    assertEquals(1, entries.size());
    assertEquals("Hello World!", entries.get(0));
}
Also used : JavaFileObject(javax.tools.JavaFileObject) OutputStream(java.io.OutputStream) TestCustomZipOutputStream(com.facebook.buck.testutil.TestCustomZipOutputStream) Test(org.junit.Test)

Example 19 with JavaFileObject

use of javax.tools.JavaFileObject in project RxCache by VictorAlbertos.

the class ActionsListProcessorTest method Test_Processor.

@Test
public void Test_Processor() throws Exception {
    JavaFileObject source = JavaFileObjects.forSourceString("RxProviders", "" + "package test;\n" + "import io.reactivex.Observable;\n" + "import io.rx_cache2.Actionable;\n" + "import io.rx_cache2.DynamicKey;\n" + "import io.rx_cache2.DynamicKeyGroup;\n" + "import io.rx_cache2.EvictDynamicKey;\n" + "import io.rx_cache2.EvictDynamicKeyGroup;\n" + "import io.rx_cache2.EvictProvider;\n" + "import io.rx_cache2.Mock;\n" + "import java.util.List;\n" + "\n" + "public interface RxProviders {\n" + "  @Actionable Observable<List<Mock>> getMocksEvictProvider(Observable<List<Mock>> oMocks,\n" + "      EvictProvider evictProvider);\n" + "\n" + "  @Actionable Observable<List<Mock>> getMocksEvictDynamicKey(Observable<List<Mock>> oMocks,\n" + "      DynamicKey dynamicKey,\n" + "      EvictDynamicKey evictDynamicKey);\n" + "\n" + "  @Actionable Observable<List<Mock>> getMocksEvictDynamicKeyGroup(Observable<List<Mock>> oMocks,\n" + "      DynamicKeyGroup dynamicKeyGroup,\n" + "      EvictDynamicKeyGroup evictDynamicKeyGroup);\n" + "}");
    JavaFileObject expectedSource = JavaFileObjects.forSourceString("test/RxProvidersActionable", "" + "package test;\n" + "import io.reactivex.Observable;\n" + "import io.rx_cache2.ActionsList;\n" + "import io.rx_cache2.DynamicKey;\n" + "import io.rx_cache2.DynamicKeyGroup;\n" + "import io.rx_cache2.EvictDynamicKey;\n" + "import io.rx_cache2.EvictDynamicKeyGroup;\n" + "import io.rx_cache2.EvictProvider;\n" + "import io.rx_cache2.Mock;\n" + "import java.util.ArrayList;\n" + "import java.util.List;\n" + "import javax.annotation.Generated;\n" + "\n" + "@Generated(\n" + "    value = \"io.rx_cache2.ActionsProcessor\",\n" + "    comments = \"Generated code from RxCache. Don't modify. Or modify. It doesn't matter.\"\n" + ")\n" + "public class RxProvidersActionable {\n" + "  public static ActionsList<Mock> getMocksEvictProvider(final RxProviders proxy) {\n" + "    ActionsList.Evict<Mock> evict = new ActionsList.Evict<Mock>() {\n" + "      @Override public Observable<List<Mock>> call(Observable<List<Mock>> elements) {\n" + "        return proxy.getMocksEvictProvider(elements, new EvictProvider(true));\n" + "      }\n" + "    } ;;\n" + "    Observable<List<Mock>> oCache = proxy.getMocksEvictProvider(Observable.<List<io.rx_cache2.Mock>>just(new ArrayList<Mock>()), new EvictProvider(false));\n" + "    return ActionsList.with(evict, oCache);\n" + "  }\n" + "\n" + "  public static ActionsList<Mock> getMocksEvictDynamicKey(final RxProviders proxy, final DynamicKey dynamicKey) {\n" + "    ActionsList.Evict<Mock> evict = new ActionsList.Evict<Mock>() {\n" + "      @Override public Observable<List<Mock>> call(Observable<List<Mock>> elements) {\n" + "        return proxy.getMocksEvictDynamicKey(elements, dynamicKey, new EvictDynamicKey(true));\n" + "      }\n" + "    } ;;\n" + "    Observable<List<Mock>> oCache = proxy.getMocksEvictDynamicKey(Observable.<List<io.rx_cache2.Mock>>just(new ArrayList<Mock>()), dynamicKey, new EvictDynamicKey(false));\n" + "    return ActionsList.with(evict, oCache);\n" + "  }\n" + "\n" + "  public static ActionsList<Mock> getMocksEvictDynamicKeyGroup(final RxProviders proxy, final DynamicKeyGroup dynamicKeyGroup) {\n" + "    ActionsList.Evict<Mock> evict = new ActionsList.Evict<Mock>() {\n" + "      @Override public Observable<List<Mock>> call(Observable<List<Mock>> elements) {\n" + "        return proxy.getMocksEvictDynamicKeyGroup(elements, dynamicKeyGroup, new EvictDynamicKeyGroup(true));\n" + "      }\n" + "    } ;;\n" + "    Observable<List<Mock>> oCache = proxy.getMocksEvictDynamicKeyGroup(Observable.<List<io.rx_cache2.Mock>>just(new ArrayList<Mock>()), dynamicKeyGroup, new EvictDynamicKeyGroup(false));\n" + "    return ActionsList.with(evict, oCache);\n" + "  }\n" + "}");
    assertAbout(javaSource()).that(source).processedWith(new io.rx_cache2.ActionsProcessor()).compilesWithoutError().and().generatesSources(expectedSource);
}
Also used : JavaFileObject(javax.tools.JavaFileObject) Test(org.junit.Test)

Example 20 with JavaFileObject

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

the class DeepLinkProcessorTest method testNonStaticMethodCompileFail.

@Test
public void testNonStaticMethodCompileFail() {
    JavaFileObject sampleActivity = JavaFileObjects.forSourceString("SampleActivity", "package com.example;" + "import com.airbnb.deeplinkdispatch.DeepLink; " + "public class SampleActivity {" + "  @DeepLink(\"airbnb://host/{arbitraryNumber}\")" + "  public Intent intentFromNoStatic(Context context){" + "    return new Intent();" + "  }" + "}");
    assertAbout(javaSource()).that(sampleActivity).processedWith(new DeepLinkProcessor()).failsToCompile().withErrorContaining("Only static methods can be annotated");
}
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