File tree Expand file tree Collapse file tree 4 files changed +28
-4
lines changed
main/kotlin/org/domaframework/doma/intellij/formatter/block
test/testData/sql/formatter Expand file tree Collapse file tree 4 files changed +28
-4
lines changed Original file line number Diff line number Diff line change @@ -136,14 +136,25 @@ open class SqlBlock(
136136 .firstOrNull()
137137 ?.childBlocks
138138
139- val firstConditionBlock = (prevChildren?.firstOrNull() as ? SqlElConditionLoopCommentBlock )
140- val endBlock = firstConditionBlock?.conditionEnd
139+ val firstConditionBlock = prevChildren?.firstOrNull { it is SqlElConditionLoopCommentBlock } as ? SqlElConditionLoopCommentBlock
140+ val endBlock =
141+ findConditionEndBlock(firstConditionBlock)
141142 if (endBlock == null ) return false
142143 val lastBlock = prevBlocks.lastOrNull()
143144
144145 return endBlock.node.startOffset > (lastBlock?.node?.startOffset ? : 0 )
145146 }
146147
148+ private fun findConditionEndBlock (firstConditionBlock : SqlElConditionLoopCommentBlock ? ): SqlElConditionLoopCommentBlock ? =
149+ (
150+ firstConditionBlock?.conditionEnd
151+ ? : (
152+ firstConditionBlock?.childBlocks?.lastOrNull {
153+ it is SqlElConditionLoopCommentBlock
154+ } as ? SqlElConditionLoopCommentBlock
155+ )?.conditionEnd
156+ )
157+
147158 protected fun isFirstChildConditionLoopDirective (): Boolean = childBlocks.firstOrNull() is SqlElConditionLoopCommentBlock
148159
149160 fun getChildBlocksDropLast (
Original file line number Diff line number Diff line change @@ -137,7 +137,7 @@ class SqlElConditionLoopCommentBlock(
137137 }
138138
139139 override fun setParentPropertyBlock (lastGroup : SqlBlock ? ) {
140- if (lastGroup is SqlElConditionLoopCommentBlock && conditionType.isEnd ()) {
140+ if (lastGroup is SqlElConditionLoopCommentBlock && ! conditionType.isStartDirective ()) {
141141 lastGroup.conditionEnd = this
142142 }
143143 }
@@ -195,7 +195,7 @@ class SqlElConditionLoopCommentBlock(
195195 is SqlSubGroupBlock -> return calculateSubGroupBlockIndent(parent, openConditionLoopDirectiveCount)
196196
197197 is SqlElConditionLoopCommentBlock -> {
198- if (conditionType.isEnd ()) {
198+ if (! conditionType.isStartDirective ()) {
199199 parent.conditionEnd = this
200200 conditionStart = parent
201201 return parent.indent.indentLen
Original file line number Diff line number Diff line change @@ -3,6 +3,11 @@ SELECT employee_id
33 , salary
44 , salary * /* yearBonusRate */ 1 .2 AS yearly_bonus
55 , salary + (salary * /* @raiseRate() */ 0 .05 ) AS new_salary
6+ , /* %if parent*/
7+ number1 .d ,
8+ /* %else*/
9+ number2 .e ,
10+ /* %end*/ number .x
611 FROM employee
712 WHERE department_id = /* departmentId */ 1
813 /* %if @minSalary() +extraAmount*/
Original file line number Diff line number Diff line change @@ -3,6 +3,14 @@ SELECT employee_id
33 , salary
44 , salary * /* yearBonusRate */ 1 .2 AS yearly_bonus
55 , salary + (salary * /* @raiseRate() */ 0 .05 ) AS new_salary
6+ , /* %if parent*/
7+ number1 .d
8+ ,
9+ /* %else*/
10+ number2 .e
11+ ,
12+ /* %end*/
13+ number .x
614 FROM employee
715 WHERE department_id = /* departmentId */ 1
816 /* %if @minSalary() + extraAmount*/
You can’t perform that action at this time.
0 commit comments