Skip to content

Commit

Permalink
Added type mapping test for cone projections.
Browse files Browse the repository at this point in the history
  • Loading branch information
traceyyoshima committed Oct 10, 2023
1 parent d400070 commit 898c404
Showing 1 changed file with 28 additions and 0 deletions.
28 changes: 28 additions & 0 deletions src/test/java/org/openrewrite/kotlin/KotlinTypeMappingTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -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<AtomicBoolean>() {
@Override
public J.FieldAccess visitFieldAccess(J.FieldAccess fieldAccess, AtomicBoolean atomicBoolean) {
if ("entries".equals(fieldAccess.getSimpleName())) {
assertThat(fieldAccess.getName().getType().toString())
.isEqualTo("kotlin.collections.Set<kotlin.collections.Map$Entry<Generic{*}, kotlin.Any>>");
assertThat(fieldAccess.getName().getFieldType().toString())
.isEqualTo("kotlin.collections.Map<Generic{*}, kotlin.Any>{name=entries,type=kotlin.collections.Set<kotlin.collections.Map$Entry<Generic{*}, kotlin.Any>>}");
found.set(true);
}
return super.visitFieldAccess(fieldAccess, atomicBoolean);
}
}.visit(cu, found);
assertThat(found.get()).isTrue();
})
)
);
}

@Test
void destructs() {
rewriteRun(
Expand Down

0 comments on commit 898c404

Please sign in to comment.