diff --git a/plugins/groovy/resources/samples/WRAPPING_AND_BRACES_SETTINGS.txt b/plugins/groovy/resources/samples/WRAPPING_AND_BRACES_SETTINGS.txt
index 54dc818a9f9c..1a3c6f98d434 100644
--- a/plugins/groovy/resources/samples/WRAPPING_AND_BRACES_SETTINGS.txt
+++ b/plugins/groovy/resources/samples/WRAPPING_AND_BRACES_SETTINGS.txt
@@ -11,6 +11,7 @@ public class ThisIsASampleClass extends C1 implements I1, I2, I3, I4, I5 {
int
i = 0
int var1 = 1; int var2 = 2
+ new int[]{-1000,-100,-10,-1,0,1,10,100,1000,10000,100000}
foo1(0x0051, 0x0052, 0x0053, 0x0054, 0x0055, 0x0056, 0x0057)
foo2 "a", "ab", "abc", "abcd", "abcde", "abcdef", "abcdefg", "abcdefgh"
int x = (3 + 4 + 5 + 6) * (7 + 8 + 9 + 10) * (11 + 12 + 13 + 14 + 0xFFFFFFFF)
diff --git a/plugins/groovy/src/org/jetbrains/plugins/groovy/codeStyle/GroovyLanguageCodeStyleSettingsProvider.java b/plugins/groovy/src/org/jetbrains/plugins/groovy/codeStyle/GroovyLanguageCodeStyleSettingsProvider.java
index 22cc5a2d23b1..9f6905d7af2b 100644
--- a/plugins/groovy/src/org/jetbrains/plugins/groovy/codeStyle/GroovyLanguageCodeStyleSettingsProvider.java
+++ b/plugins/groovy/src/org/jetbrains/plugins/groovy/codeStyle/GroovyLanguageCodeStyleSettingsProvider.java
@@ -125,10 +125,10 @@ public class GroovyLanguageCodeStyleSettingsProvider extends LanguageCodeStyleSe
"ALIGN_MULTILINE_TERNARY_OPERATION",
//"TERNARY_OPERATION_SIGNS_ON_NEXT_LINE",
- //"ARRAY_INITIALIZER_WRAP",
- //"ALIGN_MULTILINE_ARRAY_INITIALIZER_EXPRESSION",
- //"ARRAY_INITIALIZER_LBRACE_ON_NEXT_LINE",
- //"ARRAY_INITIALIZER_RBRACE_ON_NEXT_LINE",
+ "ARRAY_INITIALIZER_WRAP",
+ "ALIGN_MULTILINE_ARRAY_INITIALIZER_EXPRESSION",
+ "ARRAY_INITIALIZER_LBRACE_ON_NEXT_LINE",
+ "ARRAY_INITIALIZER_RBRACE_ON_NEXT_LINE",
"MODIFIER_LIST_WRAP",
diff --git a/plugins/groovy/src/org/jetbrains/plugins/groovy/formatter/blocks/GroovyBlockGenerator.java b/plugins/groovy/src/org/jetbrains/plugins/groovy/formatter/blocks/GroovyBlockGenerator.java
index abda0f3f9784..b72776b47d86 100644
--- a/plugins/groovy/src/org/jetbrains/plugins/groovy/formatter/blocks/GroovyBlockGenerator.java
+++ b/plugins/groovy/src/org/jetbrains/plugins/groovy/formatter/blocks/GroovyBlockGenerator.java
@@ -1,5 +1,4 @@
// Copyright 2000-2018 JetBrains s.r.o. Use of this source code is governed by the Apache 2.0 license that can be found in the LICENSE file.
-
package org.jetbrains.plugins.groovy.formatter.blocks;
import com.intellij.formatting.*;
@@ -33,6 +32,7 @@ import org.jetbrains.plugins.groovy.lang.psi.GrQualifiedReference;
import org.jetbrains.plugins.groovy.lang.psi.GroovyElementVisitor;
import org.jetbrains.plugins.groovy.lang.psi.GroovyFile;
import org.jetbrains.plugins.groovy.lang.psi.GroovyFileBase;
+import org.jetbrains.plugins.groovy.lang.psi.api.GrArrayInitializer;
import org.jetbrains.plugins.groovy.lang.psi.api.GrTryResourceList;
import org.jetbrains.plugins.groovy.lang.psi.api.auxiliary.GrListOrMap;
import org.jetbrains.plugins.groovy.lang.psi.api.auxiliary.GrThrowsClause;
@@ -620,7 +620,8 @@ public class GroovyBlockGenerator {
blockPsi instanceof GrExtendsClause && myContext.getSettings().ALIGN_MULTILINE_EXTENDS_LIST ||
blockPsi instanceof GrThrowsClause && myContext.getSettings().ALIGN_MULTILINE_THROWS_LIST ||
blockPsi instanceof GrListOrMap && myContext.getGroovySettings().ALIGN_MULTILINE_LIST_OR_MAP ||
- blockPsi instanceof GrTryResourceList && myContext.getSettings().ALIGN_MULTILINE_RESOURCES;
+ blockPsi instanceof GrTryResourceList && myContext.getSettings().ALIGN_MULTILINE_RESOURCES ||
+ blockPsi instanceof GrArrayInitializer && myContext.getSettings().ALIGN_MULTILINE_ARRAY_INITIALIZER_EXPRESSION;
}
private static boolean isListLikeClause(PsiElement blockPsi) {
@@ -630,7 +631,8 @@ public class GroovyBlockGenerator {
blockPsi instanceof GrExtendsClause ||
blockPsi instanceof GrThrowsClause ||
blockPsi instanceof GrListOrMap ||
- blockPsi instanceof GrTryResourceList;
+ blockPsi instanceof GrTryResourceList ||
+ blockPsi instanceof GrArrayInitializer;
}
private static boolean isKeyword(ASTNode node) {
diff --git a/plugins/groovy/src/org/jetbrains/plugins/groovy/formatter/processors/GroovyIndentProcessor.java b/plugins/groovy/src/org/jetbrains/plugins/groovy/formatter/processors/GroovyIndentProcessor.java
index 2e8d70e31fd5..068a96a7c4ae 100644
--- a/plugins/groovy/src/org/jetbrains/plugins/groovy/formatter/processors/GroovyIndentProcessor.java
+++ b/plugins/groovy/src/org/jetbrains/plugins/groovy/formatter/processors/GroovyIndentProcessor.java
@@ -1,5 +1,4 @@
// Copyright 2000-2018 JetBrains s.r.o. Use of this source code is governed by the Apache 2.0 license that can be found in the LICENSE file.
-
package org.jetbrains.plugins.groovy.formatter.processors;
import com.intellij.formatting.ChildAttributes;
@@ -23,6 +22,7 @@ import org.jetbrains.plugins.groovy.lang.parser.GroovyElementTypes;
import org.jetbrains.plugins.groovy.lang.psi.GroovyElementVisitor;
import org.jetbrains.plugins.groovy.lang.psi.GroovyFileBase;
import org.jetbrains.plugins.groovy.lang.psi.GroovyPsiElement;
+import org.jetbrains.plugins.groovy.lang.psi.api.GrArrayInitializer;
import org.jetbrains.plugins.groovy.lang.psi.api.GrTryResourceList;
import org.jetbrains.plugins.groovy.lang.psi.api.auxiliary.GrListOrMap;
import org.jetbrains.plugins.groovy.lang.psi.api.auxiliary.GrThrowsClause;
@@ -53,8 +53,7 @@ import org.jetbrains.plugins.groovy.lang.psi.api.types.GrWildcardTypeArgument;
import static com.intellij.formatting.Indent.*;
import static com.intellij.psi.codeStyle.CommonCodeStyleSettings.NEXT_LINE_SHIFTED;
import static com.intellij.psi.codeStyle.CommonCodeStyleSettings.NEXT_LINE_SHIFTED2;
-import static org.jetbrains.plugins.groovy.lang.psi.GroovyElementTypes.T_LPAREN;
-import static org.jetbrains.plugins.groovy.lang.psi.GroovyElementTypes.T_RPAREN;
+import static org.jetbrains.plugins.groovy.lang.psi.GroovyElementTypes.*;
/**
* @author ilyas
@@ -483,6 +482,13 @@ public class GroovyIndentProcessor extends GroovyElementVisitor {
myResult = getContinuationWithoutFirstIndent();
}
+ @Override
+ public void visitArrayInitializer(@NotNull GrArrayInitializer arrayInitializer) {
+ if (myChildType != T_LBRACE && myChildType != T_RBRACE) {
+ myResult = getContinuationWithoutFirstIndent();
+ }
+ }
+
@NotNull
public static Indent getIndentInBlock(int braceStyle) {
return braceStyle == NEXT_LINE_SHIFTED ? getNoneIndent() : getNormalIndent();
diff --git a/plugins/groovy/src/org/jetbrains/plugins/groovy/formatter/processors/GroovySpacingProcessor.java b/plugins/groovy/src/org/jetbrains/plugins/groovy/formatter/processors/GroovySpacingProcessor.java
index 2fa916ba3993..49963275e0c4 100644
--- a/plugins/groovy/src/org/jetbrains/plugins/groovy/formatter/processors/GroovySpacingProcessor.java
+++ b/plugins/groovy/src/org/jetbrains/plugins/groovy/formatter/processors/GroovySpacingProcessor.java
@@ -627,12 +627,28 @@ public class GroovySpacingProcessor extends GroovyElementVisitor {
@Nullable Boolean spaceWithinEmpty,
@Nullable Boolean leftLF,
@Nullable Boolean rightLF) {
- if (myType1 == T_LPAREN && myType2 == T_RPAREN && spaceWithinEmpty != null) {
+ return processParentheses(spaceWithin, spaceWithinEmpty, leftLF, rightLF, T_LPAREN, T_RPAREN);
+ }
+
+ private boolean processBraces(@NotNull Boolean spaceWithin,
+ @Nullable Boolean spaceWithinEmpty,
+ @Nullable Boolean leftLF,
+ @Nullable Boolean rightLF) {
+ return processParentheses(spaceWithin, spaceWithinEmpty, leftLF, rightLF, T_LBRACE, T_RBRACE);
+ }
+
+ private boolean processParentheses(@NotNull Boolean spaceWithin,
+ @Nullable Boolean spaceWithinEmpty,
+ @Nullable Boolean leftLF,
+ @Nullable Boolean rightLF,
+ @NotNull IElementType leftType,
+ @NotNull IElementType rightType) {
+ if (myType1 == leftType && myType2 == rightType && spaceWithinEmpty != null) {
createSpaceInCode(spaceWithinEmpty);
return true;
}
- else if (myType1 == T_LPAREN) {
- final ASTNode rparenth = findFrom(myChild1, T_RPAREN, true);
+ else if (myType1 == leftType) {
+ final ASTNode rparenth = findFrom(myChild1, rightType, true);
if (rparenth == null || leftLF == null) {
createSpaceInCode(spaceWithin);
}
@@ -642,8 +658,8 @@ public class GroovySpacingProcessor extends GroovyElementVisitor {
}
return true;
}
- else if (myType2 == T_RPAREN) {
- final ASTNode lparenth = findFrom(myChild1, T_LPAREN, false);
+ else if (myType2 == rightType) {
+ final ASTNode lparenth = findFrom(myChild1, leftType, false);
if (lparenth == null || rightLF == null) {
createSpaceInCode(spaceWithin);
}
@@ -1029,12 +1045,12 @@ public class GroovySpacingProcessor extends GroovyElementVisitor {
@Override
public void visitArrayInitializer(@NotNull GrArrayInitializer arrayInitializer) {
- if (isWithinBraces()) {
- createSpaceInCode(
- arrayInitializer.isEmpty() ? mySettings.SPACE_WITHIN_EMPTY_ARRAY_INITIALIZER_BRACES
- : mySettings.SPACE_WITHIN_ARRAY_INITIALIZER_BRACES
- );
- }
+ processBraces(
+ mySettings.SPACE_WITHIN_ARRAY_INITIALIZER_BRACES,
+ mySettings.SPACE_WITHIN_EMPTY_ARRAY_INITIALIZER_BRACES,
+ mySettings.ARRAY_INITIALIZER_LBRACE_ON_NEXT_LINE,
+ mySettings.ARRAY_INITIALIZER_RBRACE_ON_NEXT_LINE
+ );
}
private static boolean isOpenBlock(IElementType type) {
diff --git a/plugins/groovy/src/org/jetbrains/plugins/groovy/formatter/processors/GroovyWrappingProcessor.java b/plugins/groovy/src/org/jetbrains/plugins/groovy/formatter/processors/GroovyWrappingProcessor.java
index 112184fd541e..d07f1ad41159 100644
--- a/plugins/groovy/src/org/jetbrains/plugins/groovy/formatter/processors/GroovyWrappingProcessor.java
+++ b/plugins/groovy/src/org/jetbrains/plugins/groovy/formatter/processors/GroovyWrappingProcessor.java
@@ -18,7 +18,7 @@ import org.jetbrains.plugins.groovy.lang.parser.GroovyElementTypes;
import org.jetbrains.plugins.groovy.lang.psi.api.auxiliary.modifiers.GrModifierList;
import org.jetbrains.plugins.groovy.lang.psi.api.auxiliary.modifiers.annotation.GrAnnotation;
-import static org.jetbrains.plugins.groovy.lang.psi.GroovyElementTypes.TRY_RESOURCE_LIST;
+import static org.jetbrains.plugins.groovy.lang.psi.GroovyElementTypes.*;
/**
* @author Max Medvedev
@@ -99,6 +99,12 @@ public class GroovyWrappingProcessor {
}
}
+ if (myParentType == ARRAY_INITIALIZER) {
+ if (childType == T_LBRACE || childType == T_RBRACE) {
+ return createNoneWrap();
+ }
+ }
+
if (myParentType == GroovyElementTypes.THROW_CLAUSE && childType == GroovyTokenTypes.kTHROWS) {
return Wrap.createWrap(mySettings.THROWS_KEYWORD_WRAP, true);
}
@@ -220,6 +226,11 @@ public class GroovyWrappingProcessor {
return Wrap.createWrap(mySettings.ASSERT_STATEMENT_WRAP, false);
}
+ if (myParentType == ARRAY_INITIALIZER) {
+ myUsedDefaultWrap = true;
+ return Wrap.createWrap(mySettings.ARRAY_INITIALIZER_WRAP, false);
+ }
+
if (TokenSets.BLOCK_SET.contains(myParentType)) {
return createNormalWrap();
}
diff --git a/plugins/groovy/test/org/jetbrains/plugins/groovy/lang/formatter/GroovyCodeStyleFormatterTest.groovy b/plugins/groovy/test/org/jetbrains/plugins/groovy/lang/formatter/GroovyCodeStyleFormatterTest.groovy
index 6a8bd56b4bb3..37795c0651cc 100644
--- a/plugins/groovy/test/org/jetbrains/plugins/groovy/lang/formatter/GroovyCodeStyleFormatterTest.groovy
+++ b/plugins/groovy/test/org/jetbrains/plugins/groovy/lang/formatter/GroovyCodeStyleFormatterTest.groovy
@@ -171,4 +171,12 @@ class GroovyCodeStyleFormatterTest extends GroovyFormatterTestCase {
void testBracesEndLine() { doTest() }
void testArrayInitializerSpaces() { doTest() }
+
+ void testArrayInitializerDontWrap() { doTest() }
+
+ void testArrayInitializerWrapAlways() { doTest() }
+
+ void testArrayInitializerWrapAlwaysAlign() { doTest() }
+
+ void testArrayInitializerWrapAlwaysNl() { doTest() }
}
diff --git a/plugins/groovy/testdata/groovy/codeStyle/arrayInitializerDontWrap.test b/plugins/groovy/testdata/groovy/codeStyle/arrayInitializerDontWrap.test
new file mode 100644
index 000000000000..d6e6650ee7cd
--- /dev/null
+++ b/plugins/groovy/testdata/groovy/codeStyle/arrayInitializerDontWrap.test
@@ -0,0 +1,4 @@
+
+new int[]{-1000,-100,-10,-1,0,1,10,100,1000,10000,100000}
+-----
+new int[]{-1000, -100, -10, -1, 0, 1, 10, 100, 1000, 10000, 100000}
\ No newline at end of file
diff --git a/plugins/groovy/testdata/groovy/codeStyle/arrayInitializerWrapAlways.test b/plugins/groovy/testdata/groovy/codeStyle/arrayInitializerWrapAlways.test
new file mode 100644
index 000000000000..56e3adf4037e
--- /dev/null
+++ b/plugins/groovy/testdata/groovy/codeStyle/arrayInitializerWrapAlways.test
@@ -0,0 +1,14 @@
+
+new int[]{-1000,-100,-10,-1,0,1,10,100,1000,10000,100000}
+-----
+new int[]{-1000,
+ -100,
+ -10,
+ -1,
+ 0,
+ 1,
+ 10,
+ 100,
+ 1000,
+ 10000,
+ 100000}
\ No newline at end of file
diff --git a/plugins/groovy/testdata/groovy/codeStyle/arrayInitializerWrapAlwaysAlign.test b/plugins/groovy/testdata/groovy/codeStyle/arrayInitializerWrapAlwaysAlign.test
new file mode 100644
index 000000000000..3dabb4e83fd3
--- /dev/null
+++ b/plugins/groovy/testdata/groovy/codeStyle/arrayInitializerWrapAlwaysAlign.test
@@ -0,0 +1,15 @@
+
+
+new int[]{-1000,-100,-10,-1,0,1,10,100,1000,10000,100000}
+-----
+new int[]{-1000,
+ -100,
+ -10,
+ -1,
+ 0,
+ 1,
+ 10,
+ 100,
+ 1000,
+ 10000,
+ 100000}
\ No newline at end of file
diff --git a/plugins/groovy/testdata/groovy/codeStyle/arrayInitializerWrapAlwaysNl.test b/plugins/groovy/testdata/groovy/codeStyle/arrayInitializerWrapAlwaysNl.test
new file mode 100644
index 000000000000..6ca0703d5738
--- /dev/null
+++ b/plugins/groovy/testdata/groovy/codeStyle/arrayInitializerWrapAlwaysNl.test
@@ -0,0 +1,18 @@
+
+
+
+new int[]{-1000,-100,-10,-1,0,1,10,100,1000,10000,100000}
+-----
+new int[]{
+ -1000,
+ -100,
+ -10,
+ -1,
+ 0,
+ 1,
+ 10,
+ 100,
+ 1000,
+ 10000,
+ 100000
+}
\ No newline at end of file