Skip to content

Commit 96253f7

Browse files
committed
Refactor indentation logic and streamline expected types in SQL block classes
1 parent 3c4aa79 commit 96253f7

File tree

2 files changed

+17
-19
lines changed

2 files changed

+17
-19
lines changed

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

Lines changed: 15 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -49,6 +49,20 @@ open class SqlCommaBlock(
4949
context.enableFormat,
5050
context.formatMode,
5151
) {
52+
companion object {
53+
private val expectedTypes =
54+
listOf(
55+
SqlInsertColumnGroupBlock::class,
56+
SqlInsertValueGroupBlock::class,
57+
SqlUpdateSetGroupBlock::class,
58+
SqlUpdateColumnGroupBlock::class,
59+
SqlUpdateValueGroupBlock::class,
60+
SqlFunctionParamBlock::class,
61+
SqlWithColumnGroupBlock::class,
62+
SqlKeywordGroupBlock::class,
63+
)
64+
}
65+
5266
override val indent =
5367
ElementIndent(
5468
IndentType.COMMA,
@@ -126,23 +140,7 @@ open class SqlCommaBlock(
126140
}
127141

128142
override fun isSaveSpace(lastGroup: SqlBlock?): Boolean {
129-
val excludeTypes =
130-
listOf(
131-
SqlConditionalExpressionGroupBlock::class,
132-
)
133-
if (TypeUtil.isExpectedClassType(excludeTypes, parentBlock)) return false
134-
135-
val expectedTypes =
136-
listOf(
137-
SqlInsertColumnGroupBlock::class,
138-
SqlInsertValueGroupBlock::class,
139-
SqlUpdateSetGroupBlock::class,
140-
SqlUpdateColumnGroupBlock::class,
141-
SqlUpdateValueGroupBlock::class,
142-
SqlFunctionParamBlock::class,
143-
SqlWithColumnGroupBlock::class,
144-
SqlKeywordGroupBlock::class,
145-
)
143+
if (parentBlock is SqlConditionalExpressionGroupBlock) return false
146144
return TypeUtil.isExpectedClassType(expectedTypes, parentBlock)
147145
}
148146
}

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

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -55,8 +55,8 @@ open class SqlInlineSecondGroupBlock(
5555
parentBlock?.let { parent ->
5656
// TODO:Customize indentation within an inline group
5757
if (isEndCase) {
58-
val diff = parent.getNodeText().length.minus(getNodeText().length)
59-
parent.indent.indentLen.plus(diff)
58+
val diffTextLength = parent.getNodeText().length.minus(getNodeText().length)
59+
parent.indent.indentLen.plus(diffTextLength)
6060
} else {
6161
parent.indent.groupIndentLen.plus(1)
6262
}

0 commit comments

Comments
 (0)