Win a copy of The Java Performance Companion this week in the Performance forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

While using Compiler API annotations are not processed on implicit dependencies

 
Baltazar Gabka
Greenhorn
Posts: 2
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator

I have the code that compiles a file "A.java"

(...)
optionList.addAll(Arrays.asList("-sourcepath","D:/myproject/java/"));
optionList.addAll(Arrays.asList("-d","D:/myproject/bin/"));
optionList.addAll(Arrays.asList("-implicit:class"));
optionList.addAll(Arrays.asList("-verbose"));

CompilationTask task = compiler.getTask(null, fileManager, listener, optionList, null, compilationUnits1);
// Get the list of annotation processors
LinkedList<AbstractProcessor> processors = new LinkedList<AbstractProcessor>();
processors.add(new CodeAnalyzerProcessor());
task.setProcessors(processors);

task.call();


The file "A.java" needs files "B.java" and "C.java" which reside in the same directory.
Compilation is OK and (as expected) files B and C are also compiled.
But CodeAnalyzerProcessor is handling only file A.java. B.java and C.java are compiled but
nothing from CodeAnalyzerProcessor is invoked for them - even with "-implicit:class" options.

What am I missing?

 
Tony Docherty
Bartender
Posts: 2965
59
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
What is CodeAnalyzerProcessor?
 
Baltazar Gabka
Greenhorn
Posts: 2
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
It is class that inherits from AbstractProcessor and is used in tutorial:

http://today.java.net/pub/a/today/2008/04/10/source-code-analysis-using-java-6-compiler-apis.html

to annotations processing.




Unfortunately it looks I have found answer - implicit dependencies are not subject to annotations processing.
If one wants a file to be processed the file name must be explicitly expressed in list of files to compile.


Its a pity - it looks like if I want to perform annotation processing on all files in project I have to construct
the list with all file names and pass it to compilation task. I hoped that it would be enogh to mention one "main"
file and the rest of files will be processed because of implicit compilation. And implicit compilation is done
but not the annotations processing during this phase.

Maybe there is another solution?
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic