Skip to content

Commit 5b5f561

Browse files
authored
Merge pull request #152 from domaframework/fix/fordirective-item-specific-word-element-handling
Fixed specific element types to be treated as primitive types
2 parents 3d9af93 + f70cb45 commit 5b5f561

File tree

9 files changed

+34
-34
lines changed

9 files changed

+34
-34
lines changed

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

Lines changed: 8 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@ import com.intellij.psi.PsiClass
2020
import com.intellij.psi.PsiClassType
2121
import com.intellij.psi.PsiElement
2222
import com.intellij.psi.PsiType
23-
import com.intellij.psi.search.GlobalSearchScope
23+
import com.intellij.psi.PsiTypes
2424
import com.intellij.psi.util.CachedValue
2525
import com.intellij.psi.util.CachedValueProvider
2626
import com.intellij.psi.util.CachedValuesManager
@@ -337,6 +337,7 @@ class ForDirectiveUtil {
337337
val convertOptional = PsiClassTypeUtil.convertOptionalType(topParent.type, project)
338338
PsiParentClass(convertOptional)
339339
}
340+
// TODO: Display an error message that the property cannot be called.
340341
val parentType = PsiClassTypeUtil.convertOptionalType(parent.type, project)
341342
val classType = parentType as? PsiClassType ?: return null
342343

@@ -463,27 +464,13 @@ class ForDirectiveUtil {
463464
""
464465
}
465466

