Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Recipe descriptors part deux #308

Merged
merged 5 commits into from
Oct 3, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@ File after(String name) {
}

// NOTE: java: reference to compile is ambiguous; methods P3 & F3 match
// private static class Write {
// public static class Write {
// @BeforeTemplate
// void before(File file, CharSequence data, Charset cs) throws Exception {
// FileUtils.write(file, data, cs);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,7 @@ String after(String s) {
}

//NOTE: The test for this recipe fails, I think it could be due to a `rewrite-templating` bug
//private static class Chomp {
//public static class Chomp {
// @BeforeTemplate
// String before(String s) {
// return StringUtils.chomp(s);
Expand All @@ -72,7 +72,7 @@ String after(String s) {
//}

// NOTE: fails with __P__. inserted
//private static class Chop {
//public static class Chop {
// @BeforeTemplate
// String before(String s) {
// return StringUtils.chop(s);
Expand All @@ -88,7 +88,7 @@ String after(String s) {
//}

// NOTE: not sure if accurate replacement
//private static class Contains {
//public static class Contains {
// @BeforeTemplate
// boolean before(String s, String search) {
// return StringUtils.contains(s, search);
Expand All @@ -101,7 +101,7 @@ String after(String s) {
//}

// NOTE: Requires Java 9+ for s.chars()
//private static class CountMatchesChar {
//public static class CountMatchesChar {
// @BeforeTemplate
// int before(String s, char pattern) {
// return StringUtils.countMatches(s, pattern);
Expand Down Expand Up @@ -159,7 +159,7 @@ String after(String s) {
}

// NOTE: unlikely to go over well due to added complexity
//private static class EndsWithIgnoreCase {
//public static class EndsWithIgnoreCase {
// @BeforeTemplate
// boolean before(String s, String suffix) {
// return StringUtils.endsWithIgnoreCase(s, suffix);
Expand Down Expand Up @@ -203,7 +203,7 @@ boolean after(String s, String other) {
}

// NOTE: unlikely to go over well due to added complexity
//private static class IndexOfAny {
//public static class IndexOfAny {
// @BeforeTemplate
// int before(String s, String searchChars) {
// return StringUtils.indexOfAny(s, searchChars);
Expand All @@ -221,7 +221,7 @@ boolean after(String s, String other) {
//}

// NOTE: not sure if accurate replacement
//private static class IsAlphanumericSpace {
//public static class IsAlphanumericSpace {
// @BeforeTemplate
// boolean before(String s) {
// return StringUtils.isAlphanumericSpace(s);
Expand All @@ -234,7 +234,7 @@ boolean after(String s, String other) {


// `chars()` is only in Java 9+
//private static class IsAlphanumeric {
//public static class IsAlphanumeric {
// @BeforeTemplate
// boolean before(@Matches(RepeatableArgumentMatcher.class) String s) {
// return StringUtils.isAlphanumeric(s);
Expand All @@ -247,7 +247,7 @@ boolean after(String s, String other) {
//}

// NOTE: not sure if accurate replacement
//private static class IsAlphaSpace {
//public static class IsAlphaSpace {
// @BeforeTemplate
// boolean before(String s) {
// return StringUtils.isAlphaSpace(s);
Expand All @@ -259,7 +259,7 @@ boolean after(String s, String other) {
// }
//}

//private static class StripAll {
//public static class StripAll {
// @BeforeTemplate
// String[] before(String[] s) {
// return StringUtils.stripAll(s);
Expand All @@ -274,7 +274,7 @@ boolean after(String s, String other) {
//}

// `chars()` is only in Java 9+
//private static class IsAlpha {
//public static class IsAlpha {
// @BeforeTemplate
// boolean before(@Matches(RepeatableArgumentMatcher.class) String s) {
// return StringUtils.isAlpha(s);
Expand All @@ -287,7 +287,7 @@ boolean after(String s, String other) {
//}

// NOTE: better handled by `org.openrewrite.java.migrate.apache.commons.lang.IsNotEmptyToJdk`
//private static class IsEmpty {
//public static class IsEmpty {
// @BeforeTemplate
// boolean before(String s) {
// return StringUtils.isEmpty(s);
Expand Down Expand Up @@ -322,7 +322,7 @@ boolean after(String s, String other) {
// }
//}

//private static class Join {
//public static class Join {
// @BeforeTemplate
// String before(String s) {
// return StringUtils.join(s);
Expand All @@ -336,7 +336,7 @@ boolean after(String s, String other) {

// NOTE: not sure if accurate replacement
@SuppressWarnings("ConstantValue")
//private static class Left {
//public static class Left {
// @BeforeTemplate
// String before(String s, int l) {
// return StringUtils.left(s, l);
Expand Down Expand Up @@ -364,7 +364,7 @@ String after(String s) {
}

// NOTE: not sure if accurate replacement
//private static class Mid {
//public static class Mid {
// @BeforeTemplate
// String before(String s, int p, int l) {
// return StringUtils.mid(s, p, l);
Expand All @@ -377,7 +377,7 @@ String after(String s) {
//}

// NOTE: not sure if accurate replacement
//private static class Overlay {
//public static class Overlay {
// @BeforeTemplate
// String before(String s, int w, int l, String overlay) {
// return StringUtils.overlay(s, overlay, w, l);
Expand All @@ -390,7 +390,7 @@ String after(String s) {
//}

// NOTE: Similar issues to what LeftPad and RightPad have
//private static class Center {
//public static class Center {
// @BeforeTemplate
// String before(String s, int size) {
// return StringUtils.center(s, size);
Expand Down Expand Up @@ -419,7 +419,7 @@ String after(String s, String end) {
}
}

//private static class Repeat {
//public static class Repeat {
// @BeforeTemplate
// String before(String s, int l) {
// return StringUtils.repeat(s, l);
Expand All @@ -432,7 +432,7 @@ String after(String s, String end) {
//}

// NOTE: requires dedicated recipe to clean up `Pattern.quote(",")`
//private static class ReplaceOnce {
//public static class ReplaceOnce {
// @BeforeTemplate
// String before(String s, String search, String replacement) {
// return StringUtils.replaceOnce(s, search, replacement);
Expand Down Expand Up @@ -477,7 +477,7 @@ String after(String s) {
}

// NOTE: not sure if accurate replacement
//private static class Right {
//public static class Right {
// @BeforeTemplate
// String before(String s, int l) {
// return StringUtils.right(s, l);
Expand Down Expand Up @@ -505,7 +505,7 @@ String[] after(String s) {
}

// NOTE: requires dedicated recipe to clean up `Pattern.quote(",")`
//private static class SplitSeparator {
//public static class SplitSeparator {
// @BeforeTemplate
// String[] before(String s, String arg) {
// return StringUtils.split(s, arg);
Expand All @@ -518,7 +518,7 @@ String[] after(String s) {
//}

// NOTE: different semantics in handling max=0 to discard trailing empty strings
//private static class SplitSeparatorMax {
//public static class SplitSeparatorMax {
// @BeforeTemplate
// String[] before(String s, String arg, int max) {
// return StringUtils.split(s, arg, max);
Expand Down Expand Up @@ -546,7 +546,7 @@ String after(String s) {
}

// NOTE: suffix is a set of characters, not a complete literal string
//private static class StripEnd {
//public static class StripEnd {
// @BeforeTemplate
// String before(String s, String suffix) {
// return StringUtils.stripEnd(s, suffix);
Expand All @@ -559,7 +559,7 @@ String after(String s) {
//}

// NOTE: suffix is a set of characters, not a complete literal string
//private static class StripStart {
//public static class StripStart {
// @BeforeTemplate
// String before(String s, String chars) {
// return StringUtils.stripStart(s, chars);
Expand All @@ -572,7 +572,7 @@ String after(String s) {
//}

// NOTE: not sure if accurate replacement
//private static class StartsWith {
//public static class StartsWith {
// @BeforeTemplate
// boolean before(String s, String prefix) {
// return StringUtils.startsWith(s, prefix);
Expand All @@ -585,7 +585,7 @@ String after(String s) {
//}

// NOTE: Incorrect handling of before null/empty and separator null/empty
//private static class SubstringAfter {
//public static class SubstringAfter {
// @BeforeTemplate
// String before(String s, String sep) {
// return StringUtils.substringAfter(s, sep);
Expand All @@ -598,7 +598,7 @@ String after(String s) {
//}

// NOTE: Incorrect handling of negative values
//private static class Substring {
//public static class Substring {
// @BeforeTemplate
// String before(String s, int l, int w) {
// return StringUtils.substring(s, l, w);
Expand All @@ -611,7 +611,7 @@ String after(String s) {
//}

// NOTE: fails to account for isTitleCase
//private static class SwapCase {
//public static class SwapCase {
// @BeforeTemplate
// String before(String s, char sep) {
// return StringUtils.swapCase(s);
Expand Down Expand Up @@ -689,7 +689,7 @@ String after(String s) {
}

// NOTE: breaks on empty strings
//private static class Uncapitalize {
//public static class Uncapitalize {
// @BeforeTemplate
// String before(String s) {
// return StringUtils.uncapitalize(s);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ public class StringRules {
description = "Replace redundant `substring(..)` and `toString()` method calls with the `String` self."
)
@SuppressWarnings("StringOperationCanBeSimplified")
static class RedundantCall {
public static class RedundantCall {
@BeforeTemplate
public String start(String string) {
return string.substring(0, string.length());
Expand All @@ -51,7 +51,7 @@ public String self(String string) {
name = "Replace `String.indexOf(String, 0)` with `String.indexOf(String)`",
description = "Replace `String.indexOf(String str, int fromIndex)` with `String.indexOf(String)`.")
@SuppressWarnings("StringOperationCanBeSimplified")
static class IndexOfString {
public static class IndexOfString {
@BeforeTemplate
public int indexOfZero(String string, String test) {
return string.indexOf(test, 0);
Expand All @@ -67,7 +67,7 @@ public int indexOf(String string, String test) {
name = "Replace `String.indexOf(char, 0)` with `String.indexOf(char)`",
description = "Replace `String.indexOf(char ch, int fromIndex)` with `String.indexOf(char)`.")
@SuppressWarnings("StringOperationCanBeSimplified")
static class IndexOfChar {
public static class IndexOfChar {
@BeforeTemplate
public int indexOfZero(String string, char test) {
return string.indexOf(test, 0);
Expand All @@ -83,7 +83,7 @@ public int indexOf(String string, char test) {
name = "Replace lower and upper case `String` comparisons with `String.equalsIgnoreCase(String)`",
description = "Replace `String` equality comparisons involving `.toLowerCase()` or `.toUpperCase()` with `String.equalsIgnoreCase(String anotherString)`.")
@SuppressWarnings("StringOperationCanBeSimplified")
static class UseEqualsIgnoreCase {
public static class UseEqualsIgnoreCase {
@BeforeTemplate
public boolean bothLowerCase(String string, String test) {
return string.toLowerCase().equals(test.toLowerCase());
Expand Down
Loading
Loading