From 5e9ae7d7e454d4d67a3d2d5ed1444a727d06c2c2 Mon Sep 17 00:00:00 2001 From: Kun Li Date: Tue, 7 Nov 2023 09:35:39 -0800 Subject: [PATCH] Add test collectionLiteralExpression and fix --- .../internal/KotlinTreeParserVisitor.java | 2 +- .../kotlin/tree/AnnotationTest.java | 20 ++++++++++++++++++- 2 files changed, 20 insertions(+), 2 deletions(-) diff --git a/src/main/java/org/openrewrite/kotlin/internal/KotlinTreeParserVisitor.java b/src/main/java/org/openrewrite/kotlin/internal/KotlinTreeParserVisitor.java index 2bb412c4f..d48e0574d 100644 --- a/src/main/java/org/openrewrite/kotlin/internal/KotlinTreeParserVisitor.java +++ b/src/main/java/org/openrewrite/kotlin/internal/KotlinTreeParserVisitor.java @@ -2294,7 +2294,7 @@ public J visitDotQualifiedExpression(KtDotQualifiedExpression expression, Execut .withName(((J.MethodInvocation) methodInvocation).getName().withPrefix(prefix(callExpression))) .withPrefix(prefix(expression)); } else if (methodInvocation instanceof J.NewClass) { - if (receiver instanceof J.FieldAccess) { + if (receiver instanceof J.FieldAccess || receiver instanceof J.Identifier) { J.NewClass cur = (J.NewClass) methodInvocation; if (cur.getClazz() instanceof J.ParameterizedType) { cur = cur.withPrefix(prefix(expression)); diff --git a/src/test/java/org/openrewrite/kotlin/tree/AnnotationTest.java b/src/test/java/org/openrewrite/kotlin/tree/AnnotationTest.java index 5700b1b55..fc6f98ce3 100644 --- a/src/test/java/org/openrewrite/kotlin/tree/AnnotationTest.java +++ b/src/test/java/org/openrewrite/kotlin/tree/AnnotationTest.java @@ -466,7 +466,7 @@ annotation class B } @Test - void AnntationEntryTrailingComma() { + void AnnotationEntryTrailingComma() { rewriteRun( spec -> spec.parser(KotlinParser.builder().classpath("jackson-annotations")), kotlin( @@ -492,4 +492,22 @@ public sealed interface Fruit { ) ); } + + @Test + void collectionLiteralExpression() { + rewriteRun( + spec -> spec.parser(KotlinParser.builder().classpath("jackson-annotations")), + kotlin( + """ + import com.fasterxml.jackson.`annotation`.JsonSubTypes + + @JsonSubTypes(value = [ + JsonSubTypes . Type(value = Employee::class, name = "Employee") + ]) + public sealed interface Person { + } + """ + ) + ); + } }