public static InspectionToolWrapper findTool2RunInBatch(
     @NotNull Project project, @Nullable PsiElement element, @NotNull String name) {
   final InspectionProfile inspectionProfile =
       InspectionProjectProfileManager.getInstance(project).getInspectionProfile();
   final InspectionToolWrapper toolWrapper =
       element == null
           ? inspectionProfile.getInspectionTool(name, project)
           : inspectionProfile.getInspectionTool(name, element);
   if (toolWrapper instanceof LocalInspectionToolWrapper
       && ((LocalInspectionToolWrapper) toolWrapper).isUnfair()) {
     final LocalInspectionTool inspectionTool =
         ((LocalInspectionToolWrapper) toolWrapper).getTool();
     if (inspectionTool instanceof PairedUnfairLocalInspectionTool) {
       final String oppositeShortName =
           ((PairedUnfairLocalInspectionTool) inspectionTool).getInspectionForBatchShortName();
       if (oppositeShortName != null) {
         return element == null
             ? inspectionProfile.getInspectionTool(oppositeShortName, project)
             : inspectionProfile.getInspectionTool(oppositeShortName, element);
       }
     }
     return null;
   }
   return toolWrapper;
 }
  protected HighlightSeverity getSeverity(@NotNull RefElement element) {
    final PsiElement psiElement = element.getPointer().getContainingFile();
    if (psiElement != null) {
      final GlobalInspectionContextImpl context = getContext();
      final String shortName = getSeverityDelegateName();
      final Tools tools = context.getTools().get(shortName);
      if (tools != null) {
        for (ScopeToolState state : tools.getTools()) {
          InspectionToolWrapper toolWrapper = state.getTool();
          if (toolWrapper == getToolWrapper()) {
            return context
                .getCurrentProfile()
                .getErrorLevel(HighlightDisplayKey.find(shortName), psiElement)
                .getSeverity();
          }
        }
      }

      final InspectionProfile profile =
          InspectionProjectProfileManager.getInstance(context.getProject()).getInspectionProfile();
      final HighlightDisplayLevel level =
          profile.getErrorLevel(HighlightDisplayKey.find(shortName), psiElement);
      return level.getSeverity();
    }
    return null;
  }
 private static HighlightDisplayLevel getHighlightDisplayLevel(
     final LocalInspectionTool inspectionTool,
     final InspectionProfile inspectionProfile,
     PsiElement file) {
   final HighlightDisplayKey key = HighlightDisplayKey.find(inspectionTool.getShortName());
   return inspectionProfile.isToolEnabled(key, file)
       ? inspectionProfile.getErrorLevel(key, file)
       : HighlightDisplayLevel.DO_NOT_SHOW;
 }
