Search in sources :

Example 51 with JavaPsiFacade

use of com.intellij.psi.JavaPsiFacade 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)

Example 52 with JavaPsiFacade

use of com.intellij.psi.JavaPsiFacade in project AndroidPermissionsUsage by RomainPiel.

the class FindPermissionsUsageAction method actionPerformed.

@Override
public void actionPerformed(AnActionEvent event) {
    final VirtualFile file = event.getData(PlatformDataKeys.VIRTUAL_FILE);
    if (file == null) {
        return;
    }
    final Project project = event.getProject();
    if (project == null) {
        return;
    }
    final Module module = ModuleUtil.findModuleForFile(file, project);
    JavaPsiFacade psi = JavaPsiFacade.getInstance(project);
    final PsiClass manifestClass = psi.findClass("android.Manifest.permission", AndroidSDKScope.getScope(module));
    ProgressManager.getInstance().run(new FindPermissionUsagesTask(file, module, manifestClass));
}
Also used : VirtualFile(com.intellij.openapi.vfs.VirtualFile) JavaPsiFacade(com.intellij.psi.JavaPsiFacade) Project(com.intellij.openapi.project.Project) PsiClass(com.intellij.psi.PsiClass) Module(com.intellij.openapi.module.Module)

Aggregations

JavaPsiFacade (com.intellij.psi.JavaPsiFacade)52 PsiClass (com.intellij.psi.PsiClass)30 GlobalSearchScope (com.intellij.psi.search.GlobalSearchScope)20 Module (com.intellij.openapi.module.Module)15 Project (com.intellij.openapi.project.Project)12 PsiPackage (com.intellij.psi.PsiPackage)8 LanguageLevel (com.intellij.pom.java.LanguageLevel)7 PsiElement (com.intellij.psi.PsiElement)7 Nullable (org.jetbrains.annotations.Nullable)6 NotNull (org.jetbrains.annotations.NotNull)5 VirtualFile (com.intellij.openapi.vfs.VirtualFile)4 PsiMethod (com.intellij.psi.PsiMethod)4 PsiType (com.intellij.psi.PsiType)4 File (java.io.File)3 List (java.util.List)3 Configuration (com.android.tools.idea.configurations.Configuration)2 MergedManifest (com.android.tools.idea.model.MergedManifest)2 CompletionParameters (com.intellij.codeInsight.completion.CompletionParameters)2 LookupElement (com.intellij.codeInsight.lookup.LookupElement)2 ClassFilter (com.intellij.ide.util.ClassFilter)2