From 33a1cbf8b21c810b8b6e9a34fb58a5e5594c41af Mon Sep 17 00:00:00 2001 From: Kun Li Date: Tue, 10 Oct 2023 16:46:30 -0700 Subject: [PATCH] correct setter/getter order --- .../kotlin/internal/KotlinTreeParserVisitor.java | 8 ++++---- .../openrewrite/kotlin/tree/VariableDeclarationTest.java | 2 ++ 2 files changed, 6 insertions(+), 4 deletions(-) diff --git a/src/main/java/org/openrewrite/kotlin/internal/KotlinTreeParserVisitor.java b/src/main/java/org/openrewrite/kotlin/internal/KotlinTreeParserVisitor.java index 20f7096c6..222f67ba6 100644 --- a/src/main/java/org/openrewrite/kotlin/internal/KotlinTreeParserVisitor.java +++ b/src/main/java/org/openrewrite/kotlin/internal/KotlinTreeParserVisitor.java @@ -671,10 +671,6 @@ public J visitPropertyAccessor(KtPropertyAccessor accessor, ExecutionContext dat returnTypeExpression = accessor.getReturnTypeReference().accept(this, data).withPrefix(prefix(accessor.getReturnTypeReference())); } - if (accessor.getBodyBlockExpression() != accessor.getBodyExpression()) { - throw new UnsupportedOperationException("TODO. check what is the scenario for this case"); - } - if (accessor.getBodyBlockExpression() != null) { body = accessor.getBodyBlockExpression().accept(this, data).withPrefix(prefix(accessor.getBodyBlockExpression())); } else if (accessor.getBodyExpression() != null) { @@ -2019,6 +2015,10 @@ public J visitProperty(KtProperty property, ExecutionContext data) { setter = (J.MethodDeclaration) property.getSetter().accept(this, data); } + if (getter != null && setter != null) { + isSetterFirst = property.getSetter().getTextRange().getStartOffset() < property.getGetter().getTextRange().getStartOffset(); + } + if (property.getLastChild().getNode().getElementType() == KtTokens.SEMICOLON) { throw new UnsupportedOperationException("TODO"); } else if (!property.getAnnotationEntries().isEmpty()) { diff --git a/src/test/java/org/openrewrite/kotlin/tree/VariableDeclarationTest.java b/src/test/java/org/openrewrite/kotlin/tree/VariableDeclarationTest.java index 58b7fcd4d..cb2c17d21 100644 --- a/src/test/java/org/openrewrite/kotlin/tree/VariableDeclarationTest.java +++ b/src/test/java/org/openrewrite/kotlin/tree/VariableDeclarationTest.java @@ -61,6 +61,7 @@ void deSugar() { ); } + @ExpectedToFail("Improved to present !in to a KBinary") @Test void yikes() { rewriteRun( @@ -257,6 +258,7 @@ class Test < T > ); } + @ExpectedToFail("Improved type, condition has a owner now") @Test void ifElseExpression() { rewriteRun(