-
Notifications
You must be signed in to change notification settings - Fork 82
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
Add mapping for migration for joda LocalDate #677
base: main
Are you sure you want to change the base?
Add mapping for migration for joda LocalDate #677
Conversation
The update issue is fixed by the second commit |
Add LocalDateTime mapping |
@@ -219,10 +223,14 @@ private J migrateMethodCall(MethodCall original, MethodCall updated) { | |||
} | |||
MethodTemplate template = AllTemplates.getTemplate(original); | |||
if (template == null) { | |||
//is it a better way to print logs? |
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.
Can you generate datatable for unhandled case?
https://docs.openrewrite.org/authoring-recipes/data-tables
or atleast use ExecutionContext messaging for unhandled case.
https://javadoc.io/doc/org.openrewrite/rewrite-core/8.19.0/org/openrewrite/InMemoryExecutionContext.html
Not sure how big your repo is but the datatable will be very useful for large repos.
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.
Can you give me example usage of how to print log line please?
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.
Hi @YarochkinMichael 👋 you can find out documentation on how to generate data tables from recipes here https://docs.openrewrite.org/authoring-recipes/data-tables#generating-the-data-table
} | ||
}; | ||
|
||
private JavaTemplate build(JavaTemplate.Builder builder) { |
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.
nice
@@ -43,12 +43,16 @@ void migrateJodaTime() { | |||
java( |
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.
Could you add a test case for each template? This will at least ensure basic verification for each one.
FYI: If you use GitHub Copilot or ChatGPT, you’ll be surprised at how well they generate these test cases.
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 added a no-arg constructor. locally, for testing, I have a project with examples. After I finish migration, I will have more time to move it to tests.
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.
Most of my code is generated by ChatGPT. ;)
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.
Hi @YarochkinMichael tests are crucial for us and we require a decent test coverage.
Please see our guides here on creating RewriteTests easily.
Add LocalTime mapping |
I was able to fix all my use cases. Not all Joda types are mapped, but now it is printing message about missing mapping. @amishra-u please have a look into my last commit. on my side class variables are migrated without any issues. TODO: add tests. i have a local project I was using for testing. Need to turn it into unit tests. |
import java.util.ArrayList; | ||
import java.util.List; | ||
|
||
import static org.openrewrite.java.migrate.joda.templates.TimeClassNames.*; |
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.
import static org.openrewrite.java.migrate.joda.templates.TimeClassNames.*; | |
import static org.openrewrite.java.migrate.joda.templates.TimeClassNames.JAVA_PERIOD; | |
import static org.openrewrite.java.migrate.joda.templates.TimeClassNames.JODA_DAYS; |
import java.util.ArrayList; | ||
import java.util.List; | ||
|
||
import static org.openrewrite.java.migrate.joda.templates.TimeClassNames.*; |
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.
import static org.openrewrite.java.migrate.joda.templates.TimeClassNames.*; | |
import static org.openrewrite.java.migrate.joda.templates.TimeClassNames.JAVA_DURATION; | |
import static org.openrewrite.java.migrate.joda.templates.TimeClassNames.JODA_HOURS; |
import org.openrewrite.java.tree.Expression; | ||
|
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.
import org.openrewrite.java.tree.Expression; | |
import static org.openrewrite.java.migrate.joda.templates.TimeClassNames.JAVA_DURATION; | |
import static org.openrewrite.java.migrate.joda.templates.TimeClassNames.JODA_SECONDS; |
@amishra-u can you pls check my "fix" for class wars? |
Not only did the tests with my changes fail. |
Yes, it failed as expected Refer to this field to disable safeMigration a better way. rewrite-migrate-java/src/main/java/org/openrewrite/java/migrate/joda/JodaTimeVisitor.java Line 44 in 548f4db
|
Before this PR can be merged, please address the following:
Alternatively, you can create a local copy of the JAR with these changes and use it in your project, skipping the PR process. If someone else needs the same feature later, they can take over and upstream it. PS: I’m not on the maintainer list—this is just my general advice. |
@amishra-u My question about "safe" is more about whether it is possible just to disable it. If so, I will remove it completely. The code you see now is mostly for the test. And allow me to continue my work, of course. :) Removing the "safe" feature is a part of migration. I can extract it in a separate PR. But it makes no sense to me. |
What's changed?
Added mapping for joda LocalDate to java LocalDate
Anyone you would like to review specifically?
@amishra-u
@timtebeek
Recipe is still not updating the field as it is used further in the code.
In the snippet below, for example;
il1
will not be updated,if2
will.id2
on line 3, then it will also be skipped, butld1
updatedChecklist
No unit tests