Skip to content

Commit 580b2d9

Browse files
committed
Control line breaks for CASE, WHEN, and conditional keywords (AND, OR) in CASE-END
1 parent 88e77b3 commit 580b2d9

File tree

3 files changed

+16
-2
lines changed

3 files changed

+16
-2
lines changed

src/main/kotlin/org/domaframework/doma/intellij/formatter/block/group/keyword/condition/SqlConditionKeywordGroupBlock.kt

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -57,6 +57,7 @@ class SqlConditionKeywordGroupBlock(
5757
return when (parent) {
5858
is SqlElConditionLoopCommentBlock -> parent.indent.groupIndentLen
5959
is SqlSubGroupBlock -> calculateSubGroupIndent(groupLen)
60+
is SqlInlineSecondGroupBlock -> calculateInlineSecondIndent(groupLen)
6061
else -> parent.indent.groupIndentLen - getNodeText().length
6162
}
6263
}
@@ -68,6 +69,13 @@ class SqlConditionKeywordGroupBlock(
6869
groupLen + 1
6970
}
7071

72+
private fun calculateInlineSecondIndent(groupLen: Int): Int =
73+
if (getNodeText() == "and") {
74+
groupLen.plus(1)
75+
} else {
76+
groupLen.plus(2)
77+
}
78+
7179
override fun createGroupIndentLen(): Int {
7280
parentBlock?.let { parent ->
7381
if (parent is SqlWhereGroupBlock) {

src/main/kotlin/org/domaframework/doma/intellij/formatter/block/group/keyword/inline/SqlInlineGroupBlock.kt

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -60,4 +60,11 @@ open class SqlInlineGroupBlock(
6060
} ?: 1
6161

6262
override fun createGroupIndentLen(): Int = indent.indentLen.plus(getNodeText().length)
63+
64+
override fun isSaveSpace(lastGroup: SqlBlock?): Boolean {
65+
if (lastGroup is SqlInlineSecondGroupBlock) {
66+
return true
67+
}
68+
return super.isSaveSpace(lastGroup)
69+
}
6370
}

src/main/kotlin/org/domaframework/doma/intellij/formatter/block/group/keyword/inline/SqlInlineSecondGroupBlock.kt

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -66,6 +66,5 @@ open class SqlInlineSecondGroupBlock(
6666

6767
override fun createGroupIndentLen(): Int = indent.indentLen.plus(getNodeText().length)
6868

69-
override fun isSaveSpace(lastGroup: SqlBlock?): Boolean =
70-
(parentBlock as? SqlInlineGroupBlock)?.inlineConditions?.dropLast(1)?.isEmpty() != true
69+
override fun isSaveSpace(lastGroup: SqlBlock?): Boolean = true
7170
}

0 commit comments

Comments
 (0)