Search in sources :

Example 1 with JSContextLevel

use of com.intellij.lang.javascript.psi.resolve.JSContextLevel in project oxy-template-support-plugin by mutant-industries.

the class InnerJsReferenceExpressionResolver method getResultsFromProcessor.

/**
 *  !!    TEMP CODE -  https://youtrack.jetbrains.com/issue/IDEA-138078    !!
 *
 * duplicated code to {@link NashornJSReferenceExpressionResolver#getResultsFromProcessor(WalkUpResolveProcessor)}
 *  - {@link super#resolveInPsiClass(PsiClass, boolean)} will one day (hopefully) be protected
 */
// --------------------------------------------------------------------------------------------------------------
// --------------------------------------------------------------------------------------------------------------
protected ResolveResult[] getResultsFromProcessor(WalkUpResolveProcessor processor) {
    List<JSTaggedResolveResult> taggedResolveResults = processor.getTaggedResolveResults();
    if (taggedResolveResults.isEmpty() || (taggedResolveResults.get(0)).hasTag(JSTaggedResolveResult.ResolveResultTag.PARTIAL)) {
        Module module;
        if (JSSymbolUtil.isAccurateReferenceExpression(this.myRef)) {
            if (this.myQualifier instanceof JSReferenceExpression) {
                PsiElement qualifierResolve = ((JSReferenceExpression) this.myQualifier).resolve();
                if (qualifierResolve instanceof PsiClass) {
                    List<ResolveResult> results = this.resolveInPsiClass((PsiClass) qualifierResolve, true);
                    return results.isEmpty() ? ResolveResult.EMPTY_ARRAY : results.toArray(new ResolveResult[results.size()]);
                }
            }
            JavaPsiFacade psiFacade = JavaPsiFacade.getInstance(this.myContainingFile.getProject());
            module = ModuleUtilCore.findModuleForPsiElement(this.myContainingFile);
            JSQualifiedName qualifiedName = JSSymbolUtil.getAccurateReferenceName(this.myRef);
            if (qualifiedName != null) {
                qualifiedName = ((JSQualifiedNameImpl) qualifiedName).withoutInnermostComponent("Packages");
            }
            if (qualifiedName != null) {
                String qName = qualifiedName.getQualifiedName();
                if (module != null) {
                    PsiClass aClass = psiFacade.findClass(qName, GlobalSearchScope.moduleWithDependenciesAndLibrariesScope(module));
                    if (aClass != null) {
                        return new ResolveResult[] { new JSResolveResult(aClass) };
                    }
                }
                PsiPackage aPackage = psiFacade.findPackage(qName);
                if (aPackage != null) {
                    return new ResolveResult[] { new JSResolveResult(aPackage) };
                }
            }
        }
        JSTypeInfo typeInfo = processor.getTypeInfo();
        if (!typeInfo.myContextLevels.isEmpty() && (module = ModuleUtilCore.findModuleForPsiElement(this.myContainingFile)) != null) {
            JavaPsiFacade psiFacade = JavaPsiFacade.getInstance(this.myContainingFile.getProject());
            GlobalSearchScope scope = GlobalSearchScope.moduleWithDependenciesAndLibrariesScope(module);
            List<ResolveResult> javaResults = new SmartList();
            boolean contextResolvesToJavaClass = false;
            Iterator var9 = typeInfo.myContextLevels.iterator();
            while (var9.hasNext()) {
                JSContextLevel level = (JSContextLevel) var9.next();
                JSQualifiedName qualifiedName = level.myNamespace.getQualifiedName();
                if (level.myRelativeLevel == 0 && qualifiedName != null) {
                    PsiClass aClass = psiFacade.findClass(qualifiedName.getQualifiedName(), scope);
                    if (aClass != null) {
                        contextResolvesToJavaClass = true;
                        List<ResolveResult> results = this.resolveInPsiClass(aClass, level.myNamespace.getJSContext() == JSContext.STATIC);
                        javaResults.addAll(results);
                    }
                }
            }
            if (contextResolvesToJavaClass) {
                return javaResults.toArray(ResolveResult.EMPTY_ARRAY);
            }
        }
    }
    return processor.getResults();
}
Also used : JavaPsiFacade(com.intellij.psi.JavaPsiFacade) JSTypeInfo(com.intellij.lang.javascript.psi.resolve.JSTypeInfo) PsiClass(com.intellij.psi.PsiClass) JSResolveResult(com.intellij.lang.javascript.psi.resolve.JSResolveResult) PsiPackage(com.intellij.psi.PsiPackage) JSQualifiedName(com.intellij.lang.javascript.psi.JSQualifiedName) JSReferenceExpression(com.intellij.lang.javascript.psi.JSReferenceExpression) GlobalSearchScope(com.intellij.psi.search.GlobalSearchScope) Iterator(java.util.Iterator) JSTaggedResolveResult(com.intellij.lang.javascript.psi.resolve.JSTaggedResolveResult) Module(com.intellij.openapi.module.Module) SmartList(com.intellij.util.SmartList) JSTaggedResolveResult(com.intellij.lang.javascript.psi.resolve.JSTaggedResolveResult) JSResolveResult(com.intellij.lang.javascript.psi.resolve.JSResolveResult) ResolveResult(com.intellij.psi.ResolveResult) JSContextLevel(com.intellij.lang.javascript.psi.resolve.JSContextLevel) PsiElement(com.intellij.psi.PsiElement)

Aggregations

JSQualifiedName (com.intellij.lang.javascript.psi.JSQualifiedName)1 JSReferenceExpression (com.intellij.lang.javascript.psi.JSReferenceExpression)1 JSContextLevel (com.intellij.lang.javascript.psi.resolve.JSContextLevel)1 JSResolveResult (com.intellij.lang.javascript.psi.resolve.JSResolveResult)1 JSTaggedResolveResult (com.intellij.lang.javascript.psi.resolve.JSTaggedResolveResult)1 JSTypeInfo (com.intellij.lang.javascript.psi.resolve.JSTypeInfo)1 Module (com.intellij.openapi.module.Module)1 JavaPsiFacade (com.intellij.psi.JavaPsiFacade)1 PsiClass (com.intellij.psi.PsiClass)1 PsiElement (com.intellij.psi.PsiElement)1 PsiPackage (com.intellij.psi.PsiPackage)1 ResolveResult (com.intellij.psi.ResolveResult)1 GlobalSearchScope (com.intellij.psi.search.GlobalSearchScope)1 SmartList (com.intellij.util.SmartList)1 Iterator (java.util.Iterator)1