annotation processor problems since 9b70
Srikanth
srikanth.adayapalam at oracle.com
Fri Jul 3 04:41:13 UTC 2015
On Thursday 02 July 2015 09:35 PM, Victor Rudometov wrote:
> Hello.
> Recent changes in jdk9b70 to annotation processor (probably
> https://jbs.oracle.com/bugs/browse/JDK-8074346) made impossible to
> process the code with types that are not declared.
Hello Victor,
Thanks for the report - I am looking into this - if found necessary I'll
follow up by raising a JBS ticket.
Regards,
Srikanth
>
> F.e.:
>
> public class ThrowsException {
> public void method() throws @Annot SomeException {}
> }
>
> Is not processed because of Annot and SomeException.
>
> I did not have this problem with b69 - errors are reported, however
> the annotation processing is performed.
>
> Was it done intentionally or this is a regression?
> Are there any workarounds?
>
> Below is a simple test code:
>
> import javax.annotation.processing.AbstractProcessor;
> importjavax.annotation.processing.RoundEnvironment;
> importjavax.annotation.processing.SupportedAnnotationTypes;
> importjavax.annotation.processing.SupportedSourceVersion;
> importjavax.lang.model.element.TypeElement;
> importjavax.tools.*;
> importjava.io.CharArrayWriter;
> importjava.io.File;
> importjava.io.IOException;
> importjava.net.URISyntaxException;
> importjava.net.URL;
> importjava.util.*;
>
> import staticjavax.lang.model.SourceVersion.RELEASE_9;
>
> public classTest {
> privateList<File>sources;
>
> public static voidmain(String args[])throwsURISyntaxException {
> newTest().run();
> }
>
> public voidrun() {
> createSources().addFileToSources("c:\\data\\ThrowsException.java");
>
> DiagnosticCollector<JavaFileObject> diagnostics =newDiagnosticCollector<>();;
> JavaCompiler javac = ToolProvider.getSystemJavaCompiler();
> StandardJavaFileManager fileManager =
> javac.getStandardFileManager(null,null,null);
> Iterable<?extendsJavaFileObject> compilationUnits =
> fileManager.getJavaFileObjectsFromFiles(sources);
> CharArrayWriter errorWriter =newCharArrayWriter();
> List<String> compilerOptions = Arrays.asList(
> "-proc:only -Xmaxerrs 0 -Xmaxwarns 0".split("\\s+"));
> JavaCompiler.CompilationTask task = javac.getTask(errorWriter,
> fileManager, diagnostics, compilerOptions,null, compilationUnits);
>
> MyProcessor processor =newMyProcessor();
> task.setProcessors(Arrays.asList(processor));
>
> task.call();
>
> System.out.println(processor.wasInvoked());
>
> for(Diagnostic diagnostic : diagnostics.getDiagnostics())
> System.out.format("Error on line %d in %s%n : %s",
> diagnostic.getLineNumber(),
> diagnostic.getSource().toString(),
> diagnostic.getMessage(Locale.US));
>
> try{
> fileManager.close();
> }catch(IOException e) {
> e.printStackTrace();
> }
> }
>
> @SupportedAnnotationTypes({"*"})
> @SupportedSourceVersion(RELEASE_9)
> public static classMyProcessorextendsAbstractProcessor {
>
> private booleaninvoked=false;
>
> @Override
> public booleanprocess(Set<?extendsTypeElement> annotations, RoundEnvironment roundEnv) {
> invoked=true;
> return false;
> }
>
> public booleanwasInvoked() {
> returninvoked;
> }
> }
>
> privateTest createSources() {
> sources=newArrayList<>();
> return this;
> }
>
> privateTest addFileToSources(String path) {
> sources.add(newFile(path));
> return this;
> }
> }
>
>
> Thanks.
> Victor.
>
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mail.openjdk.java.net/pipermail/compiler-dev/attachments/20150703/e21436cb/attachment.html>
More information about the compiler-dev
mailing list