Skip to content

Commit

Permalink
Preconditions.checkNotNull recipes should retain unrelated `String.…
Browse files Browse the repository at this point in the history
…valueOf(String)` (#575)

* Delete String.valueOf(string) to string conversion

* fix test

* Slightly tweak recipe names to show difference

* Remove unused import

---------

Co-authored-by: Tim te Beek <tim@moderne.io>
  • Loading branch information
amishra-u and timtebeek authored Oct 11, 2024
1 parent 44d79d2 commit 88fbdcc
Showing 1 changed file with 12 additions and 12 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -41,36 +41,36 @@ Object after(Object object) {
}
}

// Note: Order of the below two recipes are important.
@RecipeDescriptor(
name = "`Preconditions.checkNotNull` with message to `Objects.requireNonNull`",
name = "`Preconditions.checkNotNull` with `String` message to `Objects.requireNonNull`",
description = "Migrate from Guava `Preconditions.checkNotNull` to Java 8 `java.util.Objects.requireNonNull`."
)
public static class PreconditionsCheckNotNullWithMessageToObjectsRequireNonNull {
@BeforeTemplate
Object before(Object object, Object message) {
Object before(Object object, String message) {
return com.google.common.base.Preconditions.checkNotNull(object, message);
}

@AfterTemplate
Object after(Object object, Object message) {
return java.util.Objects.requireNonNull(object, String.valueOf(message));
Object after(Object object, String message) {
return java.util.Objects.requireNonNull(object, message);
}
}

@RecipeDescriptor(
name = "`String.valueof(String)` to `String`",
description = "Migrate from `String.valueof(String)` to `String`, mainly as a cleanup after other recipes."
name = "`Preconditions.checkNotNull` with `Object` message to `Objects.requireNonNull` with `String.valueOf`",
description = "Migrate from Guava `Preconditions.checkNotNull` to Java 8 `java.util.Objects.requireNonNull`."
)
public static class StringValueOfString {
public static class PreconditionsCheckNotNullWithMessageToObjectsRequireNonNullMessageTypeObject {
@BeforeTemplate
@SuppressWarnings("UnnecessaryCallToStringValueOf")
String before(String string) {
return String.valueOf(string);
Object before(Object object, Object message) {
return com.google.common.base.Preconditions.checkNotNull(object, message);
}

@AfterTemplate
String after(String string) {
return (string);
Object after(Object object, Object message) {
return java.util.Objects.requireNonNull(object, String.valueOf(message));
}
}
}

0 comments on commit 88fbdcc

Please sign in to comment.