-
Notifications
You must be signed in to change notification settings - Fork 20
fix: Strip parameter types from METHOD_CALL patterns #179
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
fix: Strip parameter types from METHOD_CALL patterns #179
Conversation
Fixes konveyor/analyzer-lsp#854 When users specify METHOD_CALL patterns with parameter types like 'java.util.Properties.setProperty(java.lang.String, java.lang.String)', the CustomASTVisitor was failing to match these patterns because: 1. The AST resolves method names as 'ClassName.methodName' without parameter types 2. The query pattern still contained parameter types like '(Type1, Type2)' 3. The regex match would fail because of this mismatch This commit adds preprocessing in the CustomASTVisitor constructor to strip parameter types (everything within parentheses) from the query pattern before applying other transformations. This allows patterns with parameter types to match correctly against the AST-resolved method names. Example: - Input pattern: 'java.util.Properties.setProperty(java.lang.String, java.lang.String)' - Processed pattern: 'java.util.Properties.setProperty' - AST method name: 'java.util.Properties.setProperty' - Result: Match successful Signed-off-by: tsanders <tsanders@redhat.com>
WalkthroughModified the CustomASTVisitor constructor to preprocess query strings by stripping method parameter types before applying star-wildcard regex pattern matching, altering how ANNOTATION/METHOD_CALL/CONSTRUCTOR_CALL paths match patterns that include parameter type specifications. Changes
Estimated code review effort🎯 2 (Simple) | ⏱️ ~12 minutes
Poem
Pre-merge checks and finishing touches❌ Failed checks (1 warning)
✅ Passed checks (4 passed)
✨ Finishing touches
🧪 Generate unit tests (beta)
📜 Recent review detailsConfiguration used: CodeRabbit UI Review profile: CHILL Plan: Pro 📒 Files selected for processing (1)
⏰ Context from checks skipped due to timeout of 90000ms. You can increase the timeout in your CodeRabbit configuration to a maximum of 15 minutes (900000ms). (1)
🔇 Additional comments (1)
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 |
|
We need to be able to match parameter types too |
Resolved conflicts by keeping parameter extraction enhancement which is a superset of PR konveyor#179's parameter stripping fix. The resolved code: - Extracts parameters for matching (enhancement for konveyor#182) - Strips parameters from query (fix from PR konveyor#179) Both functionalities are preserved. Signed-off-by: tsanders <tsanders@redhat.com>
Description
Fixes konveyor/analyzer-lsp#854
This PR fixes a bug where METHOD_CALL rules with patterns containing parameter types (e.g.,
java.util.Properties.setProperty(java.lang.String, java.lang.String)) fail to match actual method calls.Problem
When users specify METHOD_CALL patterns with parameter types, the
CustomASTVisitorwas failing to match these patterns because:ClassName.methodNamewithout parameter types(Type1, Type2)Solution
Added preprocessing in the
CustomASTVisitorconstructor to strip parameter types (everything within parentheses) from the query pattern before applying other transformations. This allows patterns with parameter types to match correctly against the AST-resolved method names.Example
java.util.Properties.setProperty(java.lang.String, java.lang.String)java.util.Properties.setPropertyjava.util.Properties.setPropertyTest Case
The issue can be reproduced with the following rule against the
examples/customers-tomcat-legacyproject in analyzer-lsp:This rule should trigger on lines 68-70 in
src/main/java/io/konveyor/demo/ordermanagement/config/PersistenceConfig.javabut previously did not.Changes
CustomASTVisitor.javaconstructor to strip parameter types using regex\([^)]*\)before other query transformationsSummary by CodeRabbit