Skip to content

Commit 90dbb7a

Browse files
committed
Fix parent block search condition when CASE exists within conditional loop directive
1 parent 580b2d9 commit 90dbb7a

File tree

1 file changed

+9
-5
lines changed

1 file changed

+9
-5
lines changed

src/main/kotlin/org/domaframework/doma/intellij/formatter/builder/SqlBlockRelationBuilder.kt

Lines changed: 9 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,7 @@ import org.domaframework.doma.intellij.formatter.block.SqlRightPatternBlock
2222
import org.domaframework.doma.intellij.formatter.block.comment.SqlDefaultCommentBlock
2323
import org.domaframework.doma.intellij.formatter.block.comment.SqlElConditionLoopCommentBlock
2424
import org.domaframework.doma.intellij.formatter.block.conflict.SqlDoGroupBlock
25+
import org.domaframework.doma.intellij.formatter.block.group.SqlNewGroupBlock
2526
import org.domaframework.doma.intellij.formatter.block.group.column.SqlColumnDefinitionRawGroupBlock
2627
import org.domaframework.doma.intellij.formatter.block.group.column.SqlColumnRawGroupBlock
2728
import org.domaframework.doma.intellij.formatter.block.group.keyword.SqlKeywordGroupBlock
@@ -89,9 +90,9 @@ class SqlBlockRelationBuilder(
8990
)
9091
val lastGroup = blockBuilder.getLastGroupTopNodeIndexHistory()
9192
if (lastGroup is SqlElConditionLoopCommentBlock) {
92-
updateParentGroupLastConditionLoop(
93-
lastGroup, context, false) { block ->
94-
block.indent.indentLevel < childBlock.indent.indentLevel
93+
updateParentGroupLastConditionLoop(lastGroup, context, false) { block ->
94+
block.indent.indentLevel < childBlock.indent.indentLevel ||
95+
block is SqlNewGroupBlock
9596
}
9697
return
9798
}
@@ -471,10 +472,13 @@ class SqlBlockRelationBuilder(
471472
handleConditionLoopParentAssignment(lastGroupBlock, context, findParent)
472473
}
473474

474-
private fun findParentForConditionLoop(findDefaultParent: (SqlBlock) -> Boolean,findSubGroup: Boolean =false): SqlBlock? =
475+
private fun findParentForConditionLoop(
476+
findDefaultParent: (SqlBlock) -> Boolean,
477+
findSubGroup: Boolean = false,
478+
): SqlBlock? =
475479
blockBuilder.getGroupTopNodeIndexHistory().lastOrNull { block ->
476480
findDefaultParent(block) ||
477-
findSubGroup && block is SqlSubGroupBlock ||
481+
findSubGroup && block is SqlSubGroupBlock ||
478482
(block is SqlElConditionLoopCommentBlock && block.parentBlock != null)
479483
}
480484

0 commit comments

Comments
 (0)