rewrite-migrate-java
rewrite-migrate-java copied to clipboard
LombokValueToRecord results in broken if method references are used
What version of OpenRewrite are you using?
- OpenRewrite v1.2.3
- Maven/Gradle plugin v1.2.3
- rewrite-module v1.2.3
How are you running OpenRewrite?
From the sources of rewrite-migrate-java.
What is the smallest, simplest way to reproduce the problem?
The recipe correctly adapts method invocations to the changed getter naming convention: getTest() -> test(). But it does not do so for method references, i.e. a::getTest remains as it is.
Are you interested in contributing a fix to OpenRewrite?
Yes, I would like to, but could you elaborate on how openrewrite models method references? Is it some kind of member reference?
Yes, I would like to, but could you elaborate on how openrewrite models method references? Is it some kind of member reference?
Correct. There is a J.MemberReference type, which in case it is a reference to a method has a non-null methodType: https://github.com/openrewrite/rewrite/blob/516c70b89ebbb43803d2dd6e0bc2cf31307a80d3/rewrite-java/src/main/java/org/openrewrite/java/tree/J.java#L3454-L3460. This methodType is the type attribution for the method the method reference refers to.
Hope this helps!
Hope this helps!
yes! I will look into it after my vacation.
I tried to implement it, but I encountered an issue. which is demonstrated here:
- https://github.com/openrewrite/rewrite-migrate-java/pull/469
For a member reference a::getTest the field methodType is null.
It works however for static methods...
Any ideas @knutwannheden @timtebeek ?