Search in sources :

Example 1 with SearchScope

use of com.intellij.psi.search.SearchScope in project intellij-community by JetBrains.

the class GroovyRefactoringSupportProvider method isInplaceRenameAvailable.

@Override
public boolean isInplaceRenameAvailable(@NotNull PsiElement elementToRename, PsiElement nameSuggestionContext) {
    if (nameSuggestionContext != null && nameSuggestionContext.getContainingFile() != elementToRename.getContainingFile())
        return false;
    if (!(elementToRename instanceof GrLabeledStatement)) {
        return false;
    }
    SearchScope useScope = PsiSearchHelper.SERVICE.getInstance(elementToRename.getProject()).getUseScope(elementToRename);
    if (!(useScope instanceof LocalSearchScope))
        return false;
    PsiElement[] scopeElements = ((LocalSearchScope) useScope).getScope();
    if (scopeElements.length > 1) {
        return false;
    }
    PsiFile containingFile = elementToRename.getContainingFile();
    return PsiTreeUtil.isAncestor(containingFile, scopeElements[0], false);
}
Also used : LocalSearchScope(com.intellij.psi.search.LocalSearchScope) SearchScope(com.intellij.psi.search.SearchScope) LocalSearchScope(com.intellij.psi.search.LocalSearchScope) PsiFile(com.intellij.psi.PsiFile) GrLabeledStatement(org.jetbrains.plugins.groovy.lang.psi.api.statements.GrLabeledStatement) PsiElement(com.intellij.psi.PsiElement)

Example 2 with SearchScope

use of com.intellij.psi.search.SearchScope in project intellij-community by JetBrains.

the class PyInitReferenceSearchExecutor method processQuery.

public void processQuery(@NotNull ReferencesSearch.SearchParameters queryParameters, @NotNull final Processor<PsiReference> consumer) {
    PsiElement element = queryParameters.getElementToSearch();
    if (!(element instanceof PyFunction)) {
        return;
    }
    final AccessToken accessToken = ApplicationManager.getApplication().acquireReadActionLock();
    String className;
    SearchScope searchScope;
    PyFunction function;
    try {
        function = (PyFunction) element;
        if (!PyNames.INIT.equals(function.getName())) {
            return;
        }
        final PyClass pyClass = function.getContainingClass();
        if (pyClass == null) {
            return;
        }
        className = pyClass.getName();
        if (className == null) {
            return;
        }
        searchScope = queryParameters.getEffectiveSearchScope();
        if (searchScope instanceof GlobalSearchScope) {
            searchScope = GlobalSearchScope.getScopeRestrictedByFileTypes((GlobalSearchScope) searchScope, PythonFileType.INSTANCE);
        }
    } finally {
        accessToken.finish();
    }
    queryParameters.getOptimizer().searchWord(className, searchScope, UsageSearchContext.IN_CODE, true, function);
}
Also used : PyClass(com.jetbrains.python.psi.PyClass) PyFunction(com.jetbrains.python.psi.PyFunction) GlobalSearchScope(com.intellij.psi.search.GlobalSearchScope) AccessToken(com.intellij.openapi.application.AccessToken) GlobalSearchScope(com.intellij.psi.search.GlobalSearchScope) SearchScope(com.intellij.psi.search.SearchScope) PsiElement(com.intellij.psi.PsiElement)

Example 3 with SearchScope

use of com.intellij.psi.search.SearchScope in project intellij-community by JetBrains.

the class PyStringReferenceSearch method processQuery.

public void processQuery(@NotNull final ReferencesSearch.SearchParameters params, @NotNull final Processor<PsiReference> consumer) {
    final PsiElement element = params.getElementToSearch();
    if (!(element instanceof PyElement) && !(element instanceof PsiDirectory)) {
        return;
    }
    SearchScope searchScope = params.getEffectiveSearchScope();
    if (searchScope instanceof GlobalSearchScope) {
        searchScope = GlobalSearchScope.getScopeRestrictedByFileTypes((GlobalSearchScope) searchScope, PythonFileType.INSTANCE);
    }
    String name = PyUtil.computeElementNameForStringSearch(element);
    if (StringUtil.isEmpty(name)) {
        return;
    }
    params.getOptimizer().searchWord(name, searchScope, UsageSearchContext.IN_STRINGS, true, element);
}
Also used : GlobalSearchScope(com.intellij.psi.search.GlobalSearchScope) PsiDirectory(com.intellij.psi.PsiDirectory) GlobalSearchScope(com.intellij.psi.search.GlobalSearchScope) SearchScope(com.intellij.psi.search.SearchScope) PsiElement(com.intellij.psi.PsiElement) PyElement(com.jetbrains.python.psi.PyElement)

Example 4 with SearchScope

use of com.intellij.psi.search.SearchScope in project intellij-community by JetBrains.

the class JavaFxControllerFieldSearcher method execute.

