private void reportOneTagProblem(
      final XmlTag tag,
      final String name,
      final String localizedMessage,
      final IntentionAction basicIntention,
      final HighlightDisplayKey key,
      final XmlEntitiesInspection inspection,
      final int type) {
    boolean htmlTag = false;

    if (tag instanceof HtmlTag) {
      htmlTag = true;
      if (isAdditionallyDeclared(inspection.getAdditionalEntries(type), name)) return;
    }

    final InspectionProfile profile =
        InspectionProjectProfileManager.getInstance(tag.getProject()).getInspectionProfile();
    final IntentionAction intentionAction = inspection.getIntentionAction(name, type);
    if (htmlTag && profile.isToolEnabled(key, tag)) {
      addElementsForTagWithManyQuickFixes(
          tag,
          localizedMessage,
          isInjectedHtmlTagForWhichNoProblemsReporting((HtmlTag) tag)
              ? HighlightInfoType.INFORMATION
              : SeverityRegistrar.getInstance(tag.getProject())
                  .getHighlightInfoTypeBySeverity(profile.getErrorLevel(key, tag).getSeverity()),
          intentionAction,
          basicIntention);
    } else if (!htmlTag) {
      addElementsForTag(tag, localizedMessage, HighlightInfoType.ERROR, basicIntention);
    }
  }
 protected void disableInspectionTool(@NotNull String shortName) {
   InspectionProfile profile =
       InspectionProjectProfileManager.getInstance(getProject()).getInspectionProfile();
   if (profile.getInspectionTool(shortName, getProject()) != null) {
     ((InspectionProfileImpl) profile).disableTool(shortName, getProject());
   }
 }
    @Override
    public void actionPerformed(AnActionEvent e) {
      final InspectionProjectProfileManager profileManager =
          InspectionProjectProfileManager.getInstance(myProject);
      final InspectionToolWrapper toolWrapper = myTree.getSelectedToolWrapper();
      InspectionProfile inspectionProfile = myInspectionProfile;
      final boolean profileIsDefined = isProfileDefined();
      if (!profileIsDefined) {
        inspectionProfile = guessProfileToSelect(profileManager);
      }

      if (toolWrapper != null) {
        final HighlightDisplayKey key =
            HighlightDisplayKey.find(
                toolWrapper.getShortName()); // do not search for dead code entry point tool
        if (key != null) {
          if (new EditInspectionToolsSettingsAction(key)
                  .editToolSettings(
                      myProject, (InspectionProfileImpl) inspectionProfile, profileIsDefined)
              && profileIsDefined) {
            updateCurrentProfile();
          }
          return;
        }
      }
      if (EditInspectionToolsSettingsAction.editToolSettings(
              myProject, inspectionProfile, profileIsDefined, null)
          && profileIsDefined) {
        updateCurrentProfile();
      }
    }
 @SuppressWarnings({"WeakerAccess", "UnusedReturnValue"}) // used in TeamCity
 public static InspectionResultsView showOfflineView(
     @NotNull Project project,
     @Nullable final String profileName,
     @NotNull final Map<String, Map<String, Set<OfflineProblemDescriptor>>> resMap,
     @NotNull String title) {
   InspectionProfileImpl profile;
   if (profileName != null) {
     profile = InspectionProjectProfileManager.getInstance(project).getProfile(profileName, false);
     if (profile == null) {
       profile = InspectionProfileManager.getInstance().getProfile(profileName, false);
     }
   } else {
     profile = null;
   }
   final InspectionProfileImpl inspectionProfile;
   if (profile != null) {
     inspectionProfile = profile;
   } else {
     inspectionProfile =
         new InspectionProfileImpl(profileName != null ? profileName : "Server Side") {
           @Override
           public HighlightDisplayLevel getErrorLevel(
               @NotNull final HighlightDisplayKey key, PsiElement element) {
             return InspectionProfileManager.getInstance()
                 .getCurrentProfile()
                 .getErrorLevel(key, element);
           }
         };
     for (String id : resMap.keySet()) {
       inspectionProfile.enableTool(id, project);
     }
   }
   return showOfflineView(project, resMap, inspectionProfile, title);
 }
  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;
  }
 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;
 }
  @Override
  public void computeUsages(List<PsiLiteralExpression> targets) {
    final Project project = myTarget.getProject();
    final PsiElement parent = myTarget.getParent().getParent();
    final LocalInspectionsPass pass =
        new LocalInspectionsPass(
            myFile,
            myFile.getViewProvider().getDocument(),
            parent.getTextRange().getStartOffset(),
            parent.getTextRange().getEndOffset(),
            LocalInspectionsPass.EMPTY_PRIORITY_RANGE,
            false,
            HighlightInfoProcessor.getEmpty());
    final InspectionProfile inspectionProfile =
        InspectionProjectProfileManager.getInstance(project).getInspectionProfile();
    for (PsiLiteralExpression target : targets) {
      final Object value = target.getValue();
      if (!(value instanceof String)) {
        continue;
      }
      InspectionToolWrapper toolWrapperById =
          ((InspectionProfileImpl) inspectionProfile).getToolById((String) value, target);
      if (!(toolWrapperById instanceof LocalInspectionToolWrapper)) {
        continue;
      }
      final LocalInspectionToolWrapper toolWrapper =
          ((LocalInspectionToolWrapper) toolWrapperById).createCopy();
      final InspectionManagerEx managerEx =
          (InspectionManagerEx) InspectionManager.getInstance(project);
      final GlobalInspectionContextImpl context = managerEx.createNewGlobalContext(false);
      toolWrapper.initialize(context);
      ((RefManagerImpl) context.getRefManager()).inspectionReadActionStarted();
      ProgressIndicator indicator = ProgressManager.getInstance().getProgressIndicator();
      Runnable inspect =
          new Runnable() {
            @Override
            public void run() {
              pass.doInspectInBatch(
                  context,
                  managerEx,
                  Collections.<LocalInspectionToolWrapper>singletonList(toolWrapper));
            }
          };
      if (indicator == null) {
        ProgressManager.getInstance()
            .executeProcessUnderProgress(inspect, new ProgressIndicatorBase());
      } else {
        inspect.run();
      }

      for (HighlightInfo info : pass.getInfos()) {
        final PsiElement element =
            CollectHighlightsUtil.findCommonParent(myFile, info.startOffset, info.endOffset);
        if (element != null) {
          addOccurrence(element);
        }
      }
    }
  }
 public MyVisitor(@NotNull ProblemsHolder holder) {
   myHolder = holder;
   InspectionProfile profile =
       InspectionProjectProfileManager.getInstance(holder.getProject()).getInspectionProfile();
   UnusedDeclarationInspectionBase tool =
       (UnusedDeclarationInspectionBase)
           profile.getUnwrappedTool(
               UnusedDeclarationInspectionBase.SHORT_NAME, holder.getFile());
   myDeadCodeInspection = tool == null ? new UnusedDeclarationInspectionBase() : tool;
 }
  protected InspectionTool[] getInspectionTools(PsiElement psiElement, InspectionManager manager) {
    final ModifiableModel model =
        InspectionProjectProfileManager.getInstance(manager.getProject())
            .getInspectionProfile()
            .getModifiableModel();
    InspectionProfileWrapper profile = new InspectionProfileWrapper((InspectionProfile) model);
    profile.init(manager.getProject());

    return profile.getInspectionTools(psiElement);
  }
 @Override
 @NotNull
 public HighlightSeverity getSeverity(final PsiElement psiElement) {
   InspectionProfile profile =
       psiElement == null
           ? (InspectionProfile) InspectionProfileManager.getInstance().getRootProfile()
           : InspectionProjectProfileManager.getInstance(psiElement.getProject())
               .getInspectionProfile();
   HighlightDisplayLevel level = profile.getErrorLevel(myToolKey, psiElement);
   LOG.assertTrue(level != HighlightDisplayLevel.DO_NOT_SHOW);
   return level.getSeverity();
 }
