use of com.intellij.psi.search.SearchScope in project intellij-community by JetBrains.
the class NonPhysicalReferenceSearcher method processQuery.
public void processQuery(@NotNull ReferencesSearch.SearchParameters queryParameters, @NotNull Processor<PsiReference> consumer) {
if (ApplicationManager.getApplication().isUnitTestMode()) {
return;
}
final SearchScope scope = queryParameters.getScopeDeterminedByUser();
final PsiElement element = queryParameters.getElementToSearch();
final PsiFile containingFile = element.getContainingFile();
if (!(scope instanceof GlobalSearchScope) && !isApplicableTo(containingFile)) {
return;
}
final LocalSearchScope currentScope;
if (scope instanceof LocalSearchScope) {
if (queryParameters.isIgnoreAccessScope()) {
return;
}
currentScope = (LocalSearchScope) scope;
} else {
currentScope = null;
}
Project project = element.getProject();
if (!project.isInitialized()) {
// skip default and other projects that look weird
return;
}
final PsiManager psiManager = PsiManager.getInstance(project);
for (VirtualFile virtualFile : FileEditorManager.getInstance(project).getOpenFiles()) {
if (virtualFile.getFileType().isBinary()) {
continue;
}
PsiFile file = psiManager.findFile(virtualFile);
if (isApplicableTo(file)) {
final LocalSearchScope fileScope = new LocalSearchScope(file);
final LocalSearchScope searchScope = currentScope == null ? fileScope : fileScope.intersectWith(currentScope);
ReferencesSearch.searchOptimized(element, searchScope, true, queryParameters.getOptimizer(), consumer);
}
}
}
use of com.intellij.psi.search.SearchScope in project intellij-community by JetBrains.
the class JavaClassInheritorsSearcher method processInheritors.
private static boolean processInheritors(@NotNull final ClassInheritorsSearch.SearchParameters parameters, @NotNull final Processor<PsiClass> consumer) {
@NotNull final PsiClass baseClass = parameters.getClassToProcess();
if (baseClass instanceof PsiAnonymousClass || isFinal(baseClass))
return true;
final SearchScope searchScope = parameters.getScope();
Project project = PsiUtilCore.getProjectInReadAction(baseClass);
if (isJavaLangObject(baseClass)) {
return AllClassesSearch.search(searchScope, project, parameters.getNameCondition()).forEach(aClass -> {
ProgressManager.checkCanceled();
return isJavaLangObject(aClass) || consumer.process(aClass);
});
}
if (searchScope instanceof LocalSearchScope) {
return processLocalScope(project, parameters, (LocalSearchScope) searchScope, baseClass, consumer);
}
Iterable<PsiClass> cached = getOrComputeSubClasses(project, baseClass, searchScope);
for (final PsiClass subClass : cached) {
ProgressManager.checkCanceled();
if (subClass instanceof PsiAnonymousClass && !parameters.isIncludeAnonymous()) {
continue;
}
if (ReadAction.compute(() -> checkCandidate(subClass, parameters) && !consumer.process(subClass))) {
return false;
}
}
return true;
}
use of com.intellij.psi.search.SearchScope in project intellij-community by JetBrains.
the class JavaClassInheritorsSearcher method getOrComputeSubClasses.
@NotNull
private static Iterable<PsiClass> getOrComputeSubClasses(@NotNull Project project, @NotNull PsiClass baseClass, @NotNull SearchScope searchScopeForNonPhysical) {
ConcurrentMap<PsiClass, Iterable<PsiClass>> map = HighlightingCaches.getInstance(project).ALL_SUB_CLASSES;
Iterable<PsiClass> cached = map.get(baseClass);
if (cached == null) {
// returns lazy collection of subclasses. Each call to next() leads to calculation of next batch of subclasses.
Function<PsiAnchor, PsiClass> converter = anchor -> ReadAction.compute(() -> (PsiClass) anchor.retrieve());
Predicate<PsiClass> applicableFilter = candidate -> !(candidate instanceof PsiAnonymousClass) && candidate != null && !candidate.hasModifierProperty(PsiModifier.FINAL);
// for non-physical elements ignore the cache completely because non-physical elements created so often/unpredictably so I can't figure out when to clear caches in this case
boolean isPhysical = ReadAction.compute(baseClass::isPhysical);
SearchScope scopeToUse = isPhysical ? GlobalSearchScope.allScope(project) : searchScopeForNonPhysical;
LazyConcurrentCollection.MoreElementsGenerator<PsiAnchor, PsiClass> generator = (candidate, processor) -> DirectClassInheritorsSearch.search(candidate, scopeToUse).forEach(subClass -> {
ProgressManager.checkCanceled();
PsiAnchor pointer = ReadAction.compute(() -> PsiAnchor.create(subClass));
processor.consume(pointer);
return true;
});
PsiAnchor seed = ReadAction.compute(() -> PsiAnchor.create(baseClass));
// lazy collection: store underlying queue as PsiAnchors, generate new elements by running direct inheritors
Iterable<PsiClass> computed = new LazyConcurrentCollection<>(seed, converter, applicableFilter, generator);
// make sure concurrent calls of this method always return the same collection to avoid expensive duplicate work
cached = isPhysical ? ConcurrencyUtil.cacheOrGet(map, baseClass, computed) : computed;
}
return cached;
}
use of com.intellij.psi.search.SearchScope in project intellij-community by JetBrains.
the class JavaDirectInheritorsSearcher method performSearchUsingCompilerIndices.
private static CompilerDirectHierarchyInfo performSearchUsingCompilerIndices(@NotNull DirectClassInheritorsSearch.SearchParameters parameters, @NotNull SearchScope useScope, @NotNull Project project) {
if (!(useScope instanceof GlobalSearchScope))
return null;
SearchScope scope = parameters.getScope();
if (!(scope instanceof GlobalSearchScope))
return null;
PsiClass searchClass = ReadAction.compute(() -> (PsiClass) PsiUtil.preferCompiledElement(parameters.getClassToProcess()));
final CompilerReferenceService compilerReferenceService = CompilerReferenceService.getInstance(project);
return compilerReferenceService.getDirectInheritors(searchClass, (GlobalSearchScope) useScope, (GlobalSearchScope) scope, JavaFileType.INSTANCE);
}
use of com.intellij.psi.search.SearchScope in project intellij-community by JetBrains.
the class JavaOverridingMethodsSearcher method execute.
@Override
public boolean execute(@NotNull final OverridingMethodsSearch.SearchParameters parameters, @NotNull final Processor<PsiMethod> consumer) {
final PsiMethod method = parameters.getMethod();
Project project = ReadAction.compute(method::getProject);
final SearchScope searchScope = parameters.getScope();
if (searchScope instanceof LocalSearchScope) {
return processLocalScope((LocalSearchScope) searchScope, method, project, consumer);
}
Iterable<PsiMethod> cached = HighlightingCaches.getInstance(project).OVERRIDING_METHODS.get(method);
if (cached == null) {
cached = compute(method, project);
// for non-physical elements ignore the cache completely because non-physical elements created so often/unpredictably so I can't figure out when to clear caches in this case
if (ReadAction.compute(method::isPhysical)) {
HighlightingCaches.getInstance(project).OVERRIDING_METHODS.put(method, cached);
}
}
for (final PsiMethod subMethod : cached) {
ProgressManager.checkCanceled();
if (!ReadAction.compute(() -> PsiSearchScopeUtil.isInScope(searchScope, subMethod))) {
continue;
}
if (!consumer.process(subMethod) || !parameters.isCheckDeep()) {
return false;
}
}
return true;
}
Aggregations