Listen to incremental change in output bytecode



I wonder if it is possible to directly listen to incremental code changes in bytecode level (or AST level) when developing a plugin?


Currently what I've tried is subscribing to `CompilerTopic.COMPILATION_STATUS` of the opened projects, so that I can listen to the changed .class files (with auto-build turned on).


But this is not exactly what I want:

1. The auto-build functionality in IntelliJ is somehow slower than I expect. A single-line change would take ~1 sec to trigger the `automakeCompilationFinished` event, which is a noticeable delay.

2. I have to manually find out the changes.


Therefore I wonder if there are some other APIs to help me achieve this or some more appropriate ways to implement this?


Really appreciated for your help!




Comment actions Permalink

What is the purpose/use-case of detecting these changes?

Comment actions Permalink

I want to perform some incremental inter-procedure static analysis. It would be easier to do with those bytecode changes.

Comment actions Permalink

Why not use PSI from IntelliJ model, working on sources directly?

Comment actions Permalink

Working on the source here is a secondary option for me.

The main reason is that our inter-procedure analysis is done on a special IR.

Generating IR from bytecode is ideal because it contains all the information we need. While generating accurate IR from source is more difficult, this fundamentally affects the analysis result.

Eugene Zhuravlev
Comment actions Permalink

Hi Yanze,

IDEA builds internal AST (incrementally, surely) without java compiler invocation. Javac (or optionally Eclipse ecj compiler) is called only to obtain a bytecode generation. IDEA performs all analysis using the AST built directly from sources. This object model (AST) is called PSI (Program Structure Interface). You do not have to compile a project to get PSI and all refactorings, highlighting, inspections and code insight features. All these features are based on PSI and IDEA will build it for you (incrementally and transparently). For library classes PSI representation is built too (from bytecode). The PSI API is available to plugins including listeners for various code change-related events (user edits, changes from VCS, disk etc).

So I can only second Yann here: what you need is PSI API. The plugin will have to build its own IR based on PSI and then perform the analysis based on the IR built.

Or perhaps you will consider an alternative to implement the analysis directly on PSI, without any intermediate model. 

Comment actions Permalink

Hi, Eugene and Yann

Thanks for the help, the information you provided is very important to me.


I will try exploring the PSI to see if I can leverage it to achieve my goal.


Please sign in to leave a comment.