Skip to content

Commit 29fcf34

Browse files
committed
Refactor SQL block classes to remove unused conflict handling and streamline group block structure
1 parent f85d5da commit 29fcf34

File tree

8 files changed

+14
-166
lines changed

8 files changed

+14
-166
lines changed

src/main/kotlin/org/domaframework/doma/intellij/formatter/block/SqlBlock.kt

Lines changed: 0 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -31,8 +31,6 @@ import org.domaframework.doma.intellij.common.util.TypeUtil.isExpectedClassType
3131
import org.domaframework.doma.intellij.formatter.block.comment.SqlBlockCommentBlock
3232
import org.domaframework.doma.intellij.formatter.block.comment.SqlCommentBlock
3333
import org.domaframework.doma.intellij.formatter.block.comment.SqlLineCommentBlock
34-
import org.domaframework.doma.intellij.formatter.block.conflict.SqlConflictClauseBlock
35-
import org.domaframework.doma.intellij.formatter.block.conflict.SqlDoGroupBlock
3634
import org.domaframework.doma.intellij.formatter.block.expr.SqlElBlockCommentBlock
3735
import org.domaframework.doma.intellij.formatter.block.expr.SqlElConditionLoopCommentBlock
3836
import org.domaframework.doma.intellij.formatter.block.expr.SqlElSymbolBlock
@@ -207,16 +205,13 @@ open class SqlBlock(
207205
SqlColumnDefinitionRawGroupBlock::class,
208206
SqlCreateTableColumnDefinitionGroupBlock::class,
209207
SqlUpdateColumnAssignmentSymbolBlock::class,
210-
SqlDoGroupBlock::class,
211208
SqlUpdateColumnAssignmentSymbolBlock::class,
212209
)
213210

214211
if (isExpectedClassType(expectedClassTypes, childBlock)) return true
215212

216213
if (isNewLineSqlComment(child, childBlock)) return true
217214

