From c992df9732f56b5185ce5c9547aa96b849422e72 Mon Sep 17 00:00:00 2001 From: Kun Li Date: Mon, 11 Dec 2023 11:02:42 -0800 Subject: [PATCH] Revert "Update K.Constructor model" This reverts commit c37be7ba2eff2c723a6c648c0fefdfae072d4605. --- src/main/java/org/openrewrite/kotlin/KotlinVisitor.java | 3 ++- .../java/org/openrewrite/kotlin/internal/KotlinPrinter.java | 4 ++-- .../kotlin/internal/KotlinTreeParserVisitor.java | 2 +- src/main/java/org/openrewrite/kotlin/tree/K.java | 6 ------ .../org/openrewrite/kotlin/tree/ClassDeclarationTest.java | 2 +- 5 files changed, 6 insertions(+), 11 deletions(-) diff --git a/src/main/java/org/openrewrite/kotlin/KotlinVisitor.java b/src/main/java/org/openrewrite/kotlin/KotlinVisitor.java index aafa11530..91cc5e895 100644 --- a/src/main/java/org/openrewrite/kotlin/KotlinVisitor.java +++ b/src/main/java/org/openrewrite/kotlin/KotlinVisitor.java @@ -111,7 +111,8 @@ public J visitConstructor(K.Constructor constructor, P p) { K.Constructor c = constructor; c = c.withMarkers(visitMarkers(c.getMarkers(), p)); c = c.withMethodDeclaration(visitAndCast(c.getMethodDeclaration(), p)); - c = c.withInvocation(visitLeftPadded(c.getInvocation(), p)); + c = c.withColon(visitSpace(c.getColon(), KSpace.Location.CONSTRUCTOR_COLON, p)); + c = c.withConstructorInvocation(visitAndCast(c.getConstructorInvocation(), p)); return c; } diff --git a/src/main/java/org/openrewrite/kotlin/internal/KotlinPrinter.java b/src/main/java/org/openrewrite/kotlin/internal/KotlinPrinter.java index e8e907972..91e5690d4 100755 --- a/src/main/java/org/openrewrite/kotlin/internal/KotlinPrinter.java +++ b/src/main/java/org/openrewrite/kotlin/internal/KotlinPrinter.java @@ -156,9 +156,9 @@ public J visitConstructor(K.Constructor constructor, PrintOutputCapture

p) { afterSyntax(params.getMarkers(), p); p.append(")"); - visitSpace(constructor.getInvocation().getBefore(), KSpace.Location.CONSTRUCTOR_COLON, p); + visitSpace(constructor.getColon(), KSpace.Location.CONSTRUCTOR_COLON, p); p.append(':'); - visit(constructor.getInvocation().getElement(), p); + visit(constructor.getConstructorInvocation(), p); afterSyntax(constructor, p); visit(method.getBody(), p); diff --git a/src/main/java/org/openrewrite/kotlin/internal/KotlinTreeParserVisitor.java b/src/main/java/org/openrewrite/kotlin/internal/KotlinTreeParserVisitor.java index bb08d12f4..c846ee717 100644 --- a/src/main/java/org/openrewrite/kotlin/internal/KotlinTreeParserVisitor.java +++ b/src/main/java/org/openrewrite/kotlin/internal/KotlinTreeParserVisitor.java @@ -1148,7 +1148,7 @@ public J visitSecondaryConstructor(KtSecondaryConstructor constructor, Execution type )); - return delegationCall != null ? new K.Constructor(randomId(), Markers.EMPTY, methodDeclaration, Space.EMPTY, null, padLeft(prefix(constructor.getColon()), delegationCall)) : + return delegationCall != null ? new K.Constructor(randomId(), Markers.EMPTY, methodDeclaration, prefix(constructor.getColon()), delegationCall) : methodDeclaration; } diff --git a/src/main/java/org/openrewrite/kotlin/tree/K.java b/src/main/java/org/openrewrite/kotlin/tree/K.java index 075abbd30..8683444d1 100644 --- a/src/main/java/org/openrewrite/kotlin/tree/K.java +++ b/src/main/java/org/openrewrite/kotlin/tree/K.java @@ -576,15 +576,9 @@ final class Constructor implements K, Statement, TypedTree { Markers markers; J.MethodDeclaration methodDeclaration; - - @Deprecated // use `invocation` instead Space colon; - - @Deprecated // use `invocation` instead ConstructorInvocation constructorInvocation; - JLeftPadded invocation; - @Override public Constructor withType(@Nullable JavaType type) { return this; // type must be changed on method declaration diff --git a/src/test/java/org/openrewrite/kotlin/tree/ClassDeclarationTest.java b/src/test/java/org/openrewrite/kotlin/tree/ClassDeclarationTest.java index bd3a0f6c7..711ecbc6a 100644 --- a/src/test/java/org/openrewrite/kotlin/tree/ClassDeclarationTest.java +++ b/src/test/java/org/openrewrite/kotlin/tree/ClassDeclarationTest.java @@ -571,7 +571,7 @@ class SerializationException : IllegalArgumentException { cause -> assertThat(cause).isInstanceOf(J.VariableDeclarations.class) ); assertThat(constructor.getMethodDeclaration().getBody()).isNull(); - assertThat(constructor.getInvocation().getElement().getArguments()).satisfiesExactly( + assertThat(constructor.getConstructorInvocation().getArguments()).satisfiesExactly( message -> assertThat(message).isInstanceOf(J.Identifier.class), cause -> assertThat(cause).isInstanceOf(J.Identifier.class) );