Java Code Examples for com.intellij.psi.search.GlobalSearchScope#projectScope()

The following examples show how to use com.intellij.psi.search.GlobalSearchScope#projectScope() . These examples are extracted from open source projects. You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
private @NotNull List<PsiElementResolveResult> handleImportReferences(@NotNull HaskellImpdecl haskellImpdecl,
                                                                      @NotNull PsiNamedElement myElement, int i) {
    /**
     * Don't use the named element yet to determine which element we're
     * talking about, not necessary yet
     */
    List<PsiElementResolveResult> modulesFound = new ArrayList<PsiElementResolveResult>();
    List<HaskellQconid> qconidList = haskellImpdecl.getQconidList();
    if (qconidList.size() > 0){
        String moduleName = qconidList.get(0).getText();

        GlobalSearchScope globalSearchScope = GlobalSearchScope.projectScope(myElement.getProject());
        List<HaskellFile> filesByModuleName = HaskellModuleIndex.getFilesByModuleName(myElement.getProject(), moduleName, globalSearchScope);
        for (HaskellFile haskellFile : filesByModuleName) {
            HaskellModuledecl[] moduleDecls = PsiTreeUtil.getChildrenOfType(haskellFile, HaskellModuledecl.class);
            if (moduleDecls != null && moduleDecls.length > 0){
                HaskellQconid qconid = moduleDecls[0].getQconid();
                if (qconid != null) {
                    List<HaskellConid> conidList = moduleDecls[0].getQconid().getConidList();
                    modulesFound.add(new PsiElementResolveResult(conidList.get(i)));
                }
            }
        }
    }
    return modulesFound;
}
 
Example 2
Source Project: NutzCodeInsight   File: SqlsXmlUtil.java    License: Apache License 2.0 5 votes vote down vote up
public static GlobalSearchScope getSearchScope(Project project, @NotNull PsiElement element) {
    GlobalSearchScope searchScope = GlobalSearchScope.projectScope(project);
    Module module = ProjectRootManager.getInstance(project).getFileIndex().getModuleForFile(element.getContainingFile().getVirtualFile());
    if (module != null) {
        searchScope = GlobalSearchScope.moduleScope(module);
    }
    return searchScope;
}
 
Example 3
@NotNull
@Override
public NavigationItem[] getItemsByName(@NotNull final String name,
                                       @NotNull final String pattern,
                                       @NotNull final Project project,
                                       final boolean includeNonProjectItems) {
  final GlobalSearchScope scope = includeNonProjectItems ? GlobalSearchScope.allScope(project) : GlobalSearchScope.projectScope(project);
  final Collection<HaxeComponentName> result = HaxeSymbolIndex.getItemsByName(name, project, scope);
  return result.toArray(new NavigationItem[result.size()]);
}
 
Example 4
Source Project: consulo   File: TodoPackageNode.java    License: Apache License 2.0 5 votes vote down vote up
/**
 * @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</code>.
 */
public Iterator<PsiFile> getFiles(PackageElement packageElement) {
  ArrayList<PsiFile> psiFileList = new ArrayList<PsiFile>();
  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();
}
 
Example 5
@Nullable
public static XmlTag findGlobalElement(PsiElement element, String elementName) {
    final Project project = element.getProject();
    final PsiFile psiFile = PsiTreeUtil.getParentOfType(element, PsiFile.class);
    //Search first in the local file else we search globally
    if (psiFile != null) {
        final XmlTag xmlTag = findGlobalElementInFile(project, elementName, psiFile.getVirtualFile());
        if (xmlTag != null) {
            return xmlTag;
        }
    }
    final GlobalSearchScope searchScope = GlobalSearchScope.projectScope(project);
    return findGlobalElementInScope(project, elementName, searchScope);
}
 
Example 6
Source Project: consulo   File: TodoTreeHelper.java    License: Apache License 2.0 5 votes vote down vote up
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);
  }
}
 
Example 7
@NotNull
private GlobalSearchScope getSearchScope(Project project, boolean includeNonProjectItems) {
    if (includeNonProjectItems) {
        return GlobalSearchScope.allScope(project);
    } else {
        return GlobalSearchScope.projectScope(project);
    }
}
 
