com.intellij.codeInsight.daemon.HighlightDisplayKey Java Examples

The following examples show how to use com.intellij.codeInsight.daemon.HighlightDisplayKey. You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source File: InspectionsConfigTreeTable.java    From consulo with Apache License 2.0 6 votes vote down vote up
private static void collectInspectionFromNodes(final InspectionConfigTreeNode node,
                                               final Set<HighlightDisplayKey> tools,
                                               final List<InspectionConfigTreeNode> nodes) {
  if (node == null) {
    return;
  }
  nodes.add(node);

  final ToolDescriptors descriptors = node.getDescriptors();
  if (descriptors == null) {
    for (int i = 0; i < node.getChildCount(); i++) {
      collectInspectionFromNodes((InspectionConfigTreeNode)node.getChildAt(i), tools, nodes);
    }
  } else {
    final HighlightDisplayKey key = descriptors.getDefaultDescriptor().getKey();
    tools.add(key);
  }
}
 
Example #2
Source File: HighlightInfo.java    From consulo with Apache License 2.0 6 votes vote down vote up
@Nonnull
static HighlightInfo fromAnnotation(@Nonnull Annotation annotation, boolean batchMode) {
  TextAttributes forcedAttributes = annotation.getEnforcedTextAttributes();
  TextAttributesKey key = annotation.getTextAttributes();
  TextAttributesKey forcedAttributesKey = forcedAttributes == null && key != HighlighterColors.NO_HIGHLIGHTING ? key : null;

  HighlightInfo info =
          new HighlightInfo(forcedAttributes, forcedAttributesKey, convertType(annotation), annotation.getStartOffset(), annotation.getEndOffset(), annotation.getMessage(), annotation.getTooltip(),
                            annotation.getSeverity(), annotation.isAfterEndOfLine(), annotation.needsUpdateOnTyping(), annotation.isFileLevelAnnotation(), 0, annotation.getProblemGroup(), null,
                            annotation.getGutterIconRenderer());

  List<? extends Annotation.QuickFixInfo> fixes = batchMode ? annotation.getBatchFixes() : annotation.getQuickFixes();
  if (fixes != null) {
    for (Annotation.QuickFixInfo quickFixInfo : fixes) {
      TextRange range = quickFixInfo.textRange;
      HighlightDisplayKey k = quickFixInfo.key != null ? quickFixInfo.key : HighlightDisplayKey.find(ANNOTATOR_INSPECTION_SHORT_NAME);
      info.registerFix(quickFixInfo.quickFix, null, HighlightDisplayKey.getDisplayNameByKey(k), range, k);
    }
  }

  return info;
}
 
Example #3
Source File: DefaultInspectionToolPresentation.java    From consulo with Apache License 2.0 6 votes vote down vote up
protected HighlightSeverity getSeverity(@Nonnull 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;
}
 
Example #4
Source File: InspectionResultsView.java    From consulo with Apache License 2.0 6 votes vote down vote up
private boolean buildTree() {
  InspectionProfile profile = myInspectionProfile;
  boolean isGroupedBySeverity = myGlobalInspectionContext.getUIOptions().GROUP_BY_SEVERITY;
  myGroups = new HashMap<HighlightDisplayLevel, Map<String, InspectionGroupNode>>();
  final Map<String, Tools> tools = myGlobalInspectionContext.getTools();
  boolean resultsFound = false;
  for (Tools currentTools : tools.values()) {
    InspectionToolWrapper defaultToolWrapper = currentTools.getDefaultState().getTool();
    final HighlightDisplayKey key = HighlightDisplayKey.find(defaultToolWrapper.getShortName());
    for (ScopeToolState state : currentTools.getTools()) {
      InspectionToolWrapper toolWrapper = state.getTool();
      if (myProvider.checkReportedProblems(myGlobalInspectionContext, toolWrapper)) {
        addTool(toolWrapper, ((InspectionProfileImpl)profile).getErrorLevel(key, state.getScope(myProject), myProject), isGroupedBySeverity);
        resultsFound = true;
      }
    }
  }
  return resultsFound;
}
 
