Search in sources :

Example 36 with GlobalSearchScope

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

the class JavaFxPsiUtil method computeInjectedControllerClass.

@Nullable
private static CachedValueProvider.Result<PsiClass> computeInjectedControllerClass(PsiFile containingFile) {
    return ourGuard.doPreventingRecursion(containingFile, true, () -> {
        final Project project = containingFile.getProject();
        final Ref<PsiClass> injectedController = new Ref<>();
        final PsiClass fxmlLoader = JavaPsiFacade.getInstance(project).findClass(JavaFxCommonNames.JAVAFX_FXML_FXMLLOADER, GlobalSearchScope.allScope(project));
        if (fxmlLoader != null) {
            final PsiMethod[] injectControllerMethods = fxmlLoader.findMethodsByName("setController", false);
            if (injectControllerMethods.length == 1) {
                final GlobalSearchScope globalSearchScope = GlobalSearchScope.getScopeRestrictedByFileTypes(containingFile.getResolveScope(), StdFileTypes.JAVA);
                final VirtualFile[] virtualFiles = CacheManager.SERVICE.getInstance(project).getVirtualFilesWithWord(ClassUtil.extractClassName(JavaFxCommonNames.JAVAFX_FXML_FXMLLOADER), UsageSearchContext.IN_CODE, globalSearchScope, true);
                if (virtualFiles.length == 0) {
                    return new CachedValueProvider.Result<>(null, PsiModificationTracker.MODIFICATION_COUNT);
                }
                final GlobalSearchScope filesScope = GlobalSearchScope.filesScope(project, Arrays.asList(virtualFiles));
                final Processor<PsiReference> processor = loaderReference -> findControllerClassInjection(loaderReference, injectedController, injectControllerMethods[0]);
                ReferencesSearch.search(containingFile, filesScope).forEach(reference -> {
                    final PsiElement element = reference.getElement();
                    if (element instanceof PsiLiteralExpression) {
                        final PsiNewExpression expression = PsiTreeUtil.getParentOfType(element, PsiNewExpression.class);
                        if (expression != null) {
                            final PsiType type = expression.getType();
                            if (type != null && type.equalsToText(JavaFxCommonNames.JAVAFX_FXML_FXMLLOADER)) {
                                final PsiElement parent = expression.getParent();
                                if (parent instanceof PsiLocalVariable) {
                                    ReferencesSearch.search(parent).forEach(processor);
                                    final PsiClass controller = injectedController.get();
                                    if (controller != null) {
                                        return false;
                                    }
                                }
                            }
                        }
                    }
                    return true;
                });
            }
        }
        return new CachedValueProvider.Result<>(injectedController.get(), PsiModificationTracker.MODIFICATION_COUNT);
    });
}
Also used : VirtualFile(com.intellij.openapi.vfs.VirtualFile) com.intellij.openapi.util(com.intellij.openapi.util) java.util(java.util) VirtualFile(com.intellij.openapi.vfs.VirtualFile) NonNls(org.jetbrains.annotations.NonNls) THashSet(gnu.trove.THashSet) XMLLanguage(com.intellij.lang.xml.XMLLanguage) JavaGenericsUtil(com.intellij.codeInsight.daemon.impl.analysis.JavaGenericsUtil) THashMap(gnu.trove.THashMap) com.intellij.psi.xml(com.intellij.psi.xml) JavaFxControllerClassIndex(org.jetbrains.plugins.javaFX.indexing.JavaFxControllerClassIndex) Validator(com.intellij.codeInsight.daemon.Validator) CacheManager(com.intellij.psi.impl.cache.CacheManager) JavaFxPropertyTagDescriptor(org.jetbrains.plugins.javaFX.fxml.descriptors.JavaFxPropertyTagDescriptor) BiConsumer(java.util.function.BiConsumer) Project(com.intellij.openapi.project.Project) Logger(com.intellij.openapi.diagnostic.Logger) ReferencesSearch(com.intellij.psi.search.searches.ReferencesSearch) StdFileTypes(com.intellij.openapi.fileTypes.StdFileTypes) StringUtil(com.intellij.openapi.util.text.StringUtil) com.intellij.psi.util(com.intellij.psi.util) GlobalSearchScope(com.intellij.psi.search.GlobalSearchScope) JavaFxClassTagDescriptorBase(org.jetbrains.plugins.javaFX.fxml.descriptors.JavaFxClassTagDescriptorBase) XmlElementDescriptor(com.intellij.xml.XmlElementDescriptor) Collectors(java.util.stream.Collectors) UsageSearchContext(com.intellij.psi.search.UsageSearchContext) Consumer(java.util.function.Consumer) ASTNode(com.intellij.lang.ASTNode) Nullable(org.jetbrains.annotations.Nullable) Contract(org.jetbrains.annotations.Contract) HighlightUtil(com.intellij.codeInsight.daemon.impl.analysis.HighlightUtil) Processor(com.intellij.util.Processor) AnnotationUtil(com.intellij.codeInsight.AnnotationUtil) XmlAttributeDescriptor(com.intellij.xml.XmlAttributeDescriptor) Registry(com.intellij.openapi.util.registry.Registry) com.intellij.psi(com.intellij.psi) ClassInheritorsSearch(com.intellij.psi.search.searches.ClassInheritorsSearch) NotNull(org.jetbrains.annotations.NotNull) PostprocessReformattingAspect(com.intellij.psi.impl.source.PostprocessReformattingAspect) Project(com.intellij.openapi.project.Project) GlobalSearchScope(com.intellij.psi.search.GlobalSearchScope) Nullable(org.jetbrains.annotations.Nullable)

