From 8bf390b5fcddd7d81e068b84ff00d19b7165093f Mon Sep 17 00:00:00 2001 From: Tim te Beek Date: Fri, 8 Dec 2023 20:13:57 +0000 Subject: [PATCH] refactor: OpenRewrite recipe best practices Use this link to re-run the recipe: https://app.moderne.io/recipes/builder/XX1hrwagC?organizationId=T3BlblJld3JpdGU%3D Co-authored-by: Moderne --- .../org/openrewrite/launchdarkly/ChangeVariationDefault.java | 4 ++-- .../org/openrewrite/launchdarkly/RemoveBoolVariation.java | 4 ++-- .../org/openrewrite/launchdarkly/RemoveBoolVariationTest.java | 3 ++- 3 files changed, 6 insertions(+), 5 deletions(-) diff --git a/src/main/java/org/openrewrite/launchdarkly/ChangeVariationDefault.java b/src/main/java/org/openrewrite/launchdarkly/ChangeVariationDefault.java index d06efac..5d17304 100644 --- a/src/main/java/org/openrewrite/launchdarkly/ChangeVariationDefault.java +++ b/src/main/java/org/openrewrite/launchdarkly/ChangeVariationDefault.java @@ -63,8 +63,8 @@ public String getDescription() { public TreeVisitor getVisitor() { JavaIsoVisitor visitor = new JavaIsoVisitor() { @Override - public J.MethodInvocation visitMethodInvocation(J.MethodInvocation method, ExecutionContext executionContext) { - J.MethodInvocation mi = super.visitMethodInvocation(method, executionContext); + public J.MethodInvocation visitMethodInvocation(J.MethodInvocation method, ExecutionContext ctx) { + J.MethodInvocation mi = super.visitMethodInvocation(method, ctx); if (BOOL_VARIATION_MATCHER.matches(mi) && J.Literal.isLiteralValue(mi.getArguments().get(0), featureKey)) { J.Literal literal = new J.Literal(Tree.randomId(), Space.SINGLE_SPACE, Markers.EMPTY, defaultValue, defaultValue, null, JavaType.Primitive.Boolean); return mi.withArguments(ListUtils.mapLast(mi.getArguments(), a -> literal.withPrefix(a.getPrefix()))); diff --git a/src/main/java/org/openrewrite/launchdarkly/RemoveBoolVariation.java b/src/main/java/org/openrewrite/launchdarkly/RemoveBoolVariation.java index 398aff6..085fb35 100644 --- a/src/main/java/org/openrewrite/launchdarkly/RemoveBoolVariation.java +++ b/src/main/java/org/openrewrite/launchdarkly/RemoveBoolVariation.java @@ -61,8 +61,8 @@ public String getDescription() { public TreeVisitor getVisitor() { JavaVisitor visitor = new JavaVisitor() { @Override - public J visitMethodInvocation(J.MethodInvocation method, ExecutionContext executionContext) { - J.MethodInvocation mi = (J.MethodInvocation) super.visitMethodInvocation(method, executionContext); + public J visitMethodInvocation(J.MethodInvocation method, ExecutionContext ctx) { + J.MethodInvocation mi = (J.MethodInvocation) super.visitMethodInvocation(method, ctx); if (methodMatcher.matches(mi) && J.Literal.isLiteralValue(mi.getArguments().get(0), featureKey)) { doAfterVisit(new SimplifyConstantIfBranchExecution().getVisitor()); doAfterVisit(new RemoveUnusedLocalVariables(null).getVisitor()); diff --git a/src/test/java/org/openrewrite/launchdarkly/RemoveBoolVariationTest.java b/src/test/java/org/openrewrite/launchdarkly/RemoveBoolVariationTest.java index aee3d1a..3b08261 100644 --- a/src/test/java/org/openrewrite/launchdarkly/RemoveBoolVariationTest.java +++ b/src/test/java/org/openrewrite/launchdarkly/RemoveBoolVariationTest.java @@ -201,7 +201,8 @@ void foo() { } """ ), - java(""" + java( + """ class Bar { void bar() { if (true) {