Example #5
Source File: InspectionsConfigTreeTable.java    From consulo with Apache License 2.0 6 votes vote down vote up
@Nullable
private Boolean isEnabled(final List<HighlightDisplayKey> selectedInspectionsNodes) {
  Boolean isPreviousEnabled = null;
  for (final HighlightDisplayKey key : selectedInspectionsNodes) {
    final ToolsImpl tools = mySettings.getInspectionProfile().getTools(key.toString(), mySettings.getProject());
    for (final ScopeToolState state : tools.getTools()) {
      final boolean enabled = state.isEnabled();
      if (isPreviousEnabled == null) {
        isPreviousEnabled = enabled;
      } else if (!isPreviousEnabled.equals(enabled)) {
        return null;
      }
    }
  }
  return isPreviousEnabled;
}
 
Example #6
Source File: InspectionsConfigTreeTable.java    From consulo with Apache License 2.0 6 votes vote down vote up
@Nullable
@Override
public Object getValueAt(final Object node, final int column) {
  if (column == TREE_COLUMN) {
    return null;
  }
  final InspectionConfigTreeNode treeNode = (InspectionConfigTreeNode)node;
  final List<HighlightDisplayKey> inspectionsKeys = InspectionsAggregationUtil.getInspectionsKeys(treeNode);
  if (column == SEVERITIES_COLUMN) {
    final MultiColoredHighlightSeverityIconSink sink = new MultiColoredHighlightSeverityIconSink();
    for (final HighlightDisplayKey selectedInspectionsNode : inspectionsKeys) {
      final String toolId = selectedInspectionsNode.toString();
      if (mySettings.getInspectionProfile().getTools(toolId, mySettings.getProject()).isEnabled()) {
        sink.put(mySettings.getInspectionProfile().getToolDefaultState(toolId, mySettings.getProject()),
                 mySettings.getInspectionProfile().getNonDefaultTools(toolId, mySettings.getProject()));
      }
    }
    return sink.constructIcon(mySettings.getInspectionProfile());
  } else if (column == IS_ENABLED_COLUMN) {
    return isEnabled(inspectionsKeys);
  }
  throw new IllegalArgumentException();
}
 
Example #7
Source File: Descriptor.java    From consulo with Apache License 2.0 5 votes vote down vote up
public Descriptor(@Nonnull ScopeToolState state, @Nonnull InspectionProfileImpl inspectionProfile, @Nonnull Project project) {
  myState = state;
  myInspectionProfile = inspectionProfile;
  InspectionToolWrapper tool = state.getTool();
  myText = tool.getDisplayName();
  final String[] groupPath = tool.getGroupPath();
  myGroup = groupPath.length == 0 ? new String[]{InspectionProfileEntry.GENERAL_GROUP_NAME} : groupPath;
  myKey = HighlightDisplayKey.find(tool.getShortName());
  myScopeName = state.getScopeName();
  myScope = state.getScope(project);
  myLevel = inspectionProfile.getErrorLevel(myKey, myScope, project);
  myEnabled = inspectionProfile.isToolEnabled(myKey, myScope, project);
  myToolWrapper = tool;
}
 
Example #8
Source File: Annotation.java    From consulo with Apache License 2.0 5 votes vote down vote up
/**
 * Register a quickfix which would be available onTheFly and in the batch mode. Should implement both IntentionAction and LocalQuickFix.
 */
public <T extends IntentionAction & LocalQuickFix> void registerUniversalFix(@Nonnull T fix,
                                                                             @javax.annotation.Nullable TextRange range,
                                                                             @javax.annotation.Nullable final HighlightDisplayKey key) {
  registerBatchFix(fix, range, key);
  registerFix(fix, range, key);
}
 
Example #9
Source File: MockInspectionProfile.java    From consulo with Apache License 2.0 5 votes vote down vote up
@Override
public boolean isToolEnabled(final HighlightDisplayKey key, PsiElement element) {
  final InspectionToolWrapper entry = ContainerUtil.find(myInspectionTools, new Condition<InspectionToolWrapper>() {
    @Override
    public boolean value(final InspectionToolWrapper inspectionProfileEntry) {
      return key.equals(HighlightDisplayKey.find(inspectionProfileEntry.getShortName()));
    }
  });
  assert entry != null;
  return !myDisabledTools.contains(entry);
}
 
