Search in sources :

Example 1 with FilteredQuery

use of com.intellij.util.FilteredQuery in project intellij-community by JetBrains.

the class CodeInsightUtil method processSubTypes.

public static void processSubTypes(PsiType psiType, final PsiElement context, boolean getRawSubtypes, @NotNull final PrefixMatcher matcher, Consumer<PsiType> consumer) {
    int arrayDim = psiType.getArrayDimensions();
    psiType = psiType.getDeepComponentType();
    if (!(psiType instanceof PsiClassType))
        return;
    PsiClassType baseType = JavaCompletionUtil.originalize((PsiClassType) psiType);
    PsiClassType.ClassResolveResult baseResult = baseType.resolveGenerics();
    PsiClass baseClass = baseResult.getElement();
    PsiSubstitutor baseSubstitutor = baseResult.getSubstitutor();
    if (baseClass == null)
        return;
    GlobalSearchScope scope = context.getResolveScope();
    Processor<PsiClass> inheritorsProcessor = createInheritorsProcessor(context, baseType, arrayDim, getRawSubtypes, consumer, baseClass, baseSubstitutor);
    addContextTypeArguments(context, baseType, inheritorsProcessor);
    if (baseClass.hasModifierProperty(PsiModifier.FINAL))
        return;
    if (matcher.getPrefix().length() > 2) {
        JBTreeTraverser<PsiClass> traverser = new JBTreeTraverser<>(c -> Arrays.asList(c.getInnerClasses()));
        AllClassesGetter.processJavaClasses(matcher, context.getProject(), scope, psiClass -> {
            Iterable<PsiClass> inheritors = traverser.withRoot(psiClass).filter(c -> c.isInheritor(baseClass, true));
            return ContainerUtil.process(inheritors, inheritorsProcessor);
        });
    } else {
        Query<PsiClass> baseQuery = ClassInheritorsSearch.search(baseClass, scope, true, true, false);
        Query<PsiClass> query = new FilteredQuery<>(baseQuery, psiClass -> !(psiClass instanceof PsiTypeParameter) && ContainerUtil.exists(JavaCompletionUtil.getAllLookupStrings(psiClass), matcher::prefixMatches));
        query.forEach(inheritorsProcessor);
    }
}
Also used : JBTreeTraverser(com.intellij.util.containers.JBTreeTraverser) FilteredQuery(com.intellij.util.FilteredQuery) GlobalSearchScope(com.intellij.psi.search.GlobalSearchScope)

Example 2 with FilteredQuery

use of com.intellij.util.FilteredQuery in project intellij-community by JetBrains.

the class ResourceFileUtil method findResourceFileInScope.

@Nullable
public static VirtualFile findResourceFileInScope(final String resourceName, final Project project, final GlobalSearchScope scope) {
    int index = resourceName.lastIndexOf('/');
    String packageName = index >= 0 ? resourceName.substring(0, index).replace('/', '.') : "";
    final String fileName = index >= 0 ? resourceName.substring(index + 1) : resourceName;
    final VirtualFile dir = new FilteredQuery<>(DirectoryIndex.getInstance(project).getDirectoriesByPackageName(packageName, false), file -> {
        final VirtualFile child = file.findChild(fileName);
        return child != null && scope.contains(child);
    }).findFirst();
    return dir != null ? dir.findChild(fileName) : null;
}
Also used : VirtualFile(com.intellij.openapi.vfs.VirtualFile) DirectoryIndex(com.intellij.openapi.roots.impl.DirectoryIndex) Nullable(org.jetbrains.annotations.Nullable) VirtualFile(com.intellij.openapi.vfs.VirtualFile) Project(com.intellij.openapi.project.Project) GlobalSearchScope(com.intellij.psi.search.GlobalSearchScope) Condition(com.intellij.openapi.util.Condition) FilteredQuery(com.intellij.util.FilteredQuery) Nullable(org.jetbrains.annotations.Nullable)

Aggregations

GlobalSearchScope (com.intellij.psi.search.GlobalSearchScope)2 FilteredQuery (com.intellij.util.FilteredQuery)2 Project (com.intellij.openapi.project.Project)1 DirectoryIndex (com.intellij.openapi.roots.impl.DirectoryIndex)1 Condition (com.intellij.openapi.util.Condition)1 VirtualFile (com.intellij.openapi.vfs.VirtualFile)1 JBTreeTraverser (com.intellij.util.containers.JBTreeTraverser)1 Nullable (org.jetbrains.annotations.Nullable)1