Search in sources :

Example 6 with MinusculeMatcher

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));
}
Also used : MinusculeMatcher(com.intellij.psi.codeStyle.MinusculeMatcher)

Example 7 with MinusculeMatcher

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);
    }
}
Also used : SimpleTextAttributes(com.intellij.ui.SimpleTextAttributes) TextRange(com.intellij.openapi.util.TextRange) MinusculeMatcher(com.intellij.psi.codeStyle.MinusculeMatcher)

Example 8 with MinusculeMatcher

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);
    }
}
Also used : PsiStructureViewFactory(com.intellij.lang.PsiStructureViewFactory) LanguageStructureViewBuilder(com.intellij.lang.LanguageStructureViewBuilder) StructureViewBuilder(com.intellij.ide.structureView.StructureViewBuilder) FileEditor(com.intellij.openapi.fileEditor.FileEditor) StructureView(com.intellij.ide.structureView.StructureView) StructureViewTreeElement(com.intellij.ide.structureView.StructureViewTreeElement) MinusculeMatcher(com.intellij.psi.codeStyle.MinusculeMatcher) TreeElement(com.intellij.ide.util.treeView.smartTree.TreeElement) StructureViewTreeElement(com.intellij.ide.structureView.StructureViewTreeElement) Navigatable(com.intellij.pom.Navigatable) Nullable(org.jetbrains.annotations.Nullable)

Example 9 with MinusculeMatcher

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;
}
Also used : MinusculeMatcher(com.intellij.psi.codeStyle.MinusculeMatcher)

Example 10 with MinusculeMatcher

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);
            }
        }
    }
}
Also used : OptionDescription(com.intellij.ide.ui.search.OptionDescription) MinusculeMatcher(com.intellij.psi.codeStyle.MinusculeMatcher)

Aggregations

MinusculeMatcher (com.intellij.psi.codeStyle.MinusculeMatcher)12 OptionDescription (com.intellij.ide.ui.search.OptionDescription)3 ProgressIndicator (com.intellij.openapi.progress.ProgressIndicator)3 ProgressManager (com.intellij.openapi.progress.ProgressManager)3 TextRange (com.intellij.openapi.util.TextRange)3 StringUtil (com.intellij.openapi.util.text.StringUtil)3 NameUtil (com.intellij.psi.codeStyle.NameUtil)3 ContainerUtil (com.intellij.util.containers.ContainerUtil)3 java.util (java.util)3 NotNull (org.jetbrains.annotations.NotNull)3 Nullable (org.jetbrains.annotations.Nullable)3 DataManager (com.intellij.ide.DataManager)2 SearchTopHitProvider (com.intellij.ide.SearchTopHitProvider)2 ApplyIntentionAction (com.intellij.ide.actions.ApplyIntentionAction)2 OptionsTopHitProvider (com.intellij.ide.ui.OptionsTopHitProvider)2 ActionFromOptionDescriptorProvider (com.intellij.ide.ui.search.ActionFromOptionDescriptorProvider)2 SearchableOptionsRegistrar (com.intellij.ide.ui.search.SearchableOptionsRegistrar)2 SearchableOptionsRegistrarImpl (com.intellij.ide.ui.search.SearchableOptionsRegistrarImpl)2 GotoActionModel (com.intellij.ide.util.gotoByName.GotoActionModel)2 com.intellij.openapi.actionSystem (com.intellij.openapi.actionSystem)2