Skip to content

Commit

Permalink
Handle javadoc markdown comments
Browse files Browse the repository at this point in the history
Follow-up to 2dde254

Code not deliberately using the new feature may contain line comments that start with `///`, which are now parsed as the new style of markdown comments.

PiperOrigin-RevId: 641905816
  • Loading branch information
cushon authored and Error Prone Team committed Jun 10, 2024
1 parent 5f4024a commit 4c06673
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -96,9 +96,10 @@ public static String getTextFromComment(ErrorProneComment comment) {
return comment.getText().replaceAll("^\\s*/\\*\\s*(.*?)\\s*\\*/\\s*", "$1");
case LINE:
return comment.getText().replaceAll("^\\s*//\\s*", "");
case JAVADOC_LINE:
return comment.getText().replaceAll("^\\s*///\\s*", "");
case JAVADOC_BLOCK:
return comment.getText().replaceAll("^\\s*/\\*\\*\\s*(.*?)\\s*\\*/\\s*", "$1");
default:
}
throw new AssertionError(comment.getStyle());
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -254,4 +254,21 @@ public void matchingCommentsAfterwards() {
"}")
.doTest();
}

@Test
public void markdownJavadocComment() {
compilationTestHelper
.addSourceLines(
"Test.java",
"import static com.google.common.truth.Truth.assertThat;",
"class Test {",
" public void f(int x) {}",
" public void test() {",
" f(",
" /// javadoc markdown",
" /* x= */ 42);",
" }",
"}")
.doTest();
}
}

0 comments on commit 4c06673

Please sign in to comment.