rewrite-migrate-java icon indicating copy to clipboard operation
rewrite-migrate-java copied to clipboard

Add mapping for migration for joda LocalDate

Open YarochkinMichael opened this issue 9 months ago • 9 comments

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 avatar Feb 18 '25 06:02 YarochkinMichael

The update issue is fixed by the second commit

YarochkinMichael avatar Feb 18 '25 07:02 YarochkinMichael

Add LocalDateTime mapping Add tests

YarochkinMichael avatar Feb 18 '25 17:02 YarochkinMichael

Add LocalTime mapping

YarochkinMichael avatar Feb 19 '25 07:02 YarochkinMichael

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.

YarochkinMichael avatar Feb 21 '25 13:02 YarochkinMichael

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

YarochkinMichael avatar Feb 23 '25 21:02 YarochkinMichael

Not only did the tests with my changes fail.

YarochkinMichael avatar Feb 23 '25 21:02 YarochkinMichael

Not only did the tests with my changes fail.

Yes, it failed as expected

Refer to this field to disable safeMigration a better way. https://github.com/openrewrite/rewrite-migrate-java/blob/548f4dbd07ccb6853a7368e560597589420866c1/src/main/java/org/openrewrite/java/migrate/joda/JodaTimeVisitor.java#L44

amishra-u avatar Feb 24 '25 20:02 amishra-u

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.

amishra-u avatar Feb 24 '25 20:02 amishra-u

@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.

YarochkinMichael avatar Feb 25 '25 09:02 YarochkinMichael

Ideally we see the changes from https://github.com/openrewrite/rewrite-migrate-java/pull/676 adopted here, or after this is merged.

timtebeek avatar Jun 02 '25 09:06 timtebeek

As discussed, let's move this over to https://github.com/openrewrite/rewrite-joda

Thanks again!

timtebeek avatar Aug 26 '25 18:08 timtebeek