Skip to content

Commit 0f9298e

Browse files
ranuradhAnuRam123timtebeek
authored
remove parameters from .yml (#548)
Co-authored-by: anuram <[email protected]> Co-authored-by: Tim te Beek <[email protected]>
1 parent 5bfe6ac commit 0f9298e

File tree

2 files changed

+19
-10
lines changed

2 files changed

+19
-10
lines changed

src/main/java/org/openrewrite/java/migrate/ReplaceAWTGetPeerMethod.java

Lines changed: 18 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,8 @@
1616

1717
package org.openrewrite.java.migrate;
1818

19+
import com.fasterxml.jackson.annotation.JsonCreator;
20+
import lombok.AllArgsConstructor;
1921
import lombok.EqualsAndHashCode;
2022
import lombok.Value;
2123
import org.jspecify.annotations.Nullable;
@@ -30,18 +32,27 @@
3032

3133
@Value
3234
@EqualsAndHashCode(callSuper = false)
33-
class ReplaceAWTGetPeerMethod extends Recipe {
35+
@AllArgsConstructor
36+
public class ReplaceAWTGetPeerMethod extends Recipe {
3437

3538
@Option(displayName = "Method pattern to replace",
3639
description = "The method pattern to match and replace.",
37-
example = "java.awt.* getPeer()")
40+
example = "java.awt.* getPeer()",
41+
required = false)
3842
String getPeerMethodPattern;
3943

4044
@Option(displayName = "The LightweightPeer interface FQCN",
4145
description = "The fully qualified class name of the LightweightPeer interface to replace in `instanceof`.",
42-
example = "java.awt.peer.LightweightPeer")
46+
example = "java.awt.peer.LightweightPeer",
47+
required = false)
4348
String lightweightPeerFQCN;
4449

50+
@JsonCreator
51+
public ReplaceAWTGetPeerMethod() {
52+
getPeerMethodPattern = "java.awt.* getPeer()";
53+
lightweightPeerFQCN = "java.awt.peer.LightweightPeer";
54+
}
55+
4556
@Override
4657
public String getDisplayName() {
4758
return "Replace AWT `getPeer()` method";
@@ -50,8 +61,8 @@ public String getDisplayName() {
5061
@Override
5162
public String getDescription() {
5263
return "This recipe replaces the use of `getPeer()` method in `java.awt.*` classes. " +
53-
"`component.getPeer() != null` is replaced with `component.isDisplayable()` and " +
54-
"`component.getPeer() instanceof LightweightPeer` is replaced with `component.isLightweight()`.";
64+
"`component.getPeer() != null` is replaced with `component.isDisplayable()` and " +
65+
"`component.getPeer() instanceof LightweightPeer` is replaced with `component.isLightweight()`.";
5566
}
5667

5768
@Override
@@ -81,10 +92,10 @@ public J visitBinary(J.Binary binary, ExecutionContext ctx) {
8192
J.MethodInvocation mi = null;
8293
if (binaryCondition.getOperator() == J.Binary.Type.NotEqual) {
8394
if (binaryCondition.getLeft() instanceof J.MethodInvocation &&
84-
binaryCondition.getRight() instanceof J.Literal) {
95+
binaryCondition.getRight() instanceof J.Literal) {
8596
mi = (J.MethodInvocation) binaryCondition.getLeft();
8697
} else if (binaryCondition.getLeft() instanceof J.Literal &&
87-
binaryCondition.getRight() instanceof J.MethodInvocation) {
98+
binaryCondition.getRight() instanceof J.MethodInvocation) {
8899
mi = (J.MethodInvocation) binaryCondition.getRight();
89100
}
90101
}

src/main/resources/META-INF/rewrite/java-version-11.yml

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -69,9 +69,7 @@ recipeList:
6969
- org.openrewrite.java.migrate.RemovedPolicy
7070
- org.openrewrite.java.migrate.ReferenceCloneMethod
7171
- org.openrewrite.java.migrate.ThreadStopDestroy
72-
- org.openrewrite.java.migrate.ReplaceAWTGetPeerMethod:
73-
getPeerMethodPattern: java.awt.* getPeer()
74-
lightweightPeerFQCN: java.awt.peer.LightweightPeer
72+
- org.openrewrite.java.migrate.ReplaceAWTGetPeerMethod
7573
- org.openrewrite.scala.migrate.UpgradeScala_2_12
7674
- org.openrewrite.java.migrate.ReplaceComSunAWTUtilitiesMethods
7775
- org.openrewrite.java.migrate.ReplaceLocalizedStreamMethods

0 commit comments

Comments
 (0)