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
Replace Guava Optional with JDK Optional #202
Conversation
src/test/java/org/openrewrite/java/migrate/guava/PreferJavaUtilOptionalTest.java
Outdated
Show resolved
Hide resolved
Co-authored-by: Aurélien Mino <155828+murdos@users.noreply.github.com>
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.
There appear to be some minor errors in the type attribution. I think we can however fix that in a follow-up commit.
src/main/java/org/openrewrite/java/migrate/guava/PreferJavaUtilOptionalOrElseNull.java
Outdated
Show resolved
Hide resolved
J.MethodInvocation mi = super.visitMethodInvocation(method, executionContext); | ||
if (guavaCreateTempDirMatcher.matches(mi)) { | ||
return mi.withName(mi.getName().withSimpleName("orElse")) | ||
.withTemplate(JavaTemplate.builder(this::getCursor, "null").build(), mi.getCoordinates().replaceArguments()); |
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 suspect this is actually the problem of the ChangeType
recipe (I will investigate this further, when I find time), but as you can see in the following screenshot from the debugger, the type attribution of the optional
parameter refers to the correct new type, but as its owner still refers to the old JavaType.Method
object:
|
||
class A { | ||
String foo(Optional<String> optional) { | ||
return optional.orElse(null); |
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.
It looks like the type attribution is slightly messed up by the recipe. In the following screenshot you see the method type of the method invocation of the orElse()
method. I was slightly surprised by the String
return type, but I think this is normal for OpenRewrite as it uses JavaType.Method
both for method declarations and method invocations and they are slightly different in this respect. What is clearly missing, however, is the parameter type.
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.
After the addition of the applicability test in 98739f2 the tests now fail with:
Don't immediately know why; but working on other things at the moment. |
Fun to do some recipe development again; Are you OK to pickup the identified type issues separately @knutwannheden ? |
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.
👍
For #197
Thought to try my hand at a first attempt; This should cover the most common cases.
Uncovered cases are added as tests annotated with
@ExpectedToFail
.