Skip to content

Commit

Permalink
Push up disabled failing test for #309
Browse files Browse the repository at this point in the history
  • Loading branch information
timtebeek committed Jul 3, 2024
1 parent 7f1ec7f commit 045bd00
Showing 1 changed file with 56 additions and 15 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@ void castingAmbiguity() {
import java.security.AccessController;
import java.security.PrivilegedAction;
import java.security.PrivilegedExceptionAction;
class Test {
void test() {
AccessController.doPrivileged(new PrivilegedAction<Integer>() {
Expand All @@ -65,7 +65,7 @@ void test() {
import java.security.AccessController;
import java.security.PrivilegedAction;
import java.security.PrivilegedExceptionAction;
class Test {
void test() {
AccessController.doPrivileged((PrivilegedAction<Integer>) () -> 0);
Expand Down Expand Up @@ -95,7 +95,7 @@ void gson() {
import com.google.gson.JsonSerializer;
import java.time.LocalDateTime;
import java.lang.reflect.Type;
class Test {
void test() {
new GsonBuilder().registerTypeAdapter(LocalDateTime.class, new JsonSerializer<LocalDateTime>() {
Expand All @@ -112,7 +112,7 @@ public JsonElement serialize(LocalDateTime object, Type type, JsonSerializationC
import com.google.gson.JsonPrimitive;
import com.google.gson.JsonSerializer;
import java.time.LocalDateTime;
class Test {
void test() {
new GsonBuilder().registerTypeAdapter(LocalDateTime.class, (JsonSerializer<LocalDateTime>) (object, type, context) -> new JsonPrimitive(object.format(null)));
Expand Down Expand Up @@ -163,14 +163,14 @@ public void run() {
Test.this.execute();
}
};
void execute() {}
}
""",
"""
class Test {
Runnable r = Test.this::execute;
void execute() {}
}
"""
Expand Down Expand Up @@ -239,7 +239,7 @@ void emptyLambda() {
java(
"""
import java.util.function.Consumer;
class Test {
void foo() {
Consumer<Integer> s;
Expand All @@ -253,7 +253,7 @@ public void accept(Integer i) {
""",
"""
import java.util.function.Consumer;
class Test {
void foo() {
Consumer<Integer> s;
Expand All @@ -274,7 +274,7 @@ void nestedLambdaInMethodArgument() {
java(
"""
import java.util.function.Consumer;
class Test {
void bar(Consumer<Integer> c) {
}
Expand All @@ -294,7 +294,7 @@ public void accept(Integer i2) {
""",
"""
import java.util.function.Consumer;
class Test {
void bar(Consumer<Integer> c) {
}
Expand Down Expand Up @@ -646,7 +646,7 @@ public void run() {
}
});
}
int j = 0;
while (j < 20) {
run(new Runnable() {
Expand All @@ -668,13 +668,14 @@ public void run() {
@Issue("https://github.com/moderneinc/support-app/issues/17")
void lambdaWithComplexTypeInference() {
rewriteRun(
//language=java
java(
"""
import java.util.LinkedHashMap;
import java.util.Map;
import java.util.function.Supplier;
import java.util.stream.Collectors;
class Test {
void method() {
Object o = new MapDropdownChoice<String, Integer>(
Expand All @@ -697,7 +698,7 @@ public Map<String, Integer> getObject() {
});
}
}
class MapDropdownChoice<K, V> {
public MapDropdownChoice(Supplier<? extends Map<K, ? extends V>> choiceMap) {
}
Expand All @@ -708,7 +709,7 @@ public MapDropdownChoice(Supplier<? extends Map<K, ? extends V>> choiceMap) {
import java.util.Map;
import java.util.function.Supplier;
import java.util.stream.Collectors;
class Test {
void method() {
Object o = new MapDropdownChoice<String, Integer>(
Expand All @@ -725,7 +726,7 @@ void method() {
});
}
}
class MapDropdownChoice<K, V> {
public MapDropdownChoice(Supplier<? extends Map<K, ? extends V>> choiceMap) {
}
Expand All @@ -734,4 +735,44 @@ public MapDropdownChoice(Supplier<? extends Map<K, ? extends V>> choiceMap) {
)
);
}

@Disabled
@Test
@Issue("https://github.com/openrewrite/rewrite-static-analysis/issues/309")
void dontUseLambdaForMethodWithTypeParameter() {
//language=java
rewriteRun(
spec -> spec.parser(JavaParser.fromJavaVersion().dependsOn(
"""
package com.helloworld;
import java.util.List;
public interface I {
<T> List<T> call();
}
"""
)),
java(
// can't transform to lambda because of the type argument of I#call()
"""
package com.helloworld;
import java.util.List;
class Hello {
public void hello() {
final I i = new I() {
@Override
public <T> List<T> call() {
return null;
}
};
final List<String> list = i.call();
}
}
"""
)
);
}
}

0 comments on commit 045bd00

Please sign in to comment.