Skip to content

Commit 810f0a5

Browse files
committed
Slight polish
1 parent 1552cca commit 810f0a5

File tree

2 files changed

+28
-71
lines changed

2 files changed

+28
-71
lines changed

src/main/java/org/openrewrite/java/migrate/lang/var/UseVarForGenericMethodInvocations.java

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -42,7 +42,7 @@ public String getDisplayName() {
4242
public String getDescription() {
4343
//language=markdown
4444
return "Apply `var` to variables initialized by invocations of generic methods. " +
45-
"This recipe ignores generic factory methods without parameters, because open rewrite cannot handle them correctly ATM.";
45+
"This recipe ignores generic factory methods without parameters, because open rewrite cannot handle them correctly ATM.";
4646
}
4747

4848
@Override
@@ -119,7 +119,7 @@ private J.MethodInvocation makeNestedGenericsExplicit(J.MethodInvocation mi, J.V
119119
// Copy type parameters from left side to right side
120120
J.ParameterizedType rightType = (J.ParameterizedType) newClass.getClazz();
121121
return newClass.withClazz(
122-
rightType.withTypeParameters(leftTypeParams)
122+
rightType.withTypeParameters(leftTypeParams)
123123
);
124124
}
125125
}
@@ -129,7 +129,8 @@ private J.MethodInvocation makeNestedGenericsExplicit(J.MethodInvocation mi, J.V
129129

130130
/**
131131
* Extract JavaTypes from a NewClass expression's type parameters.
132-
* Returns null if not a parameterized type, or an empty list for diamond operator.
132+
*
133+
* @return null if not a parameterized type, or an empty list for diamond operator.
133134
*/
134135
private @Nullable List<JavaType> extractJavaTypes(J.NewClass newClass) {
135136
TypeTree clazz = newClass.getClazz();

src/test/java/org/openrewrite/java/migrate/lang/var/UseVarForGenericMethodInvocationsTest.java

Lines changed: 24 additions & 68 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,7 @@
1818
import org.junit.jupiter.api.Nested;
1919
import org.junit.jupiter.api.Test;
2020
import org.openrewrite.DocumentExample;
21+
import org.openrewrite.Issue;
2122
import org.openrewrite.test.RecipeSpec;
2223
import org.openrewrite.test.RewriteTest;
2324

@@ -260,81 +261,36 @@ void m() {
260261
);
261262
}
262263

264+
@Issue("https://github.com/openrewrite/rewrite-migrate-java/issues/862")
263265
@Test
264266
void nestedGenericsSimple() {
265267
//language=java
266268
rewriteRun(
267269
version(
268-
java("""
269-
package com.example.app;
270-
271-
import java.util.ArrayList;
272-
import java.util.Collections;
273-
import java.util.List;
274-
275-
class A {
276-
private void dostuff() {
277-
List<String> strs = Collections.synchronizedList(new ArrayList<>());
278-
}
279-
}
280-
""", """
281-
package com.example.app;
282-
283-
import java.util.ArrayList;
284-
import java.util.Collections;
285-
import java.util.List;
286-
287-
class A {
288-
private void dostuff() {
289-
var strs = Collections.synchronizedList(new ArrayList<String>());
290-
}
291-
}
292-
"""),
293-
10
294-
)
295-
);
296-
}
297-
298-
@Test
299-
void nestedGenericsWithMethodReference() {
300-
//language=java
301-
rewriteRun(
302-
version(
303-
java("""
304-
package com.example.app;
305-
306-
import java.util.ArrayList;
307-
import java.util.Collections;
308-
import java.util.List;
309-
310-
class A {
311-
private void dostuff() {
312-
List<String> strs = Collections.synchronizedList(new ArrayList<>());
313-
strs.forEach(this::soString);
314-
}
315-
316-
private void soString(String s) {
317-
System.out.println(s);
318-
}
319-
}
320-
""", """
321-
package com.example.app;
322-
323-
import java.util.ArrayList;
324-
import java.util.Collections;
325-
import java.util.List;
326-
327-
class A {
328-
private void dostuff() {
329-
var strs = Collections.synchronizedList(new ArrayList<String>());
330-
strs.forEach(this::soString);
270+
java(
271+
"""
272+
import java.util.ArrayList;
273+
import java.util.Collections;
274+
import java.util.List;
275+
276+
class A {
277+
void dostuff() {
278+
List<String> strs = Collections.synchronizedList(new ArrayList<>());
279+
}
331280
}
332-
333-
private void soString(String s) {
334-
System.out.println(s);
281+
""",
282+
"""
283+
import java.util.ArrayList;
284+
import java.util.Collections;
285+
import java.util.List;
286+
287+
class A {
288+
void dostuff() {
289+
var strs = Collections.synchronizedList(new ArrayList<String>());
290+
}
335291
}
336-
}
337-
"""),
292+
"""
293+
),
338294
10
339295
)
340296
);

0 commit comments

Comments
 (0)