예제 #4
0
 public boolean canCleanup(@NotNull PsiElement element) {
   if (myCanCleanup == null) {
     InspectionProfile profile =
         InspectionProjectProfileManager.getInstance(element.getProject())
             .getInspectionProfile();
     final HighlightDisplayKey key = myKey;
     if (key == null) {
       myCanCleanup = false;
     } else {
       InspectionToolWrapper toolWrapper = profile.getInspectionTool(key.toString(), element);
       myCanCleanup = toolWrapper != null && toolWrapper.isCleanupTool();
     }
   }
   return myCanCleanup;
 }
 public void updateCurrentProfile() {
   final String name = myInspectionProfile.getName();
   myInspectionProfile =
       (InspectionProfile) myInspectionProfile.getProfileManager().getProfile(name);
 }
 public boolean isProfileDefined() {
   return myInspectionProfile != null && myInspectionProfile.isEditable();
 }
 @Nullable
 public String getCurrentProfileName() {
   return myInspectionProfile == null ? null : myInspectionProfile.getDisplayName();
 }
  private void exportResults(
      @NotNull final CommonProblemDescriptor[] descriptors,
      @NotNull RefEntity refEntity,
      @NotNull Element parentNode) {
    for (CommonProblemDescriptor descriptor : descriptors) {
      @NonNls final String template = descriptor.getDescriptionTemplate();
      int line =
          descriptor instanceof ProblemDescriptor
              ? ((ProblemDescriptor) descriptor).getLineNumber()
              : -1;
      final PsiElement psiElement =
          descriptor instanceof ProblemDescriptor
              ? ((ProblemDescriptor) descriptor).getPsiElement()
              : null;
      @NonNls
      String problemText =
          StringUtil.replace(
              StringUtil.replace(
                  template,
                  "#ref",
                  psiElement != null
                      ? ProblemDescriptorUtil.extractHighlightedText(descriptor, psiElement)
                      : ""),
              " #loc ",
              " ");

      Element element = refEntity.getRefManager().export(refEntity, parentNode, line);
      if (element == null) return;
      @NonNls
      Element problemClassElement =
          new Element(InspectionsBundle.message("inspection.export.results.problem.element.tag"));
      problemClassElement.addContent(myToolWrapper.getDisplayName());

      final HighlightSeverity severity;
      if (refEntity instanceof RefElement) {
        final RefElement refElement = (RefElement) refEntity;
        severity = getSeverity(refElement);
      } else {
        final InspectionProfile profile =
            InspectionProjectProfileManager.getInstance(getContext().getProject())
                .getInspectionProfile();
        final HighlightDisplayLevel level =
            profile.getErrorLevel(
                HighlightDisplayKey.find(myToolWrapper.getShortName()), psiElement);
        severity = level.getSeverity();
      }

      if (severity != null) {
        ProblemHighlightType problemHighlightType =
            descriptor instanceof ProblemDescriptor
                ? ((ProblemDescriptor) descriptor).getHighlightType()
                : ProblemHighlightType.GENERIC_ERROR_OR_WARNING;
        final String attributeKey =
            getTextAttributeKey(getRefManager().getProject(), severity, problemHighlightType);
        problemClassElement.setAttribute("severity", severity.myName);
        problemClassElement.setAttribute("attribute_key", attributeKey);
      }

      element.addContent(problemClassElement);
      if (myToolWrapper instanceof GlobalInspectionToolWrapper) {
        final GlobalInspectionTool globalInspectionTool =
            ((GlobalInspectionToolWrapper) myToolWrapper).getTool();
        final QuickFix[] fixes = descriptor.getFixes();
        if (fixes != null) {
          @NonNls Element hintsElement = new Element("hints");
          for (QuickFix fix : fixes) {
            final String hint = globalInspectionTool.getHint(fix);
            if (hint != null) {
              @NonNls Element hintElement = new Element("hint");
              hintElement.setAttribute("value", hint);
              hintsElement.addContent(hintElement);
            }
          }
          element.addContent(hintsElement);
        }
      }
      try {
        Element descriptionElement =
            new Element(InspectionsBundle.message("inspection.export.results.description.tag"));
        descriptionElement.addContent(problemText);
        element.addContent(descriptionElement);
      } catch (IllegalDataException e) {
        //noinspection HardCodedStringLiteral,UseOfSystemOutOrSystemErr
        System.out.println(
            "Cannot save results for "
                + refEntity.getName()
                + ", inspection which caused problem: "
                + myToolWrapper.getShortName());
      }
    }
  }
예제 #9
0
    @Nullable
    public List<IntentionAction> getOptions(@NotNull PsiElement element, @Nullable Editor editor) {
      if (editor != null
          && Boolean.FALSE.equals(
              editor.getUserData(IntentionManager.SHOW_INTENTION_OPTIONS_KEY))) {
        return null;
      }
      List<IntentionAction> options = myOptions;
      HighlightDisplayKey key = myKey;
      if (myProblemGroup != null) {
        String problemName = myProblemGroup.getProblemName();
        HighlightDisplayKey problemGroupKey =
            problemName != null ? HighlightDisplayKey.findById(problemName) : null;
        if (problemGroupKey != null) {
          key = problemGroupKey;
        }
      }
      if (options != null || key == null) {
        return options;
      }
      IntentionManager intentionManager = IntentionManager.getInstance();
      List<IntentionAction> newOptions = intentionManager.getStandardIntentionOptions(key, element);
      InspectionProfile profile =
          InspectionProjectProfileManager.getInstance(element.getProject()).getInspectionProfile();
      InspectionToolWrapper toolWrapper = profile.getInspectionTool(key.toString(), element);
      if (!(toolWrapper instanceof LocalInspectionToolWrapper)) {
        HighlightDisplayKey idkey = HighlightDisplayKey.findById(key.toString());
        if (idkey != null) {
          toolWrapper = profile.getInspectionTool(idkey.toString(), element);
        }
      }
      if (toolWrapper != null) {

        myCanCleanup = toolWrapper.isCleanupTool();

        ContainerUtil.addIfNotNull(
            newOptions, intentionManager.createFixAllIntention(toolWrapper, myAction));
        InspectionProfileEntry wrappedTool =
            toolWrapper instanceof LocalInspectionToolWrapper
                ? ((LocalInspectionToolWrapper) toolWrapper).getTool()
                : ((GlobalInspectionToolWrapper) toolWrapper).getTool();
        if (wrappedTool instanceof CustomSuppressableInspectionTool) {
          final IntentionAction[] suppressActions =
              ((CustomSuppressableInspectionTool) wrappedTool).getSuppressActions(element);
          if (suppressActions != null) {
            ContainerUtil.addAll(newOptions, suppressActions);
          }
        } else {
          SuppressQuickFix[] suppressFixes = wrappedTool.getBatchSuppressActions(element);
          if (suppressFixes.length > 0) {
            ContainerUtil.addAll(
                newOptions,
                ContainerUtil.map(
                    suppressFixes,
                    new Function<SuppressQuickFix, IntentionAction>() {
                      @Override
                      public IntentionAction fun(SuppressQuickFix fix) {
                        return SuppressIntentionActionFromFix.convertBatchToSuppressIntentionAction(
                            fix);
                      }
                    }));
          }
        }
      }
      if (myProblemGroup instanceof SuppressableProblemGroup) {
        final IntentionAction[] suppressActions =
            ((SuppressableProblemGroup) myProblemGroup).getSuppressActions(element);
        ContainerUtil.addAll(newOptions, suppressActions);
      }

      synchronized (this) {
        options = myOptions;
        if (options == null) {
          myOptions = options = newOptions;
        }
        myKey = null;
      }
      return options;
    }
