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 @@ -94,7 +94,7 @@ private ImmutableList<Replacement> findReplacements() throws FormatterException
// Make sure there are no more imports before the next class (etc) definition.
Optional<Integer> maybeLaterImport = findIdentifier(afterLastImport, IMPORT_OR_CLASS_START);
if (maybeLaterImport.isPresent() && tokenAt(maybeLaterImport.get()).equals("import")) {
throw new FormatterException("Imports not contiguous (perhaps a comment separates them?)");
return ImmutableList.of();
}

int start = toks.get(unindentedFirstImportStart).getPosition();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -1320,4 +1320,31 @@ void f() {
""";
assertThat(new Formatter().formatSource(input)).isEqualTo(expected);
}

@Test
public void blockCommentBetweenImports() throws Exception {
String input =
"""
import java.util.Set;
/**Javadoc*/
import java.util.List;

class T {
List<String> xs;
Set<String> ys;
}
""";
String expected =
"""
import java.util.Set;
/** Javadoc */
import java.util.List;

class T {
List<String> xs;
Set<String> ys;
}
""";
assertThat(new Formatter().formatSourceAndFixImports(input)).isEqualTo(expected);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -402,18 +402,14 @@ public static Collection<Object[]> parameters() {
" between imports either */",
"import com.foo.Third;",
},
{
"!!Imports not contiguous (perhaps a comment separates them?)",
}
{}
},
{
{
"import com.foo.Second; /* no block comments after imports */", //
"import com.foo.First;",
},
{
"!!Imports not contiguous (perhaps a comment separates them?)",
}
{}
},
{
{
Expand Down
Loading