Skip to content

Commit ad72e03

Browse files
eamonnmcmanusgoogle-java-format Team
authored andcommitted
Recognize Markdown Javadoc in a couple of places that were missing.
We won't treat a Markdown Javadoc comment as such unless we have recorded it explicitly when visiting the node it is attached to, in `JavaInputAstVisitor`. That was missing for package declarations (for package Javadoc in `package-info.java`) and for enum constants. When a Markdown Javadoc comment is not recognized, it is treated as a regular `//` line comment that happens to have another `/` immediately after the opening `//`. In particular, if the comment is wrapped, the wrapped line will begin with `//` rather than `///`. PiperOrigin-RevId: 942158710
1 parent 2868787 commit ad72e03

2 files changed

Lines changed: 4 additions & 4 deletions

File tree

core/src/main/java/com/google/googlejavaformat/java/JavaInputAstVisitor.java

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -353,6 +353,7 @@ public Void scan(Tree tree, Void unused) {
353353

354354
@Override
355355
public Void visitCompilationUnit(CompilationUnitTree node, Void unused) {
356+
recordMarkdownJavadocPosition(node);
356357
boolean afterFirstToken = false;
357358
if (node.getPackageName() != null) {
358359
markForPartialFormat();
@@ -814,6 +815,7 @@ public Void visitEnhancedForLoop(EnhancedForLoopTree node, Void unused) {
814815
}
815816

816817
private void visitEnumConstantDeclaration(VariableTree enumConstant) {
818+
recordMarkdownJavadocPosition(enumConstant);
817819
for (AnnotationTree annotation : enumConstant.getModifiers().getAnnotations()) {
818820
scan(annotation, null);
819821
builder.forcedBreak();

core/src/test/java/com/google/googlejavaformat/java/JavadocFormattingTest.java

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -2092,12 +2092,11 @@ enum Foo {
20922092
BAR,
20932093
}
20942094
""";
2095-
// TODO(b/530532338): The wrapped line should have /// not //
20962095
String expected =
20972096
"""
20982097
enum Foo {
20992098
/// Long long long, longedy long, más fada an lá tig an oíche, chaise longue, caffè lungo, ich bin
2100-
// so lang nicht bei dir gewest
2099+
/// so lang nicht bei dir gewest
21012100
BAR,
21022101
}
21032102
""";
@@ -2114,11 +2113,10 @@ public void markdownLongCommentOnPackageDeclaration() {
21142113
/// Long long long, longedy long, más fada an lá tig an oíche, chaise longue, caffè lungo, ich bin so lang nicht bei dir gewest
21152114
package com.example;
21162115
""";
2117-
// TODO(b/530532338): The wrapped line should have /// not //
21182116
String expected =
21192117
"""
21202118
/// Long long long, longedy long, más fada an lá tig an oíche, chaise longue, caffè lungo, ich bin
2121-
// so lang nicht bei dir gewest
2119+
/// so lang nicht bei dir gewest
21222120
package com.example;
21232121
""";
21242122
doFormatTest(input, expected);

0 commit comments

Comments
 (0)