Skip to content

Commit a661681

Browse files
committed
Refactor SQL indentation logic for condition loop blocks to improve clarity and accuracy
1 parent 08ff1fe commit a661681

File tree

1 file changed

+9
-12
lines changed

1 file changed

+9
-12
lines changed

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

Lines changed: 9 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -221,20 +221,17 @@ class SqlElConditionLoopCommentBlock(
221221
is SqlKeywordGroupBlock -> {
222222
// At this point, it's not possible to determine whether the parent keyword group appears before or after this block based solely on the parent-child relationship.
223223
// Therefore, determine the position directly using the text offset.
224-
return if (!isBeforeParentBlock()) {
225-
val lastBlockConditionLoopCommentBlock: SqlElConditionLoopCommentBlock? = getLastBlockHasConditionLoopDirective()
226-
if (lastBlockConditionLoopCommentBlock != null && lastBlockConditionLoopCommentBlock.conditionEnd != null) {
227-
lastBlockConditionLoopCommentBlock.indent.indentLen
228-
} else {
229-
// The child branch applies in cases where a conditional directive is included as a child of this block.
230-
val questOffset = if (parent is SqlWithQueryGroupBlock) 0 else 1
231-
parent.indent.groupIndentLen
232-
.plus(openConditionLoopDirectiveCount * DIRECTIVE_INDENT_STEP)
233-
.plus(questOffset)
224+
if (isBeforeParentBlock()) {
225+
return parent.indent.indentLen + openConditionLoopDirectiveCount * DIRECTIVE_INDENT_STEP
226+
}
227+
getLastBlockHasConditionLoopDirective()?.let { lastBlock ->
228+
if (lastBlock.conditionEnd != null) {
229+
return lastBlock.indent.indentLen
234230
}
235-
} else {
236-
parent.indent.indentLen.plus(openConditionLoopDirectiveCount * DIRECTIVE_INDENT_STEP)
237231
}
232+
return parent.indent.groupIndentLen +
233+
openConditionLoopDirectiveCount * DIRECTIVE_INDENT_STEP +
234+
if (parent !is SqlWithQueryGroupBlock) 1 else 0
238235
}
239236
else -> return parent.indent.indentLen.plus(openConditionLoopDirectiveCount * DIRECTIVE_INDENT_STEP)
240237
}

0 commit comments

Comments
 (0)