Skip to content

Commit 7f2a32d

Browse files
authored
Merge pull request #74 from openjavaformat/javadoc-banner-comments
Leave a comment that opens with /*** out of javadoc formatting
2 parents 4978dca + 49ff83d commit 7f2a32d

2 files changed

Lines changed: 21 additions & 2 deletions

File tree

‎open-java-format/src/main/java/com/palantir/javaformat/java/JavaInput.java‎

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -154,7 +154,9 @@ public boolean isSlashStarComment() {
154154

155155
@Override
156156
public boolean isJavadocComment() {
157-
return text.startsWith("/**") && text.length() > 4;
157+
// comments like `/***` are also javadoc, but their formatting probably won't be improved
158+
// by the javadoc formatter
159+
return text.startsWith("/**") && text.charAt("/**".length()) != '*' && text.length() > 4;
158160
}
159161

160162
@Override

‎open-java-format/src/test/java/com/palantir/javaformat/java/JavadocFormattingTest.java‎

Lines changed: 18 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -55,11 +55,28 @@ public void empty() {
5555
"class Test {}",
5656
};
5757
String[] expected = {
58-
"/** */", "class Test {}",
58+
"/***/", "class Test {}",
5959
};
6060
doFormatTest(input, expected);
6161
}
6262

63+
@Test
64+
public void bannerCommentIsNotJavadoc() {
65+
// A comment that opens with three or more asterisks is left to the plain comment handling: reflowing it as
66+
// javadoc would push the asterisks onto a line of their own and turn its paragraphs into <p> tags.
67+
String[] input = {
68+
"/****************************************",
69+
" * Copyright",
70+
" *",
71+
" * Some",
72+
" *",
73+
" * Company",
74+
" ****************************************/",
75+
"class Test {}",
76+
};
77+
doFormatTest(input, input);
78+
}
79+
6380
@Test
6481
public void emptyMultipleLines() {
6582
String[] input = {

0 commit comments

Comments
 (0)