Search in sources :

Example 6 with PsiShortNamesCache

use of com.intellij.psi.search.PsiShortNamesCache in project intellij-community by JetBrains.

the class CompositeShortNamesCache method getFieldsByName.

@Override
@NotNull
public PsiField[] getFieldsByName(@NotNull String name, @NotNull GlobalSearchScope scope) {
    Merger<PsiField> merger = null;
    for (PsiShortNamesCache cache : myCaches) {
        PsiField[] classes = cache.getFieldsByName(name, scope);
        if (classes.length != 0) {
            if (merger == null)
                merger = new Merger<>();
            merger.add(classes);
        }
    }
    PsiField[] result = merger == null ? null : merger.getResult();
    return result == null ? PsiField.EMPTY_ARRAY : result;
}
Also used : PsiShortNamesCache(com.intellij.psi.search.PsiShortNamesCache) PsiField(com.intellij.psi.PsiField) NotNull(org.jetbrains.annotations.NotNull)

Example 7 with PsiShortNamesCache

use of com.intellij.psi.search.PsiShortNamesCache in project intellij-community by JetBrains.

the class CompositeShortNamesCache method getAllClassNames.

@Override
@NotNull
public String[] getAllClassNames() {
    Merger<String> merger = new Merger<>();
    for (PsiShortNamesCache cache : myCaches) {
        String[] names = cache.getAllClassNames();
        merger.add(names);
    }
    String[] result = merger.getResult();
    return result != null ? result : ArrayUtil.EMPTY_STRING_ARRAY;
}
Also used : PsiShortNamesCache(com.intellij.psi.search.PsiShortNamesCache) NotNull(org.jetbrains.annotations.NotNull)

Example 8 with PsiShortNamesCache

use of com.intellij.psi.search.PsiShortNamesCache in project intellij-community by JetBrains.

the class CompositeShortNamesCache method getClassesByName.

@Override
@NotNull
public PsiClass[] getClassesByName(@NotNull String name, @NotNull GlobalSearchScope scope) {
    Merger<PsiClass> merger = null;
    for (PsiShortNamesCache cache : myCaches) {
        PsiClass[] classes = cache.getClassesByName(name, scope);
        if (classes.length != 0) {
            if (merger == null)
                merger = new Merger<>();
            merger.add(classes);
        }
    }
    PsiClass[] result = merger == null ? null : merger.getResult();
    return result != null ? result : PsiClass.EMPTY_ARRAY;
}
Also used : PsiShortNamesCache(com.intellij.psi.search.PsiShortNamesCache) PsiClass(com.intellij.psi.PsiClass) NotNull(org.jetbrains.annotations.NotNull)

Example 9 with PsiShortNamesCache

use of com.intellij.psi.search.PsiShortNamesCache in project intellij-community by JetBrains.

the class CompositeShortNamesCache method getMethodsByNameIfNotMoreThan.

@Override
@NotNull
public PsiMethod[] getMethodsByNameIfNotMoreThan(@NonNls @NotNull final String name, @NotNull final GlobalSearchScope scope, final int maxCount) {
    Merger<PsiMethod> merger = null;
    for (PsiShortNamesCache cache : myCaches) {
        PsiMethod[] methods = cache.getMethodsByNameIfNotMoreThan(name, scope, maxCount);
        if (methods.length == maxCount)
            return methods;
        if (methods.length != 0) {
            if (merger == null)
                merger = new Merger<>();
            merger.add(methods);
        }
    }
    PsiMethod[] result = merger == null ? null : merger.getResult();
    return result == null ? PsiMethod.EMPTY_ARRAY : result;
}
Also used : PsiShortNamesCache(com.intellij.psi.search.PsiShortNamesCache) PsiMethod(com.intellij.psi.PsiMethod) NotNull(org.jetbrains.annotations.NotNull)

Example 10 with PsiShortNamesCache

use of com.intellij.psi.search.PsiShortNamesCache in project intellij-community by JetBrains.

the class ReferenceChainLink method getGlobalMembers.

