diff --git a/src/main/kotlin/org/domaframework/doma/intellij/common/util/ForDirectiveUtil.kt b/src/main/kotlin/org/domaframework/doma/intellij/common/util/ForDirectiveUtil.kt index 267eb5ee..c73fab47 100644 --- a/src/main/kotlin/org/domaframework/doma/intellij/common/util/ForDirectiveUtil.kt +++ b/src/main/kotlin/org/domaframework/doma/intellij/common/util/ForDirectiveUtil.kt @@ -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 @@ -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 @@ -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 - } } } diff --git a/src/main/kotlin/org/domaframework/doma/intellij/contributor/sql/provider/SqlParameterCompletionProvider.kt b/src/main/kotlin/org/domaframework/doma/intellij/contributor/sql/provider/SqlParameterCompletionProvider.kt index 55a8b2cc..1a4219f7 100644 --- a/src/main/kotlin/org/domaframework/doma/intellij/contributor/sql/provider/SqlParameterCompletionProvider.kt +++ b/src/main/kotlin/org/domaframework/doma/intellij/contributor/sql/provider/SqlParameterCompletionProvider.kt @@ -409,7 +409,7 @@ class SqlParameterCompletionProvider : CompletionProvider( 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) diff --git a/src/main/kotlin/org/domaframework/doma/intellij/document/generator/DocumentDaoParameterGenerator.kt b/src/main/kotlin/org/domaframework/doma/intellij/document/generator/DocumentDaoParameterGenerator.kt index 65706b7b..20333ef7 100644 --- a/src/main/kotlin/org/domaframework/doma/intellij/document/generator/DocumentDaoParameterGenerator.kt +++ b/src/main/kotlin/org/domaframework/doma/intellij/document/generator/DocumentDaoParameterGenerator.kt @@ -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) diff --git a/src/main/kotlin/org/domaframework/doma/intellij/inspection/sql/visitor/SqlInspectionVisitor.kt b/src/main/kotlin/org/domaframework/doma/intellij/inspection/sql/visitor/SqlInspectionVisitor.kt index 47f0b52e..e6d414aa 100644 --- a/src/main/kotlin/org/domaframework/doma/intellij/inspection/sql/visitor/SqlInspectionVisitor.kt +++ b/src/main/kotlin/org/domaframework/doma/intellij/inspection/sql/visitor/SqlInspectionVisitor.kt @@ -137,7 +137,7 @@ class SqlInspectionVisitor( return } val specifiedClassType = - ForDirectiveUtil.resolveForDirectiveClassTypeIfSuffixExists(project, topElement.text) + ForDirectiveUtil.resolveForDirectiveItemClassTypeBySuffixElement(topElement.text) if (specifiedClassType != null) { PsiParentClass(specifiedClassType) } else { diff --git a/src/test/kotlin/org/domaframework/doma/intellij/complate/sql/SqlCompleteTest.kt b/src/test/kotlin/org/domaframework/doma/intellij/complate/sql/SqlCompleteTest.kt index cc9463e3..09ca3125 100644 --- a/src/test/kotlin/org/domaframework/doma/intellij/complate/sql/SqlCompleteTest.kt +++ b/src/test/kotlin/org/domaframework/doma/intellij/complate/sql/SqlCompleteTest.kt @@ -117,21 +117,32 @@ 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", @@ -139,7 +150,6 @@ class SqlCompleteTest : DomaSqlTest() { "TYPE", "Integer()", ), - listOf("get()", "startsWith()", "permissions", "FALSE", "TRUE"), ) } diff --git a/src/test/kotlin/org/domaframework/doma/intellij/document/SqlSymbolDocumentTestCase.kt b/src/test/kotlin/org/domaframework/doma/intellij/document/SqlSymbolDocumentTestCase.kt index a463232c..c760f738 100644 --- a/src/test/kotlin/org/domaframework/doma/intellij/document/SqlSymbolDocumentTestCase.kt +++ b/src/test/kotlin/org/domaframework/doma/intellij/document/SqlSymbolDocumentTestCase.kt @@ -123,7 +123,7 @@ class SqlSymbolDocumentTestCase : DomaSqlTest() { fun testDocumentForItemHasNext() { val sqlName = "documentForItemHasNext" val result = - "Boolean item_has_next" + "boolean item_has_next" documentationFindTextTest(sqlName, "item_has_next", result) } @@ -131,7 +131,7 @@ class SqlSymbolDocumentTestCase : DomaSqlTest() { fun testDocumentForItemIndex() { val sqlName = "documentForItemIndex" val result = - "Integer item_index" + "int item_index" documentationFindTextTest(sqlName, "item_index", result) } diff --git a/src/test/testData/src/main/resources/META-INF/doma/example/dao/EmployeeSummaryDao/bindVariableForItemHasNextAndIndex.sql b/src/test/testData/src/main/resources/META-INF/doma/example/dao/EmployeeSummaryDao/bindVariableForItemHasNextAndIndex.sql index f608f1a3..0b2c6733 100644 --- a/src/test/testData/src/main/resources/META-INF/doma/example/dao/EmployeeSummaryDao/bindVariableForItemHasNextAndIndex.sql +++ b/src/test/testData/src/main/resources/META-INF/doma/example/dao/EmployeeSummaryDao/bindVariableForItemHasNextAndIndex.sql @@ -17,10 +17,10 @@ select p.project_id /*# "or" */ /*%end */ p.employee_id = /* member.employeeId */0 - and p.not_next = /* member_has_next.NotTRUE */false - and p.next = /* member_has_next.TRUE */false - and p.not_index = /* member_index.nextValue() */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 */ \ No newline at end of file diff --git a/src/test/testData/src/main/resources/META-INF/doma/example/dao/SqlCompleteTestDao/completeForItemIndex.sql b/src/test/testData/src/main/resources/META-INF/doma/example/dao/SqlCompleteTestDao/completeForItemIndex.sql index 6cd5603a..2291af63 100644 --- a/src/test/testData/src/main/resources/META-INF/doma/example/dao/SqlCompleteTestDao/completeForItemIndex.sql +++ b/src/test/testData/src/main/resources/META-INF/doma/example/dao/SqlCompleteTestDao/completeForItemIndex.sql @@ -3,6 +3,6 @@ where /*%for item : principal.permissions */ index = /* item_index. */0 /*%if item_has_next */ - OR flag = /* item_has_next.FALSE */false + OR flag = /* item_has_next */false /*%end */ /*%end */ \ No newline at end of file diff --git a/src/test/testData/src/main/resources/META-INF/doma/example/dao/document/DocumentTestDao/documentForItemElementByFieldAccess.sql b/src/test/testData/src/main/resources/META-INF/doma/example/dao/document/DocumentTestDao/documentForItemElementByFieldAccess.sql index 90886586..a62f054e 100644 --- a/src/test/testData/src/main/resources/META-INF/doma/example/dao/document/DocumentTestDao/documentForItemElementByFieldAccess.sql +++ b/src/test/testData/src/main/resources/META-INF/doma/example/dao/document/DocumentTestDao/documentForItemElementByFieldAccess.sql @@ -3,7 +3,7 @@ SELECT id WHERE category = 'category' -- employeesList -> List> /*%for employees : employeesList */ - -- employees_has_next -> -> List + -- employees_has_next -> boolean /*%if employees_has_next */ /*# "OR" */ /*%end */