Example #10
Source File: CodeInsightTestFixtureImpl.java    From consulo with Apache License 2.0 5 votes vote down vote up
private void enableInspectionTool(@Nonnull InspectionProfileEntry tool) {
  InspectionToolWrapper toolWrapper = InspectionToolRegistrar.wrapTool(tool);
  final String shortName = tool.getShortName();
  final HighlightDisplayKey key = HighlightDisplayKey.find(shortName);

  if (key == null) {
    String id = tool instanceof LocalInspectionTool ? ((LocalInspectionTool)tool).getID() : shortName;
    HighlightDisplayKey.register(shortName, toolWrapper.getDisplayName(), id);
  }
  myAvailableTools.put(shortName, toolWrapper);
}
 
Example #11
Source File: InspectionTestUtil.java    From consulo with Apache License 2.0 5 votes vote down vote up
public static void runTool(@Nonnull InspectionToolWrapper toolWrapper,
                           @Nonnull final AnalysisScope scope,
                           @Nonnull final GlobalInspectionContextImpl globalContext,
                           @Nonnull final InspectionManagerEx inspectionManager) {
  final String shortName = toolWrapper.getShortName();
  final HighlightDisplayKey key = HighlightDisplayKey.find(shortName);
  if (key == null){
    HighlightDisplayKey.register(shortName);
  }

  globalContext.doInspections(scope);
}
 
Example #12
Source File: LightPlatformTestCase.java    From consulo with Apache License 2.0 5 votes vote down vote up
public static void enableInspectionTool(@Nonnull Map<String, InspectionToolWrapper> availableLocalTools, @Nonnull InspectionToolWrapper toolWrapper) {
  final String shortName = toolWrapper.getShortName();
  final HighlightDisplayKey key = HighlightDisplayKey.find(shortName);
  if (key == null) {
    String id = toolWrapper instanceof LocalInspectionToolWrapper ? ((LocalInspectionToolWrapper)toolWrapper).getTool().getID() : toolWrapper.getShortName();
    HighlightDisplayKey.register(shortName, toolWrapper.getDisplayName(), id);
  }
  availableLocalTools.put(shortName, toolWrapper);
}
 
Example #13
Source File: InspectionProfileImpl.java    From consulo with Apache License 2.0 5 votes vote down vote up
@Override
public HighlightDisplayLevel getErrorLevel(@Nonnull HighlightDisplayKey inspectionToolKey, PsiElement element) {
  Project project = element == null ? null : element.getProject();
  final ToolsImpl tools = getTools(inspectionToolKey.toString(), project);
  HighlightDisplayLevel level = tools != null ? tools.getLevel(element) : HighlightDisplayLevel.WARNING;
  if (!((SeverityProvider)getProfileManager()).getOwnSeverityRegistrar().isSeverityValid(level.getSeverity().getName())) {
    level = HighlightDisplayLevel.WARNING;
    setErrorLevel(inspectionToolKey, level, project);
  }
  return level;
}
 
Example #14
Source File: InspectionProfileImpl.java    From consulo with Apache License 2.0 5 votes vote down vote up
@Override
public void convert(@Nonnull Element element, @Nonnull Project project) {
  initInspectionTools(project);
  final Element scopes = element.getChild(DefaultProjectProfileManager.SCOPES);
  if (scopes == null) {
    return;
  }
  final List children = scopes.getChildren(SCOPE);
  for (Object s : children) {
    Element scopeElement = (Element)s;
    final String profile = scopeElement.getAttributeValue(DefaultProjectProfileManager.PROFILE);
    if (profile != null) {
      final InspectionProfileImpl inspectionProfile = (InspectionProfileImpl)getProfileManager().getProfile(profile);
      if (inspectionProfile != null) {
        final NamedScope scope = getProfileManager().getScopesManager().getScope(scopeElement.getAttributeValue(NAME));
        if (scope != null) {
          for (InspectionToolWrapper toolWrapper : inspectionProfile.getInspectionTools(null)) {
            final HighlightDisplayKey key = HighlightDisplayKey.find(toolWrapper.getShortName());
            try {
              InspectionToolWrapper toolWrapperCopy = copyToolSettings(toolWrapper);
              HighlightDisplayLevel errorLevel = inspectionProfile.getErrorLevel(key, null, project);
              getTools(toolWrapper.getShortName(), project).addTool(scope, toolWrapperCopy, inspectionProfile.isToolEnabled(key), errorLevel);
            }
            catch (Exception e) {
              LOG.error(e);
            }
          }
        }
      }
    }
  }
  reduceConvertedScopes();
}
 
