use of com.intellij.psi.search.GlobalSearchScope in project intellij-community by JetBrains.
the class CodeFragmentFactoryContextWrapper method prepareResolveScope.
private static JavaCodeFragment prepareResolveScope(JavaCodeFragment codeFragment) {
GlobalSearchScope originalResolveScope = codeFragment.getResolveScope();
codeFragment.forceResolveScope(new DelegatingGlobalSearchScope(GlobalSearchScope.allScope(codeFragment.getProject())) {
final Comparator<VirtualFile> myScopeComparator = Comparator.comparing(originalResolveScope::contains).thenComparing(super::compare);
@Override
public int compare(@NotNull VirtualFile file1, @NotNull VirtualFile file2) {
// prefer files from the original resolve scope
return myScopeComparator.compare(file1, file2);
}
});
return codeFragment;
}
use of com.intellij.psi.search.GlobalSearchScope in project intellij-community by JetBrains.
the class CompilerReferenceReader method getDirectInheritors.
/**
* @return two maps of classes grouped per file
*
* 1st map: inheritors. Can be used without explicit inheritance verification
* 2nd map: candidates. One need to check that these classes are really direct inheritors
*/
@NotNull
Map<VirtualFile, Object[]> getDirectInheritors(@NotNull LightRef searchElement, @NotNull GlobalSearchScope searchScope, @NotNull GlobalSearchScope dirtyScope, @NotNull FileType fileType, @NotNull CompilerHierarchySearchType searchType) throws StorageException {
GlobalSearchScope effectiveSearchScope = GlobalSearchScope.notScope(dirtyScope).intersectWith(searchScope);
LanguageLightRefAdapter adapter = CompilerReferenceServiceImpl.findAdapterForFileType(fileType);
LOG.assertTrue(adapter != null, "adapter is null for file type: " + fileType);
Class<? extends LightRef> requiredLightRefClass = searchType.getRequiredClass(adapter);
Map<VirtualFile, Object[]> candidatesPerFile = new HashMap<>();
myIndex.get(CompilerIndices.BACK_HIERARCHY).getData(searchElement).forEach((fileId, defs) -> {
final List<LightRef> requiredCandidates = defs.stream().filter(requiredLightRefClass::isInstance).collect(toList());
if (requiredCandidates.isEmpty())
return true;
final VirtualFile file = findFile(fileId);
if (file != null && effectiveSearchScope.contains(file)) {
candidatesPerFile.put(file, searchType.convertToIds(requiredCandidates, myIndex.getByteSeqEum()));
}
return true;
});
return candidatesPerFile.isEmpty() ? Collections.emptyMap() : candidatesPerFile;
}
use of com.intellij.psi.search.GlobalSearchScope in project intellij-community by JetBrains.
the class CompilerReferenceServiceImpl method getHierarchyInfo.
@Nullable
private CompilerHierarchyInfoImpl getHierarchyInfo(@NotNull PsiNamedElement aClass, @NotNull GlobalSearchScope useScope, @NotNull GlobalSearchScope searchScope, @NotNull FileType searchFileType, @NotNull CompilerHierarchySearchType searchType) {
if (!isServiceEnabledFor(aClass) || searchScope == LibraryScopeCache.getInstance(myProject).getLibrariesOnlyScope())
return null;
try {
Map<VirtualFile, Object[]> candidatesPerFile = ReadAction.compute(() -> {
if (myProject.isDisposed())
throw new ProcessCanceledException();
return CachedValuesManager.getCachedValue(aClass, () -> CachedValueProvider.Result.create(new ConcurrentFactoryMap<HierarchySearchKey, Map<VirtualFile, Object[]>>() {
@Nullable
@Override
protected Map<VirtualFile, Object[]> create(HierarchySearchKey key) {
return calculateDirectInheritors(aClass, useScope, key.mySearchFileType, key.mySearchType);
}
}, PsiModificationTracker.MODIFICATION_COUNT, this)).get(new HierarchySearchKey(searchType, searchFileType));
});
if (candidatesPerFile == null)
return null;
GlobalSearchScope dirtyScope = myDirtyScopeHolder.getDirtyScope();
if (ElementPlace.LIB == ReadAction.compute(() -> ElementPlace.get(aClass.getContainingFile().getVirtualFile(), myProjectFileIndex))) {
dirtyScope = dirtyScope.union(LibraryScopeCache.getInstance(myProject).getLibrariesOnlyScope());
}
return new CompilerHierarchyInfoImpl(candidatesPerFile, aClass, dirtyScope, searchScope, myProject, searchFileType, searchType);
} catch (ProcessCanceledException e) {
throw e;
} catch (RuntimeException e) {
return onException(e, "hierarchy");
}
}
use of com.intellij.psi.search.GlobalSearchScope in project intellij-elixir by KronicDeth.
the class Variants method executeOnAliasedName.
/*
* Protected Instance Methods
*/
/**
* Decides whether {@code match} matches the criteria being searched for. All other {@link #execute} methods
* eventually end here.
*
* @param match
* @param aliasedName
* @param state
* @return {@code true} to keep processing; {@code false} to stop processing.
*/
@Override
protected boolean executeOnAliasedName(@NotNull PsiNamedElement match, @NotNull final String aliasedName, @NotNull ResolveState state) {
if (lookupElementList == null) {
lookupElementList = new ArrayList<LookupElement>();
}
lookupElementList.add(LookupElementBuilder.createWithSmartPointer(aliasedName, match));
String unaliasedName = UnaliasedName.unaliasedName(match);
if (unaliasedName != null) {
Project project = match.getProject();
Collection<String> indexedNameCollection = StubIndex.getInstance().getAllKeys(AllName.KEY, project);
List<String> unaliasedNestedNames = ContainerUtil.findAll(indexedNameCollection, new org.elixir_lang.Module.IsNestedUnder(unaliasedName));
if (unaliasedNestedNames.size() > 0) {
GlobalSearchScope scope = GlobalSearchScope.allScope(project);
for (String unaliasedNestedName : unaliasedNestedNames) {
Collection<NamedElement> unaliasedNestedNamedElementCollection = StubIndex.getElements(AllName.KEY, unaliasedNestedName, project, scope, NamedElement.class);
if (unaliasedNestedNamedElementCollection.size() > 0) {
List<String> unaliasedNestedNamePartList = split(unaliasedNestedName);
List<String> unaliasedNamePartList = split(unaliasedName);
List<String> aliasedNamePartList = split(aliasedName);
List<String> aliasedNestedNamePartList = new ArrayList<String>();
aliasedNestedNamePartList.addAll(aliasedNamePartList);
for (int i = unaliasedNamePartList.size(); i < unaliasedNestedNamePartList.size(); i++) {
aliasedNestedNamePartList.add(unaliasedNestedNamePartList.get(i));
}
String aliasedNestedName = concat(aliasedNestedNamePartList);
for (NamedElement unaliasedNestedNamedElement : unaliasedNestedNamedElementCollection) {
lookupElementList.add(LookupElementBuilder.createWithSmartPointer(aliasedNestedName, unaliasedNestedNamedElement));
}
}
}
}
}
return true;
}
use of com.intellij.psi.search.GlobalSearchScope in project intellij-elixir by KronicDeth.
the class Variants method addProjectNameElementsTo.
/*
* Private Instance Methods
*/
private void addProjectNameElementsTo(List<LookupElement> lookupElementList, PsiElement entrance) {
Project project = entrance.getProject();
/* getAllKeys is not the actual keys in the actual project. They need to be checked.
See https://intellij-support.jetbrains.com/hc/en-us/community/posts/207930789-StubIndex-persisting-between-test-runs-leading-to-incorrect-completions */
Collection<String> indexedNameCollection = StubIndex.getInstance().getAllKeys(AllName.KEY, project);
GlobalSearchScope scope = GlobalSearchScope.allScope(project);
Collection<String> aliasNameCollection = filterIndexedNameCollection(indexedNameCollection);
String prefix = indexedNamePrefix(multipleAliases);
Collection<String> prefixedNameCollection = filterIndexedNameCollection(aliasNameCollection, prefix);
for (String prefixedName : prefixedNameCollection) {
Collection<NamedElement> prefixedNameNamedElementCollection = StubIndex.getElements(AllName.KEY, prefixedName, project, scope, NamedElement.class);
String lookupName = lookupName(prefixedName, prefix);
for (NamedElement prefixedNameNamedElement : prefixedNameNamedElementCollection) {
/* Generalizes over whether the prefixedNameNamedElement is a source element or a compiled element as
the navigation element is defined to be always be a source element */
PsiElement navigationElement = prefixedNameNamedElement.getNavigationElement();
lookupElementList.add(LookupElementBuilder.createWithSmartPointer(lookupName, navigationElement));
}
}
}
Aggregations