Example 37 with GlobalSearchScope

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

the class PyStubsTest method ensureVariableNotInIndex.

private void ensureVariableNotInIndex(String name) {
    getTestFile();
    GlobalSearchScope scope = GlobalSearchScope.allScope(myFixture.getProject());
    Collection<PyTargetExpression> result = PyVariableNameIndex.find(name, myFixture.getProject(), scope);
    assertEquals(0, result.size());
}
Also used : GlobalSearchScope(com.intellij.psi.search.GlobalSearchScope)

Example 38 with GlobalSearchScope

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

the class PropertiesInheritorsSearcher method processQuery.

@Override
public void processQuery(@NotNull DefinitionsScopedSearch.SearchParameters queryParameters, @NotNull Processor<PsiElement> consumer) {
    final PsiElement element = queryParameters.getElement();
    Property prop = ReadAction.compute(() -> GotoPropertyParentDeclarationHandler.findProperty(element));
    if (prop == null || !(queryParameters.getScope() instanceof GlobalSearchScope)) {
        return;
    }
    ReadAction.run(() -> {
        final String key = prop.getKey();
        if (!prop.isValid() || key == null)
            return;
        final PropertiesFile currentFile = PropertiesImplUtil.getPropertiesFile(prop.getContainingFile());
        LOG.assertTrue(currentFile != null);
        final GlobalSearchScope scope = (GlobalSearchScope) queryParameters.getScope();
        currentFile.getResourceBundle().getPropertiesFiles().stream().filter(f -> f.equals(currentFile)).filter(f -> scope.contains(f.getVirtualFile())).filter(f -> PropertiesUtil.getParent(f, Collections.singleton(currentFile)) == currentFile).map(f -> f.findPropertyByKey(key)).filter(Objects::nonNull).map(IProperty::getPsiElement).anyMatch(psiElement -> {
            ProgressManager.checkCanceled();
            return !consumer.process(psiElement);
        });
    });
}
Also used : ProgressManager(com.intellij.openapi.progress.ProgressManager) Property(com.intellij.lang.properties.psi.Property) PropertiesFile(com.intellij.lang.properties.psi.PropertiesFile) GlobalSearchScope(com.intellij.psi.search.GlobalSearchScope) DefinitionsScopedSearch(com.intellij.psi.search.searches.DefinitionsScopedSearch) ReadAction(com.intellij.openapi.application.ReadAction) QueryExecutorBase(com.intellij.openapi.application.QueryExecutorBase) Objects(java.util.Objects) IProperty(com.intellij.lang.properties.IProperty) PropertiesImplUtil(com.intellij.lang.properties.PropertiesImplUtil) Processor(com.intellij.util.Processor) PsiElement(com.intellij.psi.PsiElement) PropertiesUtil(com.intellij.lang.properties.PropertiesUtil) Logger(com.intellij.openapi.diagnostic.Logger) NotNull(org.jetbrains.annotations.NotNull) Collections(java.util.Collections) GlobalSearchScope(com.intellij.psi.search.GlobalSearchScope) Objects(java.util.Objects) PropertiesFile(com.intellij.lang.properties.psi.PropertiesFile) Property(com.intellij.lang.properties.psi.Property) IProperty(com.intellij.lang.properties.IProperty) PsiElement(com.intellij.psi.PsiElement)

Example 39 with GlobalSearchScope

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

the class PyClassNameCompletionContributor method addVariantsFromIndex.

private static <T extends PsiNamedElement> void addVariantsFromIndex(final CompletionResultSet resultSet, final PsiFile targetFile, final StubIndexKey<String, T> key, final InsertHandler<LookupElement> insertHandler, final Condition<? super T> condition, Class<T> elementClass) {
    final Project project = targetFile.getProject();
    GlobalSearchScope scope = PyProjectScopeBuilder.excludeSdkTestsScope(targetFile);
    Collection<String> keys = StubIndex.getInstance().getAllKeys(key, project);
    for (final String elementName : CompletionUtil.sortMatching(resultSet.getPrefixMatcher(), keys)) {
        for (T element : StubIndex.getElements(key, elementName, project, scope, elementClass)) {
            if (condition.value(element)) {
                final String name = element.getName();
                if (name != null) {
                    resultSet.addElement(LookupElementBuilder.createWithSmartPointer(name, element).withIcon(element.getIcon(0)).withTailText(" " + ((NavigationItem) element).getPresentation().getLocationString(), true).withInsertHandler(insertHandler));
                }
            }
        }
    }
}
Also used : Project(com.intellij.openapi.project.Project) GlobalSearchScope(com.intellij.psi.search.GlobalSearchScope)

