Creating a plugin to get error messages from the Message Compile window

已回答

Hi All,

I am a little stuck on a problem. So I am working on a plugin that analyzes the compile error messages. The first task I will need to do is 

to write a method that goes into the message compile window and get the compiler output of error messages. 

I am a bit stuck on how to do this. I have tried looking through the tutorial and the source code of IntelliJ CE, and this is what I have so far.  The error messages were not printed, as the errorArray is empty.  Can anyone please help me? Thanks :) 

DataContext dataContext = e.getDataContext();
Project project = CommonDataKeys.PROJECT.getData(dataContext);
// get the message container for our project

MessagesContainer messages = new MessagesContainer(project);

String [] errorArray = messages.getMessages(CompilerMessageCategory.ERROR).toArray(new String[messages.getMessageCount(CompilerMessageCategory.ERROR)]);

for(int i = 0; i < errorArray.length; ++i){
System.out.println(errorArray[i]);
}
1
Avatar
Permanently deleted user

Anyone? 

0
Avatar
Permanently deleted user

Hi Lintzu, 

In your example you create an empty message container and then query it for messages, so there is no surprise that returned array is empty.

Please consider using 

com.intellij.openapi.compiler.CompilationStatusListener.compilationFinished()

All events of this kind are available via project-level MessageBus, topic CompilerTopics.COMPILATION_STATUS.
After you subscribed, your listener will always be notified whenever any compilation session finishes.
You can obtain compiler messages generated during this session from the passed com.intellij.openapi.compiler.CompileContext object.

0
Avatar
Permanently deleted user

Hi Eugene,

Thanks for the tip! Your solution worked for me.

 

0

请先登录再写评论。