Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ import com.intellij.psi.PsiClass
import com.intellij.psi.PsiClassType
import com.intellij.psi.PsiElement
import com.intellij.psi.PsiType
import com.intellij.psi.search.GlobalSearchScope
import com.intellij.psi.PsiTypes
import com.intellij.psi.util.CachedValue
import com.intellij.psi.util.CachedValueProvider
import com.intellij.psi.util.CachedValuesManager
Expand Down Expand Up @@ -337,6 +337,7 @@ class ForDirectiveUtil {
val convertOptional = PsiClassTypeUtil.convertOptionalType(topParent.type, project)
PsiParentClass(convertOptional)
}
// TODO: Display an error message that the property cannot be called.
val parentType = PsiClassTypeUtil.convertOptionalType(parent.type, project)
val classType = parentType as? PsiClassType ?: return null

Expand Down Expand Up @@ -463,27 +464,13 @@ class ForDirectiveUtil {
""
}

fun resolveForDirectiveClassTypeIfSuffixExists(
project: Project,
searchName: String,
): PsiType? {
fun resolveForDirectiveItemClassTypeBySuffixElement(searchName: String): PsiType? =
if (searchName.endsWith("_has_next")) {
return PsiType.getTypeByName(
"java.lang.Boolean",
project,
GlobalSearchScope.allScope(project),
)
}

if (searchName.endsWith("_index")) {
return PsiType.getTypeByName(
"java.lang.Integer",
project,
GlobalSearchScope.allScope(project),
)
PsiTypes.booleanType()
} else if (searchName.endsWith("_index")) {
PsiTypes.intType()
} else {
null
}

return null
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -409,7 +409,7 @@ class SqlParameterCompletionProvider : CompletionProvider<CompletionParameters>(
ForDirectiveUtil.findForItem(top, forDirectives = forDirectiveBlocks) ?: return false

val forItemClassType = ForDirectiveUtil.getForDirectiveItemClassType(project, forDirectiveBlocks) ?: return false
val specifiedClassType = ForDirectiveUtil.resolveForDirectiveClassTypeIfSuffixExists(project, top.text)
val specifiedClassType = ForDirectiveUtil.resolveForDirectiveItemClassTypeBySuffixElement(top.text)
val topClassType =
if (specifiedClassType != null) {
PsiParentClass(specifiedClassType)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,10 @@ class DocumentDaoParameterGenerator(
var isBatchAnnotation = false
if (ForDirectiveUtil.findForItem(searchElement, forDirectives = forDirectives) != null) {
val forItemClassType = ForDirectiveUtil.getForDirectiveItemClassType(project, forDirectives)
val specifiedClassType = ForDirectiveUtil.resolveForDirectiveClassTypeIfSuffixExists(project, searchElement.text)
val specifiedClassType =
ForDirectiveUtil.resolveForDirectiveItemClassTypeBySuffixElement(
searchElement.text,
)
topParentType =
if (specifiedClassType != null) {
PsiParentClass(specifiedClassType)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -137,7 +137,7 @@ class SqlInspectionVisitor(
return
}
val specifiedClassType =
ForDirectiveUtil.resolveForDirectiveClassTypeIfSuffixExists(project, topElement.text)
ForDirectiveUtil.resolveForDirectiveItemClassTypeBySuffixElement(topElement.text)
if (specifiedClassType != null) {
PsiParentClass(specifiedClassType)
} else {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -117,29 +117,39 @@ class SqlCompleteTest : DomaSqlTest() {
fun testCompleteForItemHasNext() {
innerDirectiveCompleteTest(
"$testDapName/completeForItemHasNext.sql",
emptyList(),
listOf(
"get()",
"startsWith()",
"permissions",
"MAX_VALUE",
"MIN_VALUE",
"FALSE",
"TRUE",
"TYPE",
"toString()",
"booleanValue()",
),
listOf("get()", "startsWith()", "permissions", "MAX_VALUE", "MIN_VALUE"),
)
}

fun testCompleteForItemIndex() {
innerDirectiveCompleteTest(
"$testDapName/completeForItemIndex.sql",
emptyList(),
listOf(
"get()",
"startsWith()",
"permissions",
"FALSE",
"TRUE",
"BYTES",
"MAX_VALUE",
"MIN_VALUE",
"SIZE",
"TYPE",
"Integer()",
),
listOf("get()", "startsWith()", "permissions", "FALSE", "TRUE"),
)
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -123,15 +123,15 @@ class SqlSymbolDocumentTestCase : DomaSqlTest() {
fun testDocumentForItemHasNext() {
val sqlName = "documentForItemHasNext"
val result =
"<a href=\"psi_element://java.lang.Boolean\">Boolean</a> item_has_next"
"<a href=\"psi_element://boolean\">boolean</a> item_has_next"

documentationFindTextTest(sqlName, "item_has_next", result)
}

fun testDocumentForItemIndex() {
val sqlName = "documentForItemIndex"
val result =
"<a href=\"psi_element://java.lang.Integer\">Integer</a> item_index"
"<a href=\"psi_element://int\">int</a> item_index"

documentationFindTextTest(sqlName, "item_index", result)
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,10 +17,10 @@ select p.project_id
/*# "or" */
/*%end */
p.employee_id = /* member.employeeId */0
and p.not_next = /* member_has_next.<error descr="The field or method [NotTRUE] does not exist in the class [Boolean]">NotTRUE</error> */false
and p.next = /* member_has_next.TRUE */false
and p.not_index = /* member_index.<error descr="The field or method [nextValue] does not exist in the class [Integer]">nextValue</error>() */999
and p.index = /* member_index.MIN_VALUE */0
and p.not_next = /* member_has_next */false
and p.next = /* member_has_next */false
and p.not_index = /* member_index */999
and p.index = /* member_index */0
/*%end */
p.employee_id = /* employees.get(0).employeeId */0
/*%end */
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,6 @@ where
/*%for item : principal.permissions */
index = /* item_index.<caret> */0
/*%if item_has_next */
OR flag = /* item_has_next.FALSE */false
OR flag = /* item_has_next */false
/*%end */
/*%end */
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ SELECT id
WHERE category = 'category'
-- employeesList -> List<List<Employee>>
/*%for employees : employeesList */
-- employees_has_next -> -> List<Employee>
-- employees_has_next -> boolean
/*%if employees_has_next */
/*# "OR" */
/*%end */
Expand Down