Exemplo n.º 1
0
 @Override
 protected void doOKAction() {
   apply((SeverityBasedTextAttributes) myOptionsList.getSelectedValue());
   final Collection<SeverityBasedTextAttributes> infoTypes =
       new HashSet<SeverityBasedTextAttributes>(
           SeverityUtil.getRegisteredHighlightingInfoTypes(mySeverityRegistrar));
   final ListModel listModel = myOptionsList.getModel();
   final List<HighlightSeverity> order = new ArrayList<HighlightSeverity>();
   for (int i = listModel.getSize() - 1; i >= 0; i--) {
     final SeverityBasedTextAttributes info =
         (SeverityBasedTextAttributes) listModel.getElementAt(i);
     order.add(info.getSeverity());
     if (!mySeverityRegistrar.isDefaultSeverity(info.getSeverity())) {
       infoTypes.remove(info);
       final Color stripeColor = info.getAttributes().getErrorStripeColor();
       mySeverityRegistrar.registerSeverity(
           info, stripeColor != null ? stripeColor : LightColors.YELLOW);
     }
   }
   for (SeverityBasedTextAttributes info : infoTypes) {
     mySeverityRegistrar.unregisterSeverity(info.getSeverity());
   }
   mySeverityRegistrar.setOrder(order);
   super.doOKAction();
 }
    @Override
    protected void fillDaemonCodeAnalyzerErrorsStatus(
        DaemonCodeAnalyzerStatus status,
        boolean fillErrorsCount,
        SeverityRegistrar severityRegistrar) {
      for (int i = 0; i < status.errorCount.length; i++) {
        final HighlightSeverity minSeverity = severityRegistrar.getSeverityByIndex(i);
        if (minSeverity == null) {
          continue;
        }

        int sum = 0;
        for (DomElement element : myDomElements) {
          final DomElementsProblemsHolder holder =
              myAnnotationsManager.getCachedProblemHolder(element);
          sum +=
              (SeverityRegistrar.getInstance(getProject())
                              .compare(minSeverity, HighlightSeverity.WARNING)
                          >= 0
                      ? holder.getProblems(element, true, true)
                      : holder.getProblems(element, true, minSeverity))
                  .size();
        }
        status.errorCount[i] = sum;
      }
    }
  private Color getColor(HighlightSeverity severity) {
    if (SeverityRegistrar.getInstance(myProject).compare(severity, HighlightSeverity.ERROR) >= 0) {
      return LightColors.RED;
    }

    if (SeverityRegistrar.getInstance(myProject).compare(severity, HighlightSeverity.WARNING)
        >= 0) {
      return LightColors.YELLOW;
    }

    return Color.white;
  }
  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 static String getTextAttributeKey(
     @NotNull Project project,
     @NotNull HighlightSeverity severity,
     @NotNull ProblemHighlightType highlightType) {
   if (highlightType == ProblemHighlightType.LIKE_DEPRECATED) {
     return HighlightInfoType.DEPRECATED.getAttributesKey().getExternalName();
   }
   if (highlightType == ProblemHighlightType.LIKE_UNKNOWN_SYMBOL
       && severity == HighlightSeverity.ERROR) {
     return HighlightInfoType.WRONG_REF.getAttributesKey().getExternalName();
   }
   if (highlightType == ProblemHighlightType.LIKE_UNUSED_SYMBOL) {
     return HighlightInfoType.UNUSED_SYMBOL.getAttributesKey().getExternalName();
   }
   SeverityRegistrar registrar =
       InspectionProjectProfileManagerImpl.getInstanceImpl(project).getSeverityRegistrar();
   return registrar.getHighlightInfoTypeBySeverity(severity).getAttributesKey().getExternalName();
 }
 @Override
 public void loadState(Element state) {
   try {
     mySeverityRegistrar.readExternal(state);
   } catch (Throwable e) {
     LOG.error(e);
   }
   super.loadState(state);
 }
  public FileLevelIntentionComponent(
      final String description,
      final HighlightSeverity severity,
      final List<Pair<HighlightInfo.IntentionActionDescriptor, TextRange>> intentions,
      final Project project,
      final PsiFile psiFile,
      final Editor editor) {
    myProject = project;

    final ShowIntentionsPass.IntentionsInfo info = new ShowIntentionsPass.IntentionsInfo();

    if (intentions != null) {
      for (Pair<HighlightInfo.IntentionActionDescriptor, TextRange> intention : intentions) {
        final HighlightInfo.IntentionActionDescriptor descriptor = intention.getFirst();
        info.intentionsToShow.add(descriptor);
        final String text = descriptor.getAction().getText();
        createActionLabel(
            text,
            new Runnable() {
              public void run() {
                ShowIntentionActionsHandler.chooseActionAndInvoke(
                    psiFile, editor, descriptor.getAction(), text);
              }
            });
      }
    }

    myLabel.setText(description);
    myLabel.setIcon(
        SeverityRegistrar.getInstance(project).compare(severity, HighlightSeverity.ERROR) >= 0
            ? ourQuickFixIcon
            : ourIntentionIcon);
    setBackground(getColor(severity));

    myLabel.addMouseListener(
        new MouseAdapter() {
          public void mouseClicked(MouseEvent e) {
            IntentionListStep step = new IntentionListStep(null, info, editor, psiFile, project);
            if (intentions != null && !intentions.isEmpty()) {
              HighlightInfo.IntentionActionDescriptor descriptor = intentions.get(0).getFirst();
              IntentionActionWithTextCaching actionWithTextCaching =
                  step.wrapAction(descriptor, psiFile, psiFile, editor);
              if (step.hasSubstep(actionWithTextCaching)) {
                step = step.getSubStep(actionWithTextCaching, null);
              }
            }
            JBPopupFactory.getInstance().createListPopup(step).showUnderneathOf(myLabel);
          }
        });
  }
