use of com.intellij.psi.codeStyle.MinusculeMatcher in project intellij-community by JetBrains.
the class NameUtilMatchingTest method assertNoPreference.
private static void assertNoPreference(@NonNls String pattern, @NonNls String name1, @NonNls String name2, NameUtil.MatchingCaseSensitivity sensitivity) {
MinusculeMatcher matcher = NameUtil.buildMatcher(pattern, sensitivity);
assertEquals(matcher.matchingDegree(name1), matcher.matchingDegree(name2));
}
use of com.intellij.psi.codeStyle.MinusculeMatcher in project intellij-community by JetBrains.
the class SpeedSearchUtil method appendColoredFragmentForMatcher.
public static void appendColoredFragmentForMatcher(@NotNull String text, SimpleColoredComponent component, @NotNull final SimpleTextAttributes attributes, @Nullable Matcher matcher, Color selectedBg, boolean selected) {
if (!(matcher instanceof MinusculeMatcher) || (Registry.is("ide.highlight.match.in.selected.only") && !selected)) {
component.append(text, attributes);
return;
}
final Iterable<TextRange> iterable = ((MinusculeMatcher) matcher).matchingFragments(text);
if (iterable != null) {
final Color fg = attributes.getFgColor();
final int style = attributes.getStyle();
final SimpleTextAttributes plain = new SimpleTextAttributes(style, fg);
final SimpleTextAttributes highlighted = new SimpleTextAttributes(selectedBg, fg, null, style | SimpleTextAttributes.STYLE_SEARCH_MATCH);
appendColoredFragments(component, text, iterable, plain, highlighted);
} else {
component.append(text, attributes);
}
}
use of com.intellij.psi.codeStyle.MinusculeMatcher in project intellij-community by JetBrains.
the class GotoClassAction method findMember.
@Nullable
private static Navigatable findMember(String pattern, PsiElement psiElement, VirtualFile file) {
final PsiStructureViewFactory factory = LanguageStructureViewBuilder.INSTANCE.forLanguage(psiElement.getLanguage());
final StructureViewBuilder builder = factory == null ? null : factory.getStructureViewBuilder(psiElement.getContainingFile());
final FileEditor[] editors = FileEditorManager.getInstance(psiElement.getProject()).getEditors(file);
if (builder == null || editors.length == 0) {
return null;
}
final StructureView view = builder.createStructureView(editors[0], psiElement.getProject());
try {
final StructureViewTreeElement element = findElement(view.getTreeModel().getRoot(), psiElement, 4);
if (element == null) {
return null;
}
final MinusculeMatcher matcher = NameUtil.buildMatcher(pattern).build();
int max = Integer.MIN_VALUE;
Object target = null;
for (TreeElement treeElement : element.getChildren()) {
if (treeElement instanceof StructureViewTreeElement) {
String presentableText = treeElement.getPresentation().getPresentableText();
if (presentableText != null) {
final int degree = matcher.matchingDegree(presentableText);
if (degree > max) {
max = degree;
target = ((StructureViewTreeElement) treeElement).getValue();
}
}
}
}
return target instanceof Navigatable ? (Navigatable) target : null;
} finally {
Disposer.dispose(view);
}
}
use of com.intellij.psi.codeStyle.MinusculeMatcher in project intellij-community by JetBrains.
the class DefaultSymbolNavigationContributor method getQualifiedNameMatcher.
private static Condition<PsiMember> getQualifiedNameMatcher(String completePattern) {
final Condition<PsiMember> qualifiedMatcher;
if (completePattern.contains(".")) {
final MinusculeMatcher matcher = NameUtil.buildMatcher("*" + StringUtil.replace(completePattern, ".", ".*")).build();
qualifiedMatcher = member -> {
String qualifiedName = PsiUtil.getMemberQualifiedName(member);
return qualifiedName != null && matcher.matches(qualifiedName);
};
} else {
//noinspection unchecked
qualifiedMatcher = Condition.TRUE;
}
return qualifiedMatcher;
}
use of com.intellij.psi.codeStyle.MinusculeMatcher in project intellij-community by JetBrains.
the class OptionsTopHitProvider method consumeTopHits.
@Override
public final void consumeTopHits(@NonNls String pattern, Consumer<Object> collector, Project project) {
if (!pattern.startsWith("#"))
return;
pattern = pattern.substring(1);
final List<String> parts = StringUtil.split(pattern, " ");
if (parts.size() == 0) {
return;
}
String id = parts.get(0);
if (getId().startsWith(id) || pattern.startsWith(" ")) {
if (pattern.startsWith(" ")) {
pattern = pattern.trim();
} else {
pattern = pattern.substring(id.length()).trim().toLowerCase();
}
final MinusculeMatcher matcher = NameUtil.buildMatcher("*" + pattern, NameUtil.MatchingCaseSensitivity.NONE);
for (OptionDescription option : getOptions(project)) {
if (matcher.matches(option.getOption())) {
collector.consume(option);
}
}
}
}
Aggregations