Example #15
Source File: HighlightInfo.java    From consulo with Apache License 2.0 5 votes vote down vote up
boolean canCleanup(@Nonnull PsiElement element) {
  if (myCanCleanup == null) {
    InspectionProfile profile = InspectionProjectProfileManager.getInstance(element.getProject()).getCurrentProfile();
    HighlightDisplayKey key = myKey;
    if (key == null) {
      myCanCleanup = false;
    }
    else {
      InspectionToolWrapper toolWrapper = profile.getInspectionTool(key.toString(), element);
      myCanCleanup = toolWrapper != null && toolWrapper.isCleanupTool();
    }
  }
  return myCanCleanup;
}
 
Example #16
Source File: HighlightInfo.java    From consulo with Apache License 2.0 5 votes vote down vote up
public IntentionActionDescriptor(@Nonnull IntentionAction action,
                                 @Nullable List<IntentionAction> options,
                                 @Nullable String displayName,
                                 @Nullable consulo.ui.image.Image icon,
                                 @Nullable HighlightDisplayKey key,
                                 @Nullable ProblemGroup problemGroup,
                                 @Nullable HighlightSeverity severity) {
  myAction = action;
  myOptions = options;
  myDisplayName = displayName;
  myIcon = icon;
  myKey = key;
  myProblemGroup = problemGroup;
  mySeverity = severity;
}
 
Example #17
Source File: HighlightInfo.java    From consulo with Apache License 2.0 5 votes vote down vote up
public void registerFix(@Nullable IntentionAction action, @Nullable List<IntentionAction> options, @Nullable String displayName, @Nullable TextRange fixRange, @Nullable HighlightDisplayKey key) {
  if (action == null) return;
  if (fixRange == null) fixRange = new TextRange(startOffset, endOffset);
  if (quickFixActionRanges == null) {
    quickFixActionRanges = ContainerUtil.createLockFreeCopyOnWriteList();
  }
  IntentionActionDescriptor desc = new IntentionActionDescriptor(action, options, displayName, null, key, getProblemGroup(), getSeverity());
  quickFixActionRanges.add(Pair.create(desc, fixRange));
  fixStartOffset = Math.min(fixStartOffset, fixRange.getStartOffset());
  fixEndOffset = Math.max(fixEndOffset, fixRange.getEndOffset());
  if (action instanceof HintAction) {
    setHint(true);
  }
}
 
Example #18
Source File: InspectionProjectProfileManager.java    From consulo with Apache License 2.0 5 votes vote down vote up
public static boolean isInformationLevel(String shortName, @Nonnull PsiElement element) {
  final HighlightDisplayKey key = HighlightDisplayKey.find(shortName);
  if (key != null) {
    final HighlightDisplayLevel errorLevel = getInstance(element.getProject()).getInspectionProfile().getErrorLevel(key, element);
    return HighlightDisplayLevel.DO_NOT_SHOW.equals(errorLevel);
  }
  return false;
}
 
Example #19
Source File: CodeSmellDetectorImpl.java    From consulo with Apache License 2.0 5 votes vote down vote up
private static String getDescription(@Nonnull HighlightInfo highlightInfo) {
  final String description = highlightInfo.getDescription();
  final HighlightInfoType type = highlightInfo.type;
  if (type instanceof HighlightInfoType.HighlightInfoTypeSeverityByKey) {
    final HighlightDisplayKey severityKey = ((HighlightInfoType.HighlightInfoTypeSeverityByKey)type).getSeverityKey();
    final String id = severityKey.getID();
    return "[" + id + "] " + description;
  }
  return description;
}
 
