-
Notifications
You must be signed in to change notification settings - Fork 424
Use caller reference in UseMethod #5391
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
base: main
Are you sure you want to change the base?
Conversation
Thanks for the help! Copying the failure from the logs here to make it easier to follow up:
rewrite/rewrite-java-tck/src/main/java/org/openrewrite/java/tree/JavadocTest.java Lines 1232 to 1266 in b110d3a
|
Great to see! Linking this discussion here as I imagine we'd need that |
Causes failures in rewrite-static-analysis |
Not sure about this one, the issue is in rewrite-static-analysis |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I am not opposed to this change. Just hesitate because it changes the TypesInUse cache.
@ValueSource(strings = { | ||
"java.util.Collection contains(..)", | ||
"java.util.Set contains(..)", | ||
"com.google.common.collect.ImmutableSet contains(..)", |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
As ImmutableSet
doesn't actually declare contains(Object)
I think we should correct this:
"com.google.common.collect.ImmutableSet contains(..)", | |
"com.google.common.collect.ImmutableCollection contains(..)", |
@Issue("https://github.com/openrewrite/rewrite/issues/5376") | ||
@ValueSource(strings = { | ||
"java.util.Collection contains(..)", | ||
"java.util.Set contains(..)", |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I see that this is what the issue is about. Appears to be quite the corner case, as in this case the implementation is inherited from ImmutableCollection
but at the same time ImmutableSet
also implements Set
, which indeed overrides the contains(Object)
method.
Curiously enough opening the call graph for Set#contains(Object)
in IDEA doesn't show this call site either.
What's changed?
Modified
UsesMethod
to track the actual invocation target type, rather than just the method's declaring type.Example Case:
The declaring type of the method
foo
isA
. But that misses matches on the interfaceI
What's your motivation?
Anything in particular you'd like reviewers to focus on?
This has a downstream regression in
rewrite-static-analysis
inCompareEnumsWithEqualityOperator
.UseMethod
matches for the exactjava.lang.Enum equals(java.lang.Object)
without overrides. This change would make the actual enum to use equals:com.pkg.MyEnum equals(java.lang.Object)
.Checklist