diff --git a/src/main/java/org/openrewrite/kotlin/internal/KotlinTreeParserVisitor.java b/src/main/java/org/openrewrite/kotlin/internal/KotlinTreeParserVisitor.java index b0ab2672b..96a152a13 100644 --- a/src/main/java/org/openrewrite/kotlin/internal/KotlinTreeParserVisitor.java +++ b/src/main/java/org/openrewrite/kotlin/internal/KotlinTreeParserVisitor.java @@ -2145,7 +2145,8 @@ public J visitClassBody(KtClassBody classBody, ExecutionContext data) { if (d instanceof KtEnumEntry) { continue; } - list.add(padRight(convertToStatement(d.accept(this, data)), Space.EMPTY)); + Statement statement = convertToStatement(d.accept(this, data)); + list.add(maybeFollowingSemicolon(statement, d)); } return new J.Block( @@ -3359,6 +3360,14 @@ private JRightPadded maybeSemicolon(J2 j, KtElement element) return padRight(j, Space.EMPTY); } + private JRightPadded maybeFollowingSemicolon(J2 j, KtElement element) { + PsiElement maybeSemicolon = findFirstNonSpaceNextSibling(element); + if (maybeSemicolon instanceof LeafPsiElement && ((LeafPsiElement) maybeSemicolon).getElementType() == KtTokens.SEMICOLON) { + return new JRightPadded<>(j, prefix(maybeSemicolon), Markers.EMPTY.add(new Semicolon(randomId()))); + } + return padRight(j, Space.EMPTY); + } + private JLeftPadded padLeft(Space left, T tree) { return new JLeftPadded<>(left, tree, Markers.EMPTY); }