Example #20
Source File: InspectionsConfigTreeTable.java    From consulo with Apache License 2.0 5 votes vote down vote up
private void setToolEnabled(boolean newState, InspectionProfileImpl profile, HighlightDisplayKey tool) {
  final String toolId = tool.toString();
  if (newState) {
    profile.enableTool(toolId, mySettings.getProject());
  }
  else {
    profile.disableTool(toolId, mySettings.getProject());
  }
  for (ScopeToolState scopeToolState : profile.getTools(toolId, mySettings.getProject()).getTools()) {
    scopeToolState.setEnabled(newState);
  }
}
 
Example #21
Source File: InspectionResultsView.java    From consulo with Apache License 2.0 5 votes vote down vote up
@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) {
      new EditInspectionToolsSettingsAction(key).editToolSettings(myProject, (InspectionProfileImpl)inspectionProfile, profileIsDefined).doWhenDone(() -> {
          if(profileIsDefined) {
            updateCurrentProfile();
          }
      });
    }
  }
  else {
    EditInspectionToolsSettingsAction.editToolSettings(myProject, inspectionProfile, profileIsDefined, null).doWhenDone(() -> {
      if (profileIsDefined) {
        updateCurrentProfile();
      }
    });
  }
}
 
Example #22
Source File: LocalInspectionsPass.java    From consulo with Apache License 2.0 5 votes vote down vote up
@Override
public boolean process(Trinity<ProblemDescriptor, LocalInspectionToolWrapper, ProgressIndicator> trinity) {
  ProgressIndicator indicator = trinity.getThird();
  if (indicator.isCanceled()) {
    return false;
  }

  ProblemDescriptor descriptor = trinity.first;
  LocalInspectionToolWrapper tool = trinity.second;
  PsiElement psiElement = descriptor.getPsiElement();
  if (psiElement == null) return true;
  PsiFile file = psiElement.getContainingFile();
  Document thisDocument = documentManager.getDocument(file);

  HighlightSeverity severity = inspectionProfile.getErrorLevel(HighlightDisplayKey.find(tool.getShortName()), file).getSeverity();

  infos.clear();
  createHighlightsForDescriptor(infos, emptyActionRegistered, ilManager, file, thisDocument, tool, severity, descriptor, psiElement);
  for (HighlightInfo info : infos) {
    final EditorColorsScheme colorsScheme = getColorsScheme();
    UpdateHighlightersUtil
            .addHighlighterToEditorIncrementally(myProject, myDocument, getFile(), myRestrictRange.getStartOffset(), myRestrictRange.getEndOffset(),
                                                 info, colorsScheme, getId(), ranges2markersCache);
  }

  return true;
}
 
Example #23
Source File: LocalInspectionsPass.java    From consulo with Apache License 2.0 5 votes vote down vote up
private void addHighlightsFromResults(@Nonnull List<HighlightInfo> outInfos, @Nonnull ProgressIndicator indicator) {
  InspectionProfile inspectionProfile = InspectionProjectProfileManager.getInstance(myProject).getInspectionProfile();
  PsiDocumentManager documentManager = PsiDocumentManager.getInstance(myProject);
  InjectedLanguageManager ilManager = InjectedLanguageManager.getInstance(myProject);
  Set<Pair<TextRange, String>> emptyActionRegistered = new THashSet<>();

  for (Map.Entry<PsiFile, List<InspectionResult>> entry : result.entrySet()) {
    indicator.checkCanceled();
    PsiFile file = entry.getKey();
    Document documentRange = documentManager.getDocument(file);
    if (documentRange == null) continue;
    List<InspectionResult> resultList = entry.getValue();
    synchronized (resultList) {
      for (InspectionResult inspectionResult : resultList) {
        indicator.checkCanceled();
        LocalInspectionToolWrapper tool = inspectionResult.tool;
        HighlightSeverity severity = inspectionProfile.getErrorLevel(HighlightDisplayKey.find(tool.getShortName()), file).getSeverity();
        for (ProblemDescriptor descriptor : inspectionResult.foundProblems) {
          indicator.checkCanceled();
          PsiElement element = descriptor.getPsiElement();
          if (element != null) {
            createHighlightsForDescriptor(outInfos, emptyActionRegistered, ilManager, file, documentRange, tool, severity, descriptor, element);
          }
        }
      }
    }
  }
}
 
