Skip to content

Commit 69eaf4f

Browse files
committed
Fixed "has_next" and "_index" element types to be treated as primitive types
1 parent 2dcabe8 commit 69eaf4f

File tree

6 files changed

+28
-31
lines changed

6 files changed

+28
-31
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
topParent
338338
}
339339
val parentType = parent.type
340+
// TODO: Display an error message that the property cannot be called.
340341
val classType = parentType as? PsiClassType ?: return null
341342

342343
var competeResult: ValidationCompleteResult? = null
@@ -460,27 +461,13 @@ class ForDirectiveUtil {
460461
""
461462
}
462463

463-
fun resolveForDirectiveClassTypeIfSuffixExists(
464-
project: Project,
465-
searchName: String,
466-
): PsiType? {
464+
fun resolveForDirectiveItemClassTypeBySuffixElement(searchName: String): PsiType? =
467465
if (searchName.endsWith("_has_next")) {
468-
return PsiType.getTypeByName(
469-
"java.lang.Boolean",
470-
project,
471-
GlobalSearchScope.allScope(project),
472-
)
473-
}
474-
475-
if (searchName.endsWith("_index")) {
476-
return PsiType.getTypeByName(
477-
"java.lang.Integer",
478-
project,
479-
GlobalSearchScope.allScope(project),
480-
)
466+
PsiTypes.booleanType()
467+
} else if (searchName.endsWith("_index")) {
468+
PsiTypes.intType()
469+
} else {
470+
null
481471
}
482-
483-
return null
484-
}
485472
}
486473
}

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
@@ -112,29 +112,39 @@ class SqlCompleteTest : DomaSqlTest() {
112112
fun testCompleteForItemHasNext() {
113113
innerDirectiveCompleteTest(
114114
"$testDapName/completeForItemHasNext.sql",
115+
emptyList(),
115116
listOf(
117+
"get()",
118+
"startsWith()",
119+
"permissions",
120+
"MAX_VALUE",
121+
"MIN_VALUE",
116122
"FALSE",
117123
"TRUE",
118124
"TYPE",
119125
"toString()",
120126
"booleanValue()",
121127
),
122-
listOf("get()", "startsWith()", "permissions", "MAX_VALUE", "MIN_VALUE"),
123128
)
124129
}
125130

126131
fun testCompleteForItemIndex() {
127132
innerDirectiveCompleteTest(
128133
"$testDapName/completeForItemIndex.sql",
134+
emptyList(),
129135
listOf(
136+
"get()",
137+
"startsWith()",
138+
"permissions",
139+
"FALSE",
140+
"TRUE",
130141
"BYTES",
131142
"MAX_VALUE",
132143
"MIN_VALUE",
133144
"SIZE",
134145
"TYPE",
135146
"Integer()",
136147
),
137-
listOf("get()", "startsWith()", "permissions", "FALSE", "TRUE"),
138148
)
139149
}
140150

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

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -101,15 +101,15 @@ class SqlSymbolDocumentTestCase : DomaSqlTest() {
101101
fun testDocumentForItemHasNext() {
102102
val sqlName = "documentForItemHasNext"
103103
val result =
104-
"<a href=\"psi_element://java.lang.Boolean\">Boolean</a> item_has_next"
104+
"<a href=\"psi_element://boolean\">boolean</a> item_has_next"
105105

106106
documentationFindTextTest(sqlName, "item_has_next", result)
107107
}
108108

109109
fun testDocumentForItemIndex() {
110110
val sqlName = "documentForItemIndex"
111111
val result =
112-
"<a href=\"psi_element://java.lang.Integer\">Integer</a> item_index"
112+
"<a href=\"psi_element://int\">int</a> item_index"
113113

114114
documentationFindTextTest(sqlName, "item_index", result)
115115
}

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)