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());
}
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));
}
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));
}
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);
}
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");
}
Aggregations