Search in sources :

Example 1 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 2 with MinusculeMatcher

use of com.intellij.psi.codeStyle.MinusculeMatcher in project intellij-community by JetBrains.

the class DefaultClassNavigationContributor method processElementsWithName.

@Override
public void processElementsWithName(@NotNull String name, @NotNull final Processor<NavigationItem> processor, @NotNull final FindSymbolParameters parameters) {
    String namePattern = StringUtil.getShortName(parameters.getCompletePattern());
    boolean hasDollar = namePattern.contains("$");
    if (hasDollar) {
        Matcher matcher = ChooseByNamePopup.patternToDetectAnonymousClasses.matcher(namePattern);
        if (matcher.matches()) {
            namePattern = matcher.group(1);
            hasDollar = namePattern.contains("$");
        }
    }
    final MinusculeMatcher innerMatcher = hasDollar ? NameUtil.buildMatcher("*" + namePattern).build() : null;
    PsiShortNamesCache.getInstance(parameters.getProject()).processClassesWithName(name, new Processor<PsiClass>() {

        final boolean isAnnotation = parameters.getLocalPatternName().startsWith("@");

        @Override
        public boolean process(PsiClass aClass) {
            if (!isPhysical(aClass))
                return true;
            if (isAnnotation && !aClass.isAnnotationType())
                return true;
            if (innerMatcher != null) {
                if (aClass.getContainingClass() == null)
                    return true;
                String jvmQName = ClassUtil.getJVMClassName(aClass);
                if (jvmQName == null || !innerMatcher.matches(StringUtil.getShortName(jvmQName)))
                    return true;
            }
            return processor.process(aClass);
        }
    }, parameters.getSearchScope(), parameters.getIdFilter());
}
Also used : MinusculeMatcher(com.intellij.psi.codeStyle.MinusculeMatcher) Matcher(java.util.regex.Matcher) PsiClass(com.intellij.psi.PsiClass) MinusculeMatcher(com.intellij.psi.codeStyle.MinusculeMatcher)

Example 3 with MinusculeMatcher

use of com.intellij.psi.codeStyle.MinusculeMatcher in project intellij-community by JetBrains.

the class FileTextFieldImpl method addMacroPaths.

private void addMacroPaths(final CompletionResult result, final String typedText) {
    result.myMacros = new ArrayList<>();
    MinusculeMatcher matcher = createMatcher(typedText);
    for (String eachMacro : myMacroMap.keySet()) {
        if (matcher.matches(eachMacro)) {
            final String eachPath = myMacroMap.get(eachMacro);
            if (eachPath != null) {
                final LookupFile macroFile = myFinder.find(eachPath);
                if (macroFile != null && macroFile.exists()) {
                    result.myMacros.add(macroFile);
                    result.myToComplete.add(macroFile);
                    macroFile.setMacro(eachMacro);
                }
            }
        }
    }
}
Also used : MinusculeMatcher(com.intellij.psi.codeStyle.MinusculeMatcher)

Example 4 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 5 with MinusculeMatcher

use of com.intellij.psi.codeStyle.MinusculeMatcher in project intellij-community by JetBrains.

the class DefaultChooseByNameItemProvider method filterElements.

