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 @@ -24,7 +24,9 @@ import org.domaframework.doma.intellij.common.psi.PsiParentClass
import org.domaframework.doma.intellij.common.util.ForDirectiveUtil
import org.domaframework.doma.intellij.extension.expr.accessElementsPrevOriginalElement
import org.domaframework.doma.intellij.extension.psi.findParameter
import org.domaframework.doma.intellij.extension.psi.getForItem
import org.domaframework.doma.intellij.psi.SqlElFieldAccessExpr
import org.domaframework.doma.intellij.psi.SqlElForDirective

class DocumentDaoParameterGenerator(
val originalElement: PsiElement,
Expand Down Expand Up @@ -59,6 +61,15 @@ class DocumentDaoParameterGenerator(
forItemClassType
}
} else {
val forDirectiveExpr =
PsiTreeUtil.getParentOfType(
searchElement,
SqlElForDirective::class.java,
)
if (forDirectiveExpr != null && forDirectiveExpr.getForItem() == searchElement) {
// For elements defined with the for directive, Dao parameters are not searched.
return
}
val daoMethod = findDaoMethod(originalElement.containingFile) ?: return
val param = daoMethod.findParameter(originalElement.text) ?: return
isBatchAnnotation = PsiDaoMethod(project, daoMethod).daoType.isBatchAnnotation()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,7 @@ class SqlSymbolDocumentTestCase : DomaSqlTest() {
addSqlFile("$testPackage/$testDaoName/documentForItemIndex.sql")
addSqlFile("$testPackage/$testDaoName/documentForItemOptionalForItem.sql")
addSqlFile("$testPackage/$testDaoName/documentForItemOptionalProperty.sql")
addSqlFile("$testPackage/$testDaoName/documentForItemInvalidPrimary.sql")
}

fun testDocumentForItemDaoParam() {
Expand Down Expand Up @@ -145,6 +146,13 @@ class SqlSymbolDocumentTestCase : DomaSqlTest() {
documentationFindTextTest(sqlName, "project", result)
}

fun testDocumentForItemInvalidPrimary() {
val sqlName = "documentForItemInvalidPrimary"
val result = " item"

documentationFindTextTest(sqlName, "item", result)
}

private fun documentationTest(
sqlName: String,
result: String?,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -42,4 +42,7 @@ public interface DocumentTestDao {
@Select
Project documentForItemOptionalProperty(Optional<List<Optional<Project>>> optionalProjects);

@Select
int documentForItemInvalidPrimary(Principal item, Principal principal);

}
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
select count(*) from principal
where
/*%for item : principal */
name = /* ite<caret>m.name */'name'
/*%if item_has_next */
/*# "or" */
/*%end */
/*%end */