From 898c4040129e333800b0d47ebd6a9fe645961e53 Mon Sep 17 00:00:00 2001 From: traceyyoshima Date: Tue, 10 Oct 2023 12:49:55 -0600 Subject: [PATCH] Added type mapping test for cone projections. --- .../kotlin/KotlinTypeMappingTest.java | 28 +++++++++++++++++++ 1 file changed, 28 insertions(+) diff --git a/src/test/java/org/openrewrite/kotlin/KotlinTypeMappingTest.java b/src/test/java/org/openrewrite/kotlin/KotlinTypeMappingTest.java index 0f5405527..88c7e3bab 100644 --- a/src/test/java/org/openrewrite/kotlin/KotlinTypeMappingTest.java +++ b/src/test/java/org/openrewrite/kotlin/KotlinTypeMappingTest.java @@ -365,6 +365,34 @@ public J.MethodInvocation visitMethodInvocation(J.MethodInvocation method, Atomi ); } + @Test + void coneProjection() { + rewriteRun( + kotlin( + """ + val map = mapOf(Pair("one", 1)) as? Map<*, *> + val s = map.orEmpty().entries.joinToString { (key, value) -> "$key: $value" } + """, spec -> spec.afterRecipe(cu -> { + AtomicBoolean found = new AtomicBoolean(false); + new KotlinIsoVisitor() { + @Override + public J.FieldAccess visitFieldAccess(J.FieldAccess fieldAccess, AtomicBoolean atomicBoolean) { + if ("entries".equals(fieldAccess.getSimpleName())) { + assertThat(fieldAccess.getName().getType().toString()) + .isEqualTo("kotlin.collections.Set>"); + assertThat(fieldAccess.getName().getFieldType().toString()) + .isEqualTo("kotlin.collections.Map{name=entries,type=kotlin.collections.Set>}"); + found.set(true); + } + return super.visitFieldAccess(fieldAccess, atomicBoolean); + } + }.visit(cu, found); + assertThat(found.get()).isTrue(); + }) + ) + ); + } + @Test void destructs() { rewriteRun(