-
Notifications
You must be signed in to change notification settings - Fork 73
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add Refaster style recipes for Guava (#522)
* Add Refaster style recipes for Guava * Update src/main/java/org/openrewrite/java/migrate/guava/NoGuavaRefaster.java Co-authored-by: github-actions[bot] <41898282+github-actions[bot]@users.noreply.github.com> --------- Co-authored-by: github-actions[bot] <41898282+github-actions[bot]@users.noreply.github.com>
- Loading branch information
1 parent
67f25e2
commit c1ed883
Showing
3 changed files
with
166 additions
and
79 deletions.
There are no files selected for viewing
59 changes: 59 additions & 0 deletions
59
src/main/java/org/openrewrite/java/migrate/guava/NoGuavaRefaster.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,59 @@ | ||
/* | ||
* Copyright 2024 the original author or authors. | ||
* <p> | ||
* Licensed under the Apache License, Version 2.0 (the "License"); | ||
* you may not use this file except in compliance with the License. | ||
* You may obtain a copy of the License at | ||
* <p> | ||
* https://www.apache.org/licenses/LICENSE-2.0 | ||
* <p> | ||
* Unless required by applicable law or agreed to in writing, software | ||
* distributed under the License is distributed on an "AS IS" BASIS, | ||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
* See the License for the specific language governing permissions and | ||
* limitations under the License. | ||
*/ | ||
package org.openrewrite.java.migrate.guava; | ||
|
||
import com.google.errorprone.refaster.annotation.AfterTemplate; | ||
import com.google.errorprone.refaster.annotation.BeforeTemplate; | ||
import org.openrewrite.java.template.RecipeDescriptor; | ||
|
||
@RecipeDescriptor( | ||
name = "Refaster style Guava to Java migration recipes.", | ||
description = "Recipes that migrate from Guava to Java, using Refaster style templates for cases beyond what declarative recipes can cover." | ||
) | ||
public class NoGuavaRefaster { | ||
|
||
@RecipeDescriptor( | ||
name = "`Preconditions.checkNotNull` to `Objects.requireNonNull`", | ||
description = "Migrate from Guava `Preconditions.checkNotNull` to Java 8 `java.util.Objects.requireNonNull`." | ||
) | ||
public static class PreconditionsCheckNotNullToObjectsRequireNonNull { | ||
@BeforeTemplate | ||
Object before(Object object, Object 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)); | ||
} | ||
} | ||
|
||
@RecipeDescriptor( | ||
name = "`String.valueof(String)` to `String`", | ||
description = "Migrate from `String.valueof(String)` to `String`, mainly as a cleanup after other recipes." | ||
) | ||
public static class StringValueOfString { | ||
@BeforeTemplate | ||
String before(String string) { | ||
return String.valueOf(string); | ||
} | ||
|
||
@AfterTemplate | ||
String after(String string) { | ||
return (string); | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters