Skip to content

Commit a29c27e

Browse files
committed
Pass the latest block while ignoring conditional and loop directive blocks.
1 parent 9fc459b commit a29c27e

File tree

2 files changed

+9
-7
lines changed

2 files changed

+9
-7
lines changed

src/main/kotlin/org/domaframework/doma/intellij/formatter/handler/NotQueryGroupHandler.kt

Lines changed: 2 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,6 @@ package org.domaframework.doma.intellij.formatter.handler
1818
import com.intellij.lang.ASTNode
1919
import org.domaframework.doma.intellij.formatter.block.SqlBlock
2020
import org.domaframework.doma.intellij.formatter.block.SqlCommaBlock
21-
import org.domaframework.doma.intellij.formatter.block.comment.SqlElConditionLoopCommentBlock
2221
import org.domaframework.doma.intellij.formatter.block.conflict.SqlConflictClauseBlock
2322
import org.domaframework.doma.intellij.formatter.block.conflict.SqlConflictExpressionSubGroupBlock
2423
import org.domaframework.doma.intellij.formatter.block.group.keyword.condition.SqlConditionKeywordGroupBlock
@@ -46,19 +45,17 @@ object NotQueryGroupHandler {
4645
lastGroup: SqlBlock?,
4746
child: ASTNode,
4847
sqlBlockFormattingCtx: SqlBlockFormattingContext,
49-
groups: List<SqlBlock>,
5048
): SqlBlock? =
5149
when {
5250
hasInKeyword(lastGroup) -> SqlParallelListBlock(child, sqlBlockFormattingCtx)
53-
lastGroupParentConditionKeywordGroup(groups) -> createConditionalExpressionGroup(child, sqlBlockFormattingCtx)
51+
lastGroupParentConditionKeywordGroup(lastGroup) -> createConditionalExpressionGroup(child, sqlBlockFormattingCtx)
5452
hasFunctionOrAliasContext(lastGroup) -> createFunctionOrValueBlock(lastGroup, child, sqlBlockFormattingCtx)
5553
lastGroup is SqlConflictClauseBlock -> SqlConflictExpressionSubGroupBlock(child, sqlBlockFormattingCtx)
5654
hasValuesContext(lastGroup) -> SqlValuesParamGroupBlock(child, sqlBlockFormattingCtx)
5755
else -> null
5856
}
5957

60-
private fun lastGroupParentConditionKeywordGroup(groups: List<SqlBlock>): Boolean =
61-
groups.lastOrNull { it !is SqlElConditionLoopCommentBlock } is SqlConditionKeywordGroupBlock
58+
private fun lastGroupParentConditionKeywordGroup(lastGroup: SqlBlock?): Boolean = lastGroup is SqlConditionKeywordGroupBlock
6259

6360
/**
6461
* Creates a keyword group block for specific keywords.

src/main/kotlin/org/domaframework/doma/intellij/formatter/util/SqlBlockGenerator.kt

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -345,6 +345,7 @@ class SqlBlockGenerator(
345345
child: ASTNode,
346346
groups: List<SqlBlock>,
347347
): SqlBlock {
348+
val ignoreConditionLoopLastBlock = groups.lastOrNull { it !is SqlElConditionLoopCommentBlock }
348349
when (lastGroup) {
349350
is SqlKeywordGroupBlock -> {
350351
CreateClauseHandler
@@ -368,7 +369,7 @@ class SqlBlockGenerator(
368369

369370
// List-type test data for IN clause
370371
NotQueryGroupHandler
371-
.getSubGroup(lastGroup, child, sqlBlockFormattingCtx, groups)
372+
.getSubGroup(ignoreConditionLoopLastBlock, child, sqlBlockFormattingCtx)
372373
?.let { return it }
373374

374375
return SqlSubQueryGroupBlock(child, sqlBlockFormattingCtx)
@@ -385,7 +386,11 @@ class SqlBlockGenerator(
385386
}
386387

387388
NotQueryGroupHandler
388-
.getSubGroup(lastGroup, child, sqlBlockFormattingCtx, groups)
389+
.getSubGroup(ignoreConditionLoopLastBlock, child, sqlBlockFormattingCtx)
390+
?.let { return it }
391+
392+
NotQueryGroupHandler
393+
.getSubGroup(lastGroup, child, sqlBlockFormattingCtx)
389394
?.let { return it }
390395

391396
return SqlSubQueryGroupBlock(child, sqlBlockFormattingCtx)

0 commit comments

Comments
 (0)