Fixed wildcard matching for elements with type information.#5833
Merged
Fixed wildcard matching for elements with type information.#5833
Conversation
jevanlingen
reviewed
Jul 30, 2025
rewrite-java-test/src/test/java/org/openrewrite/java/MethodMatcherTest.java
Show resolved
Hide resolved
jevanlingen
reviewed
Jul 30, 2025
rewrite-java-test/src/test/java/org/openrewrite/java/MethodMatcherTest.java
Show resolved
Hide resolved
3 tasks
jevanlingen
approved these changes
Jul 30, 2025
Contributor
Author
|
@timtebeek Do I add this one to the list of core changes? As MethodMatcher is quite broadly used. The tests are quite good though, so not sure. |
Member
|
Yes please add to the list of core issues to review! 🙏🏻 |
timtebeek
approved these changes
Aug 4, 2025
Comment on lines
+453
to
+455
| assertTrue(new MethodMatcher("org.junit.Assert assertTrue(String, *)").matches(mi, true)); | ||
| assertTrue(new MethodMatcher("org.junit.Assert assertTrue(double, *)").matches(mi, true)); | ||
| assertTrue(new MethodMatcher("org.junit.Assert assertTrue(java.lang.String, *)").matches(mi, true)); |
Contributor
There was a problem hiding this comment.
These three assertions surprise me. In this test the type of Foo.bar() is unknown. So why would we match against String, double, or java.lang.String?
Contributor
There was a problem hiding this comment.
I guess that is how matchUnknownTypes is supposed to work: Just match whatever, as long as the "structure" is the same.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
What's changed?
Updated the antlr code to allow for wildcard parameters similarly to dot_dot.
What's your motivation?
Before, the existing test used to work due to the following:
*gets regexed by theStringUtils.aspectjNameToPattern("*")to[^.]+.<unknown>does not contain a.so the matcher works.The current code behavior: see the
<unknown>and[^.]+Changing the test adding type information
See how that regex would no longer match?
Anyone you would like to review specifically?
@greg-at-moderne
Have you considered any alternatives or workarounds?
We could alter the
getRegexonFormalTypeto avoid changes to anltr code but that's not correct according the semantics of the code.Checklist