@Override
public boolean execute(@NotNull final ReferencesSearch.SearchParameters queryParameters, @NotNull final Processor<PsiReference> consumer) {
    final PsiElement elementToSearch = queryParameters.getElementToSearch();
    if (elementToSearch instanceof PsiField) {
        final PsiField field = (PsiField) elementToSearch;
        final PsiClass containingClass = ReadAction.compute(() -> field.getContainingClass());
        if (containingClass != null) {
            final String qualifiedName = ReadAction.compute(() -> containingClass.getQualifiedName());
            if (qualifiedName != null) {
                Project project = PsiUtilCore.getProjectInReadAction(containingClass);
                final List<PsiFile> fxmlWithController = JavaFxControllerClassIndex.findFxmlWithController(project, qualifiedName);
                for (final PsiFile file : fxmlWithController) {
                    ApplicationManager.getApplication().runReadAction(() -> {
                        final String fieldName = field.getName();
                        if (fieldName == null)
                            return;
                        final VirtualFile virtualFile = file.getViewProvider().getVirtualFile();
                        final SearchScope searchScope = queryParameters.getEffectiveSearchScope();
                        if (searchScope.contains(virtualFile)) {
                            file.accept(new XmlRecursiveElementVisitor() {

                                @Override
                                public void visitXmlAttributeValue(final XmlAttributeValue value) {
                                    final PsiReference reference = value.getReference();
                                    if (reference != null) {
                                        final PsiElement resolve = reference.resolve();
                                        if (resolve instanceof XmlAttributeValue) {
                                            final PsiElement parent = resolve.getParent();
                                            if (parent instanceof XmlAttribute) {
                                                final XmlAttribute attribute = (XmlAttribute) parent;
                                                if (FxmlConstants.FX_ID.equals(attribute.getName()) && fieldName.equals(attribute.getValue())) {
                                                    consumer.process(reference);
                                                }
                                            }
                                        }
                                    }
                                }
                            });
                        }
                    });
                }
            }
        }
    }
    return true;
}
Also used : VirtualFile(com.intellij.openapi.vfs.VirtualFile) XmlAttribute(com.intellij.psi.xml.XmlAttribute) XmlAttributeValue(com.intellij.psi.xml.XmlAttributeValue) Project(com.intellij.openapi.project.Project) SearchScope(com.intellij.psi.search.SearchScope)

Example 5 with SearchScope

use of com.intellij.psi.search.SearchScope in project intellij-community by JetBrains.

the class DeleteUnusedParameterFix method deleteElement.

protected void deleteElement(@NotNull XsltParameter obj) throws IncorrectOperationException {
    final XsltTemplate template = XsltCodeInsightUtil.getTemplate(obj.getTag(), false);
    if (template == null || template.getMatchExpression() == null) {
        final SearchScope searchScope = obj.getResolveScope();
        for (PsiReference reference : ReferencesSearch.search(obj, searchScope, false)) {
            final XmlTag t = PsiTreeUtil.getContextOfType(reference.getElement(), XmlTag.class, true);
            if (t != null && XsltSupport.XSLT_NS.equals(t.getNamespace())) {
                assert "with-param".equals(t.getLocalName());
                t.delete();
            }
        }
    }
    super.deleteElement(obj);
}
Also used : SearchScope(com.intellij.psi.search.SearchScope) PsiReference(com.intellij.psi.PsiReference) XsltTemplate(org.intellij.lang.xpath.xslt.psi.XsltTemplate) XmlTag(com.intellij.psi.xml.XmlTag)

Aggregations

SearchScope (com.intellij.psi.search.SearchScope)98 GlobalSearchScope (com.intellij.psi.search.GlobalSearchScope)42 LocalSearchScope (com.intellij.psi.search.LocalSearchScope)38 NotNull (org.jetbrains.annotations.NotNull)23 PsiElement (com.intellij.psi.PsiElement)22 Project (com.intellij.openapi.project.Project)21 VirtualFile (com.intellij.openapi.vfs.VirtualFile)18 PsiClass (com.intellij.psi.PsiClass)9 Processor (com.intellij.util.Processor)8 com.intellij.psi (com.intellij.psi)7 PsiMethod (com.intellij.psi.PsiMethod)7 PsiReference (com.intellij.psi.PsiReference)6 HashMap (com.intellij.util.containers.HashMap)6 Nullable (org.jetbrains.annotations.Nullable)6 ClassInheritorsSearch (com.intellij.psi.search.searches.ClassInheritorsSearch)5 AnalysisScope (com.intellij.analysis.AnalysisScope)4 ProgressManager (com.intellij.openapi.progress.ProgressManager)4 TextRange (com.intellij.openapi.util.TextRange)4 PsiFile (com.intellij.psi.PsiFile)4 PsiSearchHelper (com.intellij.psi.search.PsiSearchHelper)4