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

[2/x] Implement joda to java time migration recipe #582

Merged
merged 15 commits into from
Oct 23, 2024

Conversation

amishra-u
Copy link
Contributor

What's changed?

This pr is the second part of implementing the migration from Joda-Time to the Java Time API. It introduces a scanner that analyzes source files to identify variables that are unsafe to migrate.

A variable is considered unsafe if an expression referencing it doesn't have a direct replacement, or if the replacement has not yet been implemented. Any variable connected to an unsafe variable also becomes unsafe.

Key Changes:

  • Implemented a scanner that analyzes source files and records unsafe variables, which will later be used by JodaTimeVisitor.
  • Added a scanMode to JodaTimeVisitor, which assumes all variables are safe to migrate from Joda-Time to Java-Time. The scanMode flag is exclusively set by JodaTimeScanner.

Not Implemented Yet:

  • Support for class variables, method parameters, and other non-local variables.
  • A scanning recipe that integrates JodaTimeScanner and JodaTimeVisitor for the migration process.

Checklist

  • I've added unit tests to cover both positive and negative cases
  • I've read and applied the recipe conventions and best practices
  • I've used the IntelliJ IDEA auto-formatter on affected files

Copy link
Contributor

@github-actions github-actions bot left a comment

Choose a reason for hiding this comment

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

Some suggestions could not be made:

  • src/main/java/org/openrewrite/java/migrate/joda/JodaTimeVisitor.java
    • lines 133-135

amishra-u and others added 11 commits October 17, 2024 12:15
…rTest.java

Co-authored-by: github-actions[bot] <41898282+github-actions[bot]@users.noreply.github.com>
…rTest.java

Co-authored-by: github-actions[bot] <41898282+github-actions[bot]@users.noreply.github.com>
…ec.java

Co-authored-by: github-actions[bot] <41898282+github-actions[bot]@users.noreply.github.com>
…r.java

Co-authored-by: github-actions[bot] <41898282+github-actions[bot]@users.noreply.github.com>
…r.java

Co-authored-by: github-actions[bot] <41898282+github-actions[bot]@users.noreply.github.com>
…ecTest.java

Co-authored-by: github-actions[bot] <41898282+github-actions[bot]@users.noreply.github.com>
…ecTest.java

Co-authored-by: github-actions[bot] <41898282+github-actions[bot]@users.noreply.github.com>
…ClassMap.java

Co-authored-by: github-actions[bot] <41898282+github-actions[bot]@users.noreply.github.com>
…ractInstantTemplates.java

Co-authored-by: github-actions[bot] <41898282+github-actions[bot]@users.noreply.github.com>
Co-authored-by: github-actions[bot] <41898282+github-actions[bot]@users.noreply.github.com>
}
}

private static class HasJodaType extends JavaIsoVisitor<Boolean[]> {
Copy link
Member

Choose a reason for hiding this comment

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

Most OpenRewrite code uses AtomicBoolean for this purpose.

@timtebeek timtebeek added the recipe Recipe requested label Oct 22, 2024
Copy link
Contributor

@timtebeek timtebeek left a comment

Choose a reason for hiding this comment

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

Great to see the progress here! I look forward to the recipes that will use these visitors to make it available for folks to run.

@timtebeek
Copy link
Contributor

Merging this instance already, to clear out open PRs ahead of the release.

@timtebeek timtebeek merged commit 669381d into openrewrite:main Oct 23, 2024
2 checks passed
@timtebeek
Copy link
Contributor

A quick heads up that we can a recipe in bulk, and will enforce that on PRs in the near future that removed these unused fields:
460fad7

From 460fad7fec51d39bf5e3c02e0fb270946361e95e Mon Sep 17 00:00:00 2001
From: Tim te Beek <timtebeek@gmail.com>
Date: Wed, 23 Oct 2024 19:31:47 +0000
Subject: [PATCH] refactor: Kill your Zombie code

Use this link to re-run the recipe: https://app.moderne.io/builder/mybR2aHWC?organizationId=T3BlblJld3JpdGU%3D

Co-authored-by: Moderne <team@moderne.io>
---
 .../java/migrate/joda/templates/DateTimeFormatTemplates.java    | 2 --
 1 file changed, 2 deletions(-)

diff --git a/src/main/java/org/openrewrite/java/migrate/joda/templates/DateTimeFormatTemplates.java b/src/main/java/org/openrewrite/java/migrate/joda/templates/DateTimeFormatTemplates.java
index 25d5ad37b0..324ea01037 100644
--- a/src/main/java/org/openrewrite/java/migrate/joda/templates/DateTimeFormatTemplates.java
+++ b/src/main/java/org/openrewrite/java/migrate/joda/templates/DateTimeFormatTemplates.java
@@ -25,8 +25,6 @@
 
 public class DateTimeFormatTemplates {
     private final MethodMatcher forPattern = new MethodMatcher(JODA_TIME_FORMAT + " forPattern(String)");
-    private final MethodMatcher forStyle = new MethodMatcher(JODA_TIME_FORMAT + " forStyle(String)");
-    private final MethodMatcher patternForStyle = new MethodMatcher(JODA_TIME_FORMAT + " patternForStyle(String, java.util.Locale)");
     private final MethodMatcher shortDate = new MethodMatcher(JODA_TIME_FORMAT + " shortDate()");
     private final MethodMatcher mediumDate = new MethodMatcher(JODA_TIME_FORMAT + " mediumDate()");
     private final MethodMatcher longDate = new MethodMatcher(JODA_TIME_FORMAT + " longDate()");

Just in case you had planned to use those in the near future still.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
recipe Recipe requested
Projects
Archived in project
Development

Successfully merging this pull request may close these issues.

3 participants