Search in sources :

Example 21 with JavaPsiFacade

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

the class JavaFormatterTest method test.

public void test() throws Exception {
    getSettings().getRootSettings().getIndentOptions(StdFileTypes.JAVA).INDENT_SIZE = 2;
    getSettings().getRootSettings().getIndentOptions(StdFileTypes.JAVA).CONTINUATION_INDENT_SIZE = 2;
    getSettings().RIGHT_MARGIN = 37;
    getSettings().ALIGN_MULTILINE_EXTENDS_LIST = true;
    getSettings().EXTENDS_KEYWORD_WRAP = CommonCodeStyleSettings.WRAP_AS_NEEDED;
    getSettings().EXTENDS_LIST_WRAP = CommonCodeStyleSettings.WRAP_AS_NEEDED;
    getSettings().ASSERT_STATEMENT_WRAP = CommonCodeStyleSettings.WRAP_AS_NEEDED;
    getSettings().ASSERT_STATEMENT_COLON_ON_NEXT_LINE = false;
    getSettings().ALIGN_MULTILINE_BINARY_OPERATION = true;
    final JavaPsiFacade facade = getJavaFacade();
    final LanguageLevel effectiveLanguageLevel = LanguageLevelProjectExtension.getInstance(facade.getProject()).getLanguageLevel();
    LanguageLevelProjectExtension.getInstance(facade.getProject()).setLanguageLevel(LanguageLevel.JDK_1_5);
    try {
        doTextTest("public class ThisIsASampleClass extends C1 implements I1, I2, I3, I4, I5 {\n" + "  public void longerMethod() {\n" + "    assert i + j + k + l + n+ m <= 2 : \"assert description\";" + "  }\n" + "}", "public class ThisIsASampleClass\n" + "  extends C1\n" + "  implements I1, I2, I3, I4, I5 {\n" + "  public void longerMethod() {\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)

Example 22 with JavaPsiFacade

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

the class JavaFormatterTest method testSCRIDEADEV_2292.

public void testSCRIDEADEV_2292() throws IncorrectOperationException {
    getSettings().KEEP_CONTROL_STATEMENT_IN_ONE_LINE = false;
    getSettings().WHILE_ON_NEW_LINE = true;
    final JavaPsiFacade facade = getJavaFacade();
    final LanguageLevel stored = LanguageLevelProjectExtension.getInstance(facade.getProject()).getLanguageLevel();
    LanguageLevelProjectExtension.getInstance(facade.getProject()).setLanguageLevel(LanguageLevel.JDK_1_5);
    try {
        doTextTest("class Foo {\n" + "    void foo() {\n" + "        if (a) foo();\n" + "        else bar();\n" + "    }\n" + "}", "class Foo {\n" + "    void foo() {\n" + "        if (a)\n" + "            foo();\n" + "        else\n" + "            bar();\n" + "    }\n" + "}");
        doTextTest("class Foo {\n" + "    void foo() {\n" + "        for (int i = 0; i < 10; i++) foo();\n" + "    }\n" + "}", "class Foo {\n" + "    void foo() {\n" + "        for (int i = 0; i < 10; i++)\n" + "            foo();\n" + "    }\n" + "}");
        doTextTest("class Foo {\n" + "    void foo() {\n" + "        for (int var : vars) foo();\n" + "    }\n" + "}", "class Foo {\n" + "    void foo() {\n" + "        for (int var : vars)\n" + "            foo();\n" + "    }\n" + "}");
        doTextTest("class Foo {\n" + "    void foo() {\n" + "        do foo(); while (true);\n" + "    }\n" + "}", "class Foo {\n" + "    void foo() {\n" + "        do\n" + "            foo();\n" + "        while (true);\n" + "    }\n" + "}");
        doTextTest("class Foo {\n" + "    void foo() {\n" + "        while(true) foo();\n" + "    }\n" + "}", "class Foo {\n" + "    void foo() {\n" + "        while (true)\n" + "            foo();\n" + "    }\n" + "}");
        getSettings().KEEP_CONTROL_STATEMENT_IN_ONE_LINE = true;
        getSettings().WHILE_ON_NEW_LINE = false;
        doTextTest("class Foo {\n" + "    void foo() {\n" + "        if (a) foo();\n" + "        else bar();\n" + "    }\n" + "}", "class Foo {\n" + "    void foo() {\n" + "        if (a) foo();\n" + "        else bar();\n" + "    }\n" + "}");
        doTextTest("class Foo {\n" + "    void foo() {\n" + "        for (int i = 0; i < 10; i++) foo();\n" + "    }\n" + "}", "class Foo {\n" + "    void foo() {\n" + "        for (int i = 0; i < 10; i++) foo();\n" + "    }\n" + "}");
        doTextTest("class Foo {\n" + "    void foo() {\n" + "        for (int var : vars) foo();\n" + "    }\n" + "}", "class Foo {\n" + "    void foo() {\n" + "        for (int var : vars) foo();\n" + "    }\n" + "}");
        doTextTest("class Foo {\n" + "    void foo() {\n" + "        do foo(); while (true);\n" + "    }\n" + "}", "class Foo {\n" + "    void foo() {\n" + "        do foo(); while (true);\n" + "    }\n" + "}");
        doTextTest("class Foo {\n" + "    void foo() {\n" + "        while(true) foo();\n" + "    }\n" + "}", "class Foo {\n" + "    void foo() {\n" + "        while (true) foo();\n" + "    }\n" + "}");
        getSettings().RIGHT_MARGIN = 17;
        doTextTest("class Foo {\n" + "    void foo() {\n" + "        if (a) foo();\n" + "        else bar();\n" + "    }\n" + "}", "class Foo {\n" + "    void foo() {\n" + "        if (a)\n" + "            foo();\n" + "        else\n" + "            bar();\n" + "    }\n" + "}");
        getSettings().RIGHT_MARGIN = 30;
        doTextTest("class Foo {\n" + "    void foo() {\n" + "        for (int i = 0; i < 10; i++) foo();\n" + "    }\n" + "}", "class Foo {\n" + "    void foo() {\n" + "        for (int i = 0; i < 10; i++)\n" + "            foo();\n" + "    }\n" + "}");
        getSettings().RIGHT_MARGIN = 32;
        doTextTest("class Foo {\n" + "    void foo() {\n" + "        for (int var : vars) foo();\n" + "    }\n" + "}", "class Foo {\n" + "    void foo() {\n" + "        for (int var : vars)\n" + "            foo();\n" + "    }\n" + "}");
        getSettings().RIGHT_MARGIN = 12;
        doTextTest("class Foo {\n" + "    void foo() {\n" + "        do foo(); while (true);\n" + "    }\n" + "}", "class Foo {\n" + "    void foo() {\n" + "        do\n" + "            foo();\n" + "        while (true);\n" + "    }\n" + "}");
        getSettings().RIGHT_MARGIN = 23;
        doTextTest("class Foo {\n" + "    void foo() {\n" + "        while(true) foo();\n" + "    }\n" + "}", "class Foo {\n" + "    void foo() {\n" + "        while (true)\n" + "            foo();\n" + "    }\n" + "}");
    } finally {
        LanguageLevelProjectExtension.getInstance(facade.getProject()).setLanguageLevel(stored);
    }
}
Also used : JavaPsiFacade(com.intellij.psi.JavaPsiFacade) LanguageLevel(com.intellij.pom.java.LanguageLevel)

Example 23 with JavaPsiFacade

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

the class JavaFormatterTest method testSpaceAfterCommaInEnum.

public void testSpaceAfterCommaInEnum() throws IncorrectOperationException {
    getSettings().SPACE_AFTER_COMMA = true;
    final JavaPsiFacade facade = getJavaFacade();
    final LanguageLevel effectiveLanguageLevel = LanguageLevelProjectExtension.getInstance(facade.getProject()).getLanguageLevel();
    try {
        LanguageLevelProjectExtension.getInstance(facade.getProject()).setLanguageLevel(LanguageLevel.JDK_1_5);
        doTextTest("public enum StringExDirection {\n" + "\n" + "    RIGHT_TO_LEFT, LEFT_TO_RIGHT\n" + "\n" + "}", "public enum StringExDirection {\n" + "\n" + "    RIGHT_TO_LEFT, LEFT_TO_RIGHT\n" + "\n" + "}");
    } finally {
        LanguageLevelProjectExtension.getInstance(facade.getProject()).setLanguageLevel(effectiveLanguageLevel);
    }
}
Also used : JavaPsiFacade(com.intellij.psi.JavaPsiFacade) LanguageLevel(com.intellij.pom.java.LanguageLevel)

Example 24 with JavaPsiFacade

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

the class ExceptionInfoCache method findClassesPreferringMyScope.

@NotNull
private PsiClass[] findClassesPreferringMyScope(String className) {
    JavaPsiFacade psiFacade = JavaPsiFacade.getInstance(myProject);
    PsiClass[] result = psiFacade.findClasses(className, mySearchScope);
    return result.length != 0 ? result : psiFacade.findClasses(className, GlobalSearchScope.allScope(myProject));
}
Also used : JavaPsiFacade(com.intellij.psi.JavaPsiFacade) PsiClass(com.intellij.psi.PsiClass) NotNull(org.jetbrains.annotations.NotNull)

Example 25 with JavaPsiFacade

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

the class Struts2TilesModelProvider method computeModels.

@NotNull
public Collection<TilesModel> computeModels(@NotNull final Module module) {
    final Project project = module.getProject();
    final JavaPsiFacade facade = JavaPsiFacade.getInstance(project);
    final GlobalSearchScope moduleScope = GlobalSearchScope.moduleWithDependenciesAndLibrariesScope(module, false);
    // struts2-tiles plugin must be available
    final PsiClass strutsTilesListenerClass = facade.findClass(STRUTS_TILES_LISTENER_CLASS, moduleScope);
    if (strutsTilesListenerClass == null) {
        return Collections.emptyList();
    }
    final PsiClass tilesListenerClass = facade.findClass(TilesConstants.TILES_LISTENER, moduleScope);
    final StrutsPluginDomFactory<TilesDefinitions, TilesModel> factory = StrutsProjectComponent.getInstance(project).getTilesFactory();
    final Set<TilesModel> struts2TilesModels = new HashSet<>();
    final Consumer<Set<XmlFile>> consumer = definitions -> {
        final DomFileElement<TilesDefinitions> domFileElement = factory.createMergedModelRoot(definitions);
        if (domFileElement != null) {
            struts2TilesModels.add(new TilesModelImpl(definitions, domFileElement, STRUTS2_TILES_MODEL));
        }
    };
    final WebDirectoryUtil webDirectoryUtil = WebDirectoryUtil.getWebDirectoryUtil(project);
    final Collection<WebFacet> webFacets = WebFacet.getInstances(module);
    for (final WebFacet webFacet : webFacets) {
        final WebApp webApp = webFacet.getRoot();
        if (webApp == null) {
            continue;
        }
        // determine configured tiles config files
        @NonNls final Set<String> tilesConfigNames = findConfiguredTilesPaths(webApp);
        // no configured paths? use default
        if (tilesConfigNames.isEmpty()) {
            tilesConfigNames.add(DEFAULT_TILES_XML);
        }
        // resolve to XmlFile
        final Set<XmlFile> tilesFileSet = new HashSet<>();
        for (final String tilesPath : tilesConfigNames) {
            final PsiElement tilesXmlFile = webDirectoryUtil.findFileByPath(tilesPath, webFacet);
            if (tilesXmlFile instanceof XmlFile) {
                tilesFileSet.add((XmlFile) tilesXmlFile);
            }
        }
        final List<Listener> listenerList = webApp.getListeners();
        for (final Listener listener : listenerList) {
            final PsiClass listenerClass = listener.getListenerClass().getValue();
            if (strutsTilesListenerClass.equals(listenerClass) || Comparing.equal(tilesListenerClass, listenerClass)) {
                consumer.consume(tilesFileSet);
            }
        }
    }
    return struts2TilesModels;
}
Also used : JavaPsiFacade(com.intellij.psi.JavaPsiFacade) WebFacet(com.intellij.javaee.web.facet.WebFacet) XmlFile(com.intellij.psi.xml.XmlFile) JavaPsiFacade(com.intellij.psi.JavaPsiFacade) HashSet(com.intellij.util.containers.HashSet) NonNls(org.jetbrains.annotations.NonNls) THashSet(gnu.trove.THashSet) ContainerUtil(com.intellij.util.containers.ContainerUtil) StrutsProjectComponent(com.intellij.struts.StrutsProjectComponent) PsiClass(com.intellij.psi.PsiClass) Comparing(com.intellij.openapi.util.Comparing) PsiElement(com.intellij.psi.PsiElement) Project(com.intellij.openapi.project.Project) Module(com.intellij.openapi.module.Module) TilesModelProvider(com.intellij.struts.TilesModelProvider) WebDirectoryUtil(com.intellij.psi.impl.source.jsp.WebDirectoryUtil) TilesDefinitions(com.intellij.struts.dom.tiles.TilesDefinitions) TilesModel(com.intellij.struts.TilesModel) TilesConstants(com.intellij.tiles.TilesConstants) StringUtil(com.intellij.openapi.util.text.StringUtil) TilesModelImpl(com.intellij.struts.psi.TilesModelImpl) Collection(java.util.Collection) DomFileElement(com.intellij.util.xml.DomFileElement) GlobalSearchScope(com.intellij.psi.search.GlobalSearchScope) Set(java.util.Set) List(java.util.List) WebApp(com.intellij.javaee.model.xml.web.WebApp) ParamValue(com.intellij.javaee.model.xml.ParamValue) Listener(com.intellij.javaee.model.xml.Listener) NotNull(org.jetbrains.annotations.NotNull) StrutsPluginDomFactory(com.intellij.struts.StrutsPluginDomFactory) Collections(java.util.Collections) Consumer(com.intellij.util.Consumer) Condition(com.intellij.openapi.util.Condition) HashSet(com.intellij.util.containers.HashSet) THashSet(gnu.trove.THashSet) Set(java.util.Set) Listener(com.intellij.javaee.model.xml.Listener) TilesModelImpl(com.intellij.struts.psi.TilesModelImpl) DomFileElement(com.intellij.util.xml.DomFileElement) WebDirectoryUtil(com.intellij.psi.impl.source.jsp.WebDirectoryUtil) GlobalSearchScope(com.intellij.psi.search.GlobalSearchScope) PsiElement(com.intellij.psi.PsiElement) HashSet(com.intellij.util.containers.HashSet) THashSet(gnu.trove.THashSet) NonNls(org.jetbrains.annotations.NonNls) XmlFile(com.intellij.psi.xml.XmlFile) PsiClass(com.intellij.psi.PsiClass) TilesDefinitions(com.intellij.struts.dom.tiles.TilesDefinitions) TilesModel(com.intellij.struts.TilesModel) Project(com.intellij.openapi.project.Project) WebFacet(com.intellij.javaee.web.facet.WebFacet) WebApp(com.intellij.javaee.model.xml.web.WebApp) NotNull(org.jetbrains.annotations.NotNull)

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