From 0126b354d6d449138f6fb509963be87fb367f0b2 Mon Sep 17 00:00:00 2001 From: Denis Zhdanov Date: Thu, 21 Jul 2011 17:38:18 +0400 Subject: [PATCH] IDEA-72317 Java Formatter: Separate 'Space before array initializer left brace' for annotation arguments and arrays --- .../java/JavaSpacePropertyProcessor.java | 4 +++- .../formatter/java/JavaFormatterSpaceTest.java | 17 +++++++++++++++++ .../psi/codeStyle/CommonCodeStyleSettings.java | 6 ++++++ .../options/codeStyle/CodeStyleSpacesPanel.java | 1 + .../src/messages/ApplicationBundle.properties | 1 + 5 files changed, 28 insertions(+), 1 deletion(-) diff --git a/java/java-impl/src/com/intellij/psi/formatter/java/JavaSpacePropertyProcessor.java b/java/java-impl/src/com/intellij/psi/formatter/java/JavaSpacePropertyProcessor.java index 94280c15d7d3..d7ecfe2614fc 100644 --- a/java/java-impl/src/com/intellij/psi/formatter/java/JavaSpacePropertyProcessor.java +++ b/java/java-impl/src/com/intellij/psi/formatter/java/JavaSpacePropertyProcessor.java @@ -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) { diff --git a/java/java-tests/testSrc/com/intellij/psi/formatter/java/JavaFormatterSpaceTest.java b/java/java-tests/testSrc/com/intellij/psi/formatter/java/JavaFormatterSpaceTest.java index 6000ad164bd3..acb6ffc11635 100644 --- a/java/java-tests/testSrc/com/intellij/psi/formatter/java/JavaFormatterSpaceTest.java +++ b/java/java-tests/testSrc/com/intellij/psi/formatter/java/JavaFormatterSpaceTest.java @@ -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" + + "}" + ); + } } diff --git a/platform/lang-api/src/com/intellij/psi/codeStyle/CommonCodeStyleSettings.java b/platform/lang-api/src/com/intellij/psi/codeStyle/CommonCodeStyleSettings.java index c6f71b3c0480..aa59c4fb4699 100644 --- a/platform/lang-api/src/com/intellij/psi/codeStyle/CommonCodeStyleSettings.java +++ b/platform/lang-api/src/com/intellij/psi/codeStyle/CommonCodeStyleSettings.java @@ -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; diff --git a/platform/lang-impl/src/com/intellij/application/options/codeStyle/CodeStyleSpacesPanel.java b/platform/lang-impl/src/com/intellij/application/options/codeStyle/CodeStyleSpacesPanel.java index 50f1e147e357..c19232f7f408 100644 --- a/platform/lang-impl/src/com/intellij/application/options/codeStyle/CodeStyleSpacesPanel.java +++ b/platform/lang-impl/src/com/intellij/application/options/codeStyle/CodeStyleSpacesPanel.java @@ -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); diff --git a/platform/platform-resources-en/src/messages/ApplicationBundle.properties b/platform/platform-resources-en/src/messages/ApplicationBundle.properties index 9bd0dca9b3d2..f017d140b2b1 100644 --- a/platform/platform-resources-en/src/messages/ApplicationBundle.properties +++ b/platform/platform-resources-en/src/messages/ApplicationBundle.properties @@ -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