@NotNull public static GlobalSearchScope moduleScope(@NotNull Module module) { return GlobalSearchScope.moduleWithDependenciesAndLibrariesScope(module).uniteWith(module.getModuleContentWithDependenciesScope()); }
@NotNull public static GlobalSearchScope moduleScopeWithoutLibraries(@NotNull Project project, @Nullable Module module) { return module != null ? GlobalSearchScope.moduleWithDependenciesScope(module).uniteWith(module.getModuleContentWithDependenciesScope()) : GlobalSearchScope.projectScope(project); }
@Override public boolean contains(@NotNull VirtualFile file) { return GoTestFinder.isTestFile(file) && super.contains(file); } }
@NotNull @Override public SearchScope getUseScope() { return GlobalSearchScope.allScope(getProject()); }
@Nullable private VirtualFile findSingleFile(@NotNull String fileName) { if (PathUtil.isValidFileName(fileName)) { Collection<VirtualFile> files = FilenameIndex.getVirtualFilesByName(myProject, fileName, GlobalSearchScope.allScope(myProject)); if (files.size() == 1) { return ContainerUtil.getFirstItem(files); } } return null; }
public static GlobalSearchScope create(@NotNull PsiElement declarationContext, boolean filterByImportList) { if (declarationContext instanceof GoNamedElement && ((GoNamedElement)declarationContext).isBlank()) { return GlobalSearchScope.EMPTY_SCOPE; } PsiFile declarationPsiFile = declarationContext.getContainingFile(); if (!(declarationPsiFile instanceof GoFile)) { return GlobalSearchScope.fileScope(declarationPsiFile); } if (GoPsiImplUtil.isBuiltinFile(declarationPsiFile)) { return GlobalSearchScope.allScope(declarationContext.getProject()); } VirtualFile declarationFile = declarationPsiFile.getVirtualFile(); if (declarationFile == null || declarationFile.getParent() == null) { return GlobalSearchScope.fileScope(declarationPsiFile); } return new GoPathUseScope(declarationPsiFile.getProject(), declarationFile, filterByImportList); }
final GlobalSearchScope scope = GlobalSearchScope.projectScope(project); final String[] parts = MatcherUtil.getParts(pattern); 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);
@NotNull private Collection<VirtualFile> resolveVirtualFileCollection(@NotNull String path, @NotNull String basename, @NotNull GlobalSearchScope scope) { List<VirtualFile> suffixedVirtualFiles = new ArrayList<>(); PsiFile[] projectFilesWithBaseName = FilenameIndex.getFilesByName(myProject, basename, scope); for (PsiFile projectFileWithBaseName : projectFilesWithBaseName) { VirtualFile virtualFile = projectFileWithBaseName.getVirtualFile(); String virtualFilePath = virtualFile.getPath(); if (virtualFilePath.endsWith(path)) { suffixedVirtualFiles.add(virtualFile); } } return suffixedVirtualFiles; } }
@NotNull @Override public SearchScope getUseScope() { if (this instanceof GoVarDefinition || this instanceof GoConstDefinition || this instanceof GoLabelDefinition) { GoBlock block = PsiTreeUtil.getParentOfType(this, GoBlock.class); if (block != null) return new LocalSearchScope(block); } if (!isPublic()) { return GoPackageUtil.packageScope(getContainingFile()); } GoSpecType parentType = PsiTreeUtil.getStubOrPsiParentOfType(this, GoSpecType.class); if (parentType != null) { GoTypeSpec typeSpec = GoPsiImplUtil.getTypeSpecSafe(parentType); if (typeSpec != null && !StringUtil.isCapitalized(typeSpec.getName())) { return GoPackageUtil.packageScope(getContainingFile()); } } return GoUtil.goPathUseScope(this, !(this instanceof GoMethodDeclaration)); }
/** * Returns {@link GlobalSearchScope#projectScope(Project)} instance united with additional files. * * @param project current project * @return extended instance of {@link GlobalSearchScope} */ @NotNull public static GlobalSearchScope get(@NotNull Project project) { final IgnoreSearchScope scope = new IgnoreSearchScope(project); final HashSet<VirtualFile> files = ExternalIndexableSetContributor.getAdditionalFiles(project); return scope.uniteWith(GlobalSearchScope.filesScope(project, files)); }
public void testUseScope() { myFixture.configureByFiles("get_use_scope.ex"); PsiElement callable = myFixture .getFile() .findElementAt(myFixture.getCaretOffset()) .getPrevSibling() .getLastChild() .getLastChild() .getLastChild() .getLastChild() .getLastChild(); assertInstanceOf(callable, Call.class); SearchScope useScope = callable.getUseScope(); assertInstanceOf(useScope, LocalSearchScope.class); LocalSearchScope localSearchScope = (LocalSearchScope) useScope; PsiElement[] scope = localSearchScope.getScope(); assertEquals(1, scope.length); PsiElement singleScope = scope[0]; assertTrue( "Use Scope is not the surrounding if", singleScope.getText().startsWith("if auth == ") ); }
@NotNull public static GlobalSearchScope packageScope(@NotNull GoFile file) { List<GoFile> files = getAllPackageFiles(file); return GlobalSearchScope.filesWithLibrariesScope(file.getProject(), ContainerUtil.map(files, PsiFile::getVirtualFile)); }
public static boolean isClassAvailableForProject(Project project, String className) { PsiClass classInModule = JavaPsiFacade.getInstance(project).findClass(className, new EverythingGlobalScope(project)); return classInModule != null; }
private PsiClass getPsiClassByName(Project project, String cls) { GlobalSearchScope searchScope = GlobalSearchScope.allScope(project); JavaPsiFacade javaPsiFacade = JavaPsiFacade.getInstance(project); return javaPsiFacade.findClass(cls, searchScope); }
@Nullable private VirtualFile findSingleFile(@NotNull String fileName) { if (PathUtil.isValidFileName(fileName)) { Collection<VirtualFile> files = FilenameIndex.getVirtualFilesByName(myProject, fileName, GlobalSearchScope.allScope(myProject)); if (files.size() == 1) { return ContainerUtil.getFirstItem(files); } if (!files.isEmpty()) { GlobalSearchScope goPathScope = GoPathResolveScope.create(myProject, myModule, null); files = ContainerUtil.filter(files, goPathScope::accept); if (files.size() == 1) { return ContainerUtil.getFirstItem(files); } } if (!files.isEmpty()) { GlobalSearchScope smallerScope = GoUtil.moduleScopeWithoutLibraries(myProject, myModule); files = ContainerUtil.filter(files, smallerScope::accept); if (files.size() == 1) { return ContainerUtil.getFirstItem(files); } } } return null; }
@Override public boolean contains(@NotNull VirtualFile file) { return !GoTestFinder.isTestFile(file) && super.contains(file); } }
@NotNull public static GlobalSearchScope packageScope(@NotNull PsiDirectory psiDirectory, @Nullable String packageName) { List<GoFile> files = getAllPackageFiles(psiDirectory, packageName); return GlobalSearchScope.filesWithLibrariesScope(psiDirectory.getProject(), ContainerUtil.map(files, PsiFile::getVirtualFile)); }
@Override public ResolveResult[] resolve(@NotNull Project project) { GlobalSearchScope scope = GlobalSearchScope.allScope(project); return indexedNameStream(project) .filter(predicate) .flatMap(name -> namedElementCollection(project, scope, name) .stream() .map(PsiElement::getNavigationElement) .map(navigationElement -> (ResolveResult) new PsiElementResolveResult(navigationElement, false) ) ).toArray(ResolveResult[]::new); } }
@Override public boolean contains(@NotNull VirtualFile file) { if (myParent.equals(file.getParent())) { if (myAllowedPackageInExcludedDirectory == null) { return false; } Project project = getProject(); PsiFile psiFile = project != null ? PsiManager.getInstance(project).findFile(file) : null; if (!(psiFile instanceof GoFile)) { return false; } if (!myAllowedPackageInExcludedDirectory.equals(((GoFile)psiFile).getPackageName())) { return false; } } return super.contains(file); } }
public static Collection<NamedElement> namedElementCollection(@NotNull Project project, @NotNull GlobalSearchScope scope, @NotNull String name) { Collection<NamedElement> namedElementCollection; if (DumbService.isDumb(project)) { namedElementCollection = Collections.emptyList(); } else { namedElementCollection = StubIndex.getElements( AllName.KEY, name, project, scope, NamedElement.class ); } return namedElementCollection; } }