From deb6f384b8f07a156cb1f7494fc1eaf545273dd2 Mon Sep 17 00:00:00 2001 From: Knut Wannheden Date: Thu, 7 Mar 2024 14:37:13 +0100 Subject: [PATCH] Example using `Refaster.anyOf()` --- .../java/migrate/lang/StringRules.java | 17 ++++------------- 1 file changed, 4 insertions(+), 13 deletions(-) diff --git a/src/main/java/org/openrewrite/java/migrate/lang/StringRules.java b/src/main/java/org/openrewrite/java/migrate/lang/StringRules.java index f377183182..a8ec5fcfaa 100644 --- a/src/main/java/org/openrewrite/java/migrate/lang/StringRules.java +++ b/src/main/java/org/openrewrite/java/migrate/lang/StringRules.java @@ -15,6 +15,7 @@ */ package org.openrewrite.java.migrate.lang; +import com.google.errorprone.refaster.Refaster; import com.google.errorprone.refaster.annotation.AfterTemplate; import com.google.errorprone.refaster.annotation.BeforeTemplate; import org.openrewrite.java.template.RecipeDescriptor; @@ -27,22 +28,12 @@ public class StringRules { @SuppressWarnings("StringOperationCanBeSimplified") public static class RedundantCall { @BeforeTemplate - public String start(String string) { - return string.substring(0, string.length()); - } - - @BeforeTemplate - public String startAndEnd(String string) { - return string.substring(0); - } - - @BeforeTemplate - public String toString(String string) { - return string.toString(); + public String before(String string) { + return Refaster.anyOf(string.substring(0, string.length()), string.substring(0), string.toString()); } @AfterTemplate - public String self(String string) { + public String after(String string) { return string; } }