Stefan Stefan - 1 month ago 22
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")
@RpcDataTable(name="return")
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 {

@Override
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

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

public class CustomImplementsAnnotationHandler implements OverrideImplementsAnnotationsHandler {

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

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