Search in sources :

Example 46 with JavaPsiFacade

use of com.intellij.psi.JavaPsiFacade in project android by JetBrains.

the class NlProperties method currentActivityIfFoundIsDerivedFromAppCompatActivity.

private static boolean currentActivityIfFoundIsDerivedFromAppCompatActivity(@NotNull List<NlComponent> components) {
    assert !components.isEmpty();
    NlModel model = components.get(0).getModel();
    Configuration configuration = model.getConfiguration();
    String activityClassName = configuration.getActivity();
    if (activityClassName == null) {
        // Assume we are since this is how the default activities are created.
        return true;
    }
    if (activityClassName.startsWith(".")) {
        MergedManifest manifest = MergedManifest.get(model.getModule());
        String pkg = StringUtil.notNullize(manifest.getPackage());
        activityClassName = pkg + activityClassName;
    }
    JavaPsiFacade facade = JavaPsiFacade.getInstance(model.getProject());
    PsiClass activityClass = facade.findClass(activityClassName, model.getModule().getModuleScope());
    while (activityClass != null && !CLASS_APP_COMPAT_ACTIVITY.equals(activityClass.getQualifiedName())) {
        activityClass = activityClass.getSuperClass();
    }
    return activityClass != null;
}
Also used : JavaPsiFacade(com.intellij.psi.JavaPsiFacade) Configuration(com.android.tools.idea.configurations.Configuration) MergedManifest(com.android.tools.idea.model.MergedManifest) PsiClass(com.intellij.psi.PsiClass) NlModel(com.android.tools.idea.uibuilder.model.NlModel)

Example 47 with JavaPsiFacade

use of com.intellij.psi.JavaPsiFacade in project intellij-plugins by JetBrains.

the class StrutsVersionDetector method getStrutsJarRoot.

@Nullable
private static VirtualFile getStrutsJarRoot(final Module module) {
    final GlobalSearchScope scope = GlobalSearchScope.moduleRuntimeScope(module, false);
    final JavaPsiFacade psiManager = JavaPsiFacade.getInstance(module.getProject());
    final VirtualFile virtualFile = getStrutsClass(scope, psiManager);
    if (virtualFile == null || !(virtualFile.getFileSystem() instanceof JarFileSystem)) {
        return null;
    }
    final VirtualFile jarFile = JarFileSystem.getInstance().getLocalVirtualFileFor(virtualFile);
    if (jarFile == null) {
        return null;
    }
    return JarFileSystem.getInstance().getJarRootForLocalFile(jarFile);
}
Also used : JavaPsiFacade(com.intellij.psi.JavaPsiFacade) VirtualFile(com.intellij.openapi.vfs.VirtualFile) GlobalSearchScope(com.intellij.psi.search.GlobalSearchScope) JarFileSystem(com.intellij.openapi.vfs.JarFileSystem) Nullable(org.jetbrains.annotations.Nullable)

Aggregations

JavaPsiFacade (com.intellij.psi.JavaPsiFacade)47 PsiClass (com.intellij.psi.PsiClass)25 GlobalSearchScope (com.intellij.psi.search.GlobalSearchScope)16 Module (com.intellij.openapi.module.Module)12 Project (com.intellij.openapi.project.Project)10 LanguageLevel (com.intellij.pom.java.LanguageLevel)7 Nullable (org.jetbrains.annotations.Nullable)6 PsiElement (com.intellij.psi.PsiElement)5 PsiPackage (com.intellij.psi.PsiPackage)5 NotNull (org.jetbrains.annotations.NotNull)5 VirtualFile (com.intellij.openapi.vfs.VirtualFile)4 File (java.io.File)4 PsiMethod (com.intellij.psi.PsiMethod)3 PsiType (com.intellij.psi.PsiType)3 Configuration (com.android.tools.idea.configurations.Configuration)2 MergedManifest (com.android.tools.idea.model.MergedManifest)2 StringUtil (com.intellij.openapi.util.text.StringUtil)2 PsiComment (com.intellij.psi.PsiComment)2 PsiDirectory (com.intellij.psi.PsiDirectory)2 PsiElementFactory (com.intellij.psi.PsiElementFactory)2