aspose file tools*
The moose likes Java in General and the fly likes While using Compiler API annotations are not processed on implicit dependencies Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Java » Java in General
Bookmark "While using Compiler API annotations are not processed on implicit dependencies" Watch "While using Compiler API annotations are not processed on implicit dependencies" New topic
Author

While using Compiler API annotations are not processed on implicit dependencies

Baltazar Gabka
Greenhorn

Joined: Feb 05, 2013
Posts: 2

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

Joined: Aug 07, 2007
Posts: 1942
    
  28
What is CodeAnalyzerProcessor?
Baltazar Gabka
Greenhorn

Joined: Feb 05, 2013
Posts: 2
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?
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: While using Compiler API annotations are not processed on implicit dependencies
 
Similar Threads
Protected Access Confusion
Import
using package getting compiler error
public class in Java program file
using the javac -cp command