Search in sources :

Example 71 with LanguageLevel

use of com.intellij.pom.java.LanguageLevel in project intellij-community by JetBrains.

the class AnnotationFormatterTest method testEnumFormatting.

public void testEnumFormatting() throws Exception {
    defaultSettings();
    FormatterTestCase.getSettings(JavaLanguage.INSTANCE).ENUM_CONSTANTS_WRAP = CommonCodeStyleSettings.WRAP_ALWAYS;
    final LanguageLevel effectiveLanguageLevel = LanguageLevelProjectExtension.getInstance(LightPlatformTestCase.ourProject).getLanguageLevel();
    try {
        LanguageLevelProjectExtension.getInstance(LightPlatformTestCase.ourProject).setLanguageLevel(LanguageLevel.JDK_1_5);
        doTextTest("  enum Breed {\n" + "     Dalmatian (  \"spotted\" ),Labrador ( \"black\" ),Dachshund( \"brown\" );\n" + "\n" + "     // constructor\n" + "     Breed ( String colour )\n" + "        {\n" + "        this.colour = colour;\n" + "        }\n" + "\n" + "     private String colour;\n" + "\n" + "     // additional method of every Breed object\n" + "     public String getColour()\n" + "        {\n" + "        return colour;\n" + "        }\n" + "  }", "enum Breed {\n" + "    Dalmatian(\"spotted\"),\n" + "    Labrador(\"black\"),\n" + "    Dachshund(\"brown\");\n" + "\n" + "    // constructor\n" + "    Breed(String colour) {\n" + "        this.colour = colour;\n" + "    }\n" + "\n" + "    private String colour;\n" + "\n" + "    // additional method of every Breed object\n" + "    public String getColour() {\n" + "        return colour;\n" + "    }\n" + "}");
        doTextTest("  enum Breed {\n" + "     Dalmatian (  \"spotted\" ),Labrador ( \"black\" ),Dachshund( \"brown\" )\n" + "  }", "enum Breed {\n" + "    Dalmatian(\"spotted\"),\n" + "    Labrador(\"black\"),\n" + "    Dachshund(\"brown\")\n" + "}");
        doTextTest("enum Command { \n" + "        USED \n" + "        , \n" + "        UNUSED\n" + "; \n" + " }", "enum Command {\n" + "    USED,\n" + "    UNUSED;\n" + "}");
    } finally {
        LanguageLevelProjectExtension.getInstance(LightPlatformTestCase.ourProject).setLanguageLevel(effectiveLanguageLevel);
    }
}
Also used : LanguageLevel(com.intellij.pom.java.LanguageLevel)

Example 72 with LanguageLevel

use of com.intellij.pom.java.LanguageLevel 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 73 with LanguageLevel

use of com.intellij.pom.java.LanguageLevel 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)

Example 74 with LanguageLevel

use of com.intellij.pom.java.LanguageLevel in project intellij-community by JetBrains.

the class JavadocFormatterTest method test_PreserveExistingSelfClosingTags_AndGenerateOnlyPTag.

public void test_PreserveExistingSelfClosingTags_AndGenerateOnlyPTag() {
    getSettings().getRootSettings().ENABLE_JAVADOC_FORMATTING = true;
    LanguageLevel before = LanguageLevelProjectExtension.getInstance(getProject()).getLanguageLevel();
    LanguageLevelProjectExtension.getInstance(getProject()).setLanguageLevel(LanguageLevel.JDK_1_7);
    try {
        doTextTest("/**\n" + " * My test comment\n" + " * <p/>\n" + " * \n" + " * With empty line\n" + " */\n" + "class T {\n" + "}", "/**\n" + " * My test comment\n" + " * <p/>\n" + " * <p>\n" + " * With empty line\n" + " */\n" + "class T {\n" + "}");
    } finally {
        LanguageLevelProjectExtension.getInstance(getProject()).setLanguageLevel(before);
    }
}
Also used : LanguageLevel(com.intellij.pom.java.LanguageLevel)

