Skip to content

Commit

Permalink
Recipe descriptors part deux (#308)
Browse files Browse the repository at this point in the history
* Add `@RecipeDescriptor` to Maven Shared StringUtils

* Add `@RecipeDescriptor` to Plexus StringUtils

* Add `@RecipeDescriptor` to Plexus FileUtils

* Make nested classes public
  • Loading branch information
timtebeek committed Oct 3, 2023
1 parent 9db2f5c commit 5b2cb71
Show file tree
Hide file tree
Showing 3 changed files with 101 additions and 6 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -20,12 +20,15 @@
import org.apache.maven.shared.utils.StringUtils;
import org.openrewrite.apache.commons.lang.RepeatableArgumentMatcher;
import org.openrewrite.java.template.Matches;
import org.openrewrite.java.template.RecipeDescriptor;

import java.util.Objects;

@SuppressWarnings("ALL")
public class MavenSharedStringUtils {

@RecipeDescriptor(
name = "Replace `StringUtils.abbreviate(String, int)` with JDK internals",
description = "Replace Maven Shared `StringUtils.abbreviate(String str, int maxWidth)` with JDK internals.")
public static class Abbreviate {
@BeforeTemplate
String before(@Matches(RepeatableArgumentMatcher.class) String s1,
Expand All @@ -39,8 +42,11 @@ String after(String s, int width) {
}
}

@RecipeDescriptor(
name = "Replace `StringUtils.capitalise(String)` with JDK internals",
description = "Replace Maven Shared `StringUtils.capitalise(String str)` with JDK internals.")
@SuppressWarnings("ConstantValue")
public static class Capitalize {
public static class Capitalise {
@BeforeTemplate
String before(@Matches(RepeatableArgumentMatcher.class) String s) {
return StringUtils.capitalise(s);
Expand All @@ -52,6 +58,9 @@ String after(String s) {
}
}

@RecipeDescriptor(
name = "Replace `StringUtils.defaultString(Object)` with JDK internals",
description = "Replace Maven Shared `StringUtils.defaultString(Object obj)` with JDK internals.")
public static class DefaultString {
@BeforeTemplate
String before(String s) {
Expand All @@ -64,6 +73,9 @@ String after(String s) {
}
}

@RecipeDescriptor(
name = "Replace `StringUtils.defaultString(Object, String)` with JDK internals",
description = "Replace Maven Shared `StringUtils.defaultString(Object obj, String nullDefault)` with JDK internals.")
public static class DefaultStringFallback {
@BeforeTemplate
String before(String s, String nullDefault) {
Expand All @@ -76,6 +88,9 @@ String after(String s, String nullDefault) {
}
}

@RecipeDescriptor(
name = "Replace `StringUtils.deleteWhitespace(String)` with JDK internals",
description = "Replace Maven Shared `StringUtils.deleteWhitespace(String str)` with JDK internals.")
public static class DeleteWhitespace {
@BeforeTemplate
String before(@Matches(RepeatableArgumentMatcher.class) String s) {
Expand All @@ -88,6 +103,9 @@ String after(String s) {
}
}

@RecipeDescriptor(
name = "Replace `StringUtils.equalsIgnoreCase(String, String)` with JDK internals",
description = "Replace Maven Shared `StringUtils.equalsIgnoreCase(String str1, String str2)` with JDK internals.")
public static class EqualsIgnoreCase {
@BeforeTemplate
boolean before(@Matches(RepeatableArgumentMatcher.class) String s,
Expand All @@ -101,6 +119,9 @@ boolean after(String s, String other) {
}
}

@RecipeDescriptor(
name = "Replace `StringUtils.equals(String, String)` with JDK internals",
description = "Replace Maven Shared `StringUtils.equals(String str1, String str2)` with JDK internals.")
public static class Equals {
@BeforeTemplate
boolean before(String s, String other) {
Expand All @@ -113,6 +134,9 @@ boolean after(String s, String other) {
}
}

@RecipeDescriptor(
name = "Replace `StringUtils.lowerCase(String)` with JDK internals",
description = "Replace Maven Shared `StringUtils.lowerCase(String str)` with JDK internals.")
public static class Lowercase {
@BeforeTemplate
String before(@Matches(RepeatableArgumentMatcher.class) String s) {
Expand All @@ -125,6 +149,9 @@ String after(String s) {
}
}

@RecipeDescriptor(
name = "Replace `StringUtils.replace(String, String, String)` with JDK internals",
description = "Replace Maven Shared `StringUtils.replace(String text, String searchString, String replacement)` with JDK internals.")
public static class Replace {
@BeforeTemplate
String before(@Matches(RepeatableArgumentMatcher.class) String s,
Expand All @@ -139,6 +166,9 @@ String after(String s, String search, String replacement) {
}
}

@RecipeDescriptor(
name = "Replace `StringUtils.reverse(String)` with JDK internals",
description = "Replace Maven Shared `StringUtils.reverse(String str)` with JDK internals.")
public static class Reverse {
@BeforeTemplate
String before(@Matches(RepeatableArgumentMatcher.class) String s) {
Expand All @@ -151,6 +181,9 @@ String after(String s) {
}
}

@RecipeDescriptor(
name = "Replace `StringUtils.split(String)` with JDK internals",
description = "Replace Maven Shared `StringUtils.split(String str)` with JDK internals.")
public static class Split {
@BeforeTemplate
String[] before(@Matches(RepeatableArgumentMatcher.class) String s) {
Expand All @@ -163,6 +196,9 @@ String[] after(String s) {
}
}

@RecipeDescriptor(
name = "Replace `StringUtils.strip(String)` with JDK internals",
description = "Replace Maven Shared `StringUtils.strip(String str)` with JDK internals.")
public static class Strip {
@BeforeTemplate
String before(@Matches(RepeatableArgumentMatcher.class) String s) {
Expand All @@ -175,6 +211,9 @@ String after(String s) {
}
}

@RecipeDescriptor(
name = "Replace `StringUtils.trim(String)` with JDK internals",
description = "Replace Maven Shared `StringUtils.trim(String str)` with JDK internals.")
public static class Trim {
@BeforeTemplate
String before(@Matches(RepeatableArgumentMatcher.class) String s) {
Expand All @@ -187,6 +226,9 @@ String after(String s) {
}
}

@RecipeDescriptor(
name = "Replace `StringUtils.upperCase(String)` with JDK internals",
description = "Replace Maven Shared `StringUtils.upperCase(String str)` with JDK internals.")
public static class Uppercase {
@BeforeTemplate
String before(@Matches(RepeatableArgumentMatcher.class) String s) {
Expand All @@ -198,5 +240,4 @@ String after(String s) {
return (s == null ? null : s.toUpperCase());
}
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -18,13 +18,17 @@
import com.google.errorprone.refaster.annotation.AfterTemplate;
import com.google.errorprone.refaster.annotation.BeforeTemplate;
import org.codehaus.plexus.util.FileUtils;
import org.openrewrite.java.template.RecipeDescriptor;

import java.io.File;

class PlexusFileUtils {

// https://github.com/codehaus-plexus/plexus-utils/blob/master/src/main/java/org/codehaus/plexus/util/StringUtils.java

@RecipeDescriptor(
name = "Replace `FileUtils.deleteDirectory(File)` with JDK internals",
description = "Replace Plexus `FileUtils.deleteDirectory(File directory)` with JDK internals.")
static class DeleteDirectoryFile {
@BeforeTemplate
void before(File dir) throws Exception {
Expand All @@ -37,6 +41,9 @@ void after(File dir) throws Exception {
}
}

@RecipeDescriptor(
name = "Replace `FileUtils.deleteDirectory(String)` with JDK internals",
description = "Replace Plexus `FileUtils.deleteDirectory(String directory)` with JDK internals.")
static class DeleteDirectoryString {
@BeforeTemplate
void before(String dir) throws Exception {
Expand All @@ -49,6 +56,9 @@ void after(String dir) throws Exception {
}
}

@RecipeDescriptor(
name = "Replace `FileUtils.fileExists(String)` with JDK internals",
description = "Replace Plexus `FileUtils.fileExists(String fileName)` with JDK internals.")
static class FileExistsString {
@BeforeTemplate
boolean before(String fileName) throws Exception {
Expand All @@ -61,6 +71,9 @@ boolean after(String fileName) throws Exception {
}
}

@RecipeDescriptor(
name = "Replace `FileUtils.getFile(String)` with JDK internals",
description = "Replace Plexus `FileUtils.getFile(String fileName)` with JDK internals.")
static class GetFile {
@BeforeTemplate
File before(String fileName) throws Exception {
Expand All @@ -72,5 +85,4 @@ File after(String fileName) throws Exception {
return new File(fileName);
}
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -20,12 +20,15 @@
import org.codehaus.plexus.util.StringUtils;
import org.openrewrite.apache.commons.lang.RepeatableArgumentMatcher;
import org.openrewrite.java.template.Matches;
import org.openrewrite.java.template.RecipeDescriptor;

import java.util.Objects;

@SuppressWarnings("ALL")
public class PlexusStringUtils {

@RecipeDescriptor(
name = "Replace `StringUtils.abbreviate(String, int)` with JDK internals",
description = "Replace Plexus `StringUtils.abbreviate(String str, int maxWidth)` with JDK internals.")
public static class Abbreviate {
@BeforeTemplate
String before(@Matches(RepeatableArgumentMatcher.class) String s1,
Expand All @@ -39,8 +42,11 @@ String after(String s, int width) {
}
}

@RecipeDescriptor(
name = "Replace `StringUtils.capitalise(String)` with JDK internals",
description = "Replace Plexus `StringUtils.capitalise(String str)` with JDK internals.")
@SuppressWarnings("ConstantValue")
public static class Capitalize {
public static class Capitalise {
@BeforeTemplate
String before(@Matches(RepeatableArgumentMatcher.class) String s) {
return StringUtils.capitalise(s);
Expand All @@ -52,6 +58,9 @@ String after(String s) {
}
}

@RecipeDescriptor(
name = "Replace `StringUtils.defaultString(Object)` with JDK internals",
description = "Replace Plexus `StringUtils.defaultString(Object obj)` with JDK internals.")
public static class DefaultString {
@BeforeTemplate
String before(String s) {
Expand All @@ -64,6 +73,9 @@ String after(String s) {
}
}

@RecipeDescriptor(
name = "Replace `StringUtils.defaultString(Object, String)` with JDK internals",
description = "Replace Plexus `StringUtils.defaultString(Object obj, String nullDefault)` with JDK internals.")
public static class DefaultStringFallback {
@BeforeTemplate
String before(String s, String nullDefault) {
Expand All @@ -76,6 +88,9 @@ String after(String s, String nullDefault) {
}
}

@RecipeDescriptor(
name = "Replace `StringUtils.deleteWhitespace(String)` with JDK internals",
description = "Replace Plexus `StringUtils.deleteWhitespace(String str)` with JDK internals.")
public static class DeleteWhitespace {
@BeforeTemplate
String before(@Matches(RepeatableArgumentMatcher.class) String s) {
Expand All @@ -88,6 +103,9 @@ String after(String s) {
}
}

@RecipeDescriptor(
name = "Replace `StringUtils.equalsIgnoreCase(String, String)` with JDK internals",
description = "Replace Plexus `StringUtils.equalsIgnoreCase(String str1, String str2)` with JDK internals.")
public static class EqualsIgnoreCase {
@BeforeTemplate
boolean before(@Matches(RepeatableArgumentMatcher.class) String s,
Expand All @@ -101,6 +119,9 @@ boolean after(String s, String other) {
}
}

@RecipeDescriptor(
name = "Replace `StringUtils.equals(String, String)` with JDK internals",
description = "Replace Plexus `StringUtils.equals(String str1, String str2)` with JDK internals.")
public static class Equals {
@BeforeTemplate
boolean before(String s, String other) {
Expand All @@ -113,6 +134,9 @@ boolean after(String s, String other) {
}
}

@RecipeDescriptor(
name = "Replace `StringUtils.lowerCase(String)` with JDK internals",
description = "Replace Plexus `StringUtils.lowerCase(String str)` with JDK internals.")
public static class Lowercase {
@BeforeTemplate
String before(@Matches(RepeatableArgumentMatcher.class) String s) {
Expand All @@ -125,6 +149,9 @@ String after(String s) {
}
}

@RecipeDescriptor(
name = "Replace `StringUtils.replace(String, String, String)` with JDK internals",
description = "Replace Plexus `StringUtils.replace(String text, String searchString, String replacement)` with JDK internals.")
public static class Replace {
@BeforeTemplate
String before(@Matches(RepeatableArgumentMatcher.class) String s,
Expand All @@ -139,6 +166,9 @@ String after(String s, String search, String replacement) {
}
}

@RecipeDescriptor(
name = "Replace `StringUtils.reverse(String)` with JDK internals",
description = "Replace Plexus `StringUtils.reverse(String str)` with JDK internals.")
public static class Reverse {
@BeforeTemplate
String before(@Matches(RepeatableArgumentMatcher.class) String s) {
Expand All @@ -151,6 +181,9 @@ String after(String s) {
}
}

@RecipeDescriptor(
name = "Replace `StringUtils.split(String)` with JDK internals",
description = "Replace Plexus `StringUtils.split(String str)` with JDK internals.")
public static class Split {
@BeforeTemplate
String[] before(@Matches(RepeatableArgumentMatcher.class) String s) {
Expand All @@ -163,6 +196,9 @@ String[] after(String s) {
}
}

@RecipeDescriptor(
name = "Replace `StringUtils.strip(String)` with JDK internals",
description = "Replace Plexus `StringUtils.strip(String str)` with JDK internals.")
public static class Strip {
@BeforeTemplate
String before(@Matches(RepeatableArgumentMatcher.class) String s) {
Expand All @@ -175,6 +211,9 @@ String after(String s) {
}
}

@RecipeDescriptor(
name = "Replace `StringUtils.trim(String)` with JDK internals",
description = "Replace Plexus `StringUtils.trim(String str)` with JDK internals.")
public static class Trim {
@BeforeTemplate
String before(@Matches(RepeatableArgumentMatcher.class) String s) {
Expand All @@ -187,6 +226,9 @@ String after(String s) {
}
}

@RecipeDescriptor(
name = "Replace `StringUtils.upperCase(String)` with JDK internals",
description = "Replace Plexus `StringUtils.upperCase(String str)` with JDK internals.")
public static class Uppercase {
@BeforeTemplate
String before(@Matches(RepeatableArgumentMatcher.class) String s) {
Expand Down

0 comments on commit 5b2cb71

Please sign in to comment.