Skip to content

🐛 Fix matching for location METHOD_CALL and similar with parenthesis in pattern#213

Open
jmle wants to merge 1 commit intokonveyor:mainfrom
jmle:bugfix/211-fix-method-with-asterisk
Open

🐛 Fix matching for location METHOD_CALL and similar with parenthesis in pattern#213
jmle wants to merge 1 commit intokonveyor:mainfrom
jmle:bugfix/211-fix-method-with-asterisk

Conversation

@jmle
Copy link
Collaborator

@jmle jmle commented Mar 24, 2026

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

    • Improved accuracy of Java method symbol analysis.
    • Enhanced handling of complex method signatures with wildcards and alternation patterns.
  • Tests

    • Added new test coverage for enhanced symbol analysis.

… pattern

Signed-off-by: Juan Manuel Leflet Estrada <jleflete@redhat.com>
@coderabbitai
Copy link

coderabbitai bot commented Mar 24, 2026

📝 Walkthrough

Walkthrough

The 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

Cohort / File(s) Summary
Core Parameter Parsing Refactor
java-analyzer-bundle.core/src/main/java/io/konveyor/tackle/core/internal/symbol/CustomASTVisitor.java
Replaced basic regex preprocessing with parseParameterList(query) method that returns ParameterParseResult containing parameter types and exact parenthesis indices. Updated buildFqnRegexPattern to strip only the identified parameter segment. Enhanced detection to skip parameter extraction when alternation (|) is present or significant non-wildcard content follows the closing parenthesis. Removed unused java.lang.reflect.Parameter import.
Test Coverage Additions
java-analyzer-bundle.test/src/main/java/io/konveyor/tackle/core/internal/symbol/CustomASTVisitorTest.java
Added comprehensive JUnit tests for parseParameterList and buildFqnRegexPattern, validating alternation preservation, parameter list stripping, empty parentheses handling, and wildcard suffix scenarios. Expanded static imports to include assertFalse and assertNotNull.

Estimated code review effort

🎯 3 (Moderate) | ⏱️ ~20 minutes

Poem

🐰 A hop through the parameters we go,
Parsing with indices, oh what a show!
Alternations preserved, parentheses found,
Regex patterns neat and sound,
Better searches, round and round! ✨

🚥 Pre-merge checks | ✅ 2 | ❌ 1

❌ Failed checks (1 warning)

Check name Status Explanation Resolution
Docstring Coverage ⚠️ Warning Docstring coverage is 26.67% which is insufficient. The required threshold is 80.00%. Write docstrings for the functions missing them to satisfy the coverage threshold.
✅ Passed checks (2 passed)
Check name Status Explanation
Description Check ✅ Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Title check ✅ Passed The title directly addresses the main bug fix: preventing incorrect removal of parenthetical segments containing alternation patterns from method call queries, which was breaking CONSTRUCTOR_CALL and similar flows.

✏️ Tip: You can configure your own custom pre-merge checks in the settings.

✨ Finishing Touches
🧪 Generate unit tests (beta)
  • Create PR with unit tests

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.

❤️ Share

Comment @coderabbitai help to get the list of available commands and usage tips.

@jmle jmle requested review from eemcmullan and shawn-hurley March 24, 2026 13:02
Copy link

@coderabbitai coderabbitai bot left a comment

Choose a reason for hiding this comment

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

🧹 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 buildFqnRegexPattern method 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 using replaceAll("\\([^|]*\\)", "")
  • AnnotationSymbolProvider (line 99) converts alternation groups to .* before calling queryQualificationMatches

While 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 buildFqnRegexPattern represents 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 like pkg.(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

📥 Commits

Reviewing files that changed from the base of the PR and between 564267c and 8b98d2e.

📒 Files selected for processing (2)
  • java-analyzer-bundle.core/src/main/java/io/konveyor/tackle/core/internal/symbol/CustomASTVisitor.java
  • java-analyzer-bundle.test/src/main/java/io/konveyor/tackle/core/internal/symbol/CustomASTVisitorTest.java

Copy link
Contributor

@shawn-hurley shawn-hurley left a comment

Choose a reason for hiding this comment

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

This looks right to me, and the unit tests are really helpful!

An integration test would help keep this working as we make changes.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants