Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -719,7 +719,12 @@ public J visitIf(IfTree node, Space fmt) {

@Override
public J visitImport(ImportTree node, Space fmt) {
skip("import");
Space beforeImport = sourceBefore("import");
if (!beforeImport.isEmpty()) {
fmt = Space.build(
fmt.getWhitespace() + beforeImport.getWhitespace(),
ListUtils.concatAll(fmt.getComments(), beforeImport.getComments()));
}
return new J.Import(randomId(), fmt, Markers.EMPTY,
new JLeftPadded<>(node.isStatic() ? sourceBefore("static") : EMPTY,
node.isStatic(), Markers.EMPTY),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -825,7 +825,12 @@ public J visitIf(IfTree node, Space fmt) {

@Override
public J visitImport(ImportTree node, Space fmt) {
skip("import");
Space beforeImport = sourceBefore("import");
if (!beforeImport.isEmpty()) {
fmt = Space.build(
fmt.getWhitespace() + beforeImport.getWhitespace(),
ListUtils.concatAll(fmt.getComments(), beforeImport.getComments()));
}
return new J.Import(randomId(), fmt, Markers.EMPTY,
new JLeftPadded<>(node.isStatic() ? sourceBefore("static") : EMPTY,
node.isStatic(), Markers.EMPTY),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -832,7 +832,12 @@ public J visitIf(IfTree node, Space fmt) {

@Override
public J visitImport(ImportTree node, Space fmt) {
skip("import");
Space beforeImport = sourceBefore("import");
if (!beforeImport.isEmpty()) {
fmt = Space.build(
fmt.getWhitespace() + beforeImport.getWhitespace(),
ListUtils.concatAll(fmt.getComments(), beforeImport.getComments()));
}
return new J.Import(randomId(), fmt, Markers.EMPTY,
new JLeftPadded<>(node.isStatic() ? sourceBefore("static") : EMPTY,
node.isStatic(), Markers.EMPTY),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -848,7 +848,12 @@ public J visitIf(IfTree node, Space fmt) {

@Override
public J visitImport(ImportTree node, Space fmt) {
skip("import");
Space beforeImport = sourceBefore("import");
if (!beforeImport.isEmpty()) {
fmt = Space.build(
fmt.getWhitespace() + beforeImport.getWhitespace(),
ListUtils.concatAll(fmt.getComments(), beforeImport.getComments()));
}
return new J.Import(randomId(), fmt, Markers.EMPTY,
new JLeftPadded<>(node.isStatic() ? sourceBefore("static") : EMPTY,
node.isStatic(), Markers.EMPTY),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -718,7 +718,12 @@ public J visitIf(IfTree node, Space fmt) {

@Override
public J visitImport(ImportTree node, Space fmt) {
skip("import");
Space beforeImport = sourceBefore("import");
if (!beforeImport.isEmpty()) {
fmt = Space.build(
fmt.getWhitespace() + beforeImport.getWhitespace(),
ListUtils.concatAll(fmt.getComments(), beforeImport.getComments()));
}
return new J.Import(randomId(), fmt, Markers.EMPTY,
new JLeftPadded<>(node.isStatic() ? sourceBefore("static") : EMPTY,
node.isStatic(), Markers.EMPTY),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,6 @@
*/
package org.openrewrite.java.tree;

import org.junit.jupiter.api.Disabled;
import org.junit.jupiter.api.Test;
import org.openrewrite.Issue;
import org.openrewrite.test.RewriteTest;
Expand Down Expand Up @@ -188,7 +187,6 @@ void spaceBeforeSemiColon() {
);
}

@Disabled("Parser does not support semicolon after package declaration yet")
@Issue("https://github.com/openrewrite/rewrite-migrate-java/issues/396")
@Test
void semicolonAfterPackage() {
Expand All @@ -206,7 +204,6 @@ class AfterPackage { }
);
}

@Disabled("Parser does not support semicolon between imports yet")
@Issue("https://github.com/openrewrite/rewrite-migrate-java/issues/396")
@Test
void semicolonBetweenImports() {
Expand Down Expand Up @@ -239,4 +236,25 @@ void semicolonAfterImports() {
)
);
}

@Issue("https://github.com/openrewrite/rewrite/issues/6310")
@Test
void extraSemicolonAfterImportWithComment() {
rewriteRun(
spec -> spec
.typeValidationOptions(TypeValidation.all().allowNonWhitespaceInWhitespace(true)),
java(
"""
import java.util.*;; // Semicolon here
import java.io.*; // Followed by another import

public class Main {
public static void main(String[] args) {
System.out.printf("Hello and welcome!");
}
}
"""
)
);
}
}