Skip to content
Merged
Show file tree
Hide file tree
Changes from 3 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 @@ -43,7 +43,6 @@ import org.domaframework.doma.intellij.common.psi.PsiParentClass
import org.domaframework.doma.intellij.extension.expr.accessElements
import org.domaframework.doma.intellij.extension.expr.fqdn
import org.domaframework.doma.intellij.extension.getJavaClazz
import org.domaframework.doma.intellij.extension.psi.findNodeParent
import org.domaframework.doma.intellij.extension.psi.getDomaAnnotationType
import org.domaframework.doma.intellij.extension.psi.getForItem
import org.domaframework.doma.intellij.extension.psi.getIterableClazz
Expand Down Expand Up @@ -164,9 +163,6 @@ class SqlBindVariableValidInspector : LocalInspectionTool() {
// Exclude fixed Literal
if (isLiteralOrStatic(element)) return

// TODO Check function parameters in the same way as bind variables.
if (element.findNodeParent(SqlTypes.EL_PARAMETERS) != null) return

// For static property references, match against properties in the class definition
if (element.parent is SqlElStaticFieldAccessExpr) {
checkStaticFieldAndMethodAccess(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,7 @@ class DomaUseVariableTest : DomaSqlTest() {
"$testDaoName/selectOptionDoesNotCauseError.sql",
"$testDaoName/collectDoesNotCauseError.sql",
"$testDaoName/collectDoesCauseError.sql",
"$testDaoName/noErrorWhenUsedInFunctionParameters.sql",
)
myFixture.enableInspections(DaoMethodVariableInspector())
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,17 +22,20 @@ import org.domaframework.doma.intellij.inspection.sql.inspector.SqlBindVariableV
* A test that inspects whether a bind variable's parameters are defined.
*/
class ParameterDefinedTest : DomaSqlTest() {
private val testDaoName = "EmployeeSummaryDao"

override fun setUp() {
super.setUp()
addDaoJavaFile(
"EmployeeSummaryDao.java",
"$testDaoName.java",
)
addSqlFile(
"EmployeeSummaryDao/bindVariableForEntityAndNonEntityParentClass.sql",
"EmployeeSummaryDao/bindVariableForNonEntityClass.sql",
"EmployeeSummaryDao/accessStaticProperty.sql",
"EmployeeSummaryDao/batchAnnotationResolvesClassInList.sql",
"EmployeeSummaryDao/resolveDaoArgumentOfListType.sql",
"$testDaoName/bindVariableForEntityAndNonEntityParentClass.sql",
"$testDaoName/bindVariableForNonEntityClass.sql",
"$testDaoName/accessStaticProperty.sql",
"$testDaoName/batchAnnotationResolvesClassInList.sql",
"$testDaoName/resolveDaoArgumentOfListType.sql",
"$testDaoName/bindVariableInFunctionParameters.sql",
)
myFixture.enableInspections(SqlBindVariableValidInspector())
}
Expand All @@ -42,23 +45,23 @@ class ParameterDefinedTest : DomaSqlTest() {
* + Non-Entity parent class field, method reference test
*/
fun testBindVariableForEntityAndNonEntityParentClass() {
val sqlFile = findSqlFile("EmployeeSummaryDao/bindVariableForEntityAndNonEntityParentClass.sql")
val sqlFile = findSqlFile("$testDaoName/bindVariableForEntityAndNonEntityParentClass.sql")
assertNotNull("Not Found SQL File", sqlFile)
if (sqlFile == null) return

myFixture.testHighlighting(false, false, false, sqlFile)
}

fun testBindVariableForNonEntityClass() {
val sqlFile = findSqlFile("EmployeeSummaryDao/bindVariableForNonEntityClass.sql")
val sqlFile = findSqlFile("$testDaoName/bindVariableForNonEntityClass.sql")
assertNotNull("Not Found SQL File", sqlFile)
if (sqlFile == null) return

myFixture.testHighlighting(false, false, false, sqlFile)
}

fun testAccessStaticProperty() {
val sqlFile = findSqlFile("EmployeeSummaryDao/accessStaticProperty.sql")
val sqlFile = findSqlFile("$testDaoName/accessStaticProperty.sql")
assertNotNull("Not Found SQL File", sqlFile)
if (sqlFile == null) return

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

fun testBatchAnnotationResolvesClassInList() {
val sqlFile =
findSqlFile("EmployeeSummaryDao/batchAnnotationResolvesClassInList.sql")
findSqlFile("$testDaoName/batchAnnotationResolvesClassInList.sql")
assertNotNull("Not Found SQL File", sqlFile)
if (sqlFile == null) return

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

fun testResolveDaoArgumentOfListType() {
val sqlFile =
findSqlFile("EmployeeSummaryDao/resolveDaoArgumentOfListType.sql")
findSqlFile("$testDaoName/resolveDaoArgumentOfListType.sql")
assertNotNull("Not Found SQL File", sqlFile)
if (sqlFile == null) return

myFixture.testHighlighting(false, false, false, sqlFile)
}

fun testBindVariableInFunctionParameters() {
val sqlFile =
findSqlFile("$testDaoName/bindVariableInFunctionParameters.sql")
assertNotNull("Not Found SQL File", sqlFile)
if (sqlFile == null) return

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -47,5 +47,7 @@ interface DaoMethodVariableInspectionTestDao {
@Select
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>);

@Select
Project noErrorWhenUsedInFunctionParameters(Employee employee, Integer count);

}
Original file line number Diff line number Diff line change
Expand Up @@ -26,4 +26,7 @@ interface EmployeeSummaryDao {

@BatchInsert(sqlFile=true)
int[] batchAnnotationResolvesClassInList(List<Employee> employees);

@Insert(sqlFile=true)
EmployeeSummary bindVariableInFunctionParameters(Employee employee, User user);
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
select
p.project_id
, p.project_name
, p.project_number
from project p
where p.project_id = /* employee.employeeParam(count, 1) */0
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
-- Check BindVariable Definition In Function Parameters
SELECT
e.employee_id
, u.user_id
, u.user_name
FROM user u
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
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
/*%end */