I want to invoke my code before compilation.

Answered

I am writing a plugin, I want to invoke some code before compilation, so I implement CompilationStatusListener:

public interface CompilationStatusListener extends EventListener {
/**
* Invoked in a Swing dispatch thread after the compilation is finished.
*
* @param aborted true if compilation has been cancelled
* @param errors error count
* @param warnings warning count
* @param compileContext context for the finished compilation
*/
default void compilationFinished(boolean aborted, int errors, int warnings, @NotNull CompileContext compileContext){
}

default void automakeCompilationFinished(int errors, int warnings, @NotNull CompileContext compileContext) {
}

default void fileGenerated(@NotNull String outputRoot, @NotNull String relativePath) {
}
}

but the interface doesn't exist any method for my demand. Is there any method to achive that?

and I write some code in compilationFinished method, but it doesn't work.

public class CompileStatusListener implements CompilationStatusListener {
    @Override
    public void compilationFinished(boolean aborted, int errors, int warnings, @NotNull CompileContext compileContext){
        System.out.println(compileContext);
    }
}

and please help me. thank you very much.

1
2 comments

Hi,

Try implementing com.intellij.compiler.server.BuildManagerListener.

1

Thank you very much, it works.

0

Please sign in to leave a comment.