Search in sources :

Example 36 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 37 with JavaPsiFacade

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

the class DescriptionCheckerUtil method getDescriptionsDirs.

public static PsiDirectory[] getDescriptionsDirs(Module module, DescriptionType descriptionType) {
    final JavaPsiFacade javaPsiFacade = JavaPsiFacade.getInstance(module.getProject());
    final PsiPackage psiPackage = javaPsiFacade.findPackage(descriptionType.getDescriptionFolder());
    if (psiPackage != null) {
        return psiPackage.getDirectories(GlobalSearchScope.moduleWithDependenciesScope(module));
    }
    return PsiDirectory.EMPTY_ARRAY;
}
Also used : JavaPsiFacade(com.intellij.psi.JavaPsiFacade) PsiPackage(com.intellij.psi.PsiPackage)

Example 38 with JavaPsiFacade

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

the class FindClassUtil method findModulesWithClass.

/**
   * Searches the project for modules that contain the class with the specified full-qualified name within
   * the module dependencies or libraries.
   *
   * @param qualifiedName the full-qualified name of the class to find.
   * @return the modules that contain the given class in dependencies or libraries.
   */
@NotNull
public static Collection<Module> findModulesWithClass(@NotNull Project project, @NonNls @NotNull String qualifiedName) {
    GlobalSearchScope allScope = GlobalSearchScope.allScope(project);
    JavaPsiFacade facade = JavaPsiFacade.getInstance(project);
    PsiClass[] possibleClasses = facade.findClasses(qualifiedName, allScope);
    if (possibleClasses.length == 0) {
        return Collections.emptyList();
    }
    Set<Module> relevantModules = ContainerUtil.newLinkedHashSet();
    ProjectFileIndex fileIndex = ProjectRootManager.getInstance(project).getFileIndex();
    for (PsiClass aClass : possibleClasses) {
        VirtualFile classFile = aClass.getContainingFile().getVirtualFile();
        for (OrderEntry orderEntry : fileIndex.getOrderEntriesForFile(classFile)) {
            relevantModules.add(orderEntry.getOwnerModule());
        }
    }
    return relevantModules;
}
Also used : JavaPsiFacade(com.intellij.psi.JavaPsiFacade) VirtualFile(com.intellij.openapi.vfs.VirtualFile) OrderEntry(com.intellij.openapi.roots.OrderEntry) GlobalSearchScope(com.intellij.psi.search.GlobalSearchScope) ProjectFileIndex(com.intellij.openapi.roots.ProjectFileIndex) PsiClass(com.intellij.psi.PsiClass) Module(com.intellij.openapi.module.Module) NotNull(org.jetbrains.annotations.NotNull)

Example 39 with JavaPsiFacade

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

the class JavaFormatterTest method testAssertStatementWrapping2.

public void testAssertStatementWrapping2() throws Exception {
    getSettings().BINARY_OPERATION_WRAP = CommonCodeStyleSettings.DO_NOT_WRAP;
    getSettings().ASSERT_STATEMENT_WRAP = CommonCodeStyleSettings.WRAP_AS_NEEDED;
    getSettings().RIGHT_MARGIN = 37;
    final CommonCodeStyleSettings.IndentOptions options = getSettings().getRootSettings().getIndentOptions(StdFileTypes.JAVA);
    options.INDENT_SIZE = 2;
    options.CONTINUATION_INDENT_SIZE = 2;
    getSettings().ASSERT_STATEMENT_COLON_ON_NEXT_LINE = true;
    final JavaPsiFacade facade = getJavaFacade();
    final LanguageLevel effectiveLanguageLevel = LanguageLevelProjectExtension.getInstance(facade.getProject()).getLanguageLevel();
    LanguageLevelProjectExtension.getInstance(facade.getProject()).setLanguageLevel(LanguageLevel.JDK_1_5);
    try {
        doTextTest("class Foo {\n" + "    void foo() {\n" + "        assert i + j + k + l + n + m <= 2 : \"assert description\";" + "    }\n" + "}", "class Foo {\n" + "  void foo() {\n" + "    assert i + j + k + l + n + m <= 2\n" + "      : \"assert description\";\n" + "  }\n" + "}");
        getSettings().ASSERT_STATEMENT_COLON_ON_NEXT_LINE = false;
        doTextTest("class Foo {\n" + "    void foo() {\n" + "        assert i + j + k + l + n + m <= 2 : \"assert description\";" + "    }\n" + "}", "class Foo {\n" + "  void foo() {\n" + "    assert\n" + "      i + j + k + l + n + m <= 2 :\n" + "      \"assert description\";\n" + "  }\n" + "}");
    } finally {
        LanguageLevelProjectExtension.getInstance(facade.getProject()).setLanguageLevel(effectiveLanguageLevel);
    }
}
Also used : JavaPsiFacade(com.intellij.psi.JavaPsiFacade) LanguageLevel(com.intellij.pom.java.LanguageLevel) CommonCodeStyleSettings(com.intellij.psi.codeStyle.CommonCodeStyleSettings)

Example 40 with JavaPsiFacade

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

the class JavaFormatterTest method testAssertStatementWrapping.

public void testAssertStatementWrapping() throws Exception {
    getSettings().ASSERT_STATEMENT_WRAP = CommonCodeStyleSettings.WRAP_AS_NEEDED;
    getSettings().BINARY_OPERATION_WRAP = CommonCodeStyleSettings.DO_NOT_WRAP;
    getSettings().RIGHT_MARGIN = 40;
    final JavaPsiFacade facade = getJavaFacade();
    final LanguageLevel effectiveLanguageLevel = LanguageLevelProjectExtension.getInstance(facade.getProject()).getLanguageLevel();
    try {
        LanguageLevelProjectExtension.getInstance(facade.getProject()).setLanguageLevel(LanguageLevel.JDK_1_5);
        getSettings().ASSERT_STATEMENT_COLON_ON_NEXT_LINE = false;
        doTextTest("class Foo {\n" + "    void foo() {\n" + "        assert methodWithVeryVeryLongName() : foo;\n" + "        assert i + j + k + l + n + m <= 2 : \"assert description\";\n" + "    }\n" + "}\n", "class Foo {\n" + "    void foo() {\n" + "        assert methodWithVeryVeryLongName() :\n" + "                foo;\n" + "        assert i + j + k + l + n + m <= 2 :\n" + "                \"assert description\";\n" + "    }\n" + "}\n");
        getSettings().ASSERT_STATEMENT_COLON_ON_NEXT_LINE = true;
        doTextTest("class Foo {\n" + "    void foo() {\n" + "        assert methodWithVeryVeryLongName() : foo;\n" + "        assert i + j + k + l + n + m <= 2 : \"assert description\";\n" + "    }\n" + "}\n", "class Foo {\n" + "    void foo() {\n" + "        assert methodWithVeryVeryLongName()\n" + "                : foo;\n" + "        assert i + j + k + l + n + m <= 2\n" + "                : \"assert description\";\n" + "    }\n" + "}\n");
    } finally {
        LanguageLevelProjectExtension.getInstance(facade.getProject()).setLanguageLevel(effectiveLanguageLevel);
    }
}
Also used : JavaPsiFacade(com.intellij.psi.JavaPsiFacade) LanguageLevel(com.intellij.pom.java.LanguageLevel)

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