Skip to content

Commit 3897b37

Browse files
Also change Guava Predicate method name (openrewrite#473)
* Also change Guava Predicate method name Fixes openrewrite#435 * Apply suggestions from code review 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>
1 parent c82c73a commit 3897b37

File tree

2 files changed

+74
-0
lines changed

2 files changed

+74
-0
lines changed

src/main/resources/META-INF/rewrite/no-guava.yml

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -161,6 +161,10 @@ tags:
161161
- guava
162162
- RSPEC-S4738
163163
recipeList:
164+
- org.openrewrite.java.ChangeMethodName:
165+
methodPattern: com.google.common.base.Predicate apply(..)
166+
newMethodName: test
167+
matchOverrides: true
164168
- org.openrewrite.java.ChangeType:
165169
oldFullyQualifiedTypeName: com.google.common.base.Predicate
166170
newFullyQualifiedTypeName: java.util.function.Predicate
Lines changed: 70 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,70 @@
1+
/*
2+
* Copyright 2024 the original author or authors.
3+
* <p>
4+
* Licensed under the Apache License, Version 2.0 (the "License");
5+
* you may not use this file except in compliance with the License.
6+
* You may obtain a copy of the License at
7+
* <p>
8+
* https://www.apache.org/licenses/LICENSE-2.0
9+
* <p>
10+
* Unless required by applicable law or agreed to in writing, software
11+
* distributed under the License is distributed on an "AS IS" BASIS,
12+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13+
* See the License for the specific language governing permissions and
14+
* limitations under the License.
15+
*/
16+
package org.openrewrite.java.migrate.guava;
17+
18+
import org.junit.jupiter.api.Test;
19+
import org.openrewrite.DocumentExample;
20+
import org.openrewrite.java.JavaParser;
21+
import org.openrewrite.test.RecipeSpec;
22+
import org.openrewrite.test.RewriteTest;
23+
24+
import static org.openrewrite.java.Assertions.java;
25+
26+
class PreferJavaUtilPredicateTest implements RewriteTest {
27+
@Override
28+
public void defaults(RecipeSpec spec) {
29+
spec.recipeFromResources("org.openrewrite.java.migrate.guava.PreferJavaUtilPredicate")
30+
.parser(JavaParser.fromJavaVersion().classpath("guava"));
31+
}
32+
33+
@DocumentExample
34+
@Test
35+
void changeTypeAndMethodName() {
36+
rewriteRun(
37+
//language=java
38+
java(
39+
"""
40+
import com.google.common.base.Predicate;
41+
42+
class A {
43+
public static Predicate<String> makeStringPredicate() {
44+
return new Predicate<String>() {
45+
@Override
46+
public boolean apply(String input) {
47+
return input.isEmpty();
48+
}
49+
};
50+
}
51+
}
52+
""",
53+
"""
54+
import java.util.function.Predicate;
55+
56+
class A {
57+
public static Predicate<String> makeStringPredicate() {
58+
return new Predicate<String>() {
59+
@Override
60+
public boolean test(String input) {
61+
return input.isEmpty();
62+
}
63+
};
64+
}
65+
}
66+
"""
67+
)
68+
);
69+
}
70+
}

0 commit comments

Comments
 (0)