use of com.intellij.psi.search.SearchScope in project intellij-community by JetBrains.
the class DfaVariableValue method isCheapEnoughToSearch.
private static boolean isCheapEnoughToSearch(PsiField field, String name) {
SearchScope scope = field.getUseScope();
if (!(scope instanceof GlobalSearchScope))
return true;
PsiSearchHelper helper = PsiSearchHelper.SERVICE.getInstance(field.getProject());
PsiSearchHelper.SearchCostResult result = helper.isCheapEnoughToSearch(name, (GlobalSearchScope) scope, field.getContainingFile(), null);
return result != PsiSearchHelper.SearchCostResult.TOO_MANY_OCCURRENCES;
}
use of com.intellij.psi.search.SearchScope in project intellij-community by JetBrains.
the class CallerMethodsTreeStructure method buildChildren.
@NotNull
@Override
protected final Object[] buildChildren(@NotNull final HierarchyNodeDescriptor descriptor) {
PsiMember enclosingElement = ((CallHierarchyNodeDescriptor) descriptor).getEnclosingElement();
HierarchyNodeDescriptor nodeDescriptor = getBaseDescriptor();
if (enclosingElement instanceof PsiMethod) {
PsiClass clazz = enclosingElement.getContainingClass();
if (isLocalOrAnonymousClass(clazz)) {
PsiElement parent = clazz.getParent();
PsiElement grandParent = parent instanceof PsiNewExpression ? parent.getParent() : null;
if (grandParent instanceof PsiExpressionList) {
// for created anonymous class that immediately passed as argument use instantiation point as next call point (IDEA-73312)
enclosingElement = CallHierarchyNodeDescriptor.getEnclosingElement(grandParent);
}
}
}
if (!(enclosingElement instanceof PsiMethod) || nodeDescriptor == null) {
return ArrayUtil.EMPTY_OBJECT_ARRAY;
}
final PsiMethod baseMethod = (PsiMethod) ((CallHierarchyNodeDescriptor) nodeDescriptor).getTargetElement();
if (baseMethod == null) {
return ArrayUtil.EMPTY_OBJECT_ARRAY;
}
final SearchScope searchScope = getSearchScope(myScopeType, baseMethod.getContainingClass());
final PsiMethod method = (PsiMethod) enclosingElement;
final PsiClass originalClass = method.getContainingClass();
assert originalClass != null;
final PsiClassType originalType = JavaPsiFacade.getElementFactory(myProject).createType(originalClass);
final Set<PsiMethod> methodsToFind = new HashSet<>();
methodsToFind.add(method);
ContainerUtil.addAll(methodsToFind, method.findDeepestSuperMethods());
final Map<PsiMember, NodeDescriptor> methodToDescriptorMap = new HashMap<>();
for (final PsiMethod methodToFind : methodsToFind) {
final JavaCallHierarchyData data = new JavaCallHierarchyData(originalClass, methodToFind, originalType, method, methodsToFind, descriptor, methodToDescriptorMap, myProject);
MethodReferencesSearch.search(methodToFind, searchScope, true).forEach(reference -> {
for (CallReferenceProcessor processor : CallReferenceProcessor.EP_NAME.getExtensions()) {
if (!processor.process(reference, data))
break;
}
return true;
});
}
return methodToDescriptorMap.values().toArray(new Object[methodToDescriptorMap.size()]);
}
use of com.intellij.psi.search.SearchScope in project intellij-community by JetBrains.
the class AllClassesSearchExecutor method execute.
@Override
public boolean execute(@NotNull final AllClassesSearch.SearchParameters queryParameters, @NotNull final Processor<PsiClass> consumer) {
SearchScope scope = queryParameters.getScope();
if (scope instanceof GlobalSearchScope) {
return processAllClassesInGlobalScope((GlobalSearchScope) scope, queryParameters, consumer);
}
PsiElement[] scopeRoots = ((LocalSearchScope) scope).getScope();
for (final PsiElement scopeRoot : scopeRoots) {
if (!processScopeRootForAllClasses(scopeRoot, consumer))
return false;
}
return true;
}
use of com.intellij.psi.search.SearchScope in project intellij-community by JetBrains.
the class ClassesWithAnnotatedMembersSearcher method processQuery.
@Override
public void processQuery(@NotNull ClassesWithAnnotatedMembersSearch.Parameters queryParameters, @NotNull final Processor<PsiClass> consumer) {
SearchScope scope = queryParameters.getScope();
for (QueryExecutor executor : Extensions.getExtensions(ClassesWithAnnotatedMembersSearch.EP_NAME)) {
if (executor instanceof ScopedQueryExecutor) {
scope = scope.intersectWith(GlobalSearchScope.notScope(((ScopedQueryExecutor) executor).getScope(queryParameters)));
}
}
final Set<PsiClass> processed = new HashSet<>();
AnnotatedElementsSearch.searchPsiMembers(queryParameters.getAnnotationClass(), scope).forEach(member -> {
PsiClass psiClass;
AccessToken token = ReadAction.start();
try {
psiClass = member instanceof PsiClass ? (PsiClass) member : member.getContainingClass();
} finally {
token.finish();
}
if (psiClass != null && processed.add(psiClass)) {
consumer.process(psiClass);
}
return true;
});
}
use of com.intellij.psi.search.SearchScope in project intellij-community by JetBrains.
the class ConstructorReferencesSearcher method processQuery.
@Override
public void processQuery(@NotNull final ReferencesSearch.SearchParameters p, @NotNull Processor<PsiReference> consumer) {
final PsiElement element = p.getElementToSearch();
if (!(element instanceof PsiMethod)) {
return;
}
final PsiMethod method = (PsiMethod) element;
final PsiManager[] manager = new PsiManager[1];
PsiClass aClass = ApplicationManager.getApplication().runReadAction(new Computable<PsiClass>() {
@Override
public PsiClass compute() {
if (!method.isConstructor())
return null;
PsiClass aClass = method.getContainingClass();
manager[0] = aClass == null ? null : aClass.getManager();
return aClass;
}
});
if (manager[0] == null) {
return;
}
SearchScope scope = ApplicationManager.getApplication().runReadAction(new Computable<SearchScope>() {
@Override
public SearchScope compute() {
return p.getEffectiveSearchScope();
}
});
new ConstructorReferencesSearchHelper(manager[0]).processConstructorReferences(consumer, method, aClass, scope, p.getProject(), p.isIgnoreAccessScope(), true, p.getOptimizer());
}
Aggregations