Skip to content
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

Open
wants to merge 9 commits into
base: main
Choose a base branch
from

Conversation

YarochkinMichael
Copy link

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.
  • when I use id2 on line 3, then it will also be skipped, but ld1 updated
  • if i remove line 3 both line 1 and 2 will be updated
LocalDate ld1 = new LocalDate();
LocalDate ld2 = new LocalDate(0L);
LocalDate ld7 = ld1.plusDays(5);

Checklist

No unit tests

@YarochkinMichael
Copy link
Author

YarochkinMichael commented Feb 18, 2025

The update issue is fixed by the second commit

@YarochkinMichael
Copy link
Author

Add LocalDateTime mapping
Add tests

@@ -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?
Copy link
Contributor

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.

Copy link
Author

@YarochkinMichael YarochkinMichael Feb 18, 2025

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?

Copy link
Contributor

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) {
Copy link
Contributor

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(
Copy link
Contributor

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.

Copy link
Author

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.

Copy link
Author

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. ;)

Copy link
Contributor

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.

@YarochkinMichael
Copy link
Author

Add LocalTime mapping

Mikhail.Yarochkin added 3 commits February 19, 2025 17:18
@YarochkinMichael
Copy link
Author

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.*;
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
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.*;
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
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;

Comment on lines +22 to +23
import org.openrewrite.java.tree.Expression;

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
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;

@YarochkinMichael
Copy link
Author

@amishra-u can you pls check my "fix" for class wars?

@YarochkinMichael
Copy link
Author

Not only did the tests with my changes fail.

@amishra-u
Copy link
Contributor

Not only did the tests with my changes fail.

Yes, it failed as expected

Refer to this field to disable safeMigration a better way.

@amishra-u
Copy link
Contributor

amishra-u commented Feb 24, 2025

Before this PR can be merged, please address the following:

  1. Ensure unit tests are included—they are essential.
  2. Avoid merging multiple features in one PR. For example, adding new templates and disabling optional safe migration should be separate.

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.

@YarochkinMichael
Copy link
Author

@amishra-u
thank you for the reply

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.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
Status: In Progress
Development

Successfully merging this pull request may close these issues.

4 participants