Skip to content

Commit ee2f4c4

Browse files
OpenRewrite recipe best practices
Co-authored-by: Moderne <team@moderne.io>
1 parent 5f18964 commit ee2f4c4

8 files changed

Lines changed: 261 additions & 50 deletions

File tree

src/main/java/org/openrewrite/java/migrate/jakarta/UpgradeMavenEjbPluginConfiguration.java

Lines changed: 4 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -38,17 +38,11 @@
3838
public class UpgradeMavenEjbPluginConfiguration extends Recipe {
3939

4040

41-
@Override
42-
public String getDisplayName() {
43-
return "Set `maven-ejb-plugin` ejbVersion to 4.0";
44-
}
41+
String displayName = "Set `maven-ejb-plugin` ejbVersion to 4.0";
4542

46-
@Override
47-
public String getDescription() {
48-
return "Updates the `<ejbVersion>` configuration of `maven-ejb-plugin` to `4.0` when the current value " +
49-
"(or its resolved Maven property) indicates EJB 3.x. Handles the common pattern where `<ejbVersion>` " +
50-
"is coupled to the `javax.ejb-api` dependency version via a shared property, decoupling them after migration.";
51-
}
43+
String description = "Updates the `<ejbVersion>` configuration of `maven-ejb-plugin` to `4.0` when the current value " +
44+
"(or its resolved Maven property) indicates EJB 3.x. Handles the common pattern where `<ejbVersion>` " +
45+
"is coupled to the `javax.ejb-api` dependency version via a shared property, decoupling them after migration.";
5246

5347
@Override
5448
public TreeVisitor<?, ExecutionContext> getVisitor() {

src/main/java/org/openrewrite/java/migrate/lang/JavadocToMarkdownDocComment.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,10 +20,10 @@
2020
import org.openrewrite.ExecutionContext;
2121
import org.openrewrite.Preconditions;
2222
import org.openrewrite.Recipe;
23+
import org.openrewrite.Tree;
2324
import org.openrewrite.TreeVisitor;
2425
import org.openrewrite.internal.ListUtils;
2526
import org.openrewrite.internal.StringUtils;
26-
import org.openrewrite.Tree;
2727
import org.openrewrite.java.JavaIsoVisitor;
2828
import org.openrewrite.java.JavaPrinter;
2929
import org.openrewrite.java.marker.JavaVersion;

src/main/java/org/openrewrite/java/migrate/util/UseListOf.java

Lines changed: 5 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -31,17 +31,11 @@
3131
import org.openrewrite.java.tree.J;
3232
import org.openrewrite.java.tree.Statement;
3333

34-
import java.util.ArrayList;
35-
import java.util.Collections;
36-
import java.util.HashMap;
37-
import java.util.HashSet;
38-
import java.util.List;
39-
import java.util.Map;
40-
import java.util.Set;
41-
import java.util.StringJoiner;
42-
import java.util.UUID;
34+
import java.util.*;
4335
import java.util.concurrent.atomic.AtomicBoolean;
4436

37+
import static java.util.Collections.singletonList;
38+
4539
public class UseListOf extends Recipe {
4640
private static final MethodMatcher NEW_ARRAY_LIST = new MethodMatcher("java.util.ArrayList <constructor>()", true);
4741
private static final MethodMatcher LIST_ADD = new MethodMatcher("java.util.List add(..)", true);
@@ -145,7 +139,7 @@ private J reattachElementPrefixes(J applied, List<J.MethodInvocation> adds) {
145139
for (int i = 0; i < listArgs.size(); i++) {
146140
withPrefixes.add(listArgs.get(i).withPrefix(adds.get(i).getPrefix()));
147141
}
148-
return nc.withArguments(Collections.singletonList(listCall.withArguments(withPrefixes)));
142+
return nc.withArguments(singletonList(listCall.withArguments(withPrefixes)));
149143
}
150144

151145
@Override
@@ -277,7 +271,7 @@ private Expression matchAddCallOn(Statement stmt, String targetName) {
277271
return null;
278272
}
279273
Expression arg = mi.getArguments().get(0);
280-
if (arg instanceof J.Literal && ((J.Literal) arg).getValue() == null) {
274+
if (J.Literal.isLiteralValue( arg, null )) {
281275
return null;
282276
}
283277
return arg;

src/main/java/org/openrewrite/java/migrate/util/UseMapOf.java

Lines changed: 5 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -32,17 +32,11 @@
3232
import org.openrewrite.java.tree.Statement;
3333
import org.openrewrite.java.tree.TypeUtils;
3434

35-
import java.util.ArrayList;
36-
import java.util.Collections;
37-
import java.util.HashMap;
38-
import java.util.HashSet;
39-
import java.util.List;
40-
import java.util.Map;
41-
import java.util.Set;
42-
import java.util.StringJoiner;
43-
import java.util.UUID;
35+
import java.util.*;
4436
import java.util.concurrent.atomic.AtomicBoolean;
4537

38+
import static java.util.Collections.singletonList;
39+
4640
public class UseMapOf extends Recipe {
4741
private static final MethodMatcher NEW_HASH_MAP = new MethodMatcher("java.util.HashMap <constructor>()", true);
4842
private static final MethodMatcher MAP_PUT = new MethodMatcher("java.util.Map put(..)", true);
@@ -197,7 +191,7 @@ private J reattachPairPrefixes(J applied, List<J.MethodInvocation> puts, boolean
197191
}
198192
withPrefixes.add(arg);
199193
}
200-
return nc.withArguments(Collections.singletonList(mapCall.withArguments(withPrefixes)));
194+
return nc.withArguments(singletonList(mapCall.withArguments(withPrefixes)));
201195
}
202196

203197
/**
@@ -338,7 +332,7 @@ private List<Expression> matchPutCallOn(Statement stmt, String targetName) {
338332
return null;
339333
}
340334
for (Expression arg : mi.getArguments()) {
341-
if (arg instanceof J.Literal && ((J.Literal) arg).getValue() == null) {
335+
if (J.Literal.isLiteralValue( arg, null )) {
342336
return null;
343337
}
344338
}

src/main/java/org/openrewrite/java/migrate/util/UseSetOf.java

Lines changed: 5 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -31,17 +31,11 @@
3131
import org.openrewrite.java.tree.J;
3232
import org.openrewrite.java.tree.Statement;
3333

34-
import java.util.ArrayList;
35-
import java.util.Collections;
36-
import java.util.HashMap;
37-
import java.util.HashSet;
38-
import java.util.List;
39-
import java.util.Map;
40-
import java.util.Set;
41-
import java.util.StringJoiner;
42-
import java.util.UUID;
34+
import java.util.*;
4335
import java.util.concurrent.atomic.AtomicBoolean;
4436

37+
import static java.util.Collections.singletonList;
38+
4539
public class UseSetOf extends Recipe {
4640
private static final MethodMatcher NEW_HASH_SET = new MethodMatcher("java.util.HashSet <constructor>()", true);
4741
private static final MethodMatcher SET_ADD = new MethodMatcher("java.util.Set add(..)", true);
@@ -145,7 +139,7 @@ private J reattachElementPrefixes(J applied, List<J.MethodInvocation> adds) {
145139
for (int i = 0; i < setArgs.size(); i++) {
146140
withPrefixes.add(setArgs.get(i).withPrefix(adds.get(i).getPrefix()));
147141
}
148-
return nc.withArguments(Collections.singletonList(setCall.withArguments(withPrefixes)));
142+
return nc.withArguments(singletonList(setCall.withArguments(withPrefixes)));
149143
}
150144

151145
@Override
@@ -251,7 +245,7 @@ private Expression matchAddCallOn(Statement stmt, String targetName) {
251245
return null;
252246
}
253247
Expression arg = mi.getArguments().get(0);
254-
if (arg instanceof J.Literal && ((J.Literal) arg).getValue() == null) {
248+
if (J.Literal.isLiteralValue( arg, null )) {
255249
return null;
256250
}
257251
return arg;

0 commit comments

Comments
 (0)