Skip to content

Commit c7267ab

Browse files
committed
Refactor indentation logic in SqlSubGroupBlock and SqlEscapeBlock, SqlArrayWordBlock for clarity
1 parent 2c55788 commit c7267ab

File tree

3 files changed

+9
-10
lines changed

3 files changed

+9
-10
lines changed

src/main/kotlin/org/domaframework/doma/intellij/formatter/block/group/subgroup/SqlSubGroupBlock.kt

Lines changed: 2 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -109,16 +109,10 @@ abstract class SqlSubGroupBlock(
109109
return offset
110110
}
111111

112-
override fun createGroupIndentLen(): Int {
113-
return parentBlock?.let { parent ->
112+
override fun createGroupIndentLen(): Int =
113+
parentBlock?.let { parent ->
114114
parent.indent.indentLen.plus(parent.getNodeText().length.plus(1))
115115
} ?: indent.indentLen.plus(getNodeText().length)
116-
// parentBlock?.let { parent ->
117-
// // The parent groupIndent includes the number of characters in the group itself.
118-
// val baseGroupLen = parent.indent.groupIndentLen
119-
// return if (parent is SqlSubGroupBlock) baseGroupLen.plus(2) else baseGroupLen
120-
// } ?: return 1
121-
}
122116

123117
override fun isSaveSpace(lastGroup: SqlBlock?): Boolean {
124118
lastGroup?.let { lastBlock ->

src/main/kotlin/org/domaframework/doma/intellij/formatter/block/other/SqlEscapeBlock.kt

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -34,7 +34,8 @@ class SqlEscapeBlock(
3434
}
3535

3636
override fun createBlockIndentLen(): Int {
37-
isEndEscape = parentBlock?.childBlocks?.count { it is SqlEscapeBlock }?.let { it % 2 == 0 } == true || getNodeText() == "]"
37+
val hasEvenEscapeBlocks = parentBlock?.childBlocks?.count { it is SqlEscapeBlock }?.let { it % 2 == 0 } == true
38+
isEndEscape = hasEvenEscapeBlocks || getNodeText() == "]"
3839
return if (isEndEscape) {
3940
0
4041
} else {

src/main/kotlin/org/domaframework/doma/intellij/formatter/block/word/SqlArrayWordBlock.kt

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -48,7 +48,11 @@ open class SqlArrayWordBlock(
4848

4949
override fun buildChildren(): MutableList<AbstractBlock> = mutableListOf()
5050

51-
override fun createBlockIndentLen(): Int = (parentBlock as? SqlElConditionLoopCommentBlock)?.indent?.groupIndentLen ?: 1
51+
override fun createBlockIndentLen(): Int =
52+
when (val parent = parentBlock) {
53+
is SqlElConditionLoopCommentBlock -> parent.indent.groupIndentLen
54+
else -> 1
55+
}
5256

5357
override fun createGroupIndentLen(): Int =
5458
parentBlock

0 commit comments

Comments
 (0)