Formatting enum delegations lists

This commit is contained in:
Nikolay Krasko
2014-04-27 01:11:39 +04:00
parent 5839fda22f
commit 2b847cd885
19 changed files with 181 additions and 3 deletions
@@ -207,7 +207,7 @@ public class JetBlock extends AbstractBlock {
return NodeAlignmentStrategy.fromTypes(AlignmentStrategy.wrap(
createAlignment(jetCommonSettings.ALIGN_MULTILINE_BINARY_OPERATION, getAlignment())));
}
else if (parentType == DELEGATION_SPECIFIER_LIST) {
else if (parentType == DELEGATION_SPECIFIER_LIST || parentType == INITIALIZER_LIST) {
return NodeAlignmentStrategy.fromTypes(AlignmentStrategy.wrap(
createAlignment(jetCommonSettings.ALIGN_MULTILINE_EXTENDS_LIST, getAlignment())));
}
@@ -318,7 +318,7 @@ public class JetBlock extends AbstractBlock {
.set(Indent.getContinuationWithoutFirstIndent(true)),
ASTIndentStrategy.forNode("Delegation list")
.in(DELEGATION_SPECIFIER_LIST)
.in(DELEGATION_SPECIFIER_LIST, INITIALIZER_LIST)
.set(Indent.getContinuationIndent(false)),
ASTIndentStrategy.forNode("Indices")
@@ -111,7 +111,7 @@ fun createSpacingBuilder(settings: CodeStyleSettings): KotlinSpacingBuilder {
beforeInside(COLON, TYPE_COLON_ELEMENTS) { spaceIf(jetSettings.SPACE_BEFORE_TYPE_COLON) }
afterInside(COLON, TYPE_COLON_ELEMENTS) { spaceIf(jetSettings.SPACE_AFTER_TYPE_COLON) }
val EXTEND_COLON_ELEMENTS = TokenSet.create(TYPE_CONSTRAINT, CLASS, OBJECT_DECLARATION, TYPE_PARAMETER)
val EXTEND_COLON_ELEMENTS = TokenSet.create(TYPE_CONSTRAINT, CLASS, OBJECT_DECLARATION, TYPE_PARAMETER, ENUM_ENTRY)
beforeInside(COLON, EXTEND_COLON_ELEMENTS) { spaceIf(jetSettings.SPACE_BEFORE_EXTEND_COLON) }
afterInside(COLON, EXTEND_COLON_ELEMENTS) { spaceIf(jetSettings.SPACE_AFTER_EXTEND_COLON) }
@@ -23,4 +23,17 @@ object SimpleObject2 : B1(),
A1,
A2, A3
open class C1
open class C2
enum class Test : A1 {
FIRST_ITEM : Test(), C1(),
C2()
SECOND_ITEM :
Test()
THIRD_ITEM : Test(),
C1() FORTH_ITEM : Test()
}
// SET_TRUE: ALIGN_MULTILINE_EXTENDS_LIST
@@ -23,4 +23,17 @@ object SimpleObject2 : B1(),
A1,
A2, A3
open class C1
open class C2
enum class Test : A1 {
FIRST_ITEM : Test(), C1(),
C2()
SECOND_ITEM :
Test()
THIRD_ITEM : Test(),
C1() FORTH_ITEM : Test()
}
// SET_TRUE: ALIGN_MULTILINE_EXTENDS_LIST
+13
View File
@@ -23,4 +23,17 @@ object SimpleObject2: B1(),
A1,
A2, A3
open class C1
open class C2
enum class Test : A1 {
FIRST_ITEM : Test(), C1(),
C2()
SECOND_ITEM :
Test()
THIRD_ITEM : Test(),
C1() FORTH_ITEM : Test()
}
// SET_TRUE: ALIGN_MULTILINE_EXTENDS_LIST
@@ -0,0 +1,10 @@
enum class Test: A {
FIRST: Test()
SECOND:
Test()
THIRD: Test() FORTH: Test()
}
// SET_TRUE: SPACE_BEFORE_EXTEND_COLON
// SET_FALSE: SPACE_AFTER_EXTEND_COLON
@@ -0,0 +1,10 @@
enum class Test :A {
FIRST :Test()
SECOND :
Test()
THIRD :Test() FORTH :Test()
}
// SET_TRUE: SPACE_BEFORE_EXTEND_COLON
// SET_FALSE: SPACE_AFTER_EXTEND_COLON
@@ -0,0 +1,10 @@
enum class Test : A {
FIRST : Test()
SECOND:
Test()
THIRD: Test() FORTH: Test()
}
// SET_TRUE: SPACE_BEFORE_EXTEND_COLON
// SET_FALSE: SPACE_AFTER_EXTEND_COLON
@@ -0,0 +1,8 @@
// SET_TRUE: ALIGN_MULTILINE_EXTENDS_LIST
trait A1
enum class EnumTest {
ENTRY:
<caret>
}
@@ -0,0 +1,8 @@
// SET_TRUE: ALIGN_MULTILINE_EXTENDS_LIST
trait A1
enum class EnumTest {
ENTRY:
<caret>
}
@@ -0,0 +1,7 @@
// SET_TRUE: ALIGN_MULTILINE_EXTENDS_LIST
trait A1
enum class EnumTest {
ENTRY: <caret>
}
@@ -0,0 +1,8 @@
// SET_TRUE: ALIGN_MULTILINE_EXTENDS_LIST
trait A1
enum class EnumTest {
ENTRY: EnumTest(),
<caret>
}
@@ -0,0 +1,8 @@
// SET_TRUE: ALIGN_MULTILINE_EXTENDS_LIST
trait A1
enum class EnumTest {
ENTRY: EnumTest(),
<caret>
}
@@ -0,0 +1,7 @@
// SET_TRUE: ALIGN_MULTILINE_EXTENDS_LIST
trait A1
enum class EnumTest {
ENTRY: EnumTest(), <caret>
}
@@ -0,0 +1,8 @@
// SET_TRUE: ALIGN_MULTILINE_EXTENDS_LIST
trait A1
enum class EnumTest {
ENTRY: EnumTest(),
<caret>A1
}
@@ -0,0 +1,8 @@
// SET_TRUE: ALIGN_MULTILINE_EXTENDS_LIST
trait A1
enum class EnumTest {
ENTRY: EnumTest(),
<caret>A1
}
@@ -0,0 +1,7 @@
// SET_TRUE: ALIGN_MULTILINE_EXTENDS_LIST
trait A1
enum class EnumTest {
ENTRY: EnumTest(), <caret>A1
}
@@ -264,6 +264,11 @@ public class JetFormatterTestGenerated extends AbstractJetFormatterTest {
doTest("idea/testData/formatter/SpaceAroundExtendColon.after.kt");
}
@TestMetadata("SpaceAroundExtendColonInEnums.after.kt")
public void testSpaceAroundExtendColonInEnums() throws Exception {
doTest("idea/testData/formatter/SpaceAroundExtendColonInEnums.after.kt");
}
@TestMetadata("SpaceAroundExtendColonInObjects.after.kt")
public void testSpaceAroundExtendColonInObjects() throws Exception {
doTest("idea/testData/formatter/SpaceAroundExtendColonInObjects.after.kt");
@@ -532,6 +537,11 @@ public class JetFormatterTestGenerated extends AbstractJetFormatterTest {
doTestInverted("idea/testData/formatter/SpaceAroundExtendColon.after.inv.kt");
}
@TestMetadata("SpaceAroundExtendColonInEnums.after.inv.kt")
public void testSpaceAroundExtendColonInEnums() throws Exception {
doTestInverted("idea/testData/formatter/SpaceAroundExtendColonInEnums.after.inv.kt");
}
@TestMetadata("SpaceAroundExtendColonInObjects.after.inv.kt")
public void testSpaceAroundExtendColonInObjects() throws Exception {
doTestInverted("idea/testData/formatter/SpaceAroundExtendColonInObjects.after.inv.kt");
@@ -139,6 +139,21 @@ public class JetTypingIndentationTestBaseGenerated extends AbstractJetTypingInde
doNewlineTest("idea/testData/indentationOnNewline/InDelegationListNotEmpty.after.kt");
}
@TestMetadata("InEnumInitializerListAfterColon.after.kt")
public void testInEnumInitializerListAfterColon() throws Exception {
doNewlineTest("idea/testData/indentationOnNewline/InEnumInitializerListAfterColon.after.kt");
}
@TestMetadata("InEnumInitializerListAfterComma.after.kt")
public void testInEnumInitializerListAfterComma() throws Exception {
doNewlineTest("idea/testData/indentationOnNewline/InEnumInitializerListAfterComma.after.kt");
}
@TestMetadata("InEnumInitializerListNotEmpty.after.kt")
public void testInEnumInitializerListNotEmpty() throws Exception {
doNewlineTest("idea/testData/indentationOnNewline/InEnumInitializerListNotEmpty.after.kt");
}
@TestMetadata("InExpressionsParentheses.after.kt")
public void testInExpressionsParentheses() throws Exception {
doNewlineTest("idea/testData/indentationOnNewline/InExpressionsParentheses.after.kt");
@@ -242,6 +257,21 @@ public class JetTypingIndentationTestBaseGenerated extends AbstractJetTypingInde
doNewlineTestWithInvert("idea/testData/indentationOnNewline/InDelegationListNotEmpty.after.inv.kt");
}
@TestMetadata("InEnumInitializerListAfterColon.after.inv.kt")
public void testInEnumInitializerListAfterColon() throws Exception {
doNewlineTestWithInvert("idea/testData/indentationOnNewline/InEnumInitializerListAfterColon.after.inv.kt");
}
@TestMetadata("InEnumInitializerListAfterComma.after.inv.kt")
public void testInEnumInitializerListAfterComma() throws Exception {
doNewlineTestWithInvert("idea/testData/indentationOnNewline/InEnumInitializerListAfterComma.after.inv.kt");
}
@TestMetadata("InEnumInitializerListNotEmpty.after.inv.kt")
public void testInEnumInitializerListNotEmpty() throws Exception {
doNewlineTestWithInvert("idea/testData/indentationOnNewline/InEnumInitializerListNotEmpty.after.inv.kt");
}
@TestMetadata("InExpressionsParentheses.after.inv.kt")
public void testInExpressionsParentheses() throws Exception {
doNewlineTestWithInvert("idea/testData/indentationOnNewline/InExpressionsParentheses.after.inv.kt");