Skip to content

Commit dcd06a3

Browse files
committed
Generate Guava InlineMethodCalls recipes using openrewrite/rewrite#6059
1 parent 72818ad commit dcd06a3

File tree

5 files changed

+308
-16
lines changed

5 files changed

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

0 commit comments

Comments
 (0)