@Override
public boolean filterElements(@NotNull final ChooseByNameBase base, @NotNull final String pattern, boolean everywhere, @NotNull final ProgressIndicator indicator, @NotNull final Processor<Object> consumer) {
    if (base.myProject != null)
        base.myProject.putUserData(ChooseByNamePopup.CURRENT_SEARCH_PATTERN, pattern);
    String namePattern = getNamePattern(base, pattern);
    String qualifierPattern = getQualifierPattern(base, pattern);
    if (removeModelSpecificMarkup(base.getModel(), namePattern).isEmpty() && !base.canShowListForEmptyPattern())
        return true;
    final ChooseByNameModel model = base.getModel();
    String matchingPattern = convertToMatchingPattern(base, namePattern);
    if (matchingPattern == null)
        return true;
    List<MatchResult> namesList = new ArrayList<>();
    final CollectConsumer<MatchResult> collect = new SynchronizedCollectConsumer<>(namesList);
    long started;
    if (model instanceof ChooseByNameModelEx) {
        indicator.checkCanceled();
        started = System.currentTimeMillis();
        final MinusculeMatcher matcher = buildPatternMatcher(matchingPattern, NameUtil.MatchingCaseSensitivity.NONE);
        ((ChooseByNameModelEx) model).processNames(sequence -> {
            indicator.checkCanceled();
            MatchResult result = matches(base, pattern, matcher, sequence);
            if (result != null) {
                collect.consume(result);
                return true;
            }
            return false;
        }, everywhere);
        if (LOG.isDebugEnabled()) {
            LOG.debug("loaded + matched:" + (System.currentTimeMillis() - started) + "," + collect.getResult().size());
        }
    } else {
        String[] names = base.getNames(everywhere);
        started = System.currentTimeMillis();
        processNamesByPattern(base, names, matchingPattern, indicator, collect);
        if (LOG.isDebugEnabled()) {
            LOG.debug("matched:" + (System.currentTimeMillis() - started) + "," + names.length);
        }
    }
    indicator.checkCanceled();
    started = System.currentTimeMillis();
    List<MatchResult> results = (List<MatchResult>) collect.getResult();
    sortNamesList(namePattern, results);
    if (LOG.isDebugEnabled()) {
        LOG.debug("sorted:" + (System.currentTimeMillis() - started) + ",results:" + results.size());
    }
    indicator.checkCanceled();
    List<Object> sameNameElements = new SmartList<>();
    final Map<Object, MatchResult> qualifierMatchResults = ContainerUtil.newIdentityTroveMap();
    Comparator<Object> weightComparator = new Comparator<Object>() {

        @SuppressWarnings("unchecked")
        Comparator<Object> modelComparator = model instanceof Comparator ? (Comparator<Object>) model : new PathProximityComparator(myContext == null ? null : myContext.getElement());

        @Override
        public int compare(Object o1, Object o2) {
            int result = modelComparator.compare(o1, o2);
            return result != 0 ? result : qualifierMatchResults.get(o1).compareTo(qualifierMatchResults.get(o2));
        }
    };
    List<Object> qualifierMiddleMatched = new ArrayList<>();
    List<Pair<String, MinusculeMatcher>> patternsAndMatchers = getPatternsAndMatchers(qualifierPattern, base);
    boolean sortedByMatchingDegree = !(base.getModel() instanceof CustomMatcherModel);
    IdFilter idFilter = null;
    if (model instanceof ContributorsBasedGotoByModel) {
        idFilter = ((ContributorsBasedGotoByModel) model).getIdFilter(everywhere);
    }
    GlobalSearchScope searchScope = FindSymbolParameters.searchScopeFor(base.myProject, everywhere);
    FindSymbolParameters parameters = new FindSymbolParameters(pattern, namePattern, searchScope, idFilter);
    boolean afterStartMatch = false;
    for (MatchResult result : namesList) {
        indicator.checkCanceled();
        String name = result.elementName;
        boolean needSeparator = sortedByMatchingDegree && !result.startMatch && afterStartMatch;
        // use interruptible call if possible
        Object[] elements = model instanceof ContributorsBasedGotoByModel ? ((ContributorsBasedGotoByModel) model).getElementsByName(name, parameters, indicator) : model.getElementsByName(name, everywhere, namePattern);
        if (elements.length > 1) {
            sameNameElements.clear();
            qualifierMatchResults.clear();
            for (final Object element : elements) {
                indicator.checkCanceled();
                MatchResult qualifierResult = matchQualifier(element, base, patternsAndMatchers);
                if (qualifierResult != null) {
                    sameNameElements.add(element);
                    qualifierMatchResults.put(element, qualifierResult);
                }
            }
            Collections.sort(sameNameElements, weightComparator);
            for (Object element : sameNameElements) {
                if (!qualifierMatchResults.get(element).startMatch) {
                    qualifierMiddleMatched.add(element);
                    continue;
                }
                if (needSeparator && !startMiddleMatchVariants(qualifierMiddleMatched, consumer))
                    return false;
                if (!consumer.process(element))
                    return false;
                needSeparator = false;
                afterStartMatch = result.startMatch;
            }
        } else if (elements.length == 1 && matchQualifier(elements[0], base, patternsAndMatchers) != null) {
            if (needSeparator && !startMiddleMatchVariants(qualifierMiddleMatched, consumer))
                return false;
            if (!consumer.process(elements[0]))
                return false;
            afterStartMatch = result.startMatch;
        }
    }
    return ContainerUtil.process(qualifierMiddleMatched, consumer);
}
Also used : IdFilter(com.intellij.util.indexing.IdFilter) PsiProximityComparator(com.intellij.psi.util.proximity.PsiProximityComparator) GlobalSearchScope(com.intellij.psi.search.GlobalSearchScope) FList(com.intellij.util.containers.FList) MinusculeMatcher(com.intellij.psi.codeStyle.MinusculeMatcher) Pair(com.intellij.openapi.util.Pair) FindSymbolParameters(com.intellij.util.indexing.FindSymbolParameters)

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