use of com.intellij.psi.search.GlobalSearchScope in project intellij-community by JetBrains.
the class SearchScope method iterateContent.
public void iterateContent(@NotNull final Project project, final Processor<VirtualFile> processor) {
switch(getScopeType()) {
case PROJECT:
//noinspection unchecked
ProjectRootManager.getInstance(project).getFileIndex().iterateContent(new MyFileIterator(processor, Conditions.<VirtualFile>alwaysTrue()));
break;
case MODULE:
final Module module = ModuleManager.getInstance(project).findModuleByName(getModuleName());
assert module != null;
ModuleRootManager.getInstance(module).getFileIndex().iterateContent(new MyFileIterator(processor, Conditions.<VirtualFile>alwaysTrue()));
break;
case DIRECTORY:
final String dirName = getPath();
assert dirName != null;
final VirtualFile virtualFile = findFile(dirName);
if (virtualFile != null) {
iterateRecursively(virtualFile, processor, isRecursive());
}
break;
case CUSTOM:
assert myCustomScope != null;
final ContentIterator iterator;
if (myCustomScope instanceof GlobalSearchScope) {
final GlobalSearchScope searchScope = (GlobalSearchScope) myCustomScope;
iterator = new MyFileIterator(processor, virtualFile13 -> searchScope.contains(virtualFile13));
if (searchScope.isSearchInLibraries()) {
final OrderEnumerator enumerator = OrderEnumerator.orderEntries(project).withoutModuleSourceEntries().withoutDepModules();
final Collection<VirtualFile> libraryFiles = new THashSet<>();
Collections.addAll(libraryFiles, enumerator.getClassesRoots());
Collections.addAll(libraryFiles, enumerator.getSourceRoots());
final Processor<VirtualFile> adapter = virtualFile1 -> iterator.processFile(virtualFile1);
for (final VirtualFile file : libraryFiles) {
iterateRecursively(file, adapter, true);
}
}
} else {
final PsiManager manager = PsiManager.getInstance(project);
iterator = new MyFileIterator(processor, virtualFile12 -> {
final PsiFile element = manager.findFile(virtualFile12);
return element != null && PsiSearchScopeUtil.isInScope(myCustomScope, element);
});
}
ProjectRootManager.getInstance(project).getFileIndex().iterateContent(iterator);
}
}
use of com.intellij.psi.search.GlobalSearchScope in project intellij-community by JetBrains.
the class PythonImportUtils method addSymbolImportCandidates.
private static void addSymbolImportCandidates(PyElement node, String refText, @Nullable String asName, AutoImportQuickFix fix, Set<String> seenCandidateNames, PsiFile existingImportFile) {
Project project = node.getProject();
List<PsiElement> symbols = new ArrayList<>();
symbols.addAll(PyClassNameIndex.find(refText, project, true));
GlobalSearchScope scope = PyProjectScopeBuilder.excludeSdkTestsScope(node);
if (!isQualifier(node)) {
symbols.addAll(PyFunctionNameIndex.find(refText, project, scope));
}
symbols.addAll(PyVariableNameIndex.find(refText, project, scope));
if (isPossibleModuleReference(node)) {
symbols.addAll(findImportableModules(node.getContainingFile(), refText, project, scope));
}
if (!symbols.isEmpty()) {
for (PsiElement symbol : symbols) {
if (isIndexableTopLevel(symbol)) {
// we only want top-level symbols
PsiFileSystemItem srcfile = symbol instanceof PsiFileSystemItem ? ((PsiFileSystemItem) symbol).getParent() : symbol.getContainingFile();
if (srcfile != null && isAcceptableForImport(node, existingImportFile, srcfile)) {
QualifiedName importPath = QualifiedNameFinder.findCanonicalImportPath(symbol, node);
if (importPath == null) {
continue;
}
if (symbol instanceof PsiFileSystemItem) {
importPath = importPath.removeTail(1);
}
final String symbolImportQName = importPath.append(refText).toString();
if (!seenCandidateNames.contains(symbolImportQName)) {
// a new, valid hit
fix.addImport(symbol, srcfile, importPath, asName);
seenCandidateNames.add(symbolImportQName);
}
}
}
}
}
}
use of com.intellij.psi.search.GlobalSearchScope in project intellij-community by JetBrains.
the class DefaultXmlTagNameProvider method getRootTagsVariants.
private static List<LookupElement> getRootTagsVariants(final XmlTag tag, final List<LookupElement> elements) {
elements.add(LookupElementBuilder.create("?xml version=\"1.0\" encoding=\"\" ?>").withPresentableText("<?xml version=\"1.0\" encoding=\"\" ?>").withInsertHandler(new InsertHandler<LookupElement>() {
@Override
public void handleInsert(InsertionContext context, LookupElement item) {
int offset = context.getEditor().getCaretModel().getOffset();
context.getEditor().getCaretModel().moveToOffset(offset - 4);
AutoPopupController.getInstance(context.getProject()).scheduleAutoPopup(context.getEditor());
}
}));
final FileBasedIndex fbi = FileBasedIndex.getInstance();
Collection<String> result = new ArrayList<>();
Processor<String> processor = Processors.cancelableCollectProcessor(result);
fbi.processAllKeys(XmlNamespaceIndex.NAME, processor, tag.getProject());
final GlobalSearchScope scope = new EverythingGlobalScope();
for (final String ns : result) {
if (ns.startsWith("file://"))
continue;
fbi.processValues(XmlNamespaceIndex.NAME, ns, null, new FileBasedIndex.ValueProcessor<XsdNamespaceBuilder>() {
@Override
public boolean process(final VirtualFile file, XsdNamespaceBuilder value) {
List<String> tags = value.getRootTags();
for (String s : tags) {
elements.add(LookupElementBuilder.create(s).withTypeText(ns).withInsertHandler(new XmlTagInsertHandler() {
@Override
public void handleInsert(InsertionContext context, LookupElement item) {
final Editor editor = context.getEditor();
final Document document = context.getDocument();
final int caretOffset = editor.getCaretModel().getOffset();
final RangeMarker caretMarker = document.createRangeMarker(caretOffset, caretOffset);
caretMarker.setGreedyToRight(true);
XmlFile psiFile = (XmlFile) context.getFile();
boolean incomplete = XmlUtil.getTokenOfType(tag, XmlTokenType.XML_TAG_END) == null && XmlUtil.getTokenOfType(tag, XmlTokenType.XML_EMPTY_ELEMENT_END) == null;
XmlNamespaceHelper.getHelper(psiFile).insertNamespaceDeclaration(psiFile, editor, Collections.singleton(ns), null, null);
editor.getCaretModel().moveToOffset(caretMarker.getEndOffset());
XmlTag rootTag = psiFile.getRootTag();
if (incomplete) {
XmlToken token = XmlUtil.getTokenOfType(rootTag, XmlTokenType.XML_EMPTY_ELEMENT_END);
// remove tag end added by smart attribute adder :(
if (token != null)
token.delete();
PsiDocumentManager.getInstance(context.getProject()).doPostponedOperationsAndUnblockDocument(document);
super.handleInsert(context, item);
}
}
}));
}
return true;
}
}, scope);
}
return elements;
}
use of com.intellij.psi.search.GlobalSearchScope in project intellij-community by JetBrains.
the class GroovyScriptRunConfiguration method getSearchScope.
@Override
public GlobalSearchScope getSearchScope() {
GlobalSearchScope superScope = super.getSearchScope();
String path = getScriptPath();
if (path == null)
return superScope;
VirtualFile scriptFile = LocalFileSystem.getInstance().findFileByPath(path);
if (scriptFile == null)
return superScope;
GlobalSearchScope fileScope = GlobalSearchScope.fileScope(getProject(), scriptFile);
if (superScope == null)
return fileScope;
return new DelegatingGlobalSearchScope(fileScope.union(superScope)) {
@Override
public int compare(@NotNull VirtualFile file1, @NotNull VirtualFile file2) {
if (file1.equals(scriptFile))
return 1;
if (file2.equals(scriptFile))
return -1;
return super.compare(file1, file2);
}
};
}
use of com.intellij.psi.search.GlobalSearchScope in project intellij-community by JetBrains.
the class GrIntroduceParameterProcessor method getForcedType.
@NotNull
@Override
public PsiType getForcedType() {
final PsiType selectedType = mySettings.getSelectedType();
if (selectedType != null)
return selectedType;
final PsiManager manager = PsiManager.getInstance(myProject);
final GlobalSearchScope resolveScope = mySettings.getToReplaceIn().getResolveScope();
return PsiType.getJavaLangObject(manager, resolveScope);
}
Aggregations