Exemplo n.º 8
0
  void readExternal(
      @NotNull Element toolElement,
      @NotNull InspectionProfile profile,
      Map<String, List<String>> dependencies)
      throws InvalidDataException {
    final String levelName = toolElement.getAttributeValue(LEVEL_ATTRIBUTE);
    final ProfileManager profileManager = profile.getProfileManager();
    final SeverityRegistrar registrar =
        ((SeverityProvider) profileManager).getOwnSeverityRegistrar();
    HighlightDisplayLevel level =
        levelName != null ? HighlightDisplayLevel.find(registrar.getSeverity(levelName)) : null;
    if (level == null) {
      level = HighlightDisplayLevel.WARNING;
    }
    myDefaultState.setLevel(level);
    final String enabled = toolElement.getAttributeValue(ENABLED_ATTRIBUTE);
    final boolean isEnabled = enabled != null && Boolean.parseBoolean(enabled);

    final String enabledTool = toolElement.getAttributeValue(ENABLED_BY_DEFAULT_ATTRIBUTE);
    myDefaultState.setEnabled(enabledTool != null ? Boolean.parseBoolean(enabledTool) : isEnabled);
    final InspectionToolWrapper toolWrapper = myDefaultState.getTool();

    final List scopeElements = toolElement.getChildren(ProfileEx.SCOPE);
    final List<String> scopeNames = new ArrayList<String>();
    for (Object sO : scopeElements) {
      final Element scopeElement = (Element) sO;
      final String scopeName = scopeElement.getAttributeValue(ProfileEx.NAME);
      if (scopeName == null) {
        continue;
      }
      final NamedScopesHolder scopesHolder = profileManager.getScopesManager();
      NamedScope namedScope = null;
      if (scopesHolder != null) {
        namedScope = scopesHolder.getScope(scopeName);
      }
      final String errorLevel = scopeElement.getAttributeValue(LEVEL_ATTRIBUTE);
      final String enabledInScope = scopeElement.getAttributeValue(ENABLED_ATTRIBUTE);
      final InspectionToolWrapper copyToolWrapper = toolWrapper.createCopy();
      // check if unknown children exists
      if (scopeElement.getAttributes().size() > 3 || !scopeElement.getChildren().isEmpty()) {
        copyToolWrapper.getTool().readSettings(scopeElement);
      }
      HighlightDisplayLevel scopeLevel =
          errorLevel != null ? HighlightDisplayLevel.find(registrar.getSeverity(errorLevel)) : null;
      if (scopeLevel == null) {
        scopeLevel = level;
      }
      if (namedScope != null) {
        addTool(
            namedScope,
            copyToolWrapper,
            enabledInScope != null && Boolean.parseBoolean(enabledInScope),
            scopeLevel);
      } else {
        addTool(
            scopeName,
            copyToolWrapper,
            enabledInScope != null && Boolean.parseBoolean(enabledInScope),
            scopeLevel);
      }

      scopeNames.add(scopeName);
    }

    for (int i = 0; i < scopeNames.size(); i++) {
      String scopeName = scopeNames.get(i);
      List<String> order = dependencies.get(scopeName);
      if (order == null) {
        order = new ArrayList<String>();
        dependencies.put(scopeName, order);
      }
      for (int j = i + 1; j < scopeNames.size(); j++) {
        order.add(scopeNames.get(j));
      }
    }

    // check if unknown children exists
    if (toolElement.getAttributes().size() > 4
        || toolElement.getChildren().size() > scopeElements.size()) {
      toolWrapper.getTool().readSettings(toolElement);
    }

    myEnabled = isEnabled;
  }
 @Override
 public Element getState() {
   Element state = super.getState();
   mySeverityRegistrar.writeExternal(state);
   return state;
 }