Skip to content

Commit bb024d5

Browse files
authored
Generate Guava InlineMethodCalls recipes using openrewrite/rewrite#6059 (#853)
* Generate Guava InlineMethodCalls recipes using openrewrite/rewrite#6059 * Add license header * Regenerate file * Read all resources now that Guava is split across two files
1 parent 2a1a482 commit bb024d5

File tree

7 files changed

+323
-18
lines changed

7 files changed

+323
-18
lines changed
Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
<component name="ProjectRunConfigurationManager">
2+
<configuration default="false" name="InlineMethodCallsRecipeGenerator" type="Application" factoryName="Application">
3+
<option name="MAIN_CLASS_NAME" value="org.openrewrite.java.internal.parser.InlineMethodCallsRecipeGenerator" />
4+
<module name="rewrite-migrate-java.main" />
5+
<option name="PROGRAM_PARAMETERS" value="src/main/resources/META-INF/rewrite/classpath.tsv.gz src/main/resources/META-INF/rewrite/inline-guava-methods.yml org.openrewrite.java.migrate.guava.NoGuavaInlineMeMethods" />
6+
<method v="2">
7+
<option name="Make" enabled="true" />
8+
</method>
9+
</configuration>
10+
</component>
375 Bytes
Binary file not shown.
Lines changed: 310 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,310 @@
1+
# Copyright 2025 the original author or authors.
2+
# <p>
3+
# Licensed under the Moderne Source Available License (the "License");
4+
# you may not use this file except in compliance with the License.
5+
# You may obtain a copy of the License at
6+
# <p>
7+
# https://docs.moderne.io/licensing/moderne-source-available-license
8+
# <p>
9+
# Unless required by applicable law or agreed to in writing, software
10+
# distributed under the License is distributed on an "AS IS" BASIS,
11+
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12+
# See the License for the specific language governing permissions and
13+
# limitations under the License.
14+
#
15+
# Generated InlineMe recipes from TypeTable
16+
#
17+
18+
type: specs.openrewrite.org/v1beta/recipe
19+
name: org.openrewrite.java.migrate.guava.NoGuavaInlineMeMethods
20+
displayName: Inline methods annotated with `@InlineMe`
21+
description: >-
22+
Automatically generated recipes to inline method calls based on `@InlineMe` annotations
23+
discovered in the type table.
24+
recipeList:
25+
26+
# From com.google.guava:guava:33.4.8-jre
27+
- org.openrewrite.java.InlineMethodCalls:
28+
methodPattern: 'com.google.common.primitives.Booleans compare(boolean, boolean)'
29+
replacement: 'Boolean.compare(a, b)'
30+
classpathFromResources:
31+
- 'guava-33.4.8-jre'
32+
- org.openrewrite.java.InlineMethodCalls:
33+
methodPattern: 'com.google.common.primitives.Longs compare(long, long)'
34+
replacement: 'Long.compare(a, b)'
35+
classpathFromResources:
36+
- 'guava-33.4.8-jre'
37+
- org.openrewrite.java.InlineMethodCalls:
38+
methodPattern: 'com.google.common.primitives.Ints compare(int, int)'
39+
replacement: 'Integer.compare(a, b)'
40+
classpathFromResources:
41+
- 'guava-33.4.8-jre'
42+
- org.openrewrite.java.InlineMethodCalls:
43+
methodPattern: 'com.google.common.graph.ImmutableValueGraph copyOf(com.google.common.graph.ImmutableValueGraph)'
44+
replacement: 'checkNotNull(graph)'
45+
staticImports:
46+
- 'com.google.common.base.Preconditions.checkNotNull'
47+
classpathFromResources:
48+
- 'guava-33.4.8-jre'
49+
- org.openrewrite.java.InlineMethodCalls:
50+
methodPattern: 'com.google.common.primitives.Doubles compare(double, double)'
51+
replacement: 'Double.compare(a, b)'
52+
classpathFromResources:
53+
- 'guava-33.4.8-jre'
54+
- org.openrewrite.java.InlineMethodCalls:
55+
methodPattern: 'com.google.common.collect.Streams stream(java.util.Collection)'
56+
replacement: 'collection.stream()'
57+
classpathFromResources:
58+
- 'guava-33.4.8-jre'
59+
- org.openrewrite.java.InlineMethodCalls:
60+
methodPattern: 'com.google.common.collect.Streams stream(java.util.Optional)'
61+
replacement: 'optional.stream()'
62+
classpathFromResources:
63+
- 'guava-33.4.8-jre'
64+
- org.openrewrite.java.InlineMethodCalls:
65+
methodPattern: 'com.google.common.collect.Streams stream(java.util.OptionalInt)'
66+
replacement: 'optional.stream()'
67+
classpathFromResources:
68+
- 'guava-33.4.8-jre'
69+
- org.openrewrite.java.InlineMethodCalls:
70+
methodPattern: 'com.google.common.collect.Streams stream(java.util.OptionalLong)'
71+
replacement: 'optional.stream()'
72+
classpathFromResources:
73+
- 'guava-33.4.8-jre'
74+
- org.openrewrite.java.InlineMethodCalls:
75+
methodPattern: 'com.google.common.collect.Streams stream(java.util.OptionalDouble)'
76+
replacement: 'optional.stream()'
77+
classpathFromResources:
78+
- 'guava-33.4.8-jre'
79+
- org.openrewrite.java.InlineMethodCalls:
80+
methodPattern: 'com.google.common.collect.Range apply(java.lang.Comparable)'
81+
replacement: 'this.contains(input)'
82+
classpathFromResources:
83+
- 'guava-33.4.8-jre'
84+
- org.openrewrite.java.InlineMethodCalls:
85+
methodPattern: 'com.google.common.collect.Range test(java.lang.Comparable)'
86+
replacement: 'this.contains(input)'
87+
classpathFromResources:
88+
- 'guava-33.4.8-jre'
89+
- org.openrewrite.java.InlineMethodCalls:
90+
methodPattern: 'com.google.common.collect.FluentIterable from(com.google.common.collect.FluentIterable)'
91+
replacement: 'checkNotNull(iterable)'
92+
staticImports:
93+
- 'com.google.common.base.Preconditions.checkNotNull'
94+
classpathFromResources:
95+
- 'guava-33.4.8-jre'
96+
- org.openrewrite.java.InlineMethodCalls:
97+
methodPattern: 'com.google.common.collect.ImmutableList asList()'
98+
replacement: 'this'
99+
classpathFromResources:
100+
- 'guava-33.4.8-jre'
101+
- org.openrewrite.java.InlineMethodCalls:
102+
methodPattern: 'com.google.common.primitives.Chars compare(char, char)'
103+
replacement: 'Character.compare(a, b)'
104+
classpathFromResources:
105+
- 'guava-33.4.8-jre'
106+
- org.openrewrite.java.InlineMethodCalls:
107+
methodPattern: 'com.google.common.collect.TreeBasedTable rowComparator()'
108+
replacement: 'requireNonNull(this.rowKeySet().comparator())'
109+
staticImports:
110+
- 'java.util.Objects.requireNonNull'
111+
classpathFromResources:
112+
- 'guava-33.4.8-jre'
113+
- org.openrewrite.java.InlineMethodCalls:
114+
methodPattern: 'com.google.common.collect.Multisets unmodifiableMultiset(com.google.common.collect.ImmutableMultiset)'
115+
replacement: 'checkNotNull(multiset)'
116+
staticImports:
117+
- 'com.google.common.base.Preconditions.checkNotNull'
118+
classpathFromResources:
119+
- 'guava-33.4.8-jre'
120+
- org.openrewrite.java.InlineMethodCalls:
121+
methodPattern: 'com.google.common.collect.Iterators unmodifiableIterator(com.google.common.collect.UnmodifiableIterator)'
122+
replacement: 'checkNotNull(iterator)'
123+
staticImports:
124+
- 'com.google.common.base.Preconditions.checkNotNull'
125+
classpathFromResources:
126+
- 'guava-33.4.8-jre'
127+
- org.openrewrite.java.InlineMethodCalls:
128+
methodPattern: 'com.google.common.collect.Iterators peekingIterator(com.google.common.collect.PeekingIterator)'
129+
replacement: 'checkNotNull(iterator)'
130+
staticImports:
131+
- 'com.google.common.base.Preconditions.checkNotNull'
132+
classpathFromResources:
133+
- 'guava-33.4.8-jre'
134+
- org.openrewrite.java.InlineMethodCalls:
135+
methodPattern: 'com.google.common.collect.Ordering from(com.google.common.collect.Ordering)'
136+
replacement: 'checkNotNull(ordering)'
137+
staticImports:
138+
- 'com.google.common.base.Preconditions.checkNotNull'
139+
classpathFromResources:
140+
- 'guava-33.4.8-jre'
141+
- org.openrewrite.java.InlineMethodCalls:
142+
methodPattern: 'com.google.common.collect.Ordering binarySearch(java.util.List, java.lang.Object)'
143+
replacement: 'Collections.binarySearch(sortedList, key, this)'
144+
imports:
145+
- 'java.util.Collections'
146+
classpathFromResources:
147+
- 'guava-33.4.8-jre'
148+
- org.openrewrite.java.InlineMethodCalls:
149+
methodPattern: 'com.google.common.collect.Multimaps unmodifiableMultimap(com.google.common.collect.ImmutableMultimap)'
150+
replacement: 'checkNotNull(delegate)'
151+
staticImports:
152+
- 'com.google.common.base.Preconditions.checkNotNull'
153+
classpathFromResources:
154+
- 'guava-33.4.8-jre'
155+
- org.openrewrite.java.InlineMethodCalls:
156+
methodPattern: 'com.google.common.collect.Multimaps unmodifiableSetMultimap(com.google.common.collect.ImmutableSetMultimap)'
157+
replacement: 'checkNotNull(delegate)'
158+
staticImports:
159+
- 'com.google.common.base.Preconditions.checkNotNull'
160+
classpathFromResources:
161+
- 'guava-33.4.8-jre'
162+
- org.openrewrite.java.InlineMethodCalls:
163+
methodPattern: 'com.google.common.collect.Multimaps unmodifiableListMultimap(com.google.common.collect.ImmutableListMultimap)'
164+
replacement: 'checkNotNull(delegate)'
165+
staticImports:
166+
- 'com.google.common.base.Preconditions.checkNotNull'
167+
classpathFromResources:
168+
- 'guava-33.4.8-jre'
169+
- org.openrewrite.java.InlineMethodCalls:
170+
methodPattern: 'com.google.common.base.Equivalence test(java.lang.Object, java.lang.Object)'
171+
replacement: 'this.equivalent(t, u)'
172+
classpathFromResources:
173+
- 'guava-33.4.8-jre'
174+
- org.openrewrite.java.InlineMethodCalls:
175+
methodPattern: 'com.google.common.collect.Sets newSetFromMap(java.util.Map)'
176+
replacement: 'Collections.newSetFromMap(map)'
177+
imports:
178+
- 'java.util.Collections'
179+
classpathFromResources:
180+
- 'guava-33.4.8-jre'
181+
- org.openrewrite.java.InlineMethodCalls:
182+
methodPattern: 'com.google.common.base.Strings repeat(java.lang.String, int)'
183+
replacement: 'string.repeat(count)'
184+
classpathFromResources:
185+
- 'guava-33.4.8-jre'
186+
- org.openrewrite.java.InlineMethodCalls:
187+
methodPattern: 'com.google.common.hash.BloomFilter apply(java.lang.Object)'
188+
replacement: 'this.mightContain(input)'
189+
classpathFromResources:
190+
- 'guava-33.4.8-jre'
191+
- org.openrewrite.java.InlineMethodCalls:
192+
methodPattern: 'com.google.common.hash.BloomFilter test(java.lang.Object)'
193+
replacement: 'this.mightContain(input)'
194+
classpathFromResources:
195+
- 'guava-33.4.8-jre'
196+
- org.openrewrite.java.InlineMethodCalls:
197+
methodPattern: 'com.google.common.base.CharMatcher apply(java.lang.Character)'
198+
replacement: 'this.matches(character)'
199+
classpathFromResources:
200+
- 'guava-33.4.8-jre'
201+
- org.openrewrite.java.InlineMethodCalls:
202+
methodPattern: 'com.google.common.base.CharMatcher test(java.lang.Character)'
203+
replacement: 'this.matches(character)'
204+
classpathFromResources:
205+
- 'guava-33.4.8-jre'
206+
- org.openrewrite.java.InlineMethodCalls:
207+
methodPattern: 'com.google.common.collect.ComparisonChain compare(java.lang.Boolean, java.lang.Boolean)'
208+
replacement: 'this.compareFalseFirst(left, right)'
209+
classpathFromResources:
210+
- 'guava-33.4.8-jre'
211+
- org.openrewrite.java.InlineMethodCalls:
212+
methodPattern: 'com.google.common.io.Files toString(java.io.File, java.nio.charset.Charset)'
213+
replacement: 'Files.asCharSource(file, charset).read()'
214+
imports:
215+
- 'com.google.common.io.Files'
216+
classpathFromResources:
217+
- 'guava-33.4.8-jre'
218+
- org.openrewrite.java.InlineMethodCalls:
219+
methodPattern: 'com.google.common.io.Files write(java.lang.CharSequence, java.io.File, java.nio.charset.Charset)'
220+
replacement: 'Files.asCharSink(to, charset).write(from)'
221+
imports:
222+
- 'com.google.common.io.Files'
223+
classpathFromResources:
224+
- 'guava-33.4.8-jre'
225+
- org.openrewrite.java.InlineMethodCalls:
226+
methodPattern: 'com.google.common.io.Files copy(java.io.File, java.nio.charset.Charset, java.lang.Appendable)'
227+
replacement: 'Files.asCharSource(from, charset).copyTo(to)'
228+
imports:
229+
- 'com.google.common.io.Files'
230+
classpathFromResources:
231+
- 'guava-33.4.8-jre'
232+
- org.openrewrite.java.InlineMethodCalls:
233+
methodPattern: 'com.google.common.io.Files append(java.lang.CharSequence, java.io.File, java.nio.charset.Charset)'
234+
replacement: 'Files.asCharSink(to, charset, FileWriteMode.APPEND).write(from)'
235+
imports:
236+
- 'com.google.common.io.FileWriteMode'
237+
- 'com.google.common.io.Files'
238+
classpathFromResources:
239+
- 'guava-33.4.8-jre'
240+
- org.openrewrite.java.InlineMethodCalls:
241+
methodPattern: 'com.google.common.io.Files readFirstLine(java.io.File, java.nio.charset.Charset)'
242+
replacement: 'Files.asCharSource(file, charset).readFirstLine()'
243+
imports:
244+
- 'com.google.common.io.Files'
245+
classpathFromResources:
246+
- 'guava-33.4.8-jre'
247+
- org.openrewrite.java.InlineMethodCalls:
248+
methodPattern: 'com.google.common.io.Files readLines(java.io.File, java.nio.charset.Charset, com.google.common.io.LineProcessor)'
249+
replacement: 'Files.asCharSource(file, charset).readLines(callback)'
250+
imports:
251+
- 'com.google.common.io.Files'
252+
classpathFromResources:
253+
- 'guava-33.4.8-jre'
254+
- org.openrewrite.java.InlineMethodCalls:
255+
methodPattern: 'com.google.common.io.Files readBytes(java.io.File, com.google.common.io.ByteProcessor)'
256+
replacement: 'Files.asByteSource(file).read(processor)'
257+
imports:
258+
- 'com.google.common.io.Files'
259+
classpathFromResources:
260+
- 'guava-33.4.8-jre'
261+
- org.openrewrite.java.InlineMethodCalls:
262+
methodPattern: 'com.google.common.io.Files hash(java.io.File, com.google.common.hash.HashFunction)'
263+
replacement: 'Files.asByteSource(file).hash(hashFunction)'
264+
imports:
265+
- 'com.google.common.io.Files'
266+
classpathFromResources:
267+
- 'guava-33.4.8-jre'
268+
- org.openrewrite.java.InlineMethodCalls:
269+
methodPattern: 'com.google.common.util.concurrent.FluentFuture from(com.google.common.util.concurrent.FluentFuture)'
270+
replacement: 'checkNotNull(future)'
271+
staticImports:
272+
- 'com.google.common.base.Preconditions.checkNotNull'
273+
classpathFromResources:
274+
- 'guava-33.4.8-jre'
275+
- org.openrewrite.java.InlineMethodCalls:
276+
methodPattern: 'com.google.common.base.Converter apply(java.lang.Object)'
277+
replacement: 'this.convert(a)'
278+
classpathFromResources:
279+
- 'guava-33.4.8-jre'
280+
- org.openrewrite.java.InlineMethodCalls:
281+
methodPattern: 'com.google.common.primitives.Shorts compare(short, short)'
282+
replacement: 'Short.compare(a, b)'
283+
classpathFromResources:
284+
- 'guava-33.4.8-jre'
285+
- org.openrewrite.java.InlineMethodCalls:
286+
methodPattern: 'com.google.common.graph.ImmutableGraph copyOf(com.google.common.graph.ImmutableGraph)'
287+
replacement: 'checkNotNull(graph)'
288+
staticImports:
289+
- 'com.google.common.base.Preconditions.checkNotNull'
290+
classpathFromResources:
291+
- 'guava-33.4.8-jre'
292+
- org.openrewrite.java.InlineMethodCalls:
293+
methodPattern: 'com.google.common.primitives.Floats compare(float, float)'
294+
replacement: 'Float.compare(a, b)'
295+
classpathFromResources:
296+
- 'guava-33.4.8-jre'
297+
- org.openrewrite.java.InlineMethodCalls:
298+
methodPattern: 'com.google.common.collect.Iterables unmodifiableIterable(com.google.common.collect.ImmutableCollection)'
299+
replacement: 'checkNotNull(iterable)'
300+
staticImports:
301+
- 'com.google.common.base.Preconditions.checkNotNull'
302+
classpathFromResources:
303+
- 'guava-33.4.8-jre'
304+
- org.openrewrite.java.InlineMethodCalls:
305+
methodPattern: 'com.google.common.graph.ImmutableNetwork copyOf(com.google.common.graph.ImmutableNetwork)'
306+
replacement: 'checkNotNull(network)'
307+
staticImports:
308+
- 'com.google.common.base.Preconditions.checkNotNull'
309+
classpathFromResources:
310+
- 'guava-33.4.8-jre'

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

