Stefan Stefan - 1 year ago 103
Java Question

Intellij-Plugin: How to prevent Intellij to copy annotations when implementing methods

In our project we have some annotations on interfaces which are used to generate some client stub classes. We also have our own code-inspections in a intellij-plugin.

public interface BlubberRemoteService {

@RpcMethod(fc = "01")
String doTheTwist(@RpcDataTable(name = "param1") String param1);

If I use the implement methods action of Intellij it copies the annotations of the parameters:

public class BlubberRemoteServiceBean implements BlubberRemoteService {

public String doTheTwist(@RpcDataTable(name = "param1") String param1) {
return null;

How can I prevent Intellij to copy the parameter annotations to the implementation method. It is not useful there, because only the annotations of the interface are used for the generation of client stub.

Answer Source

The creation of the annotations can be prevented by registering an OverrideImplementsAnnotationHandler in the plugin.xml:

public class CustomImplementsAnnotationHandler implements OverrideImplementsAnnotationsHandler {

  public String[] getAnnotations(Project project) {
    return new String[]{};

  public String[] annotationsToRemove(Project project, @NotNull String fqName) {
    return new String[] {"package.RpcDataTable"};