File tree Expand file tree Collapse file tree 3 files changed +20
-2
lines changed
src/main/kotlin/org/domaframework/doma/intellij/formatter/block Expand file tree Collapse file tree 3 files changed +20
-2
lines changed Original file line number Diff line number Diff line change @@ -135,8 +135,16 @@ open class SqlBlock(
135135 prevBlock is SqlElConditionLoopCommentBlock &&
136136 (prevBlock.conditionType.isElse() || prevBlock.conditionType.isEnd())
137137 val hasNoChildrenExceptLast = parent.childBlocks.dropLast(1 ).isEmpty()
138+ if (parent.conditionType.isElse()) {
139+ return prevBlocks.isEmpty()
140+ }
141+
142+ val isConditionDirectiveParentGroup =
143+ parent.parentBlock?.let { grand ->
144+ grand is SqlNewGroupBlock
145+ } == true
138146
139- return isPrevBlockElseOrEnd || hasNoChildrenExceptLast
147+ return isPrevBlockElseOrEnd || ( hasNoChildrenExceptLast && isConditionDirectiveParentGroup)
140148 }
141149
142150 private fun shouldSaveSpaceForNewGroup (parent : SqlNewGroupBlock ): Boolean {
Original file line number Diff line number Diff line change @@ -17,6 +17,7 @@ package org.domaframework.doma.intellij.formatter.block.group.keyword.condition
1717
1818import com.intellij.lang.ASTNode
1919import org.domaframework.doma.intellij.formatter.block.SqlBlock
20+ import org.domaframework.doma.intellij.formatter.block.comment.SqlElConditionLoopCommentBlock
2021import org.domaframework.doma.intellij.formatter.block.group.keyword.SqlKeywordGroupBlock
2122import org.domaframework.doma.intellij.formatter.block.group.subgroup.SqlSubGroupBlock
2223import org.domaframework.doma.intellij.formatter.util.SqlBlockFormattingContext
@@ -45,7 +46,15 @@ class SqlConditionalExpressionGroupBlock(
4546 }
4647 }
4748
48- override fun createBlockIndentLen (): Int = parentBlock?.indent?.groupIndentLen?.plus(1 ) ? : 1
49+ override fun createBlockIndentLen (): Int =
50+ parentBlock?.let { parent ->
51+ if (parent is SqlElConditionLoopCommentBlock ) {
52+ parent.indent.groupIndentLen
53+ } else {
54+ parent.indent.groupIndentLen.plus(1 )
55+ }
56+ }
57+ ? : offset
4958
5059 override fun createGroupIndentLen (): Int = indent.indentLen.plus(1 )
5160}
Original file line number Diff line number Diff line change @@ -50,6 +50,7 @@ abstract class SqlSubGroupBlock(
5050 SqlWithCommonTableGroupBlock ::class ,
5151 SqlWithColumnGroupBlock ::class ,
5252 SqlCreateViewGroupBlock ::class ,
53+ SqlElConditionLoopCommentBlock ::class ,
5354 )
5455 }
5556
You can’t perform that action at this time.
0 commit comments