@Nullable
List<PsiMember> getGlobalMembers(VirtualFile placeFile, Project project) {
    if (isExpensive(project))
        return null;
    List<PsiMember> candidates = new ArrayList<>();
    AtomicInteger count = new AtomicInteger();
    Processor<PsiMember> processor = member -> {
        if (!(member instanceof PsiMethod && !ApproximateResolver.canHaveArgCount((PsiMethod) member, argCount))) {
            candidates.add(member);
        }
        return count.incrementAndGet() < 42;
    };
    PsiShortNamesCache cache = PsiShortNamesCache.getInstance(project);
    GlobalSearchScope scope = ResolveScopeManager.getInstance(project).getDefaultResolveScope(placeFile);
    if (isCall) {
        if (!cache.processMethodsWithName(referenceName, processor, scope, null)) {
            markExpensive(project);
            return null;
        }
    } else {
        PsiPackage pkg = JavaPsiFacade.getInstance(project).findPackage(referenceName);
        if (pkg != null && pkg.getDirectories(scope).length > 0)
            return null;
        if (!cache.processFieldsWithName(referenceName, processor, scope, null)) {
            markExpensive(project);
            return null;
        }
    }
    if (!cache.processClassesWithName(referenceName, processor, scope, null)) {
        markExpensive(project);
        return null;
    }
    return candidates.stream().filter(candidate -> canBeAccessible(placeFile, candidate)).collect(Collectors.toList());
}
Also used : VirtualFile(com.intellij.openapi.vfs.VirtualFile) Key(com.intellij.openapi.util.Key) GlobalSearchScope(com.intellij.psi.search.GlobalSearchScope) Set(java.util.Set) ResolveScopeManager(com.intellij.psi.impl.ResolveScopeManager) ContainerUtil(com.intellij.util.containers.ContainerUtil) Collectors(java.util.stream.Collectors) ArrayList(java.util.ArrayList) Nullable(org.jetbrains.annotations.Nullable) List(java.util.List) PsiUtilCore(com.intellij.psi.util.PsiUtilCore) AtomicInteger(java.util.concurrent.atomic.AtomicInteger) Processor(com.intellij.util.Processor) Project(com.intellij.openapi.project.Project) PsiShortNamesCache(com.intellij.psi.search.PsiShortNamesCache) com.intellij.psi(com.intellij.psi) ApproximateResolver(com.intellij.psi.impl.search.ApproximateResolver) NotNull(org.jetbrains.annotations.NotNull) PsiShortNamesCache(com.intellij.psi.search.PsiShortNamesCache) AtomicInteger(java.util.concurrent.atomic.AtomicInteger) GlobalSearchScope(com.intellij.psi.search.GlobalSearchScope) ArrayList(java.util.ArrayList) Nullable(org.jetbrains.annotations.Nullable)

Aggregations

PsiShortNamesCache (com.intellij.psi.search.PsiShortNamesCache)30 NotNull (org.jetbrains.annotations.NotNull)20 GlobalSearchScope (com.intellij.psi.search.GlobalSearchScope)11 Project (com.intellij.openapi.project.Project)6 PsiClass (com.intellij.psi.PsiClass)5 ArrayList (java.util.ArrayList)4 Nullable (org.jetbrains.annotations.Nullable)4 com.intellij.psi (com.intellij.psi)3 Processor (com.intellij.util.Processor)3 HashSet (com.intellij.util.containers.HashSet)3 Module (com.intellij.openapi.module.Module)2 PsiField (com.intellij.psi.PsiField)2 PsiMethod (com.intellij.psi.PsiMethod)2 THashSet (gnu.trove.THashSet)2 List (java.util.List)2 Matcher (java.util.regex.Matcher)2 Pattern (java.util.regex.Pattern)2 HighlightInfo (com.intellij.codeInsight.daemon.impl.HighlightInfo)1 NodeIterator (com.intellij.dupLocator.iterators.NodeIterator)1 DefaultPsiElementCellRenderer (com.intellij.ide.util.DefaultPsiElementCellRenderer)1