0

我根据本教程开发了一个自定义语言插件。

现在我想Non-ASCII characters in an identifier通过插件 API 禁用/抑制带有特定标识符消息的检查。我使用这些以“#”开头的标识符作为节标题,并且不希望对它们进行任何默认突出显示/检查。

在此处输入图像描述

4

1 回答 1

0

当您从那里添加快速修复(然后“向右”)时,IntelliJ 将自动添加抑制选项。如果你只想要一个抑制快速修复,你可以像这样在你的 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);
    }
  }
}
于 2021-10-20T13:55:07.340 回答