Search in sources :

Example 1 with GrSourceFilterScope

use of org.jetbrains.plugins.groovy.lang.psi.impl.search.GrSourceFilterScope in project intellij-community by JetBrains.

the class MethodLateBoundReferencesSearcher method getUseScope.

private static SearchScope getUseScope(final PsiMethod method) {
    final SearchScope scope = method.getUseScope();
    final PsiFile file = method.getContainingFile();
    if (file != null && scope instanceof GlobalSearchScope) {
        final VirtualFile vfile = file.getOriginalFile().getVirtualFile();
        final Project project = method.getProject();
        if (vfile != null && ProjectRootManager.getInstance(project).getFileIndex().isInSource(vfile)) {
            return new GrSourceFilterScope((GlobalSearchScope) scope);
        }
    }
    return scope;
}
Also used : VirtualFile(com.intellij.openapi.vfs.VirtualFile) Project(com.intellij.openapi.project.Project) GrSourceFilterScope(org.jetbrains.plugins.groovy.lang.psi.impl.search.GrSourceFilterScope) PsiFile(com.intellij.psi.PsiFile)

Example 2 with GrSourceFilterScope

use of org.jetbrains.plugins.groovy.lang.psi.impl.search.GrSourceFilterScope in project intellij-community by JetBrains.

the class GroovyShortNamesCache method getScriptClassesByFQName.

public List<PsiClass> getScriptClassesByFQName(final String name, final GlobalSearchScope scope, final boolean srcOnly) {
    GlobalSearchScope actualScope = srcOnly ? new GrSourceFilterScope(scope) : scope;
    final Collection<GroovyFile> files = StubIndex.getElements(GrFullScriptNameIndex.KEY, name.hashCode(), myProject, actualScope, GroovyFile.class);
    if (files.isEmpty()) {
        return Collections.emptyList();
    }
    final ArrayList<PsiClass> result = new ArrayList<>();
    for (GroovyFile file : files) {
        if (file.isScript()) {
            final PsiClass scriptClass = file.getScriptClass();
            if (scriptClass != null && name.equals(scriptClass.getQualifiedName())) {
                result.add(scriptClass);
            }
        }
    }
    return result;
}
Also used : GrSourceFilterScope(org.jetbrains.plugins.groovy.lang.psi.impl.search.GrSourceFilterScope) GlobalSearchScope(com.intellij.psi.search.GlobalSearchScope) ArrayList(java.util.ArrayList) PsiClass(com.intellij.psi.PsiClass) GroovyFile(org.jetbrains.plugins.groovy.lang.psi.GroovyFile)

Example 3 with GrSourceFilterScope

use of org.jetbrains.plugins.groovy.lang.psi.impl.search.GrSourceFilterScope in project intellij-community by JetBrains.

the class GroovyShortNamesCache method getClassesByFQName.

@NotNull
public List<PsiClass> getClassesByFQName(String name, GlobalSearchScope scope, boolean inSource) {
    final List<PsiClass> result = ContainerUtil.newArrayList();
    for (PsiElement psiClass : StubIndex.getElements(GrFullClassNameIndex.KEY, name.hashCode(), myProject, inSource ? new GrSourceFilterScope(scope) : scope, PsiClass.class)) {
        //hashcode doesn't guarantee equals
        if (name.equals(((PsiClass) psiClass).getQualifiedName())) {
            result.add((PsiClass) psiClass);
        }
    }
    result.addAll(getScriptClassesByFQName(name, scope, inSource));
    return result;
}
Also used : GrSourceFilterScope(org.jetbrains.plugins.groovy.lang.psi.impl.search.GrSourceFilterScope) PsiClass(com.intellij.psi.PsiClass) PsiElement(com.intellij.psi.PsiElement) NotNull(org.jetbrains.annotations.NotNull)

Example 4 with GrSourceFilterScope

use of org.jetbrains.plugins.groovy.lang.psi.impl.search.GrSourceFilterScope in project intellij-community by JetBrains.

the class GroovyShortNamesCache method getMethodsByName.

@Override
@NotNull
public PsiMethod[] getMethodsByName(@NonNls @NotNull String name, @NotNull GlobalSearchScope scope) {
    final Collection<? extends PsiMethod> methods = StubIndex.getElements(GrMethodNameIndex.KEY, name, myProject, new GrSourceFilterScope(scope), GrMethod.class);
    final Collection<? extends PsiMethod> annMethods = StubIndex.getElements(GrAnnotationMethodNameIndex.KEY, name, myProject, new GrSourceFilterScope(scope), GrAnnotationMethod.class);
    if (methods.isEmpty() && annMethods.isEmpty())
        return PsiMethod.EMPTY_ARRAY;
    return ArrayUtil.mergeCollections(annMethods, methods, PsiMethod.ARRAY_FACTORY);
}
Also used : GrSourceFilterScope(org.jetbrains.plugins.groovy.lang.psi.impl.search.GrSourceFilterScope) NotNull(org.jetbrains.annotations.NotNull)

Aggregations

GrSourceFilterScope (org.jetbrains.plugins.groovy.lang.psi.impl.search.GrSourceFilterScope)4 PsiClass (com.intellij.psi.PsiClass)2 NotNull (org.jetbrains.annotations.NotNull)2 Project (com.intellij.openapi.project.Project)1 VirtualFile (com.intellij.openapi.vfs.VirtualFile)1 PsiElement (com.intellij.psi.PsiElement)1 PsiFile (com.intellij.psi.PsiFile)1 GlobalSearchScope (com.intellij.psi.search.GlobalSearchScope)1 ArrayList (java.util.ArrayList)1 GroovyFile (org.jetbrains.plugins.groovy.lang.psi.GroovyFile)1