Search in sources :

Example 1 with GroovyShortNamesCache

use of org.jetbrains.plugins.groovy.lang.stubs.GroovyShortNamesCache in project intellij-community by JetBrains.

the class GroovyPositionManager method getPsiFileByLocation.

@Nullable
private PsiFile getPsiFileByLocation(@NotNull final Project project, @Nullable final Location location) {
    if (location == null)
        return null;
    final ReferenceType refType = location.declaringType();
    if (refType == null)
        return null;
    final String originalQName = refType.name().replace('/', '.');
    int dollar = originalQName.indexOf('$');
    String runtimeName = dollar >= 0 ? originalQName.substring(0, dollar) : originalQName;
    String qName = getOriginalQualifiedName(refType, runtimeName);
    GlobalSearchScope searchScope = myDebugProcess.getSearchScope();
    GroovyShortNamesCache cache = GroovyShortNamesCache.getGroovyShortNamesCache(project);
    try {
        List<PsiClass> classes = cache.getClassesByFQName(qName, searchScope, true);
        if (classes.isEmpty()) {
            classes = cache.getClassesByFQName(qName, searchScope, false);
        }
        if (classes.isEmpty()) {
            classes = cache.getClassesByFQName(qName, GlobalSearchScope.projectScope(project), false);
        }
        if (classes.isEmpty()) {
            classes = cache.getClassesByFQName(qName, addModuleContent(searchScope), false);
        }
        if (classes.isEmpty())
            return null;
        classes.sort(PsiClassUtil.createScopeComparator(searchScope));
        PsiClass clazz = classes.get(0);
        if (clazz != null)
            return clazz.getContainingFile();
    } catch (ProcessCanceledException | IndexNotReadyException e) {
        return null;
    }
    return getExtraScriptIfNotFound(project, refType, runtimeName, searchScope);
}
Also used : GlobalSearchScope(com.intellij.psi.search.GlobalSearchScope) PsiClass(com.intellij.psi.PsiClass) IndexNotReadyException(com.intellij.openapi.project.IndexNotReadyException) ReferenceType(com.sun.jdi.ReferenceType) GroovyShortNamesCache(org.jetbrains.plugins.groovy.lang.stubs.GroovyShortNamesCache) ProcessCanceledException(com.intellij.openapi.progress.ProcessCanceledException) Nullable(org.jetbrains.annotations.Nullable)

Aggregations

ProcessCanceledException (com.intellij.openapi.progress.ProcessCanceledException)1 IndexNotReadyException (com.intellij.openapi.project.IndexNotReadyException)1 PsiClass (com.intellij.psi.PsiClass)1 GlobalSearchScope (com.intellij.psi.search.GlobalSearchScope)1 ReferenceType (com.sun.jdi.ReferenceType)1 Nullable (org.jetbrains.annotations.Nullable)1 GroovyShortNamesCache (org.jetbrains.plugins.groovy.lang.stubs.GroovyShortNamesCache)1