use of com.intellij.psi.search.LocalSearchScope in project intellij-community by JetBrains.
the class RenameJavaClassProcessor method findSubmemberHidesMemberCollisions.
public static void findSubmemberHidesMemberCollisions(final PsiClass aClass, final String newName, final List<UsageInfo> result) {
if (aClass.getParent() instanceof PsiClass) {
PsiClass parent = (PsiClass) aClass.getParent();
Collection<PsiClass> inheritors = ClassInheritorsSearch.search(parent).findAll();
for (PsiClass inheritor : inheritors) {
if (newName.equals(inheritor.getName())) {
final ClassCollisionsDetector classCollisionsDetector = new ClassCollisionsDetector(aClass);
for (PsiReference reference : ReferencesSearch.search(inheritor, new LocalSearchScope(inheritor))) {
classCollisionsDetector.addClassCollisions(reference.getElement(), newName, result);
}
}
PsiClass[] inners = inheritor.getInnerClasses();
for (PsiClass inner : inners) {
if (newName.equals(inner.getName())) {
result.add(new SubmemberHidesMemberUsageInfo(inner, aClass));
}
}
}
} else if (aClass instanceof PsiTypeParameter) {
final PsiTypeParameterListOwner owner = ((PsiTypeParameter) aClass).getOwner();
if (owner instanceof PsiClass) {
final PsiClass[] supers = ((PsiClass) owner).getSupers();
for (PsiClass superClass : supers) {
if (newName.equals(superClass.getName())) {
final ClassCollisionsDetector classCollisionsDetector = new ClassCollisionsDetector(aClass);
for (PsiReference reference : ReferencesSearch.search(superClass, new LocalSearchScope(superClass))) {
classCollisionsDetector.addClassCollisions(reference.getElement(), newName, result);
}
}
PsiClass[] inners = superClass.getInnerClasses();
for (final PsiClass inner : inners) {
if (newName.equals(inner.getName())) {
ReferencesSearch.search(inner).forEach(reference -> {
PsiElement refElement = reference.getElement();
if (refElement instanceof PsiReferenceExpression && ((PsiReferenceExpression) refElement).isQualified())
return true;
MemberHidesOuterMemberUsageInfo info = new MemberHidesOuterMemberUsageInfo(refElement, aClass);
result.add(info);
return true;
});
}
}
}
}
}
}
use of com.intellij.psi.search.LocalSearchScope 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.LocalSearchScope in project intellij-community by JetBrains.
the class FunctionHelper method hasVarReference.
static boolean hasVarReference(PsiElement expressionOrCodeBlock, String name, StreamToLoopReplacementContext context) {
PsiLambdaExpression lambda = (PsiLambdaExpression) context.createExpression(name + "->" + expressionOrCodeBlock.getText());
PsiParameter var = lambda.getParameterList().getParameters()[0];
PsiElement body = lambda.getBody();
LOG.assertTrue(body != null);
return ReferencesSearch.search(var, new LocalSearchScope(body)).findFirst() != null;
}
use of com.intellij.psi.search.LocalSearchScope in project intellij-community by JetBrains.
the class JavaFindUsagesHandler method findReferencesToHighlight.
@NotNull
@Override
public Collection<PsiReference> findReferencesToHighlight(@NotNull final PsiElement target, @NotNull final SearchScope searchScope) {
if (target instanceof PsiMethod) {
final PsiMethod[] superMethods = ((PsiMethod) target).findDeepestSuperMethods();
if (superMethods.length == 0) {
return MethodReferencesSearch.search((PsiMethod) target, searchScope, true).findAll();
}
final Collection<PsiReference> result = new ArrayList<>();
GlobalSearchScope resolveScope = null;
if (searchScope instanceof LocalSearchScope) {
final PsiElement[] scopeElements = ((LocalSearchScope) searchScope).getScope();
resolveScope = GlobalSearchScope.union(ContainerUtil.map2Array(scopeElements, GlobalSearchScope.class, PsiElement::getResolveScope));
}
for (PsiMethod superMethod : superMethods) {
if (resolveScope != null) {
superMethod = PsiSuperMethodUtil.correctMethodByScope(superMethod, resolveScope);
}
result.addAll(MethodReferencesSearch.search(superMethod, searchScope, true).findAll());
}
return result;
}
return super.findReferencesToHighlight(target, searchScope);
}
use of com.intellij.psi.search.LocalSearchScope in project intellij-community by JetBrains.
the class ConvertToInstanceMethodProcessor method findUsages.
@NotNull
protected UsageInfo[] findUsages() {
LOG.assertTrue(myTargetParameter.getDeclarationScope() == myMethod);
final Project project = myMethod.getProject();
final PsiReference[] methodReferences = ReferencesSearch.search(myMethod, GlobalSearchScope.projectScope(project), false).toArray(PsiReference.EMPTY_ARRAY);
List<UsageInfo> result = new ArrayList<>();
for (final PsiReference ref : methodReferences) {
final PsiElement element = ref.getElement();
if (element instanceof PsiReferenceExpression) {
if (element.getParent() instanceof PsiMethodCallExpression) {
result.add(new MethodCallUsageInfo((PsiMethodCallExpression) element.getParent()));
}
} else if (element instanceof PsiDocTagValue) {
//TODO:!!!
result.add(new JavaDocUsageInfo(ref));
}
}
for (final PsiReference ref : ReferencesSearch.search(myTargetParameter, new LocalSearchScope(myMethod), false)) {
final PsiElement element = ref.getElement();
if (element instanceof PsiReferenceExpression || element instanceof PsiDocParamRef) {
result.add(new ParameterUsageInfo(ref));
}
}
if (myTargetClass.isInterface()) {
PsiClass[] implementingClasses = RefactoringHierarchyUtil.findImplementingClasses(myTargetClass);
for (final PsiClass implementingClass : implementingClasses) {
result.add(new ImplementingClassUsageInfo(implementingClass));
}
}
return result.toArray(new UsageInfo[result.size()]);
}
Aggregations