Lines changed: 0 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -109,20 +109,6 @@ recipeList:
109109
- org.openrewrite.java.migrate.guava.NoMapsAndSetsWithExpectedSize
110110
- org.openrewrite.java.migrate.guava.PreferMathClamp
111111

112-
---
113-
type: specs.openrewrite.org/v1beta/recipe
114-
name: org.openrewrite.java.migrate.guava.NoGuavaInlineMeMethods
115-
displayName: Inline Guava method calls
116-
description: >-
117-
Inline Guava method calls that are annotated with `@InlineMe` to their replacement method.
118-
tags:
119-
- guava
120-
preconditions:
121-
- org.openrewrite.analysis.search.FindMethods:
122-
methodPattern: com.google.common..* *(..)
123-
recipeList:
124-
- org.openrewrite.java.InlineMethodCalls
125-
126112
---
127113
type: specs.openrewrite.org/v1beta/recipe
128114
name: org.openrewrite.java.migrate.guava.PreferJavaNioCharsetStandardCharsets

src/test/java/org/openrewrite/java/migrate/guava/NoGuavaInlineMeMethodsTest.java

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -26,8 +26,7 @@ class NoGuavaInlineMeMethodsTest implements RewriteTest {
2626

2727
@Override
2828
public void defaults(RecipeSpec spec) {
29-
spec.recipeFromResource(
30-
"/META-INF/rewrite/no-guava.yml",
29+
spec.recipeFromResources(
3130
"org.openrewrite.java.migrate.guava.NoGuavaInlineMeMethods");
3231
}
3332

src/test/java/org/openrewrite/java/migrate/guava/NoGuavaJava21Test.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,7 @@ class NoGuavaJava21Test implements RewriteTest {
2828
@Override
2929
public void defaults(RecipeSpec spec) {
3030
spec
31-
.recipeFromResource("/META-INF/rewrite/no-guava.yml", "org.openrewrite.java.migrate.guava.NoGuava")
31+
.recipeFromResources("org.openrewrite.java.migrate.guava.NoGuava")
3232
.parser(JavaParser.fromJavaVersion().classpathFromResources(new InMemoryExecutionContext(), "guava"));
3333
}
3434

src/test/java/org/openrewrite/java/migrate/guava/NoGuavaTest.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,7 @@ class NoGuavaTest implements RewriteTest {
3030
@Override
3131
public void defaults(RecipeSpec spec) {
3232
spec
33-
.recipeFromResource("/META-INF/rewrite/no-guava.yml", "org.openrewrite.java.migrate.guava.NoGuava")
33+
.recipeFromResources("org.openrewrite.java.migrate.guava.NoGuava")
3434
.parser(JavaParser.fromJavaVersion().classpathFromResources(new InMemoryExecutionContext(), "guava"));
3535
}
3636

0 commit comments

Comments
 (0)