Skip to content

Commit f569bc2

Browse files
committed
Add SQL conflict clause and do group block support
1 parent ec5ab28 commit f569bc2

File tree

3 files changed

+95
-0
lines changed

3 files changed

+95
-0
lines changed

src/main/kotlin/org/domaframework/doma/intellij/common/util/TypeUtil.kt

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,8 @@ import org.domaframework.doma.intellij.extension.getJavaClazz
2424
import org.domaframework.doma.intellij.extension.psi.getClassAnnotation
2525
import org.domaframework.doma.intellij.extension.psi.isDomain
2626
import org.domaframework.doma.intellij.extension.psi.isEntity
27+
import org.domaframework.doma.intellij.formatter.block.SqlBlock
28+
import kotlin.reflect.KClass
2729

2830
object TypeUtil {
2931
/**
@@ -94,4 +96,15 @@ object TypeUtil {
9496
if (type == null) return false
9597
return PsiTypeChecker.isBaseClassType(type) || DomaClassName.isOptionalWrapperType(type.canonicalText)
9698
}
99+
100+
/**
101+
* Determines whether the specified class instance matches.
102+
*/
103+
fun isExpectedClassType(
104+
expectedClasses: List<KClass<*>>,
105+
childBlock: SqlBlock,
106+
): Boolean =
107+
expectedClasses.any { clazz ->
108+
clazz.isInstance(childBlock)
109+
}
97110
}
Lines changed: 40 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,40 @@
1+
/*
2+
* Copyright Doma Tools Authors
3+
*
4+
* Licensed under the Apache License, Version 2.0 (the "License");
5+
* you may not use this file except in compliance with the License.
6+
* You may obtain a copy of the License at
7+
*
8+
* https://www.apache.org/licenses/LICENSE-2.0
9+
*
10+
* Unless required by applicable law or agreed to in writing, software
11+
* distributed under the License is distributed on an "AS IS" BASIS,
12+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13+
* See the License for the specific language governing permissions and
14+
* limitations under the License.
15+
*/
16+
package org.domaframework.doma.intellij.formatter.block.conflict
17+
18+
import com.intellij.lang.ASTNode
19+
import org.domaframework.doma.intellij.formatter.block.SqlBlock
20+
import org.domaframework.doma.intellij.formatter.block.group.keyword.SqlKeywordGroupBlock
21+
import org.domaframework.doma.intellij.formatter.util.IndentType
22+
import org.domaframework.doma.intellij.formatter.util.SqlBlockFormattingContext
23+
24+
class SqlConflictClauseBlock(
25+
node: ASTNode,
26+
context: SqlBlockFormattingContext,
27+
) : SqlKeywordGroupBlock(
28+
node,
29+
IndentType.TOP,
30+
context,
31+
) {
32+
var doBlock: SqlDoGroupBlock? = null
33+
34+
override fun setParentGroupBlock(lastGroup: SqlBlock?) {
35+
super.setParentGroupBlock(lastGroup)
36+
indent.indentLevel = IndentType.CONFLICT
37+
indent.indentLen = createBlockIndentLen()
38+
indent.groupIndentLen = indent.indentLen.plus(getNodeText().length)
39+
}
40+
}
Lines changed: 42 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,42 @@
1+
/*
2+
* Copyright Doma Tools Authors
3+
*
4+
* Licensed under the Apache License, Version 2.0 (the "License");
5+
* you may not use this file except in compliance with the License.
6+
* You may obtain a copy of the License at
7+
*
8+
* https://www.apache.org/licenses/LICENSE-2.0
9+
*
10+
* Unless required by applicable law or agreed to in writing, software
11+
* distributed under the License is distributed on an "AS IS" BASIS,
12+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13+
* See the License for the specific language governing permissions and
14+
* limitations under the License.
15+
*/
16+
package org.domaframework.doma.intellij.formatter.block.conflict
17+
18+
import com.intellij.lang.ASTNode
19+
import org.domaframework.doma.intellij.formatter.block.SqlBlock
20+
import org.domaframework.doma.intellij.formatter.block.group.keyword.SqlKeywordGroupBlock
21+
import org.domaframework.doma.intellij.formatter.util.IndentType
22+
import org.domaframework.doma.intellij.formatter.util.SqlBlockFormattingContext
23+
24+
class SqlDoGroupBlock(
25+
node: ASTNode,
26+
context: SqlBlockFormattingContext,
27+
) : SqlKeywordGroupBlock(
28+
node,
29+
IndentType.CONFLICT,
30+
context,
31+
) {
32+
/**
33+
* **NOTHING** or **UPDATE**
34+
*/
35+
var doQueryBlock: SqlBlock? = null
36+
37+
override fun setParentPropertyBlock(lastGroup: SqlBlock?) {
38+
if (lastGroup is SqlConflictClauseBlock) {
39+
lastGroup.doBlock = this
40+
}
41+
}
42+
}

0 commit comments

Comments
 (0)