Example 40 with GlobalSearchScope

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

the class Html5CustomAttributeDescriptorsProvider method getAttributeDescriptors.

@Override
public XmlAttributeDescriptor[] getAttributeDescriptors(XmlTag tag) {
    if (tag == null || !HtmlUtil.isHtml5Context(tag)) {
        return XmlAttributeDescriptor.EMPTY;
    }
    final List<String> currentAttrs = new ArrayList<>();
    for (XmlAttribute attribute : tag.getAttributes()) {
        currentAttrs.add(attribute.getName());
    }
    final Project project = tag.getProject();
    final Collection<String> keys = CachedValuesManager.getManager(project).getCachedValue(project, () -> {
        final Collection<String> keys1 = FileBasedIndex.getInstance().getAllKeys(Html5CustomAttributesIndex.INDEX_ID, project);
        final GlobalSearchScope scope = GlobalSearchScope.allScope(project);
        return CachedValueProvider.Result.<Collection<String>>create(ContainerUtil.filter(keys1, key -> !FileBasedIndex.getInstance().processValues(Html5CustomAttributesIndex.INDEX_ID, key, null, (file, value) -> false, scope)), PsiModificationTracker.MODIFICATION_COUNT);
    });
    if (keys.isEmpty())
        return XmlAttributeDescriptor.EMPTY;
    final List<XmlAttributeDescriptor> result = new ArrayList<>();
    for (String key : keys) {
        boolean add = true;
        for (String attr : currentAttrs) {
            if (attr.startsWith(key)) {
                add = false;
            }
        }
        if (add) {
            result.add(new AnyXmlAttributeDescriptor(key));
        }
    }
    return result.toArray(new XmlAttributeDescriptor[result.size()]);
}
Also used : HtmlUtil(com.intellij.xml.util.HtmlUtil) Html5CustomAttributesIndex(com.intellij.html.index.Html5CustomAttributesIndex) XmlAttribute(com.intellij.psi.xml.XmlAttribute) Collection(java.util.Collection) GlobalSearchScope(com.intellij.psi.search.GlobalSearchScope) XmlAttributeDescriptorsProvider(com.intellij.xml.XmlAttributeDescriptorsProvider) ContainerUtil(com.intellij.util.containers.ContainerUtil) CachedValuesManager(com.intellij.psi.util.CachedValuesManager) ArrayList(java.util.ArrayList) CachedValueProvider(com.intellij.psi.util.CachedValueProvider) PsiModificationTracker(com.intellij.psi.util.PsiModificationTracker) List(java.util.List) Project(com.intellij.openapi.project.Project) XmlAttributeDescriptor(com.intellij.xml.XmlAttributeDescriptor) AnyXmlAttributeDescriptor(com.intellij.xml.impl.schema.AnyXmlAttributeDescriptor) FileBasedIndex(com.intellij.util.indexing.FileBasedIndex) XmlTag(com.intellij.psi.xml.XmlTag) AnyXmlAttributeDescriptor(com.intellij.xml.impl.schema.AnyXmlAttributeDescriptor) XmlAttribute(com.intellij.psi.xml.XmlAttribute) ArrayList(java.util.ArrayList) Project(com.intellij.openapi.project.Project) GlobalSearchScope(com.intellij.psi.search.GlobalSearchScope) XmlAttributeDescriptor(com.intellij.xml.XmlAttributeDescriptor) AnyXmlAttributeDescriptor(com.intellij.xml.impl.schema.AnyXmlAttributeDescriptor) Collection(java.util.Collection)

Aggregations

GlobalSearchScope (com.intellij.psi.search.GlobalSearchScope)485 Project (com.intellij.openapi.project.Project)145 NotNull (org.jetbrains.annotations.NotNull)134 VirtualFile (com.intellij.openapi.vfs.VirtualFile)106 Module (com.intellij.openapi.module.Module)101 Nullable (org.jetbrains.annotations.Nullable)78 PsiClass (com.intellij.psi.PsiClass)53 ArrayList (java.util.ArrayList)37 PsiFile (com.intellij.psi.PsiFile)32 PsiElement (com.intellij.psi.PsiElement)31 THashSet (gnu.trove.THashSet)22 SearchScope (com.intellij.psi.search.SearchScope)19 PsiDirectory (com.intellij.psi.PsiDirectory)18 ContainerUtil (com.intellij.util.containers.ContainerUtil)18 JSClass (com.intellij.lang.javascript.psi.ecmal4.JSClass)17 ProjectFileIndex (com.intellij.openapi.roots.ProjectFileIndex)17 com.intellij.psi (com.intellij.psi)17 List (java.util.List)17 StringUtil (com.intellij.openapi.util.text.StringUtil)15 JavaPsiFacade (com.intellij.psi.JavaPsiFacade)15