Example 75 with LanguageLevel

use of com.intellij.pom.java.LanguageLevel in project intellij-community by JetBrains.

the class JavaFormatterTest method testSpacesIncode.

public void testSpacesIncode() throws Exception {
    final JavaPsiFacade facade = getJavaFacade();
    final LanguageLevel level = LanguageLevelProjectExtension.getInstance(facade.getProject()).getLanguageLevel();
    LanguageLevelProjectExtension.getInstance(facade.getProject()).setLanguageLevel(LanguageLevel.JDK_1_5);
    try {
        doTextTest("class C<Y, X> {\n" + "}", "class C<Y, X> {\n" + "}");
        getSettings().SPACE_BEFORE_METHOD_LBRACE = true;
        getSettings().KEEP_SIMPLE_METHODS_IN_ONE_LINE = true;
        doTextTest("enum En {\n" + "    A(10) {},\n" + "    B(10) {},\n" + "    C(10);\n" + "\n" + "    En(int i) { }\n" + "}", "enum En {\n" + "    A(10) {},\n" + "    B(10) {},\n" + "    C(10);\n" + "\n" + "    En(int i) { }\n" + "}");
        doTextTest("class C {\n" + "    void foo (Map<?, String> s) {\n" + "        Set<? extends Map<?, String>.Entry<?, String>> temp = s.entries();\n" + "    }\n" + "}", "class C {\n" + "    void foo(Map<?, String> s) {\n" + "        Set<? extends Map<?, String>.Entry<?, String>> temp = s.entries();\n" + "    }\n" + "}");
        doTextTest("class B {\n" + "    public final A<String> myDelegate = new A<String>();\n" + "\n" + "    public List<? extends String> method1() {\n" + "        return myDelegate.method1();\n" + "    }\n" + "\n" + "    public String method2(String t) {\n" + "        return myDelegate.method2(t);\n" + "    }\n" + "}", "class B {\n" + "    public final A<String> myDelegate = new A<String>();\n" + "\n" + "    public List<? extends String> method1() {\n" + "        return myDelegate.method1();\n" + "    }\n" + "\n" + "    public String method2(String t) {\n" + "        return myDelegate.method2(t);\n" + "    }\n" + "}");
    } finally {
        LanguageLevelProjectExtension.getInstance(facade.getProject()).setLanguageLevel(level);
    }
}
Also used : JavaPsiFacade(com.intellij.psi.JavaPsiFacade) LanguageLevel(com.intellij.pom.java.LanguageLevel)

Aggregations

LanguageLevel (com.intellij.pom.java.LanguageLevel)98 LanguageLevelProjectExtension (com.intellij.openapi.roots.LanguageLevelProjectExtension)21 Nullable (org.jetbrains.annotations.Nullable)14 Module (com.intellij.openapi.module.Module)13 NotNull (org.jetbrains.annotations.NotNull)9 Sdk (com.intellij.openapi.projectRoots.Sdk)8 JavaPsiFacade (com.intellij.psi.JavaPsiFacade)7 Project (com.intellij.openapi.project.Project)6 VirtualFile (com.intellij.openapi.vfs.VirtualFile)6 File (java.io.File)6 IOException (java.io.IOException)5 IncorrectOperationException (com.intellij.util.IncorrectOperationException)4 LocalInspectionToolWrapper (com.intellij.codeInspection.ex.LocalInspectionToolWrapper)3 Lexer (com.intellij.lexer.Lexer)3 LanguageLevelModuleExtension (com.intellij.openapi.roots.LanguageLevelModuleExtension)3 GlobalSearchScope (com.intellij.psi.search.GlobalSearchScope)3 VisibleForTesting (com.google.common.annotations.VisibleForTesting)2 JavaProjectData (com.intellij.externalSystem.JavaProjectData)2 DisposeAwareProjectChange (com.intellij.openapi.externalSystem.util.DisposeAwareProjectChange)2 ConfigurationException (com.intellij.openapi.options.ConfigurationException)2