예제 #10
0
    @Nullable
    public List<IntentionAction> getOptions(@NotNull PsiElement element, @Nullable Editor editor) {
      if (editor != null
          && Boolean.FALSE.equals(
              editor.getUserData(IntentionManager.SHOW_INTENTION_OPTIONS_KEY))) {
        return null;
      }
      List<IntentionAction> options = myOptions;
      HighlightDisplayKey key = myKey;
      if (options != null || key == null) {
        return options;
      }
      List<IntentionAction> newOptions =
          IntentionManager.getInstance().getStandardIntentionOptions(key, element);
      InspectionProfile profile =
          InspectionProjectProfileManager.getInstance(element.getProject()).getInspectionProfile();
      InspectionProfileEntry tool = profile.getInspectionTool(key.toString(), element);
      if (!(tool instanceof LocalInspectionToolWrapper)) {
        HighlightDisplayKey idkey = HighlightDisplayKey.findById(key.toString());
        if (idkey != null) {
          tool = profile.getInspectionTool(idkey.toString(), element);
        }
      }
      InspectionProfileEntry wrappedTool = tool;
      if (tool instanceof LocalInspectionToolWrapper) {
        wrappedTool = ((LocalInspectionToolWrapper) tool).getTool();
        Class aClass = myAction.getClass();
        if (myAction instanceof QuickFixWrapper) {
          aClass = ((QuickFixWrapper) myAction).getFix().getClass();
        }
        newOptions.add(new CleanupInspectionIntention((LocalInspectionToolWrapper) tool, aClass));
      } else if (tool instanceof GlobalInspectionToolWrapper) {
        wrappedTool = ((GlobalInspectionToolWrapper) tool).getTool();
        if (wrappedTool instanceof GlobalSimpleInspectionTool
            && (myAction instanceof LocalQuickFix || myAction instanceof QuickFixWrapper)) {
          Class aClass = myAction.getClass();
          if (myAction instanceof QuickFixWrapper) {
            aClass = ((QuickFixWrapper) myAction).getFix().getClass();
          }
          newOptions.add(
              new CleanupInspectionIntention((GlobalInspectionToolWrapper) tool, aClass));
        }
      }

      if (wrappedTool instanceof CustomSuppressableInspectionTool) {
        final IntentionAction[] suppressActions =
            ((CustomSuppressableInspectionTool) wrappedTool).getSuppressActions(element);
        if (suppressActions != null) {
          ContainerUtil.addAll(newOptions, suppressActions);
        }
      }
      if (wrappedTool instanceof BatchSuppressableTool) {
        final SuppressQuickFix[] suppressActions =
            ((BatchSuppressableTool) wrappedTool).getBatchSuppressActions(element);
        ContainerUtil.addAll(
            newOptions,
            ContainerUtil.map(
                suppressActions,
                new Function<SuppressQuickFix, IntentionAction>() {
                  @Override
                  public IntentionAction fun(SuppressQuickFix fix) {
                    return InspectionManagerEx.convertBatchToSuppressIntentionAction(fix);
                  }
                }));
      }

      synchronized (this) {
        options = myOptions;
        if (options == null) {
          myOptions = options = newOptions;
        }
        myKey = null;
      }
      return options;
    }