private Compilation compareCommandDump(List<String> expected, JavaFileObject ... sourceFiles) { CommandSpec2YamlProcessor processor = new CommandSpec2YamlProcessor(); Compilation compilation = javac() .withProcessors(processor) .compile(sourceFiles); assertTrue("Expected at least " + expected.size() + " commands but found " + processor.strings.size(), expected.size() <= processor.strings.size()); for (int i = 0; i < expected.size(); i++) { assertEqualCommand(expected.get(i), processor.strings.get(i)); } return compilation; }
private Compiler compileWithGenerator(List<String> options) { return javac().withProcessors(widProcessor).withOptions(options); } }
private Compiler compileWithGenerator() { return javac().withProcessors(widProcessor); }
private Compilation compilation() { Compiler compiler = javac().withProcessors(processors).withOptions(options); if (classLoader != null) { compiler = compiler.withClasspathFrom(classLoader); } if (classPath != null) { compiler = compiler.withClasspath(classPath); } return compiler.compile(actual()); } }
@Test public void testGenerationWithProcessingOptions() throws Exception { Map<String, List<Wid>> processingResults = new HashMap<>(); widProcessor.setProcessingResults(processingResults); widProcessor.setResetResults(false); List<String> processorOptions = Arrays.asList("-AwidName=testwid", "-AgenerateTemplates=true", "-AgenerateWids=true", "-AwidsResources=testwid.wid:dummytemplate.st", "-AtemplateResources=index.html:dummytemplate.st"); Compiler compiler = compileWithGenerator(processorOptions); compiler.compile(source1); assertNotNull(processingResults); assertEquals(1, processingResults.keySet().size()); List<Wid> widInfoList = processingResults.get("org.jbpm.process.workitem.core.util.MyTestClass"); assertNotNull(widInfoList); assertEquals(1, widInfoList.size()); }
/** * Passes command-line options to the compiler. These replace any previously specified. * * @return a new instance with the same processors and the given options */ public final Compiler withOptions(Object... options) { return withOptions(ImmutableList.copyOf(options)); }
private Compilation compilation() { Compiler compiler = javac().withProcessors(processors).withOptions(options); if (classLoader != null) { compiler = compiler.withClasspathFrom(classLoader); } return compiler.compile(actual()); } }
compiler.compile(source2Interface, source2);
/** * Passes command-line options to the compiler. These replace any previously specified. * * @return a new instance with the same processors and the given options */ public final Compiler withOptions(Object... options) { return withOptions(ImmutableList.copyOf(options)); }
@Test public void intentBuilderGenerator_should_fail_when_extraIsPrivate() { JavaFileObject source = JavaFileObjects.forSourceString( "test.navigation.TestNavigationModel", Joiner.on('\n') .join( "package test.navigation;", "import dart.BindExtra;", "public class TestNavigationModel {", " @BindExtra private String extra;", "}")); Compilation compilation = javac().withProcessors(hensonProcessor()).compile(source); assertThat(compilation) .hadErrorContaining( "@BindExtra field must not be private or static. (test.navigation.TestNavigationModel.extra)"); }
@Override public void evaluate() throws Throwable { // Compiled compiled = // AnnotationUtils.getAnnotation(method.getMethod(), Compiled.class); Compiled compiled = method.getMethod().getAnnotation(Compiled.class); Class<?> clz = getTestClass().getJavaClass(); Compilation compilation = Compiler.javac() .withProcessors(Arrays.stream(compiled.processors()) .map(c -> { try { return c.newInstance(); } catch (Exception e) { throw new IllegalStateException("Annotation Processor must has no-arg public constructor"); } }) .toArray(Processor[]::new)) .withOptions(Arrays.stream(compiled.options()).toArray(Object[]::new)) .compile(Arrays.stream(compiled.sources()) .map(s -> clz.getResource(s)) .map(u -> JavaFileObjects.forResource(u)) .toArray(JavaFileObject[]::new)); method.invokeExplosively(ct, compilation); } };
compiler.compile(source1reflectionhandler);
@Test public void intentBuilderGenerator_should_fail_when_navigationModelIsInnerClass() { JavaFileObject source = JavaFileObjects.forSourceString( "test.navigation.OuterClass", Joiner.on('\n') .join( "package test.navigation;", "import dart.DartModel;", "public class OuterClass {", " @DartModel", " class TestNavigationModel {", " }", "}")); Compilation compilation = javac().withProcessors(hensonProcessor()).compile(source); assertThat(compilation) .hadErrorContaining("DartModel class TestNavigationModel must be a top level class."); }
@Test public void shouldIgnoreIfImplementsSelfValidating() { Compilation compilation = javac().withClasspathFrom(getClass().getClassLoader()) .withProcessors(new InspectorProcessor()) .compile(JavaFileObjects.forSourceLines("test.SelfValidatingFoo", "package test;\n" + "\n"
compiler.compile(source1HandlerWithParams);
@Test public void intentBuilderGenerator_should_fail_when_navigationModelIsAbstract() { JavaFileObject source = JavaFileObjects.forSourceString( "test.navigation.TestNavigationModel", Joiner.on('\n') .join( "package test.navigation;", "import dart.DartModel;", "@DartModel", "public abstract class TestNavigationModel {", "}")); Compilation compilation = javac().withProcessors(hensonProcessor()).compile(source); assertThat(compilation) .hadErrorContaining( "DartModel class TestNavigationModel must not be private, static or abstract."); }
compiler.compile(source1);
@Test public void intentBuilderGenerator_should_fail_when_navigationModelSuffixIsWrong() { JavaFileObject source = JavaFileObjects.forSourceString( "test.navigation.TestModel", Joiner.on('\n') .join( "package test.navigation;", "import dart.DartModel;", "@DartModel", "class TestModel {", "}")); Compilation compilation = javac().withProcessors(hensonProcessor()).compile(source); assertThat(compilation) .hadErrorContaining( "DartModel class TestModel does not follow the naming convention: my.package.TargetComponentNavigationModel."); }
compiler.compile(source3ServiceWithTrigger);
@Test public void intentBuilderGenerator_should_fail_when_extraIsInvalidType() { JavaFileObject source = JavaFileObjects.forSourceString( "test.navigation.TestNavigationModel", Joiner.on('\n') .join( "package test.navigation;", "import dart.BindExtra;", "public class TestNavigationModel {", " @BindExtra Object extra;", "}")); Compilation compilation = javac().withProcessors(hensonProcessor()).compile(source); assertThat(compilation) .hadErrorContaining( "The fields of class annotated with @DartModel must be primitive, Serializable or Parcelable (test.navigation.TestNavigationModel.extra)."); }