镜像站点 · 本页由第三方 GitHub 只读镜像提供,非 GitHub 官方站点,不接受任何登录或凭据输入。前往 github.com
Skip to content
Open
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 @@ -186,9 +186,34 @@ private ImmutableList<Token> generateTokens() throws LexException {
}
result = optionalizeSpacesAfterLinks(result);
result = deindentPreCodeBlocks(result);
if (classicJavadoc) {
result = removeTrailingEmptyParagraphTag(result);
}
return result;
}

private static ImmutableList<Token> removeTrailingEmptyParagraphTag(List<Token> input) {
int end = input.size() - 1;

if (end >= 0 && input.get(end) instanceof EndJavadoc) {
end--;
}

while (end >= 0 && input.get(end) instanceof Whitespace) {
end--;
}

if (end < 0 || !(input.get(end) instanceof ParagraphOpenTag)) {
return ImmutableList.copyOf(input);
}

ImmutableList.Builder<Token> result = ImmutableList.builder();
result.addAll(input.subList(0, end));
result.addAll(input.subList(input.size() - 1, input.size()));

return result.build();
}

private Token processMarkdownToken(Token markdownToken) {
// For `...`, we switch to MARKDOWN_CODE_CONTEXT for the duration of the span, and we change the
// start or end token to a Literal so it will get joined to adjacent Literal tokens. That
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -1252,6 +1252,25 @@ class Test {}
doFormatTest(input, expected);
}

@Test
public void removeTrailingEmptyParagraphTag() {
String input =
"""
/**
* The client's first name.
*
* <p>
*/
class Test {}\
""";
String expected =
"""
/** The client's first name. */
class Test {}
""";
doFormatTest(input, expected);
}

@Test
public void inferParagraphTags() {
String input =
Expand Down
Loading