Skip to content

Commit e736e61

Browse files
authored
Merge pull request #243 from domaframework/fix/no-error-when-static-field-access-element-shares-the-same-name
No error when static field-access element shares the same name as a parameter
2 parents f886c7b + 585b4ab commit e736e61

File tree

2 files changed

+12
-5
lines changed

2 files changed

+12
-5
lines changed

src/main/kotlin/org/domaframework/doma/intellij/inspection/dao/visitor/DaoMethodVariableSqlVisitor.kt

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -39,11 +39,13 @@ class DaoMethodVariableSqlVisitor(
3939

4040
// Recursively explore child elements in a file with PsiRecursiveElementVisitor.
4141
override fun visitElement(element: PsiElement) {
42+
val prevElementType = PsiTreeUtil.prevLeaf(element)?.elementType
4243
if ((
4344
element.elementType == SqlTypes.EL_IDENTIFIER ||
4445
element is SqlElPrimaryExpr
4546
) &&
46-
PsiTreeUtil.prevLeaf(element)?.elementType != SqlTypes.DOT
47+
prevElementType != SqlTypes.DOT &&
48+
prevElementType != SqlTypes.AT_SIGN
4749
) {
4850
iterator = args.minus(elements.toSet()).iterator()
4951
while (iterator.hasNext()) {

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

Lines changed: 9 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -32,8 +32,11 @@ interface DaoMethodVariableInspectionTestDao {
3232
List<Employee> nonExistSQLFile(String name);
3333

3434
@Select
35-
@Sql("select * from employee where name = /* employee.employeeName */'test'")
36-
Employee noArgumentsUsedInSQLAnnotations(Employee employee,String <error descr="There are unused parameters in the SQL [employeeName]">employeeName</error>);
35+
@Sql("select * from employee where name = /* employee.employeeName */'test' and status = /* @doma.example.entity.Project@status */'status'")
36+
Employee noArgumentsUsedInSQLAnnotations(Employee employee,
37+
String <error descr="There are unused parameters in the SQL [employeeName]">employeeName</error>,
38+
String <error descr="There are unused parameters in the SQL [status]">status</error>,
39+
String <error descr="There are unused parameters in the SQL [doma]">doma</error>);
3740

3841
@SqlProcessor
3942
<R> R biFunctionDoesNotCauseError(Integer id, BiFunction<Config, PreparedSql, R> handler);
@@ -42,10 +45,12 @@ interface DaoMethodVariableInspectionTestDao {
4245
Project selectOptionDoesNotCauseError(Employee <error descr="There are unused parameters in the SQL [employee]">employee</error>,String searchName,SelectOptions options);
4346

4447
@Select(strategy = SelectType.COLLECT)
45-
Project collectDoesNotCauseError(Employee <error descr="There are unused parameters in the SQL [employee]">employee</error>,Integer id,Collector<Project, ?, Project> collector);
48+
Project collectDoesNotCauseError(Employee <error descr="There are unused parameters in the SQL [employee]">employee</error>,Integer id,
49+
Collector<Project, ?, Project> collector);
4650

4751
@Select
48-
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>);
52+
Project collectDoesCauseError(Employee <error descr="There are unused parameters in the SQL [employee]">employee</error>,String searchName,
53+
Collector<Project, ?, Project> <error descr="There are unused parameters in the SQL [collector]">collector</error>);
4954

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

0 commit comments

Comments
 (0)