Skip to content

Commit b5e50ca

Browse files
committed
Fix field access element handling to prevent errors when names collide
1 parent c3de126 commit b5e50ca

File tree

4 files changed

+7
-8
lines changed

4 files changed

+7
-8
lines changed

src/main/kotlin/org/domaframework/doma/intellij/common/psi/PsiPatternUtil.kt

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,6 @@ import com.intellij.psi.TokenType
2424
import com.intellij.psi.tree.IElementType
2525
import com.intellij.psi.util.PsiTreeUtil
2626
import com.intellij.psi.util.elementType
27-
import com.intellij.psi.util.prevLeaf
2827
import com.intellij.psi.util.prevLeafs
2928
import com.intellij.util.ProcessingContext
3029
import org.domaframework.doma.intellij.common.sql.directive.DirectiveCompletion
@@ -79,11 +78,11 @@ object PsiPatternUtil {
7978
element: PsiElement,
8079
context: ProcessingContext?,
8180
): Boolean {
82-
val bindText = element.prevLeaf()?.text ?: ""
81+
val bindText = PsiTreeUtil.prevLeaf(element)?.text ?: ""
8382
val directiveSymbol = DirectiveCompletion.directiveSymbols
8483
return directiveSymbol.any {
8584
bindText.startsWith(it) ||
86-
(element.elementType == SqlTypes.EL_IDENTIFIER && element.prevLeaf()?.text == it) ||
85+
(element.elementType == SqlTypes.EL_IDENTIFIER && PsiTreeUtil.prevLeaf(element)?.text == it) ||
8786
(
8887
element.elementType == TokenType.BAD_CHARACTER &&
8988
element.parent

src/main/kotlin/org/domaframework/doma/intellij/common/sql/directive/DirectiveHandler.kt

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -16,8 +16,8 @@
1616
package org.domaframework.doma.intellij.common.sql.directive
1717

1818
import com.intellij.psi.PsiElement
19+
import com.intellij.psi.util.PsiTreeUtil
1920
import org.domaframework.doma.intellij.common.psi.PsiPatternUtil
20-
import org.jetbrains.kotlin.psi.psiUtil.prevLeaf
2121

2222
/**
2323
* Determine directive elements and perform code completion
@@ -31,7 +31,7 @@ open class DirectiveHandler(
3131
it: PsiElement,
3232
symbol: String,
3333
): Boolean {
34-
val prev = it.prevLeaf()
34+
val prev = PsiTreeUtil.prevLeaf(it)
3535
return (
3636
prev?.text == symbol ||
3737
it.text.startsWith(symbol)

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -43,7 +43,7 @@ class DaoMethodVariableSqlVisitor(
4343
element.elementType == SqlTypes.EL_IDENTIFIER ||
4444
element is SqlElPrimaryExpr
4545
) &&
46-
element.prevSibling?.elementType != SqlTypes.DOT
46+
PsiTreeUtil.prevLeaf(element)?.elementType != SqlTypes.DOT
4747
) {
4848
iterator = args.minus(elements.toSet()).iterator()
4949
while (iterator.hasNext()) {

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

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

3434
@Select
35-
@Sql("select * from employee where name = /* name */'test'")
36-
Employee noArgumentsUsedInSQLAnnotations(String name,Integer <error descr="There are unused parameters in the SQL [id]">id</error>);
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>);
3737

3838
@SqlProcessor
3939
<R> R biFunctionDoesNotCauseError(Integer id, BiFunction<Config, PreparedSql, R> handler);

0 commit comments

Comments
 (0)