Example 8
@Nullable
@Override
public SearchScope getAdditionalUseScope(PsiElement element) {
  if (!Blaze.isBlazeProject(element.getProject())) {
    return null;
  }
  if (isPyPackageOutsideProject(element) || isPyFileOutsideProject(element)) {
    return GlobalSearchScope.projectScope(element.getProject());
  }
  return null;
}
 
Example 9
Source Project: consulo   File: CoverageSuitesBundle.java    License: Apache License 2.0 5 votes vote down vote up
private GlobalSearchScope getSearchScopeInner(Project project) {
  final RunConfigurationBase configuration = getRunConfiguration();
  if (configuration instanceof ModuleBasedConfiguration) {
    final Module module = ((ModuleBasedConfiguration)configuration).getConfigurationModule().getModule();
    if (module != null) {
      return GlobalSearchScope.moduleRuntimeScope(module, isTrackTestFolders());
    }
  }
  return isTrackTestFolders() ? GlobalSearchScope.projectScope(project) : GlobalSearchScopesCore.projectProductionScope(project);
}
 
Example 10
@NotNull
@Override
public NavigationItem[] getItemsByName(String name, String pattern, Project project, boolean includeNonProjectItems) {
  final GlobalSearchScope scope = includeNonProjectItems ? GlobalSearchScope.allScope(project) : GlobalSearchScope.projectScope(project);
  final Collection<HaxeComponent> result = HaxeComponentIndex.getItemsByName(name, project, scope);
  return result.toArray(new NavigationItem[result.size()]);
}
 
Example 11
public GlobalSearchScope getSearchScope() {
    final Module module = getModule();
    if (module != null) {
        return GlobalSearchScope.moduleWithDependenciesScope(module);
    }
    return GlobalSearchScope.projectScope(getProject());
}
 
Example 12
/**
 * Returns references to the given element. If it is a BashPsiElement a special search scope is used to locate the elements referencing the file.
 *
 * @param element References to the given element
 * @return
 */
@NotNull
@Override
public Collection<PsiReference> findReferences(PsiElement element) {
    //fixme fix the custom scope
    SearchScope scope = (element instanceof BashPsiElement)
            ? BashElementSharedImpl.getElementUseScope((BashPsiElement) element, element.getProject())
            : GlobalSearchScope.projectScope(element.getProject());

    Query<PsiReference> search = ReferencesSearch.search(element, scope);
    return search.findAll();
}
 
Example 13
Source Project: consulo   File: IdFilter.java    License: Apache License 2.0 5 votes vote down vote up
@Nonnull
private static IdFilter buildProjectIdFilter(Project project, boolean includeNonProjectItems) {
  long started = System.currentTimeMillis();
  final BitSet idSet = new BitSet();

  ContentIterator iterator = fileOrDir -> {
    idSet.set(((VirtualFileWithId)fileOrDir).getId());
    ProgressManager.checkCanceled();
    return true;
  };

  if (!includeNonProjectItems) {
    ProjectRootManager.getInstance(project).getFileIndex().iterateContent(iterator);
  }
  else {
    FileBasedIndex.getInstance().iterateIndexableFiles(iterator, project, ProgressIndicatorProvider.getGlobalProgressIndicator());
  }

  if (LOG.isDebugEnabled()) {
    long elapsed = System.currentTimeMillis() - started;
    LOG.debug("Done filter (includeNonProjectItems=" + includeNonProjectItems + ") " + "in " + elapsed + "ms. Total files in set: " + idSet.cardinality());
  }
  return new IdFilter() {
    @Override
    public boolean containsFileId(int id) {
      return id >= 0 && idSet.get(id);
    }

    @Nonnull
    @Override
    public GlobalSearchScope getEffectiveFilteringScope() {
      return includeNonProjectItems ? GlobalSearchScope.allScope(project) : GlobalSearchScope.projectScope(project);
    }
  };
}
 
Example 14
/**
 * Finds {@link VirtualFile} instances for the specific {@link Pattern} and caches them.
 *
 * @param project current project
 * @param pattern to handle
 * @return matched files list
 */
