Skip to content

Commit 053c7a4

Browse files
committed
Add support for batch annotation with SQL completion
1 parent 329df87 commit 053c7a4

File tree

5 files changed

+26
-22
lines changed

5 files changed

+26
-22
lines changed

src/main/kotlin/org/domaframework/doma/intellij/contributor/sql/provider/SqlParameterCompletionProvider.kt

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -48,8 +48,6 @@ import org.domaframework.doma.intellij.extension.psi.findNodeParent
4848
import org.domaframework.doma.intellij.extension.psi.findSelfBlocks
4949
import org.domaframework.doma.intellij.extension.psi.findStaticField
5050
import org.domaframework.doma.intellij.extension.psi.findStaticMethod
51-
import org.domaframework.doma.intellij.extension.psi.getDomaAnnotationType
52-
import org.domaframework.doma.intellij.extension.psi.getIterableClazz
5351
import org.domaframework.doma.intellij.extension.psi.isNotWhiteSpace
5452
import org.domaframework.doma.intellij.extension.psi.searchParameter
5553
import org.domaframework.doma.intellij.extension.psi.searchStaticField
@@ -370,8 +368,8 @@ class SqlParameterCompletionProvider : CompletionProvider<CompletionParameters>(
370368
if (findParam == null) {
371369
return null
372370
}
373-
val immediate = findParam.getIterableClazz(daoMethod.getDomaAnnotationType())
374-
return PsiClassTypeUtil.convertOptionalType(immediate.type, originalFile.project)
371+
val immediate = findParam.type
372+
return PsiClassTypeUtil.convertOptionalType(immediate, originalFile.project)
375373
}
376374

377375
private fun getRefClazz(

src/main/kotlin/org/domaframework/doma/intellij/extension/psi/PsiParameterExtension.kt

Lines changed: 0 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -17,24 +17,6 @@ package org.domaframework.doma.intellij.extension.psi
1717

1818
import com.intellij.psi.PsiClassType
1919
import com.intellij.psi.PsiParameter
20-
import org.domaframework.doma.intellij.common.psi.PsiParentClass
21-
import org.domaframework.doma.intellij.common.sql.PsiClassTypeUtil
22-
23-
/**
24-
* For List type, if the annotation type is Batch type,
25-
* return the content type.
26-
*/
27-
fun PsiParameter.getIterableClazz(annotationType: DomaAnnotationType): PsiParentClass = getIterableClazz(annotationType.isBatchAnnotation())
28-
29-
fun PsiParameter.getIterableClazz(useListParam: Boolean): PsiParentClass {
30-
val immediate = this.type as? PsiClassType
31-
val classType = immediate?.let { PsiClassTypeUtil.getPsiTypeByList(it, this.project, useListParam) }
32-
if (classType != null) {
33-
val convertOptional = PsiClassTypeUtil.convertOptionalType(classType, this.project)
34-
return PsiParentClass(convertOptional)
35-
}
36-
return PsiParentClass(this.type)
37-
}
3820

3921
val PsiParameter.isFunctionClazz: Boolean
4022
get() =

src/test/kotlin/org/domaframework/doma/intellij/complate/sql/SqlCompleteTest.kt

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -34,6 +34,7 @@ class SqlCompleteTest : DomaSqlTest() {
3434
"$testDapName/completeInstancePropertyFromDaoArgumentClass.sql",
3535
"$testDapName/completeJavaPackageClass.sql",
3636
"$testDapName/completeDirective.sql",
37+
"$testDapName/completeBatchInsert.sql",
3738
"$testDapName/completeStaticPropertyFromStaticPropertyCall.sql",
3839
"$testDapName/completePropertyAfterStaticPropertyCall.sql",
3940
"$testDapName/completeBuiltinFunction.sql",
@@ -161,6 +162,21 @@ class SqlCompleteTest : DomaSqlTest() {
161162
)
162163
}
163164

165+
fun testCompleteBatchInsert() {
166+
innerDirectiveCompleteTest(
167+
"$testDapName/completeBatchInsert.sql",
168+
listOf(
169+
"employeeId",
170+
"employeeName",
171+
),
172+
listOf(
173+
"userId",
174+
"get()",
175+
"size()",
176+
),
177+
)
178+
}
179+
164180
fun testCompleteStaticPropertyFromStaticPropertyCall() {
165181
innerDirectiveCompleteTest(
166182
"$testDapName/completeStaticPropertyFromStaticPropertyCall.sql",

src/test/testData/src/main/java/doma/example/dao/SqlCompleteTestDao.java

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,9 @@ interface SqlCompleteTestDao {
2525
@Update(sqlFile = true)
2626
int completeDirective(Employee employee);
2727

28+
@BatchInsert(sqlFile = true)
29+
int completeBatchInsert(List<Employee> employees);
30+
2831
@Select
2932
Project completeStaticPropertyFromStaticPropertyCall(ProjectDetail detail);
3033

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
INSERT INTO employee
2+
(id
3+
, name)
4+
VALUES ( /* employees.userId */0
5+
, /* employees.<caret>emplo */'name')

0 commit comments

Comments
 (0)