Skip to content

Commit bbe3094

Browse files
authored
Merge pull request #82 from domaframework/fix/inspection-in-function-parameters
inspection in function parameters
2 parents 775c435 + 001eb5b commit bbe3094

File tree

7 files changed

+45
-15
lines changed

7 files changed

+45
-15
lines changed

src/main/kotlin/org/domaframework/doma/intellij/inspection/sql/inspector/SqlBindVariableValidInspector.kt

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -43,7 +43,6 @@ import org.domaframework.doma.intellij.common.psi.PsiParentClass
4343
import org.domaframework.doma.intellij.extension.expr.accessElements
4444
import org.domaframework.doma.intellij.extension.expr.fqdn
4545
import org.domaframework.doma.intellij.extension.getJavaClazz
46-
import org.domaframework.doma.intellij.extension.psi.findNodeParent
4746
import org.domaframework.doma.intellij.extension.psi.getDomaAnnotationType
4847
import org.domaframework.doma.intellij.extension.psi.getForItem
4948
import org.domaframework.doma.intellij.extension.psi.getIterableClazz
@@ -164,9 +163,6 @@ class SqlBindVariableValidInspector : LocalInspectionTool() {
164163
// Exclude fixed Literal
165164
if (isLiteralOrStatic(element)) return
166165

167-
// TODO Check function parameters in the same way as bind variables.
168-
if (element.findNodeParent(SqlTypes.EL_PARAMETERS) != null) return
169-
170166
// For static property references, match against properties in the class definition
171167
if (element.parent is SqlElStaticFieldAccessExpr) {
172168
checkStaticFieldAndMethodAccess(

src/test/kotlin/org/domaframework/doma/intellij/inspection/dao/DomaUseVariableTest.kt

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -34,6 +34,7 @@ class DomaUseVariableTest : DomaSqlTest() {
3434
"$testDaoName/selectOptionDoesNotCauseError.sql",
3535
"$testDaoName/collectDoesNotCauseError.sql",
3636
"$testDaoName/collectDoesCauseError.sql",
37+
"$testDaoName/noErrorWhenUsedInFunctionParameters.sql",
3738
)
3839
myFixture.enableInspections(DaoMethodVariableInspector())
3940
}

src/test/kotlin/org/domaframework/doma/intellij/inspection/sql/ParameterDefinedTest.kt

Lines changed: 23 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -22,17 +22,20 @@ import org.domaframework.doma.intellij.inspection.sql.inspector.SqlBindVariableV
2222
* A test that inspects whether a bind variable's parameters are defined.
2323
*/
2424
class ParameterDefinedTest : DomaSqlTest() {
25+
private val testDaoName = "EmployeeSummaryDao"
26+
2527
override fun setUp() {
2628
super.setUp()
2729
addDaoJavaFile(
28-
"EmployeeSummaryDao.java",
30+
"$testDaoName.java",
2931
)
3032
addSqlFile(
31-
"EmployeeSummaryDao/bindVariableForEntityAndNonEntityParentClass.sql",
32-
"EmployeeSummaryDao/bindVariableForNonEntityClass.sql",
33-
"EmployeeSummaryDao/accessStaticProperty.sql",
34-
"EmployeeSummaryDao/batchAnnotationResolvesClassInList.sql",
35-
"EmployeeSummaryDao/resolveDaoArgumentOfListType.sql",
33+
"$testDaoName/bindVariableForEntityAndNonEntityParentClass.sql",
34+
"$testDaoName/bindVariableForNonEntityClass.sql",
35+
"$testDaoName/accessStaticProperty.sql",
36+
"$testDaoName/batchAnnotationResolvesClassInList.sql",
37+
"$testDaoName/resolveDaoArgumentOfListType.sql",
38+
"$testDaoName/bindVariableInFunctionParameters.sql",
3639
)
3740
myFixture.enableInspections(SqlBindVariableValidInspector())
3841
}
@@ -42,23 +45,23 @@ class ParameterDefinedTest : DomaSqlTest() {
4245
* + Non-Entity parent class field, method reference test
4346
*/
4447
fun testBindVariableForEntityAndNonEntityParentClass() {
45-
val sqlFile = findSqlFile("EmployeeSummaryDao/bindVariableForEntityAndNonEntityParentClass.sql")
48+
val sqlFile = findSqlFile("$testDaoName/bindVariableForEntityAndNonEntityParentClass.sql")
4649
assertNotNull("Not Found SQL File", sqlFile)
4750
if (sqlFile == null) return
4851

4952
myFixture.testHighlighting(false, false, false, sqlFile)
5053
}
5154

5255
fun testBindVariableForNonEntityClass() {
53-
val sqlFile = findSqlFile("EmployeeSummaryDao/bindVariableForNonEntityClass.sql")
56+
val sqlFile = findSqlFile("$testDaoName/bindVariableForNonEntityClass.sql")
5457
assertNotNull("Not Found SQL File", sqlFile)
5558
if (sqlFile == null) return
5659

5760
myFixture.testHighlighting(false, false, false, sqlFile)
5861
}
5962

6063
fun testAccessStaticProperty() {
61-
val sqlFile = findSqlFile("EmployeeSummaryDao/accessStaticProperty.sql")
64+
val sqlFile = findSqlFile("$testDaoName/accessStaticProperty.sql")
6265
assertNotNull("Not Found SQL File", sqlFile)
6366
if (sqlFile == null) return
6467

@@ -67,7 +70,7 @@ class ParameterDefinedTest : DomaSqlTest() {
6770

6871
fun testBatchAnnotationResolvesClassInList() {
6972
val sqlFile =
70-
findSqlFile("EmployeeSummaryDao/batchAnnotationResolvesClassInList.sql")
73+
findSqlFile("$testDaoName/batchAnnotationResolvesClassInList.sql")
7174
assertNotNull("Not Found SQL File", sqlFile)
7275
if (sqlFile == null) return
7376

@@ -76,7 +79,16 @@ class ParameterDefinedTest : DomaSqlTest() {
7679

7780
fun testResolveDaoArgumentOfListType() {
7881
val sqlFile =
79-
findSqlFile("EmployeeSummaryDao/resolveDaoArgumentOfListType.sql")
82+
findSqlFile("$testDaoName/resolveDaoArgumentOfListType.sql")
83+
assertNotNull("Not Found SQL File", sqlFile)
84+
if (sqlFile == null) return
85+
86+
myFixture.testHighlighting(false, false, false, sqlFile)
87+
}
88+
89+
fun testBindVariableInFunctionParameters() {
90+
val sqlFile =
91+
findSqlFile("$testDaoName/bindVariableInFunctionParameters.sql")
8092
assertNotNull("Not Found SQL File", sqlFile)
8193
if (sqlFile == null) return
8294

src/test/testData/src/main/java/doma/example/dao/DaoMethodVariableInspectionTestDao.java

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -47,5 +47,7 @@ interface DaoMethodVariableInspectionTestDao {
4747
@Select
4848
Project collectDoesCauseError(Employee <error descr="There are unused parameters in the SQL [employee]">employee</error>,String searchName,Collector<Project, ?, Project> <error descr="There are unused parameters in the SQL [collector]">collector</error>);
4949

50+
@Select
51+
Project noErrorWhenUsedInFunctionParameters(Employee employee, Integer count);
5052

5153
}

src/test/testData/src/main/java/doma/example/dao/EmployeeSummaryDao.java

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -26,4 +26,7 @@ interface EmployeeSummaryDao {
2626

2727
@BatchInsert(sqlFile=true)
2828
int[] batchAnnotationResolvesClassInList(List<Employee> employees);
29+
30+
@Insert(sqlFile=true)
31+
EmployeeSummary bindVariableInFunctionParameters(Employee employee, User user);
2932
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
select
2+
p.project_id
3+
, p.project_name
4+
, p.project_number
5+
from project p
6+
where p.project_id = /* employee.employeeParam(count, 1) */0
Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
-- Check BindVariable Definition In Function Parameters
2+
SELECT
3+
e.employee_id
4+
, u.user_id
5+
, u.user_name
6+
FROM user u
7+
WHERE p.employee_id = /* employee.employeeParam(employee.<error descr="The field or method [dist] does not exist in the class [Employee]">dist</error>, employee.employeeId) */0
8+
AND p.base_rank = /* employee.employeeParam(user.userId, <error descr="The bind variable [count] does not exist in the Dao method [bindVariableInFunctionParameters]">count</error>) */0
9+
AND p.employee_id = /* employee.employeeParam(employee.<error descr="The field or method [dist] does not exist in the class [Employee]">dist</error>, <error descr="The bind variable [rank] does not exist in the Dao method [bindVariableInFunctionParameters]">rank</error>) */0
10+
/*%end */

0 commit comments

Comments
 (0)