466-
fun resolveForDirectiveClassTypeIfSuffixExists(
467-
project: Project,
468-
searchName: String,
469-
): PsiType? {
467+
fun resolveForDirectiveItemClassTypeBySuffixElement(searchName: String): PsiType? =
470468
if (searchName.endsWith("_has_next")) {
471-
return PsiType.getTypeByName(
472-
"java.lang.Boolean",
473-
project,
474-
GlobalSearchScope.allScope(project),
475-
)
476-
}
477-
478-
if (searchName.endsWith("_index")) {
479-
return PsiType.getTypeByName(
480-
"java.lang.Integer",
481-
project,
482-
GlobalSearchScope.allScope(project),
483-
)
469+
PsiTypes.booleanType()
470+
} else if (searchName.endsWith("_index")) {
471+
PsiTypes.intType()
472+
} else {
473+
null
484474
}
485-
486-
return null
487-
}
488475
}
489476
}

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -409,7 +409,7 @@ class SqlParameterCompletionProvider : CompletionProvider<CompletionParameters>(
409409
ForDirectiveUtil.findForItem(top, forDirectives = forDirectiveBlocks) ?: return false
410410

411411
val forItemClassType = ForDirectiveUtil.getForDirectiveItemClassType(project, forDirectiveBlocks) ?: return false
412-
val specifiedClassType = ForDirectiveUtil.resolveForDirectiveClassTypeIfSuffixExists(project, top.text)
412+
val specifiedClassType = ForDirectiveUtil.resolveForDirectiveItemClassTypeBySuffixElement(top.text)
413413
val topClassType =
414414
if (specifiedClassType != null) {
415415
PsiParentClass(specifiedClassType)

src/main/kotlin/org/domaframework/doma/intellij/document/generator/DocumentDaoParameterGenerator.kt

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -47,7 +47,10 @@ class DocumentDaoParameterGenerator(
4747
var isBatchAnnotation = false
4848
if (ForDirectiveUtil.findForItem(searchElement, forDirectives = forDirectives) != null) {
4949
val forItemClassType = ForDirectiveUtil.getForDirectiveItemClassType(project, forDirectives)
50-
val specifiedClassType = ForDirectiveUtil.resolveForDirectiveClassTypeIfSuffixExists(project, searchElement.text)
50+
val specifiedClassType =
51+
ForDirectiveUtil.resolveForDirectiveItemClassTypeBySuffixElement(
52+
searchElement.text,
53+
)
5154
topParentType =
5255
if (specifiedClassType != null) {
5356
PsiParentClass(specifiedClassType)

src/main/kotlin/org/domaframework/doma/intellij/inspection/sql/visitor/SqlInspectionVisitor.kt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -137,7 +137,7 @@ class SqlInspectionVisitor(
137137
return
138138
}
139139
val specifiedClassType =
140-
ForDirectiveUtil.resolveForDirectiveClassTypeIfSuffixExists(project, topElement.text)
140+
ForDirectiveUtil.resolveForDirectiveItemClassTypeBySuffixElement(topElement.text)
141141
if (specifiedClassType != null) {
142142
PsiParentClass(specifiedClassType)
143143
} else {

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

Lines changed: 12 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -117,29 +117,39 @@ class SqlCompleteTest : DomaSqlTest() {
117117
fun testCompleteForItemHasNext() {
118118
innerDirectiveCompleteTest(
119119
"$testDapName/completeForItemHasNext.sql",
120+
emptyList(),
120121
listOf(
122+
"get()",
123+
"startsWith()",
124+
"permissions",
125+
"MAX_VALUE",
126+
"MIN_VALUE",
121127
"FALSE",
122128
"TRUE",
123129
"TYPE",
124130
"toString()",
125131
"booleanValue()",
126132
),
127-
listOf("get()", "startsWith()", "permissions", "MAX_VALUE", "MIN_VALUE"),
128133
)
129134
}
130135

131136
fun testCompleteForItemIndex() {
132137
innerDirectiveCompleteTest(
133138
"$testDapName/completeForItemIndex.sql",
139+
emptyList(),
134140
listOf(
141+
"get()",
142+
"startsWith()",
143+
"permissions",
144+
"FALSE",
145+
"TRUE",
135146
"BYTES",
136147
"MAX_VALUE",
137148
"MIN_VALUE",
138149
"SIZE",
139150
"TYPE",
140151
"Integer()",
141152
),
142-
listOf("get()", "startsWith()", "permissions", "FALSE", "TRUE"),
143153
)
144154
}
145155

src/test/kotlin/org/domaframework/doma/intellij/document/SqlSymbolDocumentTestCase.kt

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -123,15 +123,15 @@ class SqlSymbolDocumentTestCase : DomaSqlTest() {
123123
fun testDocumentForItemHasNext() {
124124
val sqlName = "documentForItemHasNext"
125125
val result =
126-
"<a href=\"psi_element://java.lang.Boolean\">Boolean</a> item_has_next"
126+
"<a href=\"psi_element://boolean\">boolean</a> item_has_next"
127127

128128
documentationFindTextTest(sqlName, "item_has_next", result)
129129
}
130130

131131
fun testDocumentForItemIndex() {
132132
val sqlName = "documentForItemIndex"
133133
val result =
134-
"<a href=\"psi_element://java.lang.Integer\">Integer</a> item_index"
134+
"<a href=\"psi_element://int\">int</a> item_index"
135135

136136
documentationFindTextTest(sqlName, "item_index", result)
137137
}

src/test/testData/src/main/resources/META-INF/doma/example/dao/EmployeeSummaryDao/bindVariableForItemHasNextAndIndex.sql

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -17,10 +17,10 @@ select p.project_id
1717
/*# "or" */
1818
/*%end */
1919
p.employee_id = /* member.employeeId */0
20-
and p.not_next = /* member_has_next.<error descr="The field or method [NotTRUE] does not exist in the class [Boolean]">NotTRUE</error> */false
21-
and p.next = /* member_has_next.TRUE */false
22-
and p.not_index = /* member_index.<error descr="The field or method [nextValue] does not exist in the class [Integer]">nextValue</error>() */999
23-
and p.index = /* member_index.MIN_VALUE */0
20+
and p.not_next = /* member_has_next */false
21+
and p.next = /* member_has_next */false
22+
and p.not_index = /* member_index */999
23+
and p.index = /* member_index */0
2424
/*%end */
2525
p.employee_id = /* employees.get(0).employeeId */0
2626
/*%end */

src/test/testData/src/main/resources/META-INF/doma/example/dao/SqlCompleteTestDao/completeForItemIndex.sql

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,6 @@ where
33
/*%for item : principal.permissions */
44
index = /* item_index.<caret> */0
55
/*%if item_has_next */
6-
OR flag = /* item_has_next.FALSE */false
6+
OR flag = /* item_has_next */false
77
/*%end */
88
/*%end */

src/test/testData/src/main/resources/META-INF/doma/example/dao/document/DocumentTestDao/documentForItemElementByFieldAccess.sql

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@ SELECT id
33
WHERE category = 'category'
44
-- employeesList -> List<List<Employee>>
55
/*%for employees : employeesList */
6-
-- employees_has_next -> -> List<Employee>
6+
-- employees_has_next -> boolean
77
/*%if employees_has_next */
88
/*# "OR" */
99
/*%end */

0 commit comments

Comments
 (0)