【问题标题】:Disable Inspections for a specific PsiElement subclass禁用特定 PsiElement 子类的检查
【发布时间】:2021-10-04 04:42:45
【问题描述】:

我基于这个this tutorial开发了一个自定义语言插件。

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

【问题讨论】:

    标签: java intellij-plugin intellij-inspections


    【解决方案1】:

    当您从那里添加快速修复(然后“向右”)时,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);
        }
      }
    }
    

    【讨论】:

    • 谢谢,但我不知道如何使用这个类QuickFixSuppress。如何将它与holder.registerProblem 一起使用?
    猜你喜欢
    • 2014-01-25
    • 2011-04-30
    • 1970-01-01
    • 2020-06-28
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2017-08-26
    相关资源
    最近更新 更多