Skip to content

Conversation

@xterao
Copy link
Collaborator

@xterao xterao commented Jun 5, 2025

Address an issue in DAO method argument usage validation where a method parameter was not error-highlighted if a field-access element invoked a property with the same name.

Update the logic that retrieves preceding elements under inspection to use the PsiTreeUtil API.

@xterao xterao self-assigned this Jun 5, 2025
@xterao xterao added the bug Something isn't working label Jun 5, 2025
@github-actions github-actions bot added the fix Bug fixes label Jun 5, 2025
@xterao xterao requested a review from Copilot June 5, 2025 07:30
@xterao xterao added this to the 1.0.0 Release milestone Jun 5, 2025
@xterao xterao linked an issue Jun 5, 2025 that may be closed by this pull request
Copy link
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull Request Overview

Addresses an issue where DAO method parameters weren’t flagged if accessed via a field on an object; updates the logic to use IntelliJ’s PsiTreeUtil.prevLeaf API when checking preceding SQL elements.

  • Replace prevSibling and extension prevLeaf() calls with PsiTreeUtil.prevLeaf(...) in visitor, directive handler, and pattern util
  • Update a test case to validate that a field-accessed property (employee.employeeName) is correctly treated as unused when the standalone parameter is provided

Reviewed Changes

Copilot reviewed 4 out of 4 changed files in this pull request and generated 3 comments.

File Description
src/test/.../DaoMethodVariableInspectionTestDao.java Updated SQL annotation and parameters in test to cover field access
src/main/kotlin/.../DaoMethodVariableSqlVisitor.kt Swapped element.prevSibling for PsiTreeUtil.prevLeaf(element)
src/main/kotlin/.../common/sql/directive/DirectiveHandler.kt Replaced extension prevLeaf() with PsiTreeUtil.prevLeaf(it)
src/main/kotlin/.../common/psi/PsiPatternUtil.kt Changed prevLeaf() calls to PsiTreeUtil.prevLeaf(element)
Comments suppressed due to low confidence (1)

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

  • [nitpick] Add a unit test covering cases where there is whitespace or comments between a field-access dot and the identifier to verify that the new prevLeaf logic still correctly recognizes the dot separator.
PsiTreeUtil.prevLeaf(element)?.elementType != SqlTypes.DOT

@xterao xterao merged commit f886c7b into main Jun 5, 2025
5 checks passed
@xterao xterao deleted the fix/no-error-when-a-field-access-element-shares-the-same-name branch June 5, 2025 07:47
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

bug Something isn't working fix Bug fixes

Projects

None yet

Development

Successfully merging this pull request may close these issues.

No error when a field-access element shares the same name as a parameter

2 participants