Search in sources :

Example 76 with GlobalSearchScope

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

the class TodoPackageNode method getFileCount.

private int getFileCount(final PackageElement packageElement) {
    int count = 0;
    if (getSettings().isFlattenPackages()) {
        final PsiPackage aPackage = packageElement.getPackage();
        final Module module = packageElement.getModule();
        final GlobalSearchScope scope = module != null ? GlobalSearchScope.moduleScope(module) : GlobalSearchScope.projectScope(aPackage.getProject());
        final PsiDirectory[] directories = aPackage.getDirectories(scope);
        for (PsiDirectory directory : directories) {
            Iterator<PsiFile> iterator = myBuilder.getFilesUnderDirectory(directory);
            while (iterator.hasNext()) {
                PsiFile psiFile = iterator.next();
                if (getStructure().accept(psiFile))
                    count++;
            }
        }
    } else {
        Iterator<PsiFile> iterator = getFiles(packageElement);
        while (iterator.hasNext()) {
            PsiFile psiFile = iterator.next();
            if (getStructure().accept(psiFile)) {
                count++;
            }
        }
    }
    return count;
}
Also used : GlobalSearchScope(com.intellij.psi.search.GlobalSearchScope) PsiDirectory(com.intellij.psi.PsiDirectory) PsiPackage(com.intellij.psi.PsiPackage) PsiFile(com.intellij.psi.PsiFile) Module(com.intellij.openapi.module.Module)

Example 77 with GlobalSearchScope

use of com.intellij.psi.search.GlobalSearchScope 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();
        }
    }
}
Also used : NavigationItem(com.intellij.navigation.NavigationItem) java.util(java.util) ArrayUtil(com.intellij.util.ArrayUtil) MinusculeMatcher(com.intellij.psi.codeStyle.MinusculeMatcher) HashSet(com.intellij.util.containers.HashSet) THashSet(gnu.trove.THashSet) IdFilter(com.intellij.util.indexing.IdFilter) ChooseByNameContributorEx(com.intellij.navigation.ChooseByNameContributorEx) NameUtil(com.intellij.psi.codeStyle.NameUtil) InheritanceUtil(com.intellij.psi.util.InheritanceUtil) Project(com.intellij.openapi.project.Project) PsiShortNamesCache(com.intellij.psi.search.PsiShortNamesCache) PsiUtil(com.intellij.psi.util.PsiUtil) Logger(com.intellij.openapi.diagnostic.Logger) ProgressManager(com.intellij.openapi.progress.ProgressManager) StringUtil(com.intellij.openapi.util.text.StringUtil) GlobalSearchScope(com.intellij.psi.search.GlobalSearchScope) DefaultPsiElementCellRenderer(com.intellij.ide.util.DefaultPsiElementCellRenderer) Nullable(org.jetbrains.annotations.Nullable) PsiSearchScopeUtil(com.intellij.psi.search.PsiSearchScopeUtil) Processor(com.intellij.util.Processor) com.intellij.psi(com.intellij.psi) NotNull(org.jetbrains.annotations.NotNull) FindSymbolParameters(com.intellij.util.indexing.FindSymbolParameters) Condition(com.intellij.openapi.util.Condition) IdFilter(com.intellij.util.indexing.IdFilter) PsiShortNamesCache(com.intellij.psi.search.PsiShortNamesCache) GlobalSearchScope(com.intellij.psi.search.GlobalSearchScope) THashSet(gnu.trove.THashSet)

Example 78 with GlobalSearchScope

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

the class PackageUtil method getSubpackages.

@NotNull
public static PsiPackage[] getSubpackages(@NotNull PsiPackage aPackage, @Nullable Module module, final boolean searchInLibraries) {
    final GlobalSearchScope scopeToShow = getScopeToShow(aPackage.getProject(), module, searchInLibraries);
    List<PsiPackage> result = new ArrayList<>();
    for (PsiPackage psiPackage : aPackage.getSubPackages(scopeToShow)) {
        // skip "default" subpackages as they should be attributed to other modules
        // this is the case when contents of one module is nested into contents of another
        final String name = psiPackage.getName();
        if (name != null && !name.isEmpty()) {
            result.add(psiPackage);
        }
    }
    return result.toArray(new PsiPackage[result.size()]);
}
Also used : GlobalSearchScope(com.intellij.psi.search.GlobalSearchScope) NotNull(org.jetbrains.annotations.NotNull)

Example 79 with GlobalSearchScope

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

the class PackageElementNode method getChildren.

