Search in sources :

Example 21 with LocalSearchScope

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;
}
Also used : RenamePsiElementProcessor(com.intellij.refactoring.rename.RenamePsiElementProcessor) LocalSearchScope(com.intellij.psi.search.LocalSearchScope) HashMap(java.util.HashMap)

Example 22 with LocalSearchScope

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);
        }
    }
}
Also used : LocalSearchScope(com.intellij.psi.search.LocalSearchScope) VirtualFile(com.intellij.openapi.vfs.VirtualFile) Project(com.intellij.openapi.project.Project) GlobalSearchScope(com.intellij.psi.search.GlobalSearchScope) GlobalSearchScope(com.intellij.psi.search.GlobalSearchScope) SearchScope(com.intellij.psi.search.SearchScope) LocalSearchScope(com.intellij.psi.search.LocalSearchScope)

Example 23 with LocalSearchScope

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;
}
Also used : LocalSearchScope(com.intellij.psi.search.LocalSearchScope)

Example 24 with LocalSearchScope

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);
}
Also used : LocalSearchScope(com.intellij.psi.search.LocalSearchScope) GlobalSearchScope(com.intellij.psi.search.GlobalSearchScope) ArrayList(java.util.ArrayList) NotNull(org.jetbrains.annotations.NotNull)

Example 25 with LocalSearchScope

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()]);
}
Also used : LocalSearchScope(com.intellij.psi.search.LocalSearchScope) PsiDocTagValue(com.intellij.psi.javadoc.PsiDocTagValue) Project(com.intellij.openapi.project.Project) PsiDocParamRef(com.intellij.psi.impl.source.javadoc.PsiDocParamRef) UsageInfo(com.intellij.usageView.UsageInfo) NotNull(org.jetbrains.annotations.NotNull)

Aggregations

LocalSearchScope (com.intellij.psi.search.LocalSearchScope)113 SearchScope (com.intellij.psi.search.SearchScope)31 NotNull (org.jetbrains.annotations.NotNull)22 PsiElement (com.intellij.psi.PsiElement)19 GlobalSearchScope (com.intellij.psi.search.GlobalSearchScope)19 Project (com.intellij.openapi.project.Project)18 Nullable (org.jetbrains.annotations.Nullable)13 ArrayList (java.util.ArrayList)12 VirtualFile (com.intellij.openapi.vfs.VirtualFile)11 UsageInfo (com.intellij.usageView.UsageInfo)11 TextRange (com.intellij.openapi.util.TextRange)9 IncorrectOperationException (com.intellij.util.IncorrectOperationException)9 com.intellij.psi (com.intellij.psi)8 PsiReference (com.intellij.psi.PsiReference)8 PsiFile (com.intellij.psi.PsiFile)7 ReferencesSearch (com.intellij.psi.search.searches.ReferencesSearch)7 AnalysisScope (com.intellij.analysis.AnalysisScope)6 Processor (com.intellij.util.Processor)6 PsiTreeUtil (com.intellij.psi.util.PsiTreeUtil)5 Ref (com.intellij.openapi.util.Ref)4