use of com.intellij.util.indexing.FindSymbolParameters 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);
}
use of com.intellij.util.indexing.FindSymbolParameters in project intellij-community by JetBrains.
the class DefaultSymbolNavigationContributor method processElementsWithName.
@Override
public void processElementsWithName(@NotNull String name, @NotNull final Processor<NavigationItem> processor, @NotNull final FindSymbolParameters parameters) {
GlobalSearchScope scope = parameters.getSearchScope();
IdFilter filter = parameters.getIdFilter();
PsiShortNamesCache cache = PsiShortNamesCache.getInstance(scope.getProject());
String completePattern = parameters.getCompletePattern();
final Condition<PsiMember> qualifiedMatcher = getQualifiedNameMatcher(completePattern);
//noinspection UnusedDeclaration
final Set<PsiMethod> collectedMethods = new THashSet<>();
boolean success = cache.processFieldsWithName(name, field -> {
if (isOpenable(field) && qualifiedMatcher.value(field))
return processor.process(field);
return true;
}, scope, filter) && cache.processClassesWithName(name, aClass -> {
if (isOpenable(aClass) && qualifiedMatcher.value(aClass))
return processor.process(aClass);
return true;
}, scope, filter) && cache.processMethodsWithName(name, method -> {
if (!method.isConstructor() && isOpenable(method) && qualifiedMatcher.value(method)) {
collectedMethods.add(method);
}
return true;
}, scope, filter);
if (success) {
// hashSuperMethod accesses index and can not be invoked without risk of the deadlock in processMethodsWithName
Iterator<PsiMethod> iterator = collectedMethods.iterator();
while (iterator.hasNext()) {
PsiMethod method = iterator.next();
if (!hasSuperMethod(method, scope, qualifiedMatcher) && !processor.process(method))
return;
ProgressManager.checkCanceled();
iterator.remove();
}
}
}
Aggregations