@Override
@NotNull
public Collection<AbstractTreeNode> getChildren() {
    final PackageElement value = getValue();
    if (value == null)
        return Collections.emptyList();
    final List<AbstractTreeNode> children = new ArrayList<>();
    final Module module = value.getModule();
    final PsiPackage aPackage = value.getPackage();
    if (!getSettings().isFlattenPackages()) {
        final PsiPackage[] subpackages = PackageUtil.getSubpackages(aPackage, module, isLibraryElement());
        for (PsiPackage subpackage : subpackages) {
            PackageUtil.addPackageAsChild(children, subpackage, module, getSettings(), isLibraryElement());
        }
    }
    // process only files in package's directories
    final GlobalSearchScope scopeToShow = PackageUtil.getScopeToShow(aPackage.getProject(), module, isLibraryElement());
    PsiFile[] packageChildren = aPackage.getFiles(scopeToShow);
    for (PsiFile file : packageChildren) {
        if (file.getVirtualFile() != null) {
            children.add(new PsiFileNode(getProject(), file, getSettings()));
        }
    }
    return children;
}
Also used : GlobalSearchScope(com.intellij.psi.search.GlobalSearchScope) AbstractTreeNode(com.intellij.ide.util.treeView.AbstractTreeNode) PsiPackage(com.intellij.psi.PsiPackage) PsiFile(com.intellij.psi.PsiFile) Module(com.intellij.openapi.module.Module) NotNull(org.jetbrains.annotations.NotNull)

Example 80 with GlobalSearchScope

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

the class PsiClassImplUtil method getClassUseScope.

@NotNull
public static SearchScope getClassUseScope(@NotNull PsiClass aClass) {
    if (aClass instanceof PsiAnonymousClass) {
        return new LocalSearchScope(aClass);
    }
    final GlobalSearchScope maximalUseScope = ResolveScopeManager.getElementUseScope(aClass);
    PsiFile file = aClass.getContainingFile();
    if (PsiImplUtil.isInServerPage(file))
        return maximalUseScope;
    final PsiClass containingClass = aClass.getContainingClass();
    if (aClass.hasModifierProperty(PsiModifier.PUBLIC) || aClass.hasModifierProperty(PsiModifier.PROTECTED)) {
        return containingClass == null ? maximalUseScope : containingClass.getUseScope();
    } else if (aClass.hasModifierProperty(PsiModifier.PRIVATE) || aClass instanceof PsiTypeParameter) {
        PsiClass topClass = PsiUtil.getTopLevelClass(aClass);
        return new LocalSearchScope(topClass == null ? aClass.getContainingFile() : topClass);
    } else {
        PsiPackage aPackage = null;
        if (file instanceof PsiJavaFile) {
            aPackage = JavaPsiFacade.getInstance(aClass.getProject()).findPackage(((PsiJavaFile) file).getPackageName());
        }
        if (aPackage == null) {
            PsiDirectory dir = file.getContainingDirectory();
            if (dir != null) {
                aPackage = JavaDirectoryService.getInstance().getPackage(dir);
            }
        }
        if (aPackage != null) {
            SearchScope scope = PackageScope.packageScope(aPackage, false);
            scope = scope.intersectWith(maximalUseScope);
            return scope;
        }
        return new LocalSearchScope(file);
    }
}
Also used : LocalSearchScope(com.intellij.psi.search.LocalSearchScope) GlobalSearchScope(com.intellij.psi.search.GlobalSearchScope) SearchScope(com.intellij.psi.search.SearchScope) LocalSearchScope(com.intellij.psi.search.LocalSearchScope) GlobalSearchScope(com.intellij.psi.search.GlobalSearchScope) NotNull(org.jetbrains.annotations.NotNull)

Aggregations

GlobalSearchScope (com.intellij.psi.search.GlobalSearchScope)485 Project (com.intellij.openapi.project.Project)145 NotNull (org.jetbrains.annotations.NotNull)134 VirtualFile (com.intellij.openapi.vfs.VirtualFile)106 Module (com.intellij.openapi.module.Module)101 Nullable (org.jetbrains.annotations.Nullable)78 PsiClass (com.intellij.psi.PsiClass)53 ArrayList (java.util.ArrayList)37 PsiFile (com.intellij.psi.PsiFile)32 PsiElement (com.intellij.psi.PsiElement)31 THashSet (gnu.trove.THashSet)22 SearchScope (com.intellij.psi.search.SearchScope)19 PsiDirectory (com.intellij.psi.PsiDirectory)18 ContainerUtil (com.intellij.util.containers.ContainerUtil)18 JSClass (com.intellij.lang.javascript.psi.ecmal4.JSClass)17 ProjectFileIndex (com.intellij.openapi.roots.ProjectFileIndex)17 com.intellij.psi (com.intellij.psi)17 List (java.util.List)17 StringUtil (com.intellij.openapi.util.text.StringUtil)15 JavaPsiFacade (com.intellij.psi.JavaPsiFacade)15