IDEA-72317 Java Formatter: Separate 'Space before array initializer left brace' for annotation arguments and arrays

This commit is contained in:
Denis Zhdanov
2011-07-21 17:40:42 +04:00
parent 6f1b6d0625
commit 0126b354d6
5 changed files with 28 additions and 1 deletions
@@ -1440,7 +1440,9 @@ public class JavaSpacePropertyProcessor extends JavaElementVisitor {
}
// There is a possible case that annotation key-value pair is used in 'shorten' form (with implicit name 'values'). It's also
// possible that target value is surrounded by curly braces. We want to define child role accordingly then.
else if (myRole1 == ChildRole.LPARENTH && mySettings.SPACE_BEFORE_ARRAY_INITIALIZER_LBRACE && myRole2 == ChildRole.ANNOTATION_VALUE) {
else if (myRole1 == ChildRole.LPARENTH && mySettings.SPACE_BEFORE_ANNOTATION_ARRAY_INITIALIZER_LBRACE
&& myRole2 == ChildRole.ANNOTATION_VALUE)
{
createSpaceInCode(true);
}
else if (myRole1 == ChildRole.LPARENTH || myRole2 == ChildRole.RPARENTH) {
@@ -382,4 +382,21 @@ public class JavaFormatterSpaceTest extends AbstractJavaFormatterTest {
"});"
);
}
public void testBeforeAnnotationArrayInitializer() throws Exception {
// Inspired by IDEA-72317
getSettings().SPACE_BEFORE_ARRAY_INITIALIZER_LBRACE = false;
getSettings().SPACE_BEFORE_ANNOTATION_ARRAY_INITIALIZER_LBRACE = true;
doClassTest(
"@SuppressWarnings({\"HardCodedStringLiteral\"})\n" +
"void test() {\n" +
" int[] data = new int[] {1, 2, 3};\n" +
"}",
"@SuppressWarnings( {\"HardCodedStringLiteral\"})\n" +
"void test() {\n" +
" int[] data = new int[]{1, 2, 3};\n" +
"}"
);
}
}
@@ -624,6 +624,12 @@ public class CommonCodeStyleSettings {
*/
public boolean SPACE_BEFORE_ARRAY_INITIALIZER_LBRACE = false;
/**
* '@SuppressWarnings({"unchecked"})
* or
* '@SuppressWarnings( {"unchecked"})
*/
public boolean SPACE_BEFORE_ANNOTATION_ARRAY_INITIALIZER_LBRACE = false;
public boolean SPACE_BEFORE_ELSE_KEYWORD = true;
public boolean SPACE_BEFORE_WHILE_KEYWORD = true;
@@ -67,6 +67,7 @@ public class CodeStyleSpacesPanel extends OptionTreeWithPreviewPanel {
initBooleanField("SPACE_BEFORE_FINALLY_LBRACE", ApplicationBundle.message("checkbox.spaces.finally.left.brace"), SPACES_BEFORE_LEFT_BRACE);
initBooleanField("SPACE_BEFORE_SYNCHRONIZED_LBRACE", ApplicationBundle.message("checkbox.spaces.synchronized.left.brace"), SPACES_BEFORE_LEFT_BRACE);
initBooleanField("SPACE_BEFORE_ARRAY_INITIALIZER_LBRACE", ApplicationBundle.message("checkbox.spaces.array.initializer.left.brace"), SPACES_BEFORE_LEFT_BRACE);
initBooleanField("SPACE_BEFORE_ANNOTATION_ARRAY_INITIALIZER_LBRACE", ApplicationBundle.message("checkbox.spaces.annotation.array.initializer.left.brace"), SPACES_BEFORE_LEFT_BRACE);
initCustomOptions(SPACES_BEFORE_LEFT_BRACE);
initBooleanField("SPACE_BEFORE_ELSE_KEYWORD", ApplicationBundle.message("checkbox.spaces.else.keyword"), SPACES_BEFORE_KEYWORD);
@@ -277,6 +277,7 @@ checkbox.spaces.catch.left.brace='catch' left brace
checkbox.spaces.finally.left.brace='finally' left brace
checkbox.spaces.synchronized.left.brace='synchronized' left brace
checkbox.spaces.array.initializer.left.brace=Array initializer left brace
checkbox.spaces.annotation.array.initializer.left.brace=Annotation array initializer left brace
checkbox.spaces.else.keyword='else' keyword
checkbox.spaces.while.keyword='while' keyword
checkbox.spaces.catch.keyword='catch' keyword