Ejemplo n.º 11
0
 private void onClose() {
   if (isModified()) {
     for (HectorComponentPanel panel : myAdditionalPanels) {
       try {
         panel.apply();
       } catch (ConfigurationException e) {
         // shouldn't be
       }
     }
     forceDaemonRestart();
     InspectionProjectProfileManager.getInstance(myFile.getProject()).updateStatusBar();
   }
 }
  @Override
  @Nullable
  public TextEditorHighlightingPass createHighlightingPass(
      @NotNull final PsiFile file, @NotNull final Editor editor) {
    TextRange textRange = FileStatusMap.getDirtyTextRange(editor, Pass.LOCAL_INSPECTIONS);
    if (textRange == null
        || !InspectionProjectProfileManager.getInstance(file.getProject()).isProfileLoaded()
        || myFileTools.containsKey(file) && !myFileTools.get(file)) {
      return null;
    }

    return new LocalInspectionsPass(
        file,
        editor.getDocument(),
        0,
        file.getTextLength(),
        LocalInspectionsPass.EMPTY_PRIORITY_RANGE,
        true,
        new DefaultHighlightInfoProcessor()) {
      @NotNull
      @Override
      List<LocalInspectionToolWrapper> getInspectionTools(
          @NotNull InspectionProfileWrapper profile) {
        List<LocalInspectionToolWrapper> tools = super.getInspectionTools(profile);
        List<LocalInspectionToolWrapper> result =
            new ArrayList<LocalInspectionToolWrapper>(tools.size());
        for (LocalInspectionToolWrapper tool : tools) {
          if (tool.runForWholeFile()) result.add(tool);
        }
        myFileTools.put(file, !result.isEmpty());
        return result;
      }

      @Override
      protected String getPresentableName() {
        return DaemonBundle.message("pass.whole.inspections");
      }

      @Override
      void inspectInjectedPsi(
          @NotNull List<PsiElement> elements,
          boolean onTheFly,
          @NotNull ProgressIndicator indicator,
          @NotNull InspectionManager iManager,
          boolean inVisibleRange,
          boolean checkDumbAwareness,
          @NotNull List<LocalInspectionToolWrapper> wrappers) {
        // already inspected in LIP
      }
    };
  }
 @NotNull
 @Override
 public Collection<BooleanOptionDescription> getOptions(@Nullable Project project) {
   if (project == null) return ContainerUtil.emptyList();
   List<BooleanOptionDescription> result = ContainerUtil.newArrayList();
   List<Tools> tools =
       InspectionProjectProfileManager.getInstance(project)
           .getCurrentProfile()
           .getAllEnabledInspectionTools(project);
   for (Tools tool : tools) {
     result.add(new ToolOptionDescription(tool, project));
   }
   return result;
 }
