Search in sources :

Example 71 with GlobalSearchScope

use of com.intellij.psi.search.GlobalSearchScope in project intellij-elixir by KronicDeth.

the class FileReferenceFilter method resolveAbsolutePath.

@Nullable
private VirtualFile resolveAbsolutePath(@NotNull String path) {
    VirtualFile asIsFile = pathToVirtualFile(path);
    if (asIsFile != null) {
        return asIsFile;
    }
    String projectBasedPath = path.startsWith(myProject.getBasePath()) ? path : new File(myProject.getBasePath(), path).getAbsolutePath();
    VirtualFile projectBasedFile = pathToVirtualFile(projectBasedPath);
    if (projectBasedFile != null) {
        return projectBasedFile;
    }
    Matcher filenameMatcher = PATTERN_FILENAME.matcher(path);
    if (filenameMatcher.find()) {
        String filename = filenameMatcher.group(1);
        GlobalSearchScope projectScope = ProjectScope.getProjectScope(myProject);
        PsiFile[] projectFiles = FilenameIndex.getFilesByName(myProject, filename, projectScope);
        if (projectFiles.length > 0) {
            return projectFiles[0].getVirtualFile();
        }
        GlobalSearchScope libraryScope = ProjectScope.getLibrariesScope(myProject);
        PsiFile[] libraryFiles = FilenameIndex.getFilesByName(myProject, filename, libraryScope);
        if (libraryFiles.length > 0) {
            return libraryFiles[0].getVirtualFile();
        }
    }
    return null;
}
Also used : VirtualFile(com.intellij.openapi.vfs.VirtualFile) Matcher(java.util.regex.Matcher) GlobalSearchScope(com.intellij.psi.search.GlobalSearchScope) PsiFile(com.intellij.psi.PsiFile) VirtualFile(com.intellij.openapi.vfs.VirtualFile) File(java.io.File) PsiFile(com.intellij.psi.PsiFile) Nullable(org.jetbrains.annotations.Nullable)

Example 72 with GlobalSearchScope

use of com.intellij.psi.search.GlobalSearchScope in project intellij-elixir by KronicDeth.

the class ElixirPsiImplUtil method moduleWithDependentsScope.

private static GlobalSearchScope moduleWithDependentsScope(PsiElement element) {
    VirtualFile virtualFile = element.getContainingFile().getVirtualFile();
    Project project = element.getProject();
    com.intellij.openapi.module.Module module = ModuleUtilCore.findModuleForFile(virtualFile, project);
    GlobalSearchScope globalSearchScope;
    // module can be null for scratch files
    if (module != null) {
        globalSearchScope = GlobalSearchScope.moduleWithDependentsScope(module);
    } else {
        globalSearchScope = GlobalSearchScope.allScope(project);
    }
    return globalSearchScope;
}
Also used : VirtualFile(com.intellij.openapi.vfs.VirtualFile) Project(com.intellij.openapi.project.Project) GlobalSearchScope(com.intellij.psi.search.GlobalSearchScope)

Example 73 with GlobalSearchScope

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

the class SourceScope method evaluateScopesAndUnite.

private static GlobalSearchScope evaluateScopesAndUnite(final Module[] modules, final ScopeForModuleEvaluator evaluator) {
    GlobalSearchScope scope = evaluator.evaluate(modules[0]);
    for (int i = 1; i < modules.length; i++) {
        final Module module = modules[i];
        final GlobalSearchScope otherscope = evaluator.evaluate(module);
        scope = scope.uniteWith(otherscope);
    }
    return scope;
}
Also used : GlobalSearchScope(com.intellij.psi.search.GlobalSearchScope) Module(com.intellij.openapi.module.Module)

Example 74 with GlobalSearchScope

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

the class TodoJavaTreeHelper method traverseSubPackages.

private static void traverseSubPackages(PsiPackage psiPackage, Module module, TodoTreeBuilder builder, Project project, Set<PsiPackage> packages) {
    if (!isPackageEmpty(new PackageElement(module, psiPackage, false), builder, project)) {
        packages.add(psiPackage);
    }
    GlobalSearchScope scope = module != null ? GlobalSearchScope.moduleScope(module) : GlobalSearchScope.projectScope(project);
    final PsiPackage[] subPackages = psiPackage.getSubPackages(scope);
    for (PsiPackage subPackage : subPackages) {
        traverseSubPackages(subPackage, module, builder, project, packages);
    }
}
Also used : GlobalSearchScope(com.intellij.psi.search.GlobalSearchScope) PackageElement(com.intellij.ide.projectView.impl.nodes.PackageElement)

Example 75 with GlobalSearchScope

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

the class TodoPackageNode method getFiles.

/**
   * @return read-only iterator of all valid PSI files that can have T.O.D.O items
   *         and which are located under specified {@code psiDirctory}.
   */
public Iterator<PsiFile> getFiles(PackageElement packageElement) {
    ArrayList<PsiFile> psiFileList = new ArrayList<>();
    GlobalSearchScope scope = packageElement.getModule() != null ? GlobalSearchScope.moduleScope(packageElement.getModule()) : GlobalSearchScope.projectScope(myProject);
    final PsiDirectory[] directories = packageElement.getPackage().getDirectories(scope);
    for (PsiDirectory directory : directories) {
        Iterator<PsiFile> files = myBuilder.getFiles(directory, false);
        for (; files.hasNext(); ) {
            psiFileList.add(files.next());
        }
    }
    return psiFileList.iterator();
}
Also used : GlobalSearchScope(com.intellij.psi.search.GlobalSearchScope) PsiDirectory(com.intellij.psi.PsiDirectory) PsiFile(com.intellij.psi.PsiFile)

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