use of com.intellij.util.text.Matcher in project intellij-community by JetBrains.
the class VariantsCompletionAction method calcWords.
private static String[] calcWords(final String prefix, Editor editor) {
final Matcher matcher = NameUtil.buildMatcher(prefix, 0, true, true);
final Set<String> words = new HashSet<>();
CharSequence chars = editor.getDocument().getCharsSequence();
IdTableBuilding.scanWords(new IdTableBuilding.ScanWordProcessor() {
@Override
public void run(final CharSequence chars, @Nullable char[] charsArray, final int start, final int end) {
final String word = chars.subSequence(start, end).toString();
if (matcher.matches(word)) {
words.add(word);
}
}
}, chars, 0, chars.length());
ArrayList<String> sortedWords = new ArrayList<>(words);
Collections.sort(sortedWords);
return ArrayUtil.toStringArray(sortedWords);
}
use of com.intellij.util.text.Matcher in project intellij-community by JetBrains.
the class ChooseByNameBase method calcSelectedIndex.
@VisibleForTesting
public int calcSelectedIndex(Object[] modelElements, String trimmedText) {
if (myModel instanceof Comparator) {
return 0;
}
Matcher matcher = buildPatternMatcher(transformPattern(trimmedText));
final String statContext = statisticsContext();
Comparator<Object> itemComparator = Comparator.comparing(e -> trimmedText.equalsIgnoreCase(myModel.getElementName(e))).thenComparing(e -> matchingDegree(matcher, e)).thenComparing(e -> getUseCount(statContext, e)).reversed();
int bestPosition = 0;
while (bestPosition < modelElements.length - 1 && isSpecialElement(modelElements[bestPosition])) bestPosition++;
for (int i = 1; i < modelElements.length; i++) {
final Object modelElement = modelElements[i];
if (isSpecialElement(modelElement))
continue;
if (itemComparator.compare(modelElement, modelElements[bestPosition]) < 0) {
bestPosition = i;
}
}
return bestPosition;
}
use of com.intellij.util.text.Matcher in project intellij-community by JetBrains.
the class GotoActionItemProvider method processIntentions.
private boolean processIntentions(String pattern, Processor<MatchedValue> consumer, DataContext dataContext) {
MinusculeMatcher matcher = NameUtil.buildMatcher("*" + pattern, NameUtil.MatchingCaseSensitivity.NONE);
Map<String, ApplyIntentionAction> intentionMap = myIntentions.getValue();
JBIterable<ActionWrapper> intentions = JBIterable.from(intentionMap.keySet()).transform(intentionText -> {
ApplyIntentionAction intentionAction = intentionMap.get(intentionText);
if (myModel.actionMatches(pattern, matcher, intentionAction) == MatchMode.NONE)
return null;
return new ActionWrapper(intentionAction, intentionText, MatchMode.INTENTION, dataContext);
}).filter(Condition.NOT_NULL);
return processItems(pattern, intentions, consumer);
}
use of com.intellij.util.text.Matcher in project intellij-community by JetBrains.
the class InspectionListCellRenderer method getListCellRendererComponent.
@Override
public Component getListCellRendererComponent(JList list, Object value, int index, boolean sel, boolean focus) {
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();
final Color fg = sel ? UIUtil.getListSelectionForeground() : UIUtil.getListForeground();
panel.setBackground(bg);
panel.setForeground(fg);
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;
Matcher matcher = MatcherHolder.getAssociatedMatcher(list);
List<TextRange> fragments = matcher == null ? null : ((MinusculeMatcher) matcher).matchingFragments(matchingText);
List<TextRange> adjustedFragments = new ArrayList<>();
if (fragments != null) {
adjustedFragments.addAll(fragments);
}
final int splitPoint = adjustRanges(adjustedFragments, inspectionName.length() + 1);
final SimpleColoredComponent c = new SimpleColoredComponent();
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();
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);
right.add(group, BorderLayout.CENTER);
final JLabel icon = new JLabel(getIcon(toolWrapper));
icon.setBackground(bg);
icon.setForeground(fg);
right.add(icon, BorderLayout.EAST);
panel.add(right, BorderLayout.EAST);
} else {
// E.g. "..." item
return value == ChooseByNameBase.NON_PREFIX_SEPARATOR ? ChooseByNameBase.renderNonPrefixSeparatorComponent(UIUtil.getListBackground()) : super.getListCellRendererComponent(list, value, index, sel, focus);
}
return panel;
}
use of com.intellij.util.text.Matcher in project intellij-community by JetBrains.
the class PluginsTableRenderer method getTableCellRendererComponent.
@Override
public Component getTableCellRendererComponent(JTable table, Object value, boolean isSelected, boolean hasFocus, int row, int column) {
if (myPluginDescriptor != null) {
Couple<Color> colors = UIUtil.getCellColors(table, isSelected, row, column);
Color fg = colors.getFirst();
final Color background = colors.getSecond();
Color grayedFg = isSelected ? fg : new JBColor(Gray._130, Gray._120);
myPanel.setBackground(background);
myName.setForeground(fg);
myCategory.setForeground(grayedFg);
myStatus.setForeground(grayedFg);
myLastUpdated.setForeground(grayedFg);
myDownloads.setForeground(grayedFg);
myName.clear();
myName.setOpaque(false);
myCategory.clear();
myCategory.setOpaque(false);
String pluginName = myPluginDescriptor.getName() + " ";
Object query = table.getClientProperty(SpeedSearchSupply.SEARCH_QUERY_KEY);
SimpleTextAttributes attr = new SimpleTextAttributes(UIUtil.getListBackground(isSelected), UIUtil.getListForeground(isSelected), JBColor.RED, SimpleTextAttributes.STYLE_PLAIN);
Matcher matcher = NameUtil.buildMatcher("*" + query, NameUtil.MatchingCaseSensitivity.NONE);
if (query instanceof String) {
SpeedSearchUtil.appendColoredFragmentForMatcher(pluginName, myName, attr, matcher, UIUtil.getTableBackground(isSelected), true);
} else {
myName.append(pluginName);
}
String category = myPluginDescriptor.getCategory() == null ? null : StringUtil.toUpperCase(myPluginDescriptor.getCategory());
if (category != null) {
if (query instanceof String) {
SpeedSearchUtil.appendColoredFragmentForMatcher(category, myCategory, attr, matcher, UIUtil.getTableBackground(isSelected), true);
} else {
myCategory.append(category);
}
} else if (!myPluginsView) {
myCategory.append(AvailablePluginsManagerMain.N_A);
}
myStatus.setIcon(AllIcons.Nodes.Plugin);
if (myPluginDescriptor.isBundled()) {
myCategory.append(" [Bundled]");
myStatus.setIcon(AllIcons.Nodes.PluginJB);
}
String vendor = myPluginDescriptor.getVendor();
if (vendor != null && StringUtil.containsIgnoreCase(vendor, "jetbrains")) {
myStatus.setIcon(AllIcons.Nodes.PluginJB);
}
String downloads = myPluginDescriptor.getDownloads();
if (downloads != null && myPluginDescriptor instanceof PluginNode) {
if (downloads.length() > 3) {
downloads = new DecimalFormat("#,###").format(Integer.parseInt(downloads));
}
myDownloads.setText(downloads);
myRating.setRate(((PluginNode) myPluginDescriptor).getRating());
myLastUpdated.setText(DateFormatUtil.formatBetweenDates(((PluginNode) myPluginDescriptor).getDate(), System.currentTimeMillis()));
}
// plugin state-dependent rendering
PluginId pluginId = myPluginDescriptor.getPluginId();
IdeaPluginDescriptor installed = PluginManager.getPlugin(pluginId);
if (installed != null && ((IdeaPluginDescriptorImpl) installed).isDeleted()) {
// existing plugin uninstalled (both views)
myStatus.setIcon(AllIcons.Nodes.PluginRestart);
if (!isSelected)
myName.setForeground(FileStatus.DELETED.getColor());
myPanel.setToolTipText(IdeBundle.message("plugin.manager.uninstalled.tooltip"));
} else if (ourState.wasInstalled(pluginId)) {
// new plugin installed (both views)
myStatus.setIcon(AllIcons.Nodes.PluginRestart);
if (!isSelected)
myName.setForeground(FileStatus.ADDED.getColor());
myPanel.setToolTipText(IdeBundle.message("plugin.manager.installed.tooltip"));
} else if (ourState.wasUpdated(pluginId)) {
// existing plugin updated (both views)
myStatus.setIcon(AllIcons.Nodes.PluginRestart);
if (!isSelected)
myName.setForeground(FileStatus.ADDED.getColor());
myPanel.setToolTipText(IdeBundle.message("plugin.manager.updated.tooltip"));
} else if (ourState.hasNewerVersion(pluginId)) {
// existing plugin has a newer version (both views)
myStatus.setIcon(AllIcons.Nodes.Pluginobsolete);
if (!isSelected)
myName.setForeground(FileStatus.MODIFIED.getColor());
if (!myPluginsView && installed != null) {
myPanel.setToolTipText(IdeBundle.message("plugin.manager.new.version.tooltip", installed.getVersion()));
} else {
myPanel.setToolTipText(IdeBundle.message("plugin.manager.update.available.tooltip"));
}
} else if (isIncompatible(myPluginDescriptor, table.getModel())) {
// a plugin is incompatible with current installation (both views)
if (!isSelected)
myName.setForeground(JBColor.RED);
myPanel.setToolTipText(whyIncompatible(myPluginDescriptor, table.getModel()));
} else if (!myPluginDescriptor.isEnabled() && myPluginsView) {
// a plugin is disabled (plugins view only)
myStatus.setIcon(IconLoader.getDisabledIcon(myStatus.getIcon()));
}
}
return myPanel;
}
Aggregations