0

I developed a Custom Language plugin based on this this tutorial.

Now I'd like to disable/suppress Inspection with message Non-ASCII characters in an identifier for specific identifiers via Plugin API. I use these identifiers which start with '#' as sections headers and do not want any default highlightning/inspections for them.

enter image description here

schmidt9
  • 4,436
  • 1
  • 26
  • 32

1 Answers1

0

IntelliJ will automatically add a suppress option when you add a quick fix (then go "right") from there. If you only want a suppress quick fix, you can add it like this in your holder.registerProblem(...)

private static class QuickFixSuppress implements SuppressQuickFix {
  @NotNull private static final String SUPPRESS_ID = new EjbBusinessMethodPublicInspection().getSuppressId();

  @Override
  public boolean isAvailable(@NotNull Project project, @NotNull PsiElement psiElement) {
    return psiElement instanceof PsiMethod;
  }

  @Override
  public boolean isSuppressAll() {
    return false;
  }

  @Nls
  @NotNull
  @Override
  public String getFamilyName() {
    return "Suppress " + SUPPRESS_ID;
  }

  @Override
  public void applyFix(@NotNull Project project, @NotNull ProblemDescriptor problemDescriptor) {
    final PsiElement element = problemDescriptor.getPsiElement();
    if (element instanceof PsiMethod) {
      PsiMethod psiMethod = (PsiMethod) element;
      JavaSuppressionUtil.addSuppressAnnotation(project, psiMethod, psiMethod, SUPPRESS_ID);
    }
  }
}
  • Thanks but I do not get how to use this class `QuickFixSuppress`. How do I use it with `holder.registerProblem`? – schmidt9 Oct 20 '21 at 17:48