@NotNull
public Collection<VirtualFile> getFilesForPattern(@NotNull final Project project, @NotNull Pattern pattern) {
    final GlobalSearchScope scope = GlobalSearchScope.projectScope(project);
    final String[] parts = MatcherUtil.getParts(pattern);

    if (parts.length > 0) {
        final String key = StringUtil.join(parts, Constants.DOLLAR);
        if (cacheMap.get(key) == null) {
            final THashSet<VirtualFile> files = new THashSet<>(1000);

            projectFileIndex.iterateContent(fileOrDir -> {
                final String name = fileOrDir.getName();
                if (MatcherUtil.matchAnyPart(parts, name)) {
                    for (VirtualFile file : FilenameIndex.getVirtualFilesByName(project, name, scope)) {
                        if (file.isValid() && MatcherUtil.matchAllParts(parts, file.getPath())) {
                            files.add(file);
                        }
                    }
                }
                return true;
            });

            cacheMap.put(key, files);
        }

        return cacheMap.get(key);
    }

    return new ArrayList<>();
}
 
Example 15
Source Project: consulo   File: AnalysisScope.java    License: Apache License 2.0 4 votes vote down vote up
@Nonnull
public SearchScope toSearchScope() {
  switch (myType) {
    case CUSTOM:
      return myScope;
    case DIRECTORY:
      return GlobalSearchScopesCore.directoryScope((PsiDirectory)myElement, true);
    case FILE:
      return new LocalSearchScope(myElement);
    case INVALID:
      return LocalSearchScope.EMPTY;
    case MODULE:
      GlobalSearchScope moduleScope = GlobalSearchScope.moduleScope(myModule);
      return myIncludeTestSource ? moduleScope : GlobalSearchScope.notScope(GlobalSearchScopesCore.projectTestScope(myModule.getProject())).intersectWith(moduleScope);
    case MODULES:
      SearchScope scope = GlobalSearchScope.EMPTY_SCOPE;
      for (Module module : myModules) {
        scope = scope.union(GlobalSearchScope.moduleScope(module));
      }
      return scope;
    case PROJECT:
      return myIncludeTestSource ? GlobalSearchScope.projectScope(myProject) : GlobalSearchScopesCore.projectProductionScope(myProject);
    case VIRTUAL_FILES:
      return new GlobalSearchScope() {
        @Override
        public boolean contains(@Nonnull VirtualFile file) {
          return myFilesSet.contains(file);
        }

        @Override
        public int compare(@Nonnull VirtualFile file1, @Nonnull VirtualFile file2) {
          return 0;
        }

        @Override
        public boolean isSearchInModuleContent(@Nonnull Module aModule) {
          return false;
        }

        @Override
        public boolean isSearchInLibraries() {
          return false;
        }
      };
    default:
      LOG.error("invalid type " + myType);
      return GlobalSearchScope.EMPTY_SCOPE;
  }
}
 
Example 16
public AbstractTreeClassChooserDialog(String title, Project project, final Class<T> elementClass, @Nullable T initialClass) {
  this(title, project, GlobalSearchScope.projectScope(project), elementClass, null, initialClass);
}
 
Example 17
public static List<DomElement> getFlows(Project project) {
    final GlobalSearchScope searchScope = GlobalSearchScope.projectScope(project);
    return getFlowsInScope(project, searchScope);
}
 
Example 18
private GlobalSearchScope getScope(Project project, boolean includeNonProjectItems) {
  return includeNonProjectItems ? GlobalSearchScope.allScope(project) : GlobalSearchScope.projectScope(project);
}
 
Example 19
public GraphQLConfigManager(Project myProject) {
    this.myProject = myProject;
    this.projectScope = GlobalSearchScope.projectScope(myProject);
    this.graphQLConfigGlobMatcher = ServiceManager.getService(myProject, GraphQLConfigGlobMatcher.class);
    this.pluginDescriptor = PluginManager.getPlugin(PluginId.getId("com.intellij.lang.jsgraphql"));
}
 
Example 20
protected BaseRefactoringProcessor(@Nonnull Project project, @Nullable Runnable prepareSuccessfulCallback) {
  this(project, GlobalSearchScope.projectScope(project), prepareSuccessfulCallback);
}