diff options
Diffstat (limited to 'platform/lang-impl/src/com/intellij/codeInspection')
3 files changed, 82 insertions, 55 deletions
diff --git a/platform/lang-impl/src/com/intellij/codeInspection/actions/GotoInspectionModel.java b/platform/lang-impl/src/com/intellij/codeInspection/actions/GotoInspectionModel.java index 4c6efc2b7897..ddcce12a9236 100644 --- a/platform/lang-impl/src/com/intellij/codeInspection/actions/GotoInspectionModel.java +++ b/platform/lang-impl/src/com/intellij/codeInspection/actions/GotoInspectionModel.java @@ -22,13 +22,11 @@ import com.intellij.codeInspection.ex.ScopeToolState; import com.intellij.ide.IdeBundle; import com.intellij.ide.util.gotoByName.SimpleChooseByNameModel; import com.intellij.openapi.project.Project; +import com.intellij.openapi.util.text.StringUtil; import com.intellij.profile.codeInspection.InspectionProfileManager; -import com.intellij.util.ArrayUtil; -import com.intellij.util.containers.MultiMap; import javax.swing.*; import java.util.HashMap; -import java.util.HashSet; import java.util.Map; import java.util.Set; @@ -36,11 +34,10 @@ import java.util.Set; * @author Konstantin Bulenkov */ public class GotoInspectionModel extends SimpleChooseByNameModel { - private final MultiMap<String, InspectionToolWrapper> myToolNames = MultiMap.createSmartList(); - private final Map<String, Set<InspectionToolWrapper>> myGroupNames = new HashMap<String, Set<InspectionToolWrapper>>(); - private final Map<String, InspectionToolWrapper> myToolShortNames = new HashMap<String, InspectionToolWrapper>(); + private static final InspectionToolWrapper[] EMPTY_WRAPPERS_ARRAY = new InspectionToolWrapper[0]; + private final Map<String, InspectionToolWrapper> myToolNames = new HashMap<String, InspectionToolWrapper>(); private final String[] myNames; - private final ListCellRenderer myListCellRenderer = new InspectionListCellRenderer(); + private final InspectionListCellRenderer myListCellRenderer = new InspectionListCellRenderer(); public GotoInspectionModel(Project project) { @@ -48,28 +45,14 @@ public class GotoInspectionModel extends SimpleChooseByNameModel { final InspectionProfileImpl rootProfile = (InspectionProfileImpl)InspectionProfileManager.getInstance().getRootProfile(); for (ScopeToolState state : rootProfile.getAllTools(project)) { InspectionToolWrapper tool = state.getTool(); - InspectionToolWrapper workingTool = tool; - if (tool instanceof LocalInspectionToolWrapper) { - workingTool = LocalInspectionToolWrapper.findTool2RunInBatch(project, null, tool.getShortName()); - if (workingTool == null) { - continue; - } + if (tool instanceof LocalInspectionToolWrapper && ((LocalInspectionToolWrapper)tool).isUnfair()) { + continue; } - myToolNames.putValue(tool.getDisplayName(), workingTool); - final String groupName = tool.getGroupDisplayName(); - Set<InspectionToolWrapper> toolsInGroup = myGroupNames.get(groupName); - if (toolsInGroup == null) { - toolsInGroup = new HashSet<InspectionToolWrapper>(); - myGroupNames.put(groupName, toolsInGroup); - } - toolsInGroup.add(workingTool); - myToolShortNames.put(tool.getShortName(), workingTool); + final String name = tool.getDisplayName() + " " + StringUtil.join(tool.getGroupPath(), " "); + myToolNames.put(name, tool); } - - final Set<String> nameIds = new HashSet<String>(); - nameIds.addAll(myToolNames.keySet()); - nameIds.addAll(myGroupNames.keySet()); - myNames = ArrayUtil.toStringArray(nameIds); + final Set<String> strings = myToolNames.keySet(); + myNames = strings.toArray(new String[strings.size()]); } @Override @@ -83,25 +66,19 @@ public class GotoInspectionModel extends SimpleChooseByNameModel { } @Override - public Object[] getElementsByName(final String id, final String pattern) { - final Set<InspectionToolWrapper> result = new HashSet<InspectionToolWrapper>(); - result.addAll(myToolNames.get(id)); - InspectionToolWrapper e = myToolShortNames.get(id); - if (e != null) { - result.add(e); - } - final Set<InspectionToolWrapper> entries = myGroupNames.get(id); - if (entries != null) { - result.addAll(entries); + public Object[] getElementsByName(final String name, final String pattern) { + final InspectionToolWrapper tool = myToolNames.get(name); + if (tool == null) { + return EMPTY_WRAPPERS_ARRAY; } - return result.toArray(new InspectionToolWrapper[result.size()]); + return new InspectionToolWrapper[] {tool}; } @Override public String getElementName(final Object element) { if (element instanceof InspectionToolWrapper) { InspectionToolWrapper entry = (InspectionToolWrapper)element; - return entry.getDisplayName() + " " + entry.getGroupDisplayName(); + return entry.getDisplayName() + " " + StringUtil.join(entry.getGroupPath(), " "); } return null; } diff --git a/platform/lang-impl/src/com/intellij/codeInspection/actions/InspectionListCellRenderer.java b/platform/lang-impl/src/com/intellij/codeInspection/actions/InspectionListCellRenderer.java index 8608a2d13142..c7386b2ffcb5 100644 --- a/platform/lang-impl/src/com/intellij/codeInspection/actions/InspectionListCellRenderer.java +++ b/platform/lang-impl/src/com/intellij/codeInspection/actions/InspectionListCellRenderer.java @@ -1,5 +1,5 @@ /* - * Copyright 2000-2012 JetBrains s.r.o. + * Copyright 2000-2014 JetBrains s.r.o. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -20,6 +20,10 @@ import com.intellij.ide.util.gotoByName.ChooseByNameBase; import com.intellij.lang.Language; import com.intellij.openapi.fileTypes.LanguageFileType; import com.intellij.openapi.fileTypes.UnknownFileType; +import com.intellij.openapi.util.TextRange; +import com.intellij.openapi.util.registry.Registry; +import com.intellij.openapi.util.text.StringUtil; +import com.intellij.psi.codeStyle.MinusculeMatcher; import com.intellij.ui.JBColor; import com.intellij.ui.SimpleColoredComponent; import com.intellij.ui.SimpleTextAttributes; @@ -31,6 +35,8 @@ import org.jetbrains.annotations.NotNull; import javax.swing.*; import java.awt.*; +import java.util.ArrayList; +import java.util.List; /** * @author Konstantin Bulenkov @@ -38,24 +44,31 @@ import java.awt.*; @SuppressWarnings({"GtkPreferredJComboBoxRenderer"}) public class InspectionListCellRenderer extends DefaultListCellRenderer implements MatcherHolder { private Matcher myMatcher; - private final SimpleTextAttributes SELECTED; - private final SimpleTextAttributes PLAIN; + private final SimpleTextAttributes mySelected; + private final SimpleTextAttributes myPlain; + private final SimpleTextAttributes myHighlighted; public InspectionListCellRenderer() { - SELECTED = new SimpleTextAttributes(UIUtil.getListSelectionBackground(), - UIUtil.getListSelectionForeground(), - JBColor.RED, - SimpleTextAttributes.STYLE_PLAIN); - PLAIN = new SimpleTextAttributes(UIUtil.getListBackground(), - UIUtil.getListForeground(), - JBColor.RED, - SimpleTextAttributes.STYLE_PLAIN); + mySelected = new SimpleTextAttributes(UIUtil.getListSelectionBackground(), + UIUtil.getListSelectionForeground(), + JBColor.RED, + SimpleTextAttributes.STYLE_PLAIN); + myPlain = new SimpleTextAttributes(UIUtil.getListBackground(), + UIUtil.getListForeground(), + JBColor.RED, + SimpleTextAttributes.STYLE_PLAIN); + myHighlighted = new SimpleTextAttributes(UIUtil.getListBackground(), + UIUtil.getListForeground(), + null, + SimpleTextAttributes.STYLE_SEARCH_MATCH); } @Override public Component getListCellRendererComponent(JList list, Object value, int index, boolean sel, boolean focus) { - final JPanel panel = new JPanel(new BorderLayout()); + final BorderLayout layout = new BorderLayout(); + layout.setHgap(5); + final JPanel panel = new JPanel(layout); panel.setOpaque(true); final Color bg = sel ? UIUtil.getListSelectionBackground() : UIUtil.getListBackground(); @@ -63,15 +76,37 @@ public class InspectionListCellRenderer extends DefaultListCellRenderer implemen panel.setBackground(bg); panel.setForeground(fg); - SimpleTextAttributes attr = sel ? SELECTED : PLAIN; if (value instanceof InspectionToolWrapper) { final InspectionToolWrapper toolWrapper = (InspectionToolWrapper)value; + final String inspectionName = " " + toolWrapper.getDisplayName(); + final String groupName = StringUtil.join(toolWrapper.getGroupPath(), " | "); + final String matchingText = inspectionName + "|" + groupName; + List<TextRange> fragments = ((MinusculeMatcher)myMatcher).matchingFragments(matchingText); + List<TextRange> adjustedFragments = new ArrayList<TextRange>(); + if (fragments != null) { + adjustedFragments.addAll(fragments); + } + final int splitPoint = adjustRanges(adjustedFragments, inspectionName.length() + 1); final SimpleColoredComponent c = new SimpleColoredComponent(); - SpeedSearchUtil.appendColoredFragmentForMatcher(" " + toolWrapper.getDisplayName(), c, attr, myMatcher, bg, sel); + final boolean matchHighlighting = Registry.is("ide.highlight.match.in.selected.only") && !sel; + if (matchHighlighting) { + c.append(inspectionName, myPlain); + } + else { + final List<TextRange> ranges = adjustedFragments.subList(0, splitPoint); + SpeedSearchUtil.appendColoredFragments(c, inspectionName, ranges, sel ? mySelected : myPlain, myHighlighted); + } panel.add(c, BorderLayout.WEST); final SimpleColoredComponent group = new SimpleColoredComponent(); - SpeedSearchUtil.appendColoredFragmentForMatcher(toolWrapper.getGroupDisplayName() + " ", group, attr, myMatcher, bg, sel); + if (matchHighlighting) { + group.append(groupName, SimpleTextAttributes.GRAYED_ATTRIBUTES); + } + else { + final SimpleTextAttributes attributes = sel ? mySelected : SimpleTextAttributes.GRAYED_ATTRIBUTES; + final List<TextRange> ranges = adjustedFragments.subList(splitPoint, adjustedFragments.size()); + SpeedSearchUtil.appendColoredFragments(group, groupName, ranges, attributes, myHighlighted); + } final JPanel right = new JPanel(new BorderLayout()); right.setBackground(bg); right.setForeground(fg); @@ -91,6 +126,21 @@ public class InspectionListCellRenderer extends DefaultListCellRenderer implemen return panel; } + private static int adjustRanges(List<TextRange> ranges, int offset) { + int result = 0; + for (int i = 0; i < ranges.size(); i++) { + final TextRange range = ranges.get(i); + final int startOffset = range.getStartOffset(); + if (startOffset < offset) { + result = i + 1; + } + else { + ranges.set(i, new TextRange(startOffset - offset, range.getEndOffset() - offset)); + } + } + return result; + } + @NotNull private static Icon getIcon(@NotNull InspectionToolWrapper tool) { Icon icon = null; diff --git a/platform/lang-impl/src/com/intellij/codeInspection/actions/ViewOfflineResultsAction.java b/platform/lang-impl/src/com/intellij/codeInspection/actions/ViewOfflineResultsAction.java index 0a7c8b24a275..b1ee98ac92fe 100644 --- a/platform/lang-impl/src/com/intellij/codeInspection/actions/ViewOfflineResultsAction.java +++ b/platform/lang-impl/src/com/intellij/codeInspection/actions/ViewOfflineResultsAction.java @@ -77,7 +77,7 @@ public class ViewOfflineResultsAction extends AnAction implements DumbAware { final Presentation presentation = event.getPresentation(); final Project project = event.getData(CommonDataKeys.PROJECT); presentation.setEnabled(project != null); - presentation.setVisible(ActionPlaces.MAIN_MENU.equals(event.getPlace()) && !PlatformUtils.isCidr()); + presentation.setVisible(ActionPlaces.isMainMenuOrActionSearch(event.getPlace()) && !PlatformUtils.isCidr()); } @Override |