Search in sources :

Example 31 with GlobalSearchScope

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

the class GroovyGoToSymbolContributor method getItemsByName.

@Override
@NotNull
public NavigationItem[] getItemsByName(String name, String pattern, Project project, boolean includeNonProjectItems) {
    GlobalSearchScope scope = includeNonProjectItems ? GlobalSearchScope.allScope(project) : GlobalSearchScope.projectScope(project);
    List<NavigationItem> symbols = new ArrayList<>();
    symbols.addAll(StubIndex.getElements(GrFieldNameIndex.KEY, name, project, scope, GrField.class));
    symbols.addAll(StubIndex.getElements(GrMethodNameIndex.KEY, name, project, scope, GrMethod.class));
    symbols.addAll(StubIndex.getElements(GrAnnotationMethodNameIndex.KEY, name, project, scope, GrAnnotationMethod.class));
    return symbols.toArray(new NavigationItem[symbols.size()]);
}
Also used : GrField(org.jetbrains.plugins.groovy.lang.psi.api.statements.GrField) NavigationItem(com.intellij.navigation.NavigationItem) GlobalSearchScope(com.intellij.psi.search.GlobalSearchScope) ArrayList(java.util.ArrayList) GrMethod(org.jetbrains.plugins.groovy.lang.psi.api.statements.typedef.members.GrMethod) GrAnnotationMethod(org.jetbrains.plugins.groovy.lang.psi.api.statements.typedef.members.GrAnnotationMethod) NotNull(org.jetbrains.annotations.NotNull)

Example 32 with GlobalSearchScope

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

the class SceneBuilderImpl method prepareCustomComponents.

@NotNull
private Collection<CustomComponent> prepareCustomComponents(Collection<PsiClass> psiClasses) {
    final JavaPsiFacade psiFacade = JavaPsiFacade.getInstance(myProject);
    final GlobalSearchScope scope = GlobalSearchScope.allScope(myProject);
    final Map<String, BuiltinComponent> builtinComponents = loadBuiltinComponents(className -> psiFacade.findClass(className, scope) != null);
    final List<CustomComponent> customComponents = new ArrayList<>();
    for (PsiClass psiClass : psiClasses) {
        final String qualifiedName = psiClass.getQualifiedName();
        final String name = psiClass.getName();
        if (qualifiedName != null && name != null) {
            BuiltinComponent parentComponent = null;
            for (PsiClass aClass = psiClass; aClass != null; aClass = aClass.getSuperClass()) {
                final BuiltinComponent component = builtinComponents.get(aClass.getQualifiedName());
                if (component != null) {
                    parentComponent = component;
                    break;
                }
            }
            final String moduleName = getComponentModuleName(psiClass);
            final Map<String, String> attributes = parentComponent != null ? parentComponent.getAttributes() : Collections.emptyMap();
            customComponents.add(new CustomComponent(name, qualifiedName, moduleName, attributes));
        }
    }
    return customComponents;
}
Also used : JavaPsiFacade(com.intellij.psi.JavaPsiFacade) GlobalSearchScope(com.intellij.psi.search.GlobalSearchScope) PsiClass(com.intellij.psi.PsiClass) NotNull(org.jetbrains.annotations.NotNull)

Example 33 with GlobalSearchScope

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

the class SceneBuilderImpl method collectCustomComponents.

private Collection<CustomComponent> collectCustomComponents() {
    if (myProject.isDisposed()) {
        return Collections.emptyList();
    }
    final PsiClass nodeClass = JavaPsiFacade.getInstance(myProject).findClass(JavaFxCommonNames.JAVAFX_SCENE_NODE, GlobalSearchScope.allScope(myProject));
    if (nodeClass == null) {
        return Collections.emptyList();
    }
    final Collection<PsiClass> psiClasses = CachedValuesManager.getCachedValue(nodeClass, () -> {
        // Take custom components from libraries, but not from the project modules, because SceneBuilder instantiates the components' classes.
        // Modules might be not compiled or may change since last compile, it's too expensive to keep track of that.
        final GlobalSearchScope scope = ProjectScope.getLibrariesScope(nodeClass.getProject());
        final String ideJdkVersion = Object.class.getPackage().getSpecificationVersion();
        final LanguageLevel ideLanguageLevel = LanguageLevel.parse(ideJdkVersion);
        final Query<PsiClass> query = ClassInheritorsSearch.search(nodeClass, scope, true, true, false);
        final Set<PsiClass> result = new THashSet<>();
        query.forEach(psiClass -> {
            if (psiClass.hasModifierProperty(PsiModifier.PUBLIC) && !psiClass.hasModifierProperty(PsiModifier.ABSTRACT) && !isBuiltInComponent(psiClass) && isCompatibleLanguageLevel(psiClass, ideLanguageLevel)) {
                result.add(psiClass);
            }
        });
        return CachedValueProvider.Result.create(result, PsiModificationTracker.JAVA_STRUCTURE_MODIFICATION_COUNT);
    });
    if (psiClasses.isEmpty()) {
        return Collections.emptyList();
    }
    return prepareCustomComponents(psiClasses);
}
Also used : GlobalSearchScope(com.intellij.psi.search.GlobalSearchScope) LanguageLevel(com.intellij.pom.java.LanguageLevel) PsiClass(com.intellij.psi.PsiClass) THashSet(gnu.trove.THashSet)

Example 34 with GlobalSearchScope

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

the class JavaFxImplicitUsageProvider method isImplicitMethodUsage.

private static boolean isImplicitMethodUsage(@NotNull PsiMethod method) {
    if (!isImplicitFxmlAccess(method))
        return false;
    if (isInvokedByFxmlLoader(method)) {
        return true;
    }
    final GlobalSearchScope projectScope = GlobalSearchScope.projectScope(method.getProject());
    final GlobalSearchScope fxmlScope = new JavaFxScopeEnlarger.GlobalFxmlSearchScope(projectScope);
    return isFxmlUsage(method, fxmlScope);
}
Also used : GlobalSearchScope(com.intellij.psi.search.GlobalSearchScope)

Example 35 with GlobalSearchScope

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

the class JavaFxPsiUtil method isControllerClass.

public static boolean isControllerClass(@NotNull PsiClass psiClass) {
    final Project project = psiClass.getProject();
    final GlobalSearchScope resolveScope = psiClass.getResolveScope();
    if (isControllerClassName(project, psiClass.getQualifiedName(), resolveScope)) {
        return true;
    }
    final Ref<Boolean> refFound = new Ref<>(false);
    ClassInheritorsSearch.search(psiClass, resolveScope, true, true, false).forEach((aClass) -> {
        if (isControllerClassName(project, aClass.getQualifiedName(), resolveScope)) {
            refFound.set(true);
            return false;
        }
        return true;
    });
    return refFound.get();
}
Also used : Project(com.intellij.openapi.project.Project) GlobalSearchScope(com.intellij.psi.search.GlobalSearchScope)

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