File tree Expand file tree Collapse file tree
src/test/java/org/openrewrite/staticanalysis Expand file tree Collapse file tree Original file line number Diff line number Diff line change @@ -1786,4 +1786,25 @@ record R(String s) {}
17861786 )
17871787 );
17881788 }
1789+
1790+ @ Issue ("https://github.com/openrewrite/rewrite-static-analysis/issues/20" )
1791+ @ Test
1792+ void castToTypeParameterInLambda () {
1793+ // given / when / then
1794+ rewriteRun (
1795+ //language=java
1796+ java (
1797+ """
1798+ class SequenceFileReader<K, V> {
1799+ interface Converter<T> {
1800+ T convert(Object o);
1801+ }
1802+
1803+ private Converter<K> keyConverter = o -> (K) o;
1804+ private Converter<V> valConverter = o -> (V) o;
1805+ }
1806+ """
1807+ )
1808+ );
1809+ }
17891810}
Original file line number Diff line number Diff line change @@ -830,4 +830,72 @@ public void run() {
830830 )
831831 );
832832 }
833+
834+ @ Issue ("https://github.com/openrewrite/rewrite-static-analysis/issues/20" )
835+ @ Test
836+ void anonymousClassInsideParameterizedMethodCall () {
837+ // given / when / then
838+ rewriteRun (
839+ //language=java
840+ java (
841+ """
842+ import java.util.function.Supplier;
843+ import java.util.concurrent.atomic.AtomicInteger;
844+
845+ class TypeLiteral<T> {
846+ }
847+
848+ class Binder {
849+ <T> Binding<T> bind(TypeLiteral<T> typeLiteral) {
850+ return new Binding<>();
851+ }
852+ }
853+
854+ class Binding<T> {
855+ void toInstance(T instance) {
856+ }
857+ }
858+
859+ class Test {
860+ void test(Binder binder) {
861+ final AtomicInteger suffix = new AtomicInteger();
862+ binder.bind(new TypeLiteral<Supplier<String>>() {
863+ }).toInstance(new Supplier<String>() {
864+ @Override
865+ public String get() {
866+ return suffix.getAndIncrement() + "";
867+ }
868+ });
869+ }
870+ }
871+ """ ,
872+ """
873+ import java.util.function.Supplier;
874+ import java.util.concurrent.atomic.AtomicInteger;
875+
876+ class TypeLiteral<T> {
877+ }
878+
879+ class Binder {
880+ <T> Binding<T> bind(TypeLiteral<T> typeLiteral) {
881+ return new Binding<>();
882+ }
883+ }
884+
885+ class Binding<T> {
886+ void toInstance(T instance) {
887+ }
888+ }
889+
890+ class Test {
891+ void test(Binder binder) {
892+ final AtomicInteger suffix = new AtomicInteger();
893+ binder.bind(new TypeLiteral<Supplier<String>>() {
894+ }).toInstance(() -> suffix.getAndIncrement() + "");
895+ }
896+ }
897+ """
898+ )
899+ );
900+ }
833901}
You can’t perform that action at this time.
0 commit comments