assertEquals(1, compiler.failCompile().size());
}
@Test
public void testProcessorErrorOnElement() throws Exception {
DiskFileSystem fs = diskFS("compiler.annotationexception");
Compiler compiler = Compiler.builder().javaCompiler(compilerProvider).sourcePath(fs).output(new RAMFileSystem()).build();
@javax.annotation.processing.SupportedSourceVersion(javax.lang.model.SourceVersion.RELEASE_6)
@javax.annotation.processing.SupportedAnnotationTypes({"*"})
class Processor1 extends AbstractProcessor {
@Override
public boolean process(Set<? extends TypeElement> annotations, RoundEnvironment roundEnv) {
Set<? extends Element> elements = roundEnv.getElementsAnnotatedWith(Deprecated.class);
if (elements.size() == 1) {
Element elt = elements.iterator().next();
processingEnv.getMessager().printMessage(Diagnostic.Kind.ERROR, "the_message", elt);
}
return false;
}
}
compiler.addAnnotationProcessor(new Processor1());
try {
compiler.compile();
fail();
}
catch (CompilationException e) {
List<CompilationError> errors = e.getErrors();
assertEquals(1, errors.size());
CompilationError error = errors.get(0);
assertEquals(null, error.getCode());
assertEquals(Collections.<String>emptyList(), error.getArguments());
assertEquals(fs.getPath("compiler", "annotationexception", "A.java"), error.getSourceFile());
assertTrue(error.getMessage().contains("the_message"));
assertNotNull(error.getSourceFile());
assertNotNull(error.getLocation());
String absolutePath = error.getSourceFile().getAbsolutePath();
char separator = File.separatorChar;