Example #24
Source File: LocalInspectionsPass.java    From consulo with Apache License 2.0 5 votes vote down vote up
@Nullable
private HighlightInfo createHighlightInfo(@Nonnull ProblemDescriptor descriptor,
                                          @Nonnull LocalInspectionToolWrapper tool,
                                          @Nonnull HighlightInfoType level,
                                          @Nonnull Set<Pair<TextRange, String>> emptyActionRegistered,
                                          @Nonnull PsiElement element) {
  @NonNls String message = ProblemDescriptorUtil.renderDescriptionMessage(descriptor, element);

  final HighlightDisplayKey key = HighlightDisplayKey.find(tool.getShortName());
  final InspectionProfile inspectionProfile = myProfileWrapper.getInspectionProfile();
  if (!inspectionProfile.isToolEnabled(key, getFile())) return null;

  HighlightInfoType type = new HighlightInfoType.HighlightInfoTypeImpl(level.getSeverity(element), level.getAttributesKey());
  final String plainMessage = message.startsWith("<html>") ? StringUtil.unescapeXml(XmlStringUtil.stripHtml(message).replaceAll("<[^>]*>", "")) : message;
  @NonNls final String link = " <a " +
                              "href=\"#inspection/" +
                              tool.getShortName() +
                              "\"" +
                              (UIUtil.isUnderDarcula() ? " color=\"7AB4C9\" " : "") +
                              ">" +
                              DaemonBundle.message("inspection.extended.description") +
                              "</a> " +
                              myShortcutText;

  @NonNls String tooltip = null;
  if (descriptor.showTooltip()) {
    tooltip = XmlStringUtil.wrapInHtml((message.startsWith("<html>") ? XmlStringUtil.stripHtml(message) : XmlStringUtil.escapeString(message)) + link);
  }
  HighlightInfo highlightInfo = highlightInfoFromDescriptor(descriptor, type, plainMessage, tooltip, element);
  if (highlightInfo != null) {
    registerQuickFixes(tool, descriptor, highlightInfo, emptyActionRegistered);
  }
  return highlightInfo;
}
 
Example #25
Source File: LocalInspectionsPass.java    From consulo with Apache License 2.0 5 votes vote down vote up
private static void registerQuickFixes(@Nonnull LocalInspectionToolWrapper tool,
                                       @Nonnull ProblemDescriptor descriptor,
                                       @Nonnull HighlightInfo highlightInfo,
                                       @Nonnull Set<Pair<TextRange, String>> emptyActionRegistered) {
  final HighlightDisplayKey key = HighlightDisplayKey.find(tool.getShortName());
  boolean needEmptyAction = true;
  final QuickFix[] fixes = descriptor.getFixes();
  if (fixes != null && fixes.length > 0) {
    for (int k = 0; k < fixes.length; k++) {
      if (fixes[k] != null) { // prevent null fixes from var args
        QuickFixAction.registerQuickFixAction(highlightInfo, QuickFixWrapper.wrap(descriptor, k), key);
        needEmptyAction = false;
      }
    }
  }
  HintAction hintAction = descriptor instanceof ProblemDescriptorImpl ? ((ProblemDescriptorImpl)descriptor).getHintAction() : null;
  if (hintAction != null) {
    QuickFixAction.registerQuickFixAction(highlightInfo, hintAction, key);
    needEmptyAction = false;
  }
  if (((ProblemDescriptorBase)descriptor).getEnforcedTextAttributes() != null) {
    needEmptyAction = false;
  }
  if (needEmptyAction && emptyActionRegistered.add(Pair.create(highlightInfo.getFixTextRange(), tool.getShortName()))) {
    IntentionAction emptyIntentionAction = new EmptyIntentionAction(tool.getDisplayName());
    QuickFixAction.registerQuickFixAction(highlightInfo, emptyIntentionAction, key);
  }
}
 
Example #26
Source File: LocalInspectionsPass.java    From consulo with Apache License 2.0 5 votes vote down vote up
@Nonnull
List<LocalInspectionToolWrapper> getInspectionTools(@Nonnull InspectionProfileWrapper profile) {
  final InspectionToolWrapper[] toolWrappers = profile.getInspectionProfile().getInspectionTools(getFile());
  InspectionProfileWrapper.checkInspectionsDuplicates(toolWrappers);
  List<LocalInspectionToolWrapper> enabled = new ArrayList<>();
  for (InspectionToolWrapper toolWrapper : toolWrappers) {
    ProgressManager.checkCanceled();
    if (!profile.isToolEnabled(HighlightDisplayKey.find(toolWrapper.getShortName()), getFile())) continue;
    LocalInspectionToolWrapper wrapper = null;
    if (toolWrapper instanceof LocalInspectionToolWrapper) {
      wrapper = (LocalInspectionToolWrapper)toolWrapper;
    }
    else if (toolWrapper instanceof GlobalInspectionToolWrapper) {
      final GlobalInspectionToolWrapper globalInspectionToolWrapper = (GlobalInspectionToolWrapper)toolWrapper;
      wrapper = globalInspectionToolWrapper.getSharedLocalInspectionToolWrapper();
    }
    if (wrapper == null) continue;
    String language = wrapper.getLanguage();
    if (language != null && Language.findLanguageByID(language) == null) {
      continue; // filter out at least unknown languages
    }
    if (myIgnoreSuppressed && SuppressionUtil.inspectionResultSuppressed(getFile(), wrapper.getTool())) {
      continue;
    }
    enabled.add(wrapper);
  }
  return enabled;
}
 
Example #27
Source File: QuickFixAction.java    From consulo with Apache License 2.0 5 votes vote down vote up
public static void registerQuickFixAction(@Nullable HighlightInfo info,
                                          @Nullable TextRange fixRange,
                                          @Nullable IntentionAction action,
                                          @Nullable final HighlightDisplayKey key) {
  if (info == null) return;
  info.registerFix(action, null, HighlightDisplayKey.getDisplayNameByKey(key), fixRange, key);
}
 
Example #28
Source File: IntentionManagerImpl.java    From consulo with Apache License 2.0 5 votes vote down vote up
@Override
@Nonnull
public List<IntentionAction> getStandardIntentionOptions(@Nonnull final HighlightDisplayKey displayKey, @Nonnull final PsiElement context) {
  List<IntentionAction> options = new ArrayList<>();
  options.add(new EditInspectionToolsSettingsAction(displayKey));
  options.add(new RunInspectionIntention(displayKey));
  options.add(new DisableInspectionToolAction(displayKey));
  return options;
}
 
Example #29
Source File: SingleInspectionProfilePanel.java    From consulo with Apache License 2.0 5 votes vote down vote up
private void updateErrorLevel(final InspectionConfigTreeNode child,
                              final boolean showOptionsAndDescriptorPanels,
                              @Nonnull HighlightDisplayLevel level) {
  final HighlightDisplayKey key = child.getDefaultDescriptor().getKey();
  mySelectedProfile.setErrorLevel(key, level, null, myProjectProfileManager.getProject());
  child.dropCache();
  if (showOptionsAndDescriptorPanels) {
    updateOptionsAndDescriptionPanel(new TreePath(child.getPath()));
  }
}
 
Example #30
Source File: ScopesAndSeveritiesTable.java    From consulo with Apache License 2.0 5 votes vote down vote up
protected TableSettings(final List<InspectionConfigTreeNode> nodes,
                        final InspectionProfileImpl inspectionProfile,
                        final Project project) {
  myNodes = nodes;
  myKeys = new ArrayList<HighlightDisplayKey>(myNodes.size());
  myKeyNames = new ArrayList<String>(myNodes.size());
  for(final InspectionConfigTreeNode node : nodes) {
    final HighlightDisplayKey key = node.getDefaultDescriptor().getKey();
    myKeys.add(key);
    myKeyNames.add(key.toString());
  }

  myInspectionProfile = inspectionProfile;
  myProject = project;
}