Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -1786,4 +1786,25 @@ record R(String s) {}
)
);
}

@Issue("https://github.com/openrewrite/rewrite-static-analysis/issues/20")
@Test
void castToTypeParameterInLambda() {
// given / when / then
rewriteRun(
//language=java
java(
"""
class SequenceFileReader<K, V> {
interface Converter<T> {
T convert(Object o);
}

private Converter<K> keyConverter = o -> (K) o;
private Converter<V> valConverter = o -> (V) o;
}
"""
)
);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -830,4 +830,72 @@ public void run() {
)
);
}

@Issue("https://github.com/openrewrite/rewrite-static-analysis/issues/20")
@Test
void anonymousClassInsideParameterizedMethodCall() {
// given / when / then
rewriteRun(
//language=java
java(
"""
import java.util.function.Supplier;
import java.util.concurrent.atomic.AtomicInteger;

class TypeLiteral<T> {
}

class Binder {
<T> Binding<T> bind(TypeLiteral<T> typeLiteral) {
return new Binding<>();
}
}

class Binding<T> {
void toInstance(T instance) {
}
}

class Test {
void test(Binder binder) {
final AtomicInteger suffix = new AtomicInteger();
binder.bind(new TypeLiteral<Supplier<String>>() {
}).toInstance(new Supplier<String>() {
@Override
public String get() {
return suffix.getAndIncrement() + "";
}
});
}
}
""",
"""
import java.util.function.Supplier;
import java.util.concurrent.atomic.AtomicInteger;

class TypeLiteral<T> {
}

class Binder {
<T> Binding<T> bind(TypeLiteral<T> typeLiteral) {
return new Binding<>();
}
}

class Binding<T> {
void toInstance(T instance) {
}
}

class Test {
void test(Binder binder) {
final AtomicInteger suffix = new AtomicInteger();
binder.bind(new TypeLiteral<Supplier<String>>() {
}).toInstance(() -> suffix.getAndIncrement() + "");
}
}
"""
)
);
}
}
Loading