Stop comments that share a line from doubling each other's indent by abashev · Pull Request #42 · openjavaformat/open-java-format · GitHub
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 @@ -491,4 +491,21 @@ void formatsDeeplyNestedCallsQuickly() {

assertTimeoutPreemptively(Duration.ofSeconds(10), () -> formatter.formatSource(input));
}

@Test
void indentsCommentsThatShareALineLinearly() throws FormatterException {
// Commented-out code that had javadoc in it puts many multi-line comments on one line: "*//** javadoc *//*".
// Each comment's continuation lines are indented to the column where the comment starts, and the column after
// a comment used to be counted from where it started plus its last line, which already holds that indent. So
// every comment started twice as far right as the one before, and these sixteen came out as 4.3 MB.
StringBuilder input = new StringBuilder("/*\nclass X {\n");
for (int i = 0; i < 16; i++) {
input.append("\t*//** javadoc *//*\n\tpublic void foo(Bar bar) {}\n\n");
}
input.append("}*/\n");
Formatter formatter = Formatter.createFormatter(
JavaFormatterOptions.builder().style(Style.OJF).build());

assertThat(formatter.formatSource(input.toString()).length()).isLessThan(10_000);
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
/*
class X {
*//** javadoc *//*
public void foo(Bar bar) {}

*//** javadoc *//*
public void foo(Bar bar) {}

*//** javadoc *//*
public void foo(Bar bar) {}

*//** javadoc *//*
public void foo(Bar bar) {}
}*/
Loading