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);
}
}
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);
}
}
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);
}
}
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);
}
}
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);
}
}
Aggregations