Skip to content

Commit ab0a522

Browse files
committed
Refactor SQL indentation logic for sub-group blocks and clean up formatting
1 parent 4de78cd commit ab0a522

File tree

1 file changed

+11
-8
lines changed

1 file changed

+11
-8
lines changed

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

Lines changed: 11 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -69,7 +69,7 @@ class SqlElConditionLoopCommentBlock(
6969
companion object {
7070
private const val DIRECTIVE_INDENT_STEP = 2
7171
private const val DEFAULT_INDENT_OFFSET = 1
72-
72+
7373
private val LINE_BREAK_PARENT_TYPES =
7474
listOf(
7575
SqlSubGroupBlock::class,
@@ -273,11 +273,14 @@ class SqlElConditionLoopCommentBlock(
273273
}
274274

275275
fun checkConditionLoopDirectiveParentBlock(block: SqlBlock): Boolean = isBeforeParentBlock() && parentBlock == block
276-
277-
private fun calculateSubGroupBlockIndent(parent: SqlSubGroupBlock, openDirectiveCount: Int): Int {
276+
277+
private fun calculateSubGroupBlockIndent(
278+
parent: SqlSubGroupBlock,
279+
openDirectiveCount: Int,
280+
): Int {
278281
val parentGroupIndentLen = parent.indent.groupIndentLen
279282
val grand = parent.parentBlock
280-
283+
281284
grand?.let { grandParent ->
282285
when (grandParent) {
283286
is SqlCreateKeywordGroupBlock -> {
@@ -292,23 +295,23 @@ class SqlElConditionLoopCommentBlock(
292295
}
293296
}
294297
}
295-
298+
296299
return if (shouldNotIndent(parent)) {
297300
parentGroupIndentLen.plus(openDirectiveCount * DIRECTIVE_INDENT_STEP)
298301
} else {
299302
parentGroupIndentLen.plus(openDirectiveCount * DIRECTIVE_INDENT_STEP).plus(DEFAULT_INDENT_OFFSET)
300303
}
301304
}
302-
305+
303306
private fun calculatePreviousTextLength(parent: SqlSubGroupBlock): Int {
304307
var prevTextLen = DEFAULT_INDENT_OFFSET
305308
parent.prevChildren?.dropLast(1)?.forEach { prev ->
306309
prevTextLen = prevTextLen.plus(prev.getNodeText().length)
307310
}
308311
return prevTextLen
309312
}
310-
313+
311314
private fun shouldNotIndent(parent: SqlSubGroupBlock): Boolean =
312315
TypeUtil.isExpectedClassType(SqlRightPatternBlock.NOT_INDENT_EXPECTED_TYPES, parent) ||
313-
parent is SqlWithCommonTableGroupBlock
316+
parent is SqlWithCommonTableGroupBlock
314317
}

0 commit comments

Comments
 (0)