下面列出了com.intellij.psi.search.GlobalSearchScope#allScope ( ) 实例代码,或者点击链接到github查看源代码,也可以在右侧发表评论。
public static PhpInjectFileReference getInjectFileReference(@NotNull Project project, @NotNull Function function, int argumentIndex) {
FileBasedIndex index = FileBasedIndex.getInstance();
GlobalSearchScope scope = GlobalSearchScope.allScope(project);
Ref<List<PhpInjectFileReference>> result = new Ref<>(ContainerUtil.emptyList());
result.set(index.getValues(KEY, function.getFQN() + ":" + argumentIndex, scope));
if (result.get().isEmpty() && function instanceof PhpClassMember) {
PhpClassHierarchyUtils.processSuperMembers((PhpClassMember)function, (classMember, subClass, baseClass) -> {
List<PhpInjectFileReference> values = index.getValues(KEY, classMember.getFQN() + ":" + argumentIndex, scope);
if (values.isEmpty()) {
return true;
} else {
result.set(values);
return false;
}
});
}
if (result.get().isEmpty()) {
return null;
}
return result.get().get(0);
}
@Nullable
public static PsiFile findCmtFileFromSource(@NotNull Project project, @NotNull String filenameWithoutExtension) {
if (!DumbService.isDumb(project)) {
GlobalSearchScope scope = GlobalSearchScope.allScope(project);
String filename = filenameWithoutExtension + ".cmt";
PsiFile[] cmtFiles = FilenameIndex.getFilesByName(project, filename, scope);
if (cmtFiles.length == 0) {
if (LOG.isDebugEnabled()) {
LOG.debug("File module for " + filename + " is NOT FOUND, files found: [" + Joiner.join(", ", cmtFiles) + "]");
}
return null;
}
if (LOG.isDebugEnabled()) {
LOG.debug("Found cmt " + filename + " (" + cmtFiles[0].getVirtualFile().getPath() + ")");
}
return cmtFiles[0];
} else {
LOG.info("Cant find cmt while reindexing");
}
return null;
}
/**
* search class by class name.
*
* @param name
* @param project
* @return
*/
private static PsiClass searchClassByName(String name, Project project) {
GlobalSearchScope searchScope = GlobalSearchScope.allScope(project);
PsiClass[] psiClasses = PsiShortNamesCache.getInstance(project).getClassesByName(name, searchScope);
if (psiClasses.length == 1) {
return psiClasses[0];
}
if (psiClasses.length > 1) {
for (PsiClass pc :
psiClasses) {
PsiJavaFile psiJavaFile = (PsiJavaFile) pc.getContainingFile();
String packageName = psiJavaFile.getPackageName();
if (List.class.getPackage().getName().equals(packageName) ||
packageName.contains("io.xujiaji.xmvp")) {
return pc;
}
}
}
return null;
}
private XDebugSessionTab(@Nonnull XDebugSessionImpl session, @Nullable Image icon, @Nullable ExecutionEnvironment environment) {
super(session.getProject(), "Debug", session.getSessionName(), GlobalSearchScope.allScope(session.getProject()));
setSession(session, environment, icon);
myUi.addContent(createFramesContent(), 0, PlaceInGrid.left, false);
addVariablesAndWatches(session);
attachToSession(session);
DefaultActionGroup focus = new DefaultActionGroup();
focus.add(ActionManager.getInstance().getAction(XDebuggerActions.FOCUS_ON_BREAKPOINT));
myUi.getOptions().setAdditionalFocusActions(focus);
myUi.addListener(new ContentManagerAdapter() {
@Override
public void selectionChanged(ContentManagerEvent event) {
Content content = event.getContent();
if (mySession != null && content.isSelected() && getWatchesContentId().equals(ViewImpl.ID.get(content))) {
myRebuildWatchesRunnable.run();
}
}
}, myRunContentDescriptor);
rebuildViews();
}
@Nullable
public PsiMethod getBusPostMethod(Project project) {
JavaPsiFacade javaPsiFacade = JavaPsiFacade.getInstance(project);
GlobalSearchScope globalSearchScope = GlobalSearchScope.allScope(project);
PsiClass busClass = javaPsiFacade.findClass(getBusClassName(), globalSearchScope);
if (busClass != null) {
for (PsiMethod psiMethod : busClass.getMethods()) {
if (psiMethod.getName().equals("post")) {
return psiMethod;
}
}
}
return null;
}
/**
* Finds all fully qualified template names starting with a given prefix with respect to aliases
* and template visibility.
*/
public static Collection<Fragment> getPossibleNextIdentifierFragments(
Project project, PsiElement identifierElement, String identifier, boolean isDelegate) {
AliasMapper mapper = new AliasMapper(identifierElement.getContainingFile());
GlobalSearchScope scope =
isDelegate
? GlobalSearchScope.allScope(project)
: GlobalSearchScope.allScope(project)
.intersectWith(
GlobalSearchScope.notScope(
GlobalSearchScope.fileScope(
identifierElement.getContainingFile().getOriginalFile())));
return TemplateBlockIndex.INSTANCE
.getAllKeys(project)
.stream()
// Filter out private templates, assuming those end with "_".
.filter((key) -> !key.endsWith("_"))
// Filter out deltemplates or normal templates based on `isDelegate`.
// Also checks template's lang.
.filter(
(key) ->
TemplateBlockIndex.INSTANCE
.get(key, project, scope)
.stream()
.anyMatch((block) -> block.isDelegate() == isDelegate))
// Project matches into denormalized key space.
.flatMap(mapper::denormalizeIdentifier)
// Find the denormalized keys that match the identifier.
.filter((key) -> key.startsWith(identifier))
// Collect next fragments.
.map((key) -> getNextFragment(key, identifier))
.collect(Collectors.toList());
}
@Override
@Nonnull
public Object[] getElementsByName(final String name, final boolean checkBoxState, final String pattern) {
GlobalSearchScope scope = myShowLibraryContents ? GlobalSearchScope.allScope(myProject) : GlobalSearchScope.projectScope(myProject);
final PsiFile[] psiFiles = FilenameIndex.getFilesByName(myProject, name, scope);
return filterFiles(psiFiles);
}
@NotNull
private GlobalSearchScope getSearchScope(Project project, boolean includeNonProjectItems) {
if (includeNonProjectItems) {
return GlobalSearchScope.allScope(project);
} else {
return GlobalSearchScope.projectScope(project);
}
}
@Test
public void testShouldNotFindReferencesOfNonGaugeElement() throws Exception {
when(element.getProject()).thenReturn(project);
ReferencesSearch.SearchParameters searchParameters = new ReferencesSearch.SearchParameters(element, GlobalSearchScope.allScope(project), true);
when(helper.shouldFindReferences(searchParameters, searchParameters.getElementToSearch())).thenReturn(false);
new ReferenceSearch(helper).processQuery(searchParameters, psiReference -> false);
verify(helper, never()).getPsiElements(any(StepCollector.class), any(PsiElement.class));
}
@Override
@Nonnull
public String[] getNames(final boolean checkBoxState) {
final String[] fileNames;
if (myFileType != null && myProject != null) {
GlobalSearchScope scope = myShowLibraryContents ? GlobalSearchScope.allScope(myProject) : GlobalSearchScope.projectScope(myProject);
Collection<VirtualFile> virtualFiles = FileTypeIndex.getFiles(myFileType, scope);
fileNames = ContainerUtil.map2Array(virtualFiles, String.class, new Function<VirtualFile, String>() {
@Override
public String fun(VirtualFile file) {
return file.getName();
}
});
}
else {
fileNames = FilenameIndex.getAllFilenames(myProject);
}
final Set<String> array = new THashSet<String>();
for (String fileName : fileNames) {
if (!array.contains(fileName)) {
array.add(fileName);
}
}
final String[] result = ArrayUtil.toStringArray(array);
Arrays.sort(result);
return result;
}
/** Add the global filters, wrapped to separate them from blaze problems. */
private void addWrappedPredefinedFilters() {
GlobalSearchScope scope = GlobalSearchScope.allScope(project);
for (ConsoleFilterProvider provider : ConsoleFilterProvider.FILTER_PROVIDERS.getExtensions()) {
Arrays.stream(getFilters(scope, provider))
.forEach(f -> consoleView.addMessageFilter(NonProblemFilterWrapper.wrap(f)));
}
}
static private boolean processInheritors(final String qName, final PsiElement context, final Processor<? super PsiElement> consumer) {
final Set<String> namesSet = new THashSet<String>();
final LinkedList<String> namesQueue = new LinkedList<String>();
namesQueue.add(qName);
final Project project = context.getProject();
final GlobalSearchScope scope = GlobalSearchScope.allScope(project);
while (!namesQueue.isEmpty()) {
final String name = namesQueue.pollFirst();
if (!namesSet.add(name)) {
continue;
}
List<List<HaxeClassInfo>> files = FileBasedIndex.getInstance().getValues(HaxeInheritanceIndex.HAXE_INHERITANCE_INDEX, name, scope);
files.addAll(FileBasedIndex.getInstance().getValues(HaxeTypeDefInheritanceIndex.HAXE_TYPEDEF_INHERITANCE_INDEX, name, scope));
for (List<HaxeClassInfo> subClassInfoList : files) {
for (HaxeClassInfo subClassInfo : subClassInfoList) {
final HaxeClass subClass = HaxeResolveUtil.findClassByQName(subClassInfo.getValue(), context.getManager(), scope);
if (subClass != null) {
if (!consumer.process(subClass)) {
return true;
}
namesQueue.add(subClass.getQualifiedName());
}
}
}
}
return true;
}
/**
* @deprecated use {@link #LogConsoleImpl(com.intellij.openapi.project.Project, java.io.File, java.nio.charset.Charset, long, String, boolean, com.intellij.psi.search.GlobalSearchScope)}
*/
public LogConsoleImpl(Project project,
@Nonnull File file,
@Nonnull Charset charset,
long skippedContents,
String title,
final boolean buildInActions) {
this(project, file, charset, skippedContents, title, buildInActions, GlobalSearchScope.allScope(project));
}
private static boolean isLazyOrProvider(PsiClass psiClass) {
if (psiClass == null) {
return false;
}
Project project = psiClass.getProject();
JavaPsiFacade javaPsiFacade = JavaPsiFacade.getInstance(project);
GlobalSearchScope globalSearchScope = GlobalSearchScope.allScope(project);
PsiClass lazyClass = javaPsiFacade.findClass(CLASS_LAZY, globalSearchScope);
PsiClass providerClass = javaPsiFacade.findClass(CLASS_PROVIDER, globalSearchScope);
return psiClass.equals(lazyClass) || psiClass.equals(providerClass);
}
@Nonnull
@Override
public GlobalSearchScope getUseScope(@Nonnull PsiElement element) {
return GlobalSearchScope.allScope(element.getProject());
}
@Nonnull
@Override
public GlobalSearchScope getDefaultResolveScope(VirtualFile vFile) {
return GlobalSearchScope.allScope(myProject);
}
public static Set<VirtualFile> findFilesInProject(@NotNull String filename, @NotNull Project project) {
GlobalSearchScope scope = GlobalSearchScope.allScope(project);
Collection<VirtualFile> virtualFilesByName = FilenameIndex.getVirtualFilesByName(project, filename, scope);
return new HashSet<>(virtualFilesByName);
}
private GlobalSearchScope getScope(Project project, boolean includeNonProjectItems) {
return includeNonProjectItems ? GlobalSearchScope.allScope(project) : GlobalSearchScope.projectScope(project);
}
public LogConsoleBase(@Nonnull Project project, @Nullable Reader reader, String title, final boolean buildInActions, LogFilterModel model) {
this(project, reader, title, buildInActions, model, GlobalSearchScope.allScope(project));
}
@Inject
public LibraryScopeCache(Project project) {
myProject = project;
myLibrariesOnlyScope = new LibrariesOnlyScope(GlobalSearchScope.allScope(myProject), myProject);
}