🐛 Fix matching for location METHOD_CALL and similar with parenthesis in pattern#213
🐛 Fix matching for location METHOD_CALL and similar with parenthesis in pattern#213jmle wants to merge 1 commit intokonveyor:mainfrom
Conversation
… pattern Signed-off-by: Juan Manuel Leflet Estrada <jleflete@redhat.com>
📝 WalkthroughWalkthroughThe changes refactor parameter list parsing in CustomASTVisitor to replace a simple regex approach with a parameter-aware parsing flow that extracts indices and detects alternation patterns, while adding comprehensive test coverage for the new logic. Changes
Estimated code review effort🎯 3 (Moderate) | ⏱️ ~20 minutes Poem
🚥 Pre-merge checks | ✅ 2 | ❌ 1❌ Failed checks (1 warning)
✅ Passed checks (2 passed)
✏️ Tip: You can configure your own custom pre-merge checks in the settings. ✨ Finishing Touches🧪 Generate unit tests (beta)
Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out. Comment |
There was a problem hiding this comment.
🧹 Nitpick comments (1)
java-analyzer-bundle.core/src/main/java/io/konveyor/tackle/core/internal/symbol/CustomASTVisitor.java (1)
324-330: Consider harmonizing FQN pattern normalization across providers.The new
buildFqnRegexPatternmethod in CustomASTVisitor correctly preserves alternation groups (per its explicit comment), but related code in other providers handles parenthetical content differently:
SymbolProvider.queryQualificationMatches(line 210) strips all parenthetical content usingreplaceAll("\\([^|]*\\)", "")AnnotationSymbolProvider(line 99) converts alternation groups to.*before callingqueryQualificationMatchesWhile these differences appear intentional given their separate contexts (CustomASTVisitor for AST matching, SymbolProvider for qualification extraction, AnnotationSymbolProvider for annotation resolution), the inconsistency creates a maintenance burden. If
buildFqnRegexPatternrepresents a more correct approach, consider whether other providers should adopt it or if a shared utility should be established to ensure consistent handling of patterns likepkg.(A|B).🤖 Prompt for AI Agents
Verify each finding against the current code and only fix it if needed. In `@java-analyzer-bundle.core/src/main/java/io/konveyor/tackle/core/internal/symbol/CustomASTVisitor.java` around lines 324 - 330, Inconsistent handling of parenthetical alternation in FQN pattern normalization should be unified: extract the logic in CustomASTVisitor.buildFqnRegexPattern into a shared utility (e.g., FqnPattern.normalizePreserveAlternation) and update SymbolProvider.queryQualificationMatches and AnnotationSymbolProvider to call that utility instead of using replaceAll("\\([^|]*\\)", "") or converting alternation to ".*" prematurely; ensure the shared method preserves alternation groups, only strips parameter lists (as buildFqnRegexPattern does using parsed.paramOpenIndex/paramCloseIndex semantics), and then replaces unqualified "*" with ".*" so all three usages share identical normalization behavior.
🤖 Prompt for all review comments with AI agents
Verify each finding against the current code and only fix it if needed.
Nitpick comments:
In
`@java-analyzer-bundle.core/src/main/java/io/konveyor/tackle/core/internal/symbol/CustomASTVisitor.java`:
- Around line 324-330: Inconsistent handling of parenthetical alternation in FQN
pattern normalization should be unified: extract the logic in
CustomASTVisitor.buildFqnRegexPattern into a shared utility (e.g.,
FqnPattern.normalizePreserveAlternation) and update
SymbolProvider.queryQualificationMatches and AnnotationSymbolProvider to call
that utility instead of using replaceAll("\\([^|]*\\)", "") or converting
alternation to ".*" prematurely; ensure the shared method preserves alternation
groups, only strips parameter lists (as buildFqnRegexPattern does using
parsed.paramOpenIndex/paramCloseIndex semantics), and then replaces unqualified
"*" with ".*" so all three usages share identical normalization behavior.
ℹ️ Review info
⚙️ Run configuration
Configuration used: defaults
Review profile: CHILL
Plan: Pro
Run ID: 490485c7-8d41-4bb6-8868-068a47bca7b8
📒 Files selected for processing (2)
java-analyzer-bundle.core/src/main/java/io/konveyor/tackle/core/internal/symbol/CustomASTVisitor.javajava-analyzer-bundle.test/src/main/java/io/konveyor/tackle/core/internal/symbol/CustomASTVisitorTest.java
shawn-hurley
left a comment
There was a problem hiding this comment.
This looks right to me, and the unit tests are really helpful!
An integration test would help keep this working as we make changes.
Problem: For patterns like org.library.(Class1|Class2), CustomASTVisitor stripped all (...) segments when building the FQN regex (same as for method parameter lists). That removed the alternation group and broke CONSTRUCTOR_CALL / similar flows after parameter-matching work landed.
Change: Only remove a parenthetical segment when it is parsed as a trailing Java parameter list (same heuristics as before: no | inside, nothing meaningful after ) except *, etc.). Alternation groups stay in the pattern for String.matches. Logic lives in parseParameterList, ParameterParseResult, and buildFqnRegexPattern; extractParameterTypes still delegates to that parse.
Tests: New CustomASTVisitorTest cases for alternation preservation, multi-alternative groups, wildcards after alternation, and param stripping unchanged for normal Type.method(...) patterns.
Summary by CodeRabbit
Bug Fixes
Tests