Ejemplo n.º 14
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;
 }
 private static boolean isAvailable(PyCallExpression node) {
   final InspectionProfile profile =
       InspectionProjectProfileManager.getInstance(node.getProject()).getInspectionProfile();
   final InspectionToolWrapper inspectionTool =
       profile.getInspectionTool("PyCompatibilityInspection", node.getProject());
   if (inspectionTool != null) {
     final InspectionProfileEntry inspection = inspectionTool.getTool();
     if (inspection instanceof PyCompatibilityInspection) {
       final JDOMExternalizableStringList versions =
           ((PyCompatibilityInspection) inspection).ourVersions;
       for (String s : versions) {
         if (!LanguageLevel.fromPythonVersion(s).supportsSetLiterals()) return false;
       }
     }
   }
   return LanguageLevel.forElement(node).supportsSetLiterals();
 }
Ejemplo n.º 16
0
  private void checkRequiredAttributes(
      XmlTag tag, String name, XmlElementDescriptor elementDescriptor) {
    XmlAttributeDescriptor[] attributeDescriptors = elementDescriptor.getAttributesDescriptors(tag);
    Set<String> requiredAttributes = null;

    for (XmlAttributeDescriptor attribute : attributeDescriptors) {
      if (attribute != null && attribute.isRequired()) {
        if (requiredAttributes == null) {
          requiredAttributes = new HashSet<String>();
        }
        requiredAttributes.add(attribute.getName(tag));
      }
    }

    if (requiredAttributes != null) {
      for (final String attrName : requiredAttributes) {
        if (tag.getAttribute(attrName, "") == null
            && !XmlExtension.getExtension(tag.getContainingFile())
                .isRequiredAttributeImplicitlyPresent(tag, attrName)) {

          final InsertRequiredAttributeFix insertRequiredAttributeIntention =
              new InsertRequiredAttributeFix(tag, attrName, null);
          final String localizedMessage =
              XmlErrorMessages.message("element.doesnt.have.required.attribute", name, attrName);
          final InspectionProfile profile =
              InspectionProjectProfileManager.getInstance(tag.getProject()).getInspectionProfile();
          final LocalInspectionToolWrapper toolWrapper =
              (LocalInspectionToolWrapper)
                  profile.getInspectionTool(RequiredAttributesInspection.SHORT_NAME, tag);
          if (toolWrapper != null) {
            RequiredAttributesInspection inspection =
                (RequiredAttributesInspection) toolWrapper.getTool();
            reportOneTagProblem(
                tag,
                attrName,
                localizedMessage,
                insertRequiredAttributeIntention,
                HighlightDisplayKey.find(RequiredAttributesInspection.SHORT_NAME),
                inspection,
                XmlEntitiesInspection.NOT_REQUIRED_ATTRIBUTE);
          }
        }
      }
    }
  }
 private void addRemoveTestsScope(Project project, boolean add) {
   final InspectionProjectProfileManager profileManager =
       InspectionProjectProfileManager.getInstance(project);
   final InspectionProfileImpl profile =
       (InspectionProfileImpl) profileManager.getCurrentProfile();
   final String shortName = myInspection.getShortName();
   final InspectionToolWrapper tool = profile.getInspectionTool(shortName, project);
   if (tool == null) {
     return;
   }
   if (add) {
     final NamedScope namedScope = NamedScopesHolder.getScope(project, "Tests");
     final HighlightDisplayKey key = HighlightDisplayKey.find(shortName);
     final HighlightDisplayLevel level = profile.getErrorLevel(key, namedScope, project);
     profile.addScope(tool, namedScope, level, false, project);
   } else {
     profile.removeScope(shortName, "Tests", project);
   }
   profile.scopesChanged();
 }
  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());
      }
    }
  }
