Skip to content

Commit 49e358d

Browse files
authored
Merge pull request #167 from domaframework/fix/documentasion-for-item
Fix to not display Dao parameter information in the document for elements defined with the for directive.
2 parents 6db946f + d6b6dbc commit 49e358d

File tree

4 files changed

+30
-0
lines changed

4 files changed

+30
-0
lines changed

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

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,9 @@ import org.domaframework.doma.intellij.common.psi.PsiParentClass
2424
import org.domaframework.doma.intellij.common.util.ForDirectiveUtil
2525
import org.domaframework.doma.intellij.extension.expr.accessElementsPrevOriginalElement
2626
import org.domaframework.doma.intellij.extension.psi.findParameter
27+
import org.domaframework.doma.intellij.extension.psi.getForItem
2728
import org.domaframework.doma.intellij.psi.SqlElFieldAccessExpr
29+
import org.domaframework.doma.intellij.psi.SqlElForDirective
2830

2931
class DocumentDaoParameterGenerator(
3032
val originalElement: PsiElement,
@@ -59,6 +61,15 @@ class DocumentDaoParameterGenerator(
5961
forItemClassType
6062
}
6163
} else {
64+
val forDirectiveExpr =
65+
PsiTreeUtil.getParentOfType(
66+
searchElement,
67+
SqlElForDirective::class.java,
68+
)
69+
if (forDirectiveExpr != null && forDirectiveExpr.getForItem() == searchElement) {
70+
// For elements defined with the for directive, Dao parameters are not searched.
71+
return
72+
}
6273
val daoMethod = findDaoMethod(originalElement.containingFile) ?: return
6374
val param = daoMethod.findParameter(originalElement.text) ?: return
6475
isBatchAnnotation = PsiDaoMethod(project, daoMethod).daoType.isBatchAnnotation()

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

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -44,6 +44,7 @@ class SqlSymbolDocumentTestCase : DomaSqlTest() {
4444
addSqlFile("$testPackage/$testDaoName/documentForItemIndex.sql")
4545
addSqlFile("$testPackage/$testDaoName/documentForItemOptionalForItem.sql")
4646
addSqlFile("$testPackage/$testDaoName/documentForItemOptionalProperty.sql")
47+
addSqlFile("$testPackage/$testDaoName/documentForItemInvalidPrimary.sql")
4748
}
4849

4950
fun testDocumentForItemDaoParam() {
@@ -145,6 +146,13 @@ class SqlSymbolDocumentTestCase : DomaSqlTest() {
145146
documentationFindTextTest(sqlName, "project", result)
146147
}
147148

149+
fun testDocumentForItemInvalidPrimary() {
150+
val sqlName = "documentForItemInvalidPrimary"
151+
val result = " item"
152+
153+
documentationFindTextTest(sqlName, "item", result)
154+
}
155+
148156
private fun documentationTest(
149157
sqlName: String,
150158
result: String?,

src/test/testData/src/main/java/doma/example/dao/document/DocumentTestDao.java

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -42,4 +42,7 @@ public interface DocumentTestDao {
4242
@Select
4343
Project documentForItemOptionalProperty(Optional<List<Optional<Project>>> optionalProjects);
4444

45+
@Select
46+
int documentForItemInvalidPrimary(Principal item, Principal principal);
47+
4548
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
select count(*) from principal
2+
where
3+
/*%for item : principal */
4+
name = /* ite<caret>m.name */'name'
5+
/*%if item_has_next */
6+
/*# "or" */
7+
/*%end */
8+
/*%end */

0 commit comments

Comments
 (0)