use of com.intellij.psi.search.LocalSearchScope in project intellij-community by JetBrains.
the class MemberInplaceRenamer method appendAdditionalElement.
@Override
protected boolean appendAdditionalElement(Collection<PsiReference> refs, Collection<Pair<PsiElement, TextRange>> stringUsages) {
boolean showChooser = super.appendAdditionalElement(refs, stringUsages);
PsiNamedElement variable = getVariable();
if (variable != null) {
final PsiElement substituted = getSubstituted();
if (substituted != null) {
appendAdditionalElement(stringUsages, variable, substituted);
RenamePsiElementProcessor processor = RenamePsiElementProcessor.forElement(substituted);
final HashMap<PsiElement, String> allRenames = new HashMap<>();
PsiFile currentFile = PsiDocumentManager.getInstance(myProject).getPsiFile(myEditor.getDocument());
processor.prepareRenaming(substituted, "", allRenames, new LocalSearchScope(currentFile));
for (PsiElement element : allRenames.keySet()) {
appendAdditionalElement(stringUsages, variable, element);
}
}
}
return showChooser;
}
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