218-
if (lastGroup is SqlConflictClauseBlock) return false
219-
220215
return (
221216
isNewLineGroupBlockAfterRegistrationChild(childBlock, lastGroup) ||
222217
(childBlock is SqlRightPatternBlock && childBlock.isNewLine(lastGroup))

src/main/kotlin/org/domaframework/doma/intellij/formatter/block/conflict/SqlConflictClauseBlock.kt

Lines changed: 0 additions & 40 deletions
This file was deleted.

src/main/kotlin/org/domaframework/doma/intellij/formatter/block/conflict/SqlDoGroupBlock.kt

Lines changed: 0 additions & 42 deletions
This file was deleted.

src/main/kotlin/org/domaframework/doma/intellij/formatter/block/group/keyword/SqlUpdateKeywordGroupBlock.kt

Lines changed: 4 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -15,31 +15,20 @@
1515
*/
1616
package org.domaframework.doma.intellij.formatter.block.group.keyword
1717

18-
import com.intellij.formatting.Alignment
19-
import com.intellij.formatting.FormattingMode
2018
import com.intellij.formatting.Indent
21-
import com.intellij.formatting.SpacingBuilder
22-
import com.intellij.formatting.Wrap
2319
import com.intellij.lang.ASTNode
2420
import com.intellij.psi.formatter.common.AbstractBlock
25-
import org.domaframework.doma.intellij.formatter.IndentType
2621
import org.domaframework.doma.intellij.formatter.block.SqlBlock
22+
import org.domaframework.doma.intellij.formatter.util.IndentType
23+
import org.domaframework.doma.intellij.formatter.util.SqlBlockFormattingContext
2724

2825
open class SqlUpdateKeywordGroupBlock(
2926
node: ASTNode,
30-
wrap: Wrap?,
31-
alignment: Alignment?,
32-
spacingBuilder: SpacingBuilder,
33-
enableFormat: Boolean,
34-
formatMode: FormattingMode,
27+
context: SqlBlockFormattingContext,
3528
) : SqlKeywordGroupBlock(
3629
node,
3730
IndentType.SECOND,
38-
wrap,
39-
alignment,
40-
spacingBuilder,
41-
enableFormat,
42-
formatMode,
31+
context,
4332
) {
4433
override fun setParentGroupBlock(block: SqlBlock?) {
4534
super.setParentGroupBlock(block)

src/main/kotlin/org/domaframework/doma/intellij/formatter/block/group/keyword/update/SqlUpdateQueryGroupBlock.kt

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,6 @@ package org.domaframework.doma.intellij.formatter.block.group.keyword.update
1717

1818
import com.intellij.lang.ASTNode
1919
import org.domaframework.doma.intellij.formatter.block.SqlBlock
20-
import org.domaframework.doma.intellij.formatter.block.conflict.SqlDoGroupBlock
2120
import org.domaframework.doma.intellij.formatter.block.group.keyword.top.SqlTopQueryGroupBlock
2221
import org.domaframework.doma.intellij.formatter.util.IndentType
2322
import org.domaframework.doma.intellij.formatter.util.SqlBlockFormattingContext
@@ -63,9 +62,6 @@ class SqlUpdateQueryGroupBlock(
6362
return preChildBlock.indent.indentLen.minus(diffPretextLen)
6463
}
6564
} else {
66-
if (preChildBlock is SqlDoGroupBlock && getNodeText() == "update") {
67-
preChildBlock.doQueryBlock = this
68-
}
6965
return createBlockIndentLen(preChildBlock)
7066
}
7167
}

src/main/kotlin/org/domaframework/doma/intellij/formatter/block/group/subgroup/SqlUpdateColumnGroupBlock.kt

Lines changed: 3 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -15,14 +15,11 @@
1515
*/
1616
package org.domaframework.doma.intellij.formatter.block.group.subgroup
1717

18-
import com.intellij.formatting.Alignment
19-
import com.intellij.formatting.FormattingMode
20-
import com.intellij.formatting.SpacingBuilder
21-
import com.intellij.formatting.Wrap
2218
import com.intellij.lang.ASTNode
2319
import com.intellij.psi.formatter.common.AbstractBlock
2420
import org.domaframework.doma.intellij.formatter.block.SqlBlock
2521
import org.domaframework.doma.intellij.formatter.block.group.keyword.SqlUpdateKeywordGroupBlock
22+
import org.domaframework.doma.intellij.formatter.util.SqlBlockFormattingContext
2623
import org.domaframework.doma.intellij.psi.SqlTypes
2724

2825
/**
@@ -31,18 +28,10 @@ import org.domaframework.doma.intellij.psi.SqlTypes
3128
*/
3229
class SqlUpdateColumnGroupBlock(
3330
node: ASTNode,
34-
wrap: Wrap?,
35-
alignment: Alignment?,
36-
spacingBuilder: SpacingBuilder,
37-
enableFormat: Boolean,
38-
formatMode: FormattingMode,
31+
context: SqlBlockFormattingContext,
3932
) : SqlSubGroupBlock(
4033
node,
41-
wrap,
42-
alignment,
43-
spacingBuilder,
44-
enableFormat,
45-
formatMode,
34+
context,
4635
) {
4736
override fun setParentGroupBlock(block: SqlBlock?) {
4837
super.setParentGroupBlock(block)

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

Lines changed: 7 additions & 45 deletions
Original file line numberDiff line numberDiff line change
@@ -31,15 +31,12 @@ import org.domaframework.doma.intellij.formatter.block.SqlTableBlock
3131
import org.domaframework.doma.intellij.formatter.block.SqlWordBlock
3232
import org.domaframework.doma.intellij.formatter.block.comment.SqlBlockCommentBlock
3333
import org.domaframework.doma.intellij.formatter.block.comment.SqlCommentBlock
34-
import org.domaframework.doma.intellij.formatter.block.conflict.SqlConflictClauseBlock
35-
import org.domaframework.doma.intellij.formatter.block.conflict.SqlDoGroupBlock
3634
import org.domaframework.doma.intellij.formatter.block.expr.SqlElBlockCommentBlock
3735
import org.domaframework.doma.intellij.formatter.block.expr.SqlElConditionLoopCommentBlock
3836
import org.domaframework.doma.intellij.formatter.block.group.column.SqlColumnBlock
3937
import org.domaframework.doma.intellij.formatter.block.group.column.SqlColumnDefinitionRawGroupBlock
4038
import org.domaframework.doma.intellij.formatter.block.group.keyword.SqlInlineGroupBlock
4139
import org.domaframework.doma.intellij.formatter.block.group.keyword.SqlInlineSecondGroupBlock
42-
import org.domaframework.doma.intellij.formatter.block.group.keyword.SqlJoinGroupBlock
4340
import org.domaframework.doma.intellij.formatter.block.group.keyword.SqlKeywordGroupBlock
4441
import org.domaframework.doma.intellij.formatter.block.group.keyword.condition.SqlConditionKeywordGroupBlock
4542
import org.domaframework.doma.intellij.formatter.block.group.keyword.condition.SqlConditionalExpressionGroupBlock
@@ -123,13 +120,6 @@ class SqlBlockUtil(
123120
}
124121
}
125122

126-
IndentType.CONFLICT -> {
127-
if (lastGroupBlock is SqlConflictClauseBlock) {
128-
return SqlKeywordBlock(child, indentLevel, sqlBlockFormattingCtx)
129-
}
130-
return SqlConflictClauseBlock(child, sqlBlockFormattingCtx)
131-
}
132-
133123
else -> return SqlKeywordBlock(child, indentLevel, sqlBlockFormattingCtx)
134124
}
135125
return SqlKeywordBlock(child, indentLevel, sqlBlockFormattingCtx)
@@ -140,10 +130,10 @@ class SqlBlockUtil(
140130
keywordText: String,
141131
child: ASTNode,
142132
lastGroupBlock: SqlBlock?,
143-
): SqlBlock {
133+
): SqlBlock =
144134
when (indentLevel) {
145135
IndentType.JOIN -> {
146-
return JoinGroupUtil.getJoinKeywordGroupBlock(
136+
JoinGroupUtil.getJoinKeywordGroupBlock(
147137
lastGroupBlock,
148138
keywordText,
149139
child,
@@ -152,14 +142,14 @@ class SqlBlockUtil(
152142
}
153143

154144
IndentType.INLINE_SECOND -> {
155-
return SqlInlineSecondGroupBlock(
145+
SqlInlineSecondGroupBlock(
156146
child,
157147
sqlBlockFormattingCtx,
158148
)
159149
}
160150

161151
IndentType.TOP -> {
162-
return when (keywordText) {
152+
when (keywordText) {
163153
"select" ->
164154
SqlSelectQueryGroupBlock(
165155
child,
@@ -178,12 +168,6 @@ class SqlBlockUtil(
178168
sqlBlockFormattingCtx,
179169
)
180170

181-
"do" ->
182-
SqlDoGroupBlock(
183-
child,
184-
sqlBlockFormattingCtx,
185-
)
186-
187171
"update" ->
188172
SqlUpdateQueryGroupBlock(
189173
child,
@@ -200,7 +184,7 @@ class SqlBlockUtil(
200184
}
201185

202186
IndentType.SECOND -> {
203-
return if (keywordText == "set") {
187+
if (keywordText == "set") {
204188
SqlUpdateSetGroupBlock(
205189
child,
206190
sqlBlockFormattingCtx,
@@ -215,12 +199,7 @@ class SqlBlockUtil(
215199
}
216200

217201
IndentType.SECOND_OPTION -> {
218-
return if (keywordText == "on" && lastGroupBlock !is SqlJoinGroupBlock) {
219-
SqlConflictClauseBlock(
220-
child,
221-
sqlBlockFormattingCtx,
222-
)
223-
} else if (SqlKeywordUtil.isConditionKeyword(keywordText)) {
202+
if (SqlKeywordUtil.isConditionKeyword(keywordText)) {
224203
SqlConditionKeywordGroupBlock(
225204
child,
226205
sqlBlockFormattingCtx,
@@ -234,31 +213,14 @@ class SqlBlockUtil(
234213
}
235214
}
236215

237-
IndentType.CONFLICT -> {
238-
return if (lastGroupBlock is SqlConflictClauseBlock) {
239-
SqlKeywordBlock(
240-
child,
241-
indentLevel,
242-
sqlBlockFormattingCtx,
243-
)
244-
} else {
245-
SqlKeywordGroupBlock(
246-
child,
247-
indentLevel,
248-
sqlBlockFormattingCtx,
249-
)
250-
}
251-
}
252-
253216
else -> {
254-
return SqlKeywordGroupBlock(
217+
SqlKeywordGroupBlock(
255218
child,
256219
indentLevel,
257220
sqlBlockFormattingCtx,
258221
)
259222
}
260223
}
261-
}
262224

263225
fun getSubGroupBlock(
264226
lastGroup: SqlBlock?,

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

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,6 @@ enum class IndentType(
2020
private val group: Boolean = false,
2121
) {
2222
FILE(0, true),
23-
CONFLICT(1, true),
2423
TOP(1, true),
2524
SECOND(2, true),
2625
JOIN(3, true),

0 commit comments

Comments
 (0)