File tree Expand file tree Collapse file tree 4 files changed +23
-4
lines changed
main/kotlin/org/domaframework/doma/intellij/formatter/block
test/testData/sql/formatter Expand file tree Collapse file tree 4 files changed +23
-4
lines changed Original file line number Diff line number Diff line change @@ -136,8 +136,14 @@ 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+ firstConditionBlock?.conditionEnd
142+ ? : (
143+ firstConditionBlock?.childBlocks?.lastOrNull {
144+ it is SqlElConditionLoopCommentBlock
145+ } as ? SqlElConditionLoopCommentBlock
146+ )?.conditionEnd
141147 if (endBlock == null ) return false
142148 val lastBlock = prevBlocks.lastOrNull()
143149
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