Skip to content

Commit 180b215

Browse files
committed
Revert "Joda-time: Make safe migration optional (#811)"
This reverts commit 531270b.
1 parent 531270b commit 180b215

File tree

3 files changed

+7
-31
lines changed

3 files changed

+7
-31
lines changed

src/main/java/org/openrewrite/java/migrate/joda/JodaTimeRecipe.java

Lines changed: 6 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -15,11 +15,12 @@
1515
*/
1616
package org.openrewrite.java.migrate.joda;
1717

18-
import lombok.EqualsAndHashCode;
1918
import lombok.Getter;
20-
import lombok.Value;
2119
import org.jspecify.annotations.Nullable;
22-
import org.openrewrite.*;
20+
import org.openrewrite.ExecutionContext;
21+
import org.openrewrite.Preconditions;
22+
import org.openrewrite.ScanningRecipe;
23+
import org.openrewrite.TreeVisitor;
2324
import org.openrewrite.java.search.UsesType;
2425
import org.openrewrite.java.tree.J;
2526
import org.openrewrite.java.tree.J.VariableDeclarations.NamedVariable;
@@ -29,23 +30,7 @@
2930

3031
import static java.util.Collections.emptyList;
3132

32-
@EqualsAndHashCode(callSuper = false)
33-
@Value
3433
public class JodaTimeRecipe extends ScanningRecipe<JodaTimeRecipe.Accumulator> {
35-
36-
/**
37-
* Controls whether additional safety checks are performed during the migration process.
38-
* When enabled, the recipe will verify that expressions are safe to migrate before performing the migration.
39-
* This helps prevent potential issues or bugs that might arise from automatic migration.
40-
*/
41-
@Option(displayName = "Safe migration only",
42-
description = "When enabled, performs additional safety checks to verify that expressions are safe to migrate before converting them. " +
43-
"Safety checks include analyzing method parameters, return values, and variable usages across class boundaries.",
44-
required = false
45-
)
46-
@Nullable
47-
Boolean safeMigrationOnly;
48-
4934
@Override
5035
public String getDisplayName() {
5136
return "Migrate Joda-Time to Java time";
@@ -63,12 +48,12 @@ public Accumulator getInitialValue(ExecutionContext ctx) {
6348

6449
@Override
6550
public TreeVisitor<?, ExecutionContext> getScanner(Accumulator acc) {
66-
return new JodaTimeScanner(acc, Boolean.TRUE.equals(safeMigrationOnly));
51+
return new JodaTimeScanner(acc);
6752
}
6853

6954
@Override
7055
public TreeVisitor<?, ExecutionContext> getVisitor(Accumulator acc) {
71-
JodaTimeVisitor jodaTimeVisitor = new JodaTimeVisitor(acc, Boolean.TRUE.equals(safeMigrationOnly), new LinkedList<>());
56+
JodaTimeVisitor jodaTimeVisitor = new JodaTimeVisitor(acc, true, new LinkedList<>());
7257
return Preconditions.check(new UsesType<>("org.joda.time.*", true), jodaTimeVisitor);
7358
}
7459

src/main/java/org/openrewrite/java/migrate/joda/JodaTimeScanner.java

Lines changed: 0 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -41,21 +41,15 @@ class JodaTimeScanner extends ScopeAwareVisitor {
4141

4242
@Getter
4343
private final JodaTimeRecipe.Accumulator acc;
44-
private final boolean safeMigrationOnly;
4544

4645
private final Map<NamedVariable, Set<NamedVariable>> varDependencies = new HashMap<>();
4746
private final Map<JavaType, Set<String>> unsafeVarsByType = new HashMap<>();
4847
private final Map<JavaType.Method, Set<NamedVariable>> methodReferencedVars = new HashMap<>();
4948
private final Map<JavaType.Method, Set<UnresolvedVar>> methodUnresolvedReferencedVars = new HashMap<>();
5049

5150
public JodaTimeScanner(JodaTimeRecipe.Accumulator acc) {
52-
this(acc, true);
53-
}
54-
55-
public JodaTimeScanner(JodaTimeRecipe.Accumulator acc, boolean safeMigrationOnly) {
5651
super(new LinkedList<>());
5752
this.acc = acc;
58-
this.safeMigrationOnly = safeMigrationOnly;
5953
}
6054

6155
@Override
@@ -73,9 +67,6 @@ public Javadoc visitReference(Javadoc.Reference reference, ExecutionContext ctx)
7367

7468
@Override
7569
public J visitCompilationUnit(J.CompilationUnit cu, ExecutionContext ctx) {
76-
if (!safeMigrationOnly) { // skip scan if safe mode is disabled
77-
return cu;
78-
}
7970
super.visitCompilationUnit(cu, ctx);
8071
Set<NamedVariable> allReachable = new HashSet<>();
8172
for (NamedVariable var : acc.getUnsafeVars()) {

src/test/java/org/openrewrite/java/migrate/joda/JodaTimeRecipeTest.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,7 @@ class JodaTimeRecipeTest implements RewriteTest {
3030
@Override
3131
public void defaults(RecipeSpec spec) {
3232
spec
33-
.recipe(new JodaTimeRecipe(true))
33+
.recipe(new JodaTimeRecipe())
3434
.parser(JavaParser.fromJavaVersion().classpath("joda-time"));
3535
}
3636

0 commit comments

Comments
 (0)