Output of JavaSourceTransformingCompiler ignored when "javac in-process" compiler selected

My plugin works fine transforms Java source prior to compilation. When the external javac compiler is selected it works fine. The transformed source is compiled. When "javac in-process" is selected, my transforming compiler is called however the transformed content is ignored as the original source is compiled.

What do I need to do to make it work with the in-process Java compiler?

1 comment
Comment actions Permalink

Hi Michael,

The in-process compiler unlike others, reads file content for sources from the VFS. This means that at the moment of compilation the VFS should be synchronized with the data on disk at least for those files that are passed to compiler. Please check that your implementation of source transforming compiler either makes modifications to the file through VFS API, or, if it writes data directly on disk, calls synchronous "refresh()" on the modified VirtuallFile, so that VFS becomes aware of changes your compiler has made.
Please make sure that refresh is called from UI thread, because when you leave your compiler you should ensure that changes are made into the VFS to guarantee that in-proces javac will "see" them.
This can be accomplished by the call:

      UIUtil.invokeAndWaitIfNeeded(new Runnable() {
        public void run() {
          file.refresh(false, false);

In general I would avoid using in-process javac compiler due to theese implementation subtleties. We'll come up with something in the coming version of IDEA to simplify its usage.

  Eugene Zhuravlev

Please sign in to leave a comment.