Ejemplo n.º 19
0
  public static void doSetup(
      final LightProjectDescriptor descriptor,
      final LocalInspectionTool[] localInspectionTools,
      final Map<String, InspectionTool> availableInspectionTools)
      throws Exception {
    assertNull(
        "Previous test "
            + ourTestCase
            + " hasn't called tearDown(). Probably overriden without super call.",
        ourTestCase);
    IdeaLogger.ourErrorsOccurred = null;

    if (ourProject == null || !ourProjectDescriptor.equals(descriptor)) {
      initProject(descriptor);
    }

    ProjectManagerEx.getInstanceEx().setCurrentTestProject(ourProject);

    ((PsiDocumentManagerImpl) PsiDocumentManager.getInstance(getProject()))
        .clearUncommitedDocuments();

    for (LocalInspectionTool tool : localInspectionTools) {
      enableInspectionTool(availableInspectionTools, new LocalInspectionToolWrapper(tool));
    }

    final InspectionProfileImpl profile =
        new InspectionProfileImpl("Configurable") {
          @NotNull
          public InspectionProfileEntry[] getInspectionTools(PsiElement element) {
            if (availableInspectionTools != null) {
              final Collection<InspectionTool> tools = availableInspectionTools.values();
              return tools.toArray(new InspectionTool[tools.size()]);
            }
            return new InspectionTool[0];
          }

          @Override
          public List<ToolsImpl> getAllEnabledInspectionTools() {
            List<ToolsImpl> result = new ArrayList<ToolsImpl>();
            for (InspectionProfileEntry entry : getInspectionTools(null)) {
              result.add(new ToolsImpl(entry, entry.getDefaultLevel(), true));
            }
            return result;
          }

          public boolean isToolEnabled(HighlightDisplayKey key, PsiElement element) {
            return key != null && availableInspectionTools.containsKey(key.toString());
          }

          public HighlightDisplayLevel getErrorLevel(
              @NotNull HighlightDisplayKey key, PsiElement element) {
            InspectionTool localInspectionTool = availableInspectionTools.get(key.toString());
            return localInspectionTool != null
                ? localInspectionTool.getDefaultLevel()
                : HighlightDisplayLevel.WARNING;
          }

          public InspectionTool getInspectionTool(
              @NotNull String shortName, @NotNull PsiElement element) {
            if (availableInspectionTools.containsKey(shortName)) {
              return availableInspectionTools.get(shortName);
            }
            return null;
          }
        };
    final InspectionProfileManager inspectionProfileManager =
        InspectionProfileManager.getInstance();
    inspectionProfileManager.addProfile(profile);
    inspectionProfileManager.setRootProfile(profile.getName());
    InspectionProjectProfileManager.getInstance(getProject()).updateProfile(profile);
    InspectionProjectProfileManager.getInstance(getProject()).setProjectProfile(profile.getName());

    assertFalse(getPsiManager().isDisposed());

    CodeStyleSettingsManager.getInstance(getProject())
        .setTemporarySettings(new CodeStyleSettings());
  }
Ejemplo n.º 20
0
 @NotNull
 public static SeverityRegistrar getSeverityRegistrar(@Nullable Project project) {
   return project == null
       ? InspectionProfileManager.getInstance().getSeverityRegistrar()
       : InspectionProjectProfileManager.getInstance(project).getSeverityRegistrar();
 }
Ejemplo n.º 21
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;
    }
 private static boolean isInspectionEnabled(PsiFile file, Project project) {
   final InspectionProfile profile =
       InspectionProjectProfileManager.getInstance(project).getInspectionProfile();
   final HighlightDisplayKey unusedDefKey = HighlightDisplayKey.find(SHORT_NAME);
   return profile.isToolEnabled(unusedDefKey, file);
 }
 private static GrUnresolvedAccessInspection getInstance(PsiFile file, Project project) {
   final InspectionProfile profile =
       InspectionProjectProfileManager.getInstance(project).getInspectionProfile();
   return (GrUnresolvedAccessInspection) profile.getUnwrappedTool(SHORT_NAME, file);
 }
 private static HighlightDisplayLevel getHighlightDisplayLevel(
     Project project, GrReferenceElement ref) {
   final InspectionProfile profile =
       InspectionProjectProfileManager.getInstance(project).getInspectionProfile();
   return profile.getErrorLevel(HighlightDisplayKey.find(SHORT_NAME), ref);
 }
Ejemplo n.º 25
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;
    }