Drooling messages when calling CompilerContext.addMessage(...)

Hello,

In my plugin, I create a CompilationStatusListener and perform static analysis on Java code whenever a build occurs. I'm seeing error state get drooled between compilations.

Example:

1) User compiles Foo.java

2) My plugin finds an error, I call CompilerContext.addMessage(...)

3) As expected, an error appears in the compiler message window for Foo.java. The editor window for Foo.java file has a red wave underline beneath the tab so the user knows about the error.

4) The user fixes the problem and recompiles.

5) My plugin finds no errors, so no errors appear in the compiler message window. It seems like Intellij will automatically clear out previous compiler messages, correct? The life cycle for managing error messages is not explicitly stated in the JavaDoc for addMessage(...).

6) BUG: Even though there are no errors in the compiler message window, the editor window for Foo.java still has a red wave underline. If I close the editor for Foo.java and reopen it, the tab still has a red wave underline. Therefore, this is most likely not a Swing painting issue. All of my calls to addMessage are on the EDT thread.

QUESTIONS
It seems like state from CompileContext.addMessage is getting drooled and not cleared out.
Is a plugin responsible for clearing out messages or Intellij IDE? Is there a removeMessage(...) method that I should be calling?

Thanks in advanced!

2 comments
Comment actions Permalink

Hello JoeNearBoston,

Performing static analysis in a CompilationStatusListener is not the right
thing to do.

The preferable way to perform custom static analysis is not to hook into
the compile process at all, but rather by plugging into background code analysis
(for example, by providing a custom ExternalAnnotator for the Java language).

If you do want to perform analysis on compilation (for example, if you're
using compiled .class files to perform the analysis), the correct way to
do this is to provider a custom compiler of type Validator.

In my plugin, I create a CompilationStatusListener and perform static
analysis on Java code whenever a build occurs. I'm seeing error state
get drooled between compilations.

Example:

1) User compiles Foo.java

2) My plugin finds an error, I call CompilerContext.addMessage(...)

3) As expected, an error appears in the compiler message window for
Foo.java. The editor window for Foo.java file has a red wave underline
beneath the tab so the user knows about the error.

4) The user fixes the problem and recompiles.

5) My plugin finds no errors, so no errors appear in the compiler
message window. It seems like Intellij will automatically clear out
previous compiler messages, correct? The life cycle for managing error
messages is not explicitly stated in the JavaDoc for addMessage(...).

6) BUG: Even though there are no errors in the compiler message
window, the editor window for Foo.java still has a red wave underline.
If I close the editor for Foo.java and reopen it, the tab still has a
red wave underline. Therefore, this is most likely not a Swing
painting issue. All of my calls to addMessage are on the EDT thread.

QUESTIONS

It seems like state from CompileContext.addMessage is getting drooled
and not cleared out.

Is a plugin responsible for clearing out messages or Intellij IDE? Is
there a removeMessage(...) method that I should be calling?

Thanks in advanced!

--
Dmitry Jemerov
Development Lead
JetBrains, Inc.
http://www.jetbrains.com/
"Develop with Pleasure!"


0
Comment actions Permalink

Dmitry,

Yes, I'm performing static analysis on Java class files, not raw Java source files. I want this static analysis to run whenever the class files update. I don't want the user to have to perform some action to kick off my plugin every time they recompile. Therefore, based on your previous post, using Validator seems like my best option.

I just tried using Validator instead of CompilationStatusListener as an experiment. The control flow is pretty much the same as before and I still see the drooling state between compilations.

1) My plugin performs static analysis within a Validator.process(...) method.

2) My Validator.getProcessingItems(...) method doesn't perform any analysis, It simply returns all the Java src by calling CompileScope.getFiles(StdFileTypes.JAVA, false);

3) Let's say my plugin finds an error in the user's Foo.class, I then make a call to CompileContext.addMessage(...) where the input VirtualFile corresponds to Foo.java.

4) As I expect, an error appears in the compilation message window. The editor for Foo.java has a red wave underline as I hope.

5) The user fixes the problem and recompiles.

6) My plugin doesn't find any errors, so I don't make any calls to CompileContext.addMessage(...)

7) BUG: The editor for Foo.java still has a red wave underline. The Project view on the left side also displays a red wave underline underneath the file Foo.java.

0

Please sign in to leave a comment.