Skip to content

Commit 045bd00

Browse files
committed
Push up disabled failing test for #309
1 parent 7f1ec7f commit 045bd00

File tree

1 file changed

+56
-15
lines changed

1 file changed

+56
-15
lines changed

src/test/java/org/openrewrite/staticanalysis/UseLambdaForFunctionalInterfaceTest.java

Lines changed: 56 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -45,7 +45,7 @@ void castingAmbiguity() {
4545
import java.security.AccessController;
4646
import java.security.PrivilegedAction;
4747
import java.security.PrivilegedExceptionAction;
48-
48+
4949
class Test {
5050
void test() {
5151
AccessController.doPrivileged(new PrivilegedAction<Integer>() {
@@ -65,7 +65,7 @@ void test() {
6565
import java.security.AccessController;
6666
import java.security.PrivilegedAction;
6767
import java.security.PrivilegedExceptionAction;
68-
68+
6969
class Test {
7070
void test() {
7171
AccessController.doPrivileged((PrivilegedAction<Integer>) () -> 0);
@@ -95,7 +95,7 @@ void gson() {
9595
import com.google.gson.JsonSerializer;
9696
import java.time.LocalDateTime;
9797
import java.lang.reflect.Type;
98-
98+
9999
class Test {
100100
void test() {
101101
new GsonBuilder().registerTypeAdapter(LocalDateTime.class, new JsonSerializer<LocalDateTime>() {
@@ -112,7 +112,7 @@ public JsonElement serialize(LocalDateTime object, Type type, JsonSerializationC
112112
import com.google.gson.JsonPrimitive;
113113
import com.google.gson.JsonSerializer;
114114
import java.time.LocalDateTime;
115-
115+
116116
class Test {
117117
void test() {
118118
new GsonBuilder().registerTypeAdapter(LocalDateTime.class, (JsonSerializer<LocalDateTime>) (object, type, context) -> new JsonPrimitive(object.format(null)));
@@ -163,14 +163,14 @@ public void run() {
163163
Test.this.execute();
164164
}
165165
};
166-
166+
167167
void execute() {}
168168
}
169169
""",
170170
"""
171171
class Test {
172172
Runnable r = Test.this::execute;
173-
173+
174174
void execute() {}
175175
}
176176
"""
@@ -239,7 +239,7 @@ void emptyLambda() {
239239
java(
240240
"""
241241
import java.util.function.Consumer;
242-
242+
243243
class Test {
244244
void foo() {
245245
Consumer<Integer> s;
@@ -253,7 +253,7 @@ public void accept(Integer i) {
253253
""",
254254
"""
255255
import java.util.function.Consumer;
256-
256+
257257
class Test {
258258
void foo() {
259259
Consumer<Integer> s;
@@ -274,7 +274,7 @@ void nestedLambdaInMethodArgument() {
274274
java(
275275
"""
276276
import java.util.function.Consumer;
277-
277+
278278
class Test {
279279
void bar(Consumer<Integer> c) {
280280
}
@@ -294,7 +294,7 @@ public void accept(Integer i2) {
294294
""",
295295
"""
296296
import java.util.function.Consumer;
297-
297+
298298
class Test {
299299
void bar(Consumer<Integer> c) {
300300
}
@@ -646,7 +646,7 @@ public void run() {
646646
}
647647
});
648648
}
649-
649+
650650
int j = 0;
651651
while (j < 20) {
652652
run(new Runnable() {
@@ -668,13 +668,14 @@ public void run() {
668668
@Issue("https://github.com/moderneinc/support-app/issues/17")
669669
void lambdaWithComplexTypeInference() {
670670
rewriteRun(
671+
//language=java
671672
java(
672673
"""
673674
import java.util.LinkedHashMap;
674675
import java.util.Map;
675676
import java.util.function.Supplier;
676677
import java.util.stream.Collectors;
677-
678+
678679
class Test {
679680
void method() {
680681
Object o = new MapDropdownChoice<String, Integer>(
@@ -697,7 +698,7 @@ public Map<String, Integer> getObject() {
697698
});
698699
}
699700
}
700-
701+
701702
class MapDropdownChoice<K, V> {
702703
public MapDropdownChoice(Supplier<? extends Map<K, ? extends V>> choiceMap) {
703704
}
@@ -708,7 +709,7 @@ public MapDropdownChoice(Supplier<? extends Map<K, ? extends V>> choiceMap) {
708709
import java.util.Map;
709710
import java.util.function.Supplier;
710711
import java.util.stream.Collectors;
711-
712+
712713
class Test {
713714
void method() {
714715
Object o = new MapDropdownChoice<String, Integer>(
@@ -725,7 +726,7 @@ void method() {
725726
});
726727
}
727728
}
728-
729+
729730
class MapDropdownChoice<K, V> {
730731
public MapDropdownChoice(Supplier<? extends Map<K, ? extends V>> choiceMap) {
731732
}
@@ -734,4 +735,44 @@ public MapDropdownChoice(Supplier<? extends Map<K, ? extends V>> choiceMap) {
734735
)
735736
);
736737
}
738+
739+
@Disabled
740+
@Test
741+
@Issue("https://github.com/openrewrite/rewrite-static-analysis/issues/309")
742+
void dontUseLambdaForMethodWithTypeParameter() {
743+
//language=java
744+
rewriteRun(
745+
spec -> spec.parser(JavaParser.fromJavaVersion().dependsOn(
746+
"""
747+
package com.helloworld;
748+
749+
import java.util.List;
750+
751+
public interface I {
752+
<T> List<T> call();
753+
}
754+
"""
755+
)),
756+
java(
757+
// can't transform to lambda because of the type argument of I#call()
758+
"""
759+
package com.helloworld;
760+
761+
import java.util.List;
762+
763+
class Hello {
764+
public void hello() {
765+
final I i = new I() {
766+
@Override
767+
public <T> List<T> call() {
768+
return null;
769+
}
770+
};
771+
final List<String> list = i.call();
772+
}
773+
}
774+
"""
775+
)
776+
);
777+
}
737778
}

0 commit comments

Comments
 (0)