Skip to content

Commit 28937f9

Browse files
cpovirkcushon
authored andcommitted
Indent list items 2 spaces (in addition to any indentation from nested lists)
MOE_MIGRATED_REVID=134770008
1 parent 41d4254 commit 28937f9

File tree

3 files changed

+29
-25
lines changed

3 files changed

+29
-25
lines changed

core/src/main/java/com/google/googlejavaformat/java/javadoc/JavadocWriter.java

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -51,6 +51,7 @@ final class JavadocWriter {
5151
private boolean continuingListItemOfInnermostList;
5252
private boolean continuingFooterTag;
5353
private final NestingCounter continuingListItemCount = new NestingCounter();
54+
private final NestingCounter continuingListCount = new NestingCounter();
5455
private int remainingOnLine;
5556
private boolean atStartOfLine;
5657
private RequestedWhitespace requestedWhitespace = NONE;
@@ -103,6 +104,7 @@ void writeFooterJavadocTagStart(Token token) {
103104
*/
104105
continuingListItemOfInnermostList = false;
105106
continuingListItemCount.reset();
107+
continuingListCount.reset();
106108

107109
if (!wroteAnythingSignificant) {
108110
// Javadoc consists solely of tags. This is frowned upon in general but OK for @Overrides.
@@ -123,6 +125,7 @@ void writeListOpen(Token token) {
123125

124126
writeToken(token);
125127
continuingListItemOfInnermostList = false;
128+
continuingListCount.increment();
126129

127130
requestNewline();
128131
}
@@ -131,6 +134,7 @@ void writeListClose(Token token) {
131134
requestNewline();
132135

133136
continuingListItemCount.decrementIfPositive();
137+
continuingListCount.decrementIfPositive();
134138
writeToken(token);
135139

136140
// TODO(cushon): only if continuingListItemCount == 0?
@@ -378,7 +382,7 @@ enum AutoIndent {
378382
}
379383

380384
private int innerIndent() {
381-
int innerIndent = continuingListItemCount.value() * 4;
385+
int innerIndent = continuingListItemCount.value() * 4 + continuingListCount.value() * 2;
382386
if (continuingFooterTag) {
383387
innerIndent += 4;
384388
}

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

Lines changed: 17 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -698,14 +698,14 @@ public void lists() {
698698
" * Foo.",
699699
" *",
700700
" * <ul>",
701-
" * <li>1",
702-
" * <ul>",
703-
" * <li>1a",
704-
" * <li>1b",
705-
" * </ul>",
706-
" * more 1",
707-
" * <p>still more 1",
708-
" * <li>2",
701+
" * <li>1",
702+
" * <ul>",
703+
" * <li>1a",
704+
" * <li>1b",
705+
" * </ul>",
706+
" * more 1",
707+
" * <p>still more 1",
708+
" * <li>2",
709709
" * </ul>",
710710
" */",
711711
"class Test {}",
@@ -729,9 +729,9 @@ public void listItemWrap() {
729729
" * Foo.",
730730
" *",
731731
" * <ul>",
732-
" * <li>234567890 234567890 234567890 234567890 234567890 234567890 234567890 234567890"
732+
" * <li>234567890 234567890 234567890 234567890 234567890 234567890 234567890 234567890"
733733
+ " 234567890",
734-
" * 234567890",
734+
" * 234567890",
735735
" * </ul>",
736736
" */",
737737
"class Test {}",
@@ -755,7 +755,7 @@ public void unclosedList() {
755755
" * Foo.",
756756
" *",
757757
" * <ul>",
758-
" * <li>1",
758+
" * <li>1",
759759
" *",
760760
" * @return blah",
761761
" */",
@@ -928,10 +928,10 @@ public void paramsOtherIndents() {
928928
" * @param foo a",
929929
" * <p>b",
930930
" * <ul>",
931-
" * <li>a",
932-
" * <ul>",
933-
" * <li>x",
934-
" * </ul>",
931+
" * <li>a",
932+
" * <ul>",
933+
" * <li>x",
934+
" * </ul>",
935935
" * </ul>",
936936
" *", // TODO(cpovirk): Ideally we would probably eliminate this.
937937
" * @param bar another",
@@ -1066,8 +1066,8 @@ public void inferParagraphTags() {
10661066
" * </pre>",
10671067
" *",
10681068
" * <ul>",
1069-
" * <li>foo",
1070-
" * <p>bar",
1069+
" * <li>foo",
1070+
" * <p>bar",
10711071
" * </ul>",
10721072
" */",
10731073
"class Test {}",

core/src/test/resources/com/google/googlejavaformat/java/testdata/B30153869.output

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
* one
33
*
44
* <ol>
5-
* <li>two
5+
* <li>two
66
* </ol>
77
*
88
* <p>
@@ -14,13 +14,13 @@ class T {
1414
* One
1515
*
1616
* <ul>
17-
* <li>a
18-
* <ul>
19-
* <li>b
20-
* <li>c
21-
* </ul>
17+
* <li>a
18+
* <ul>
19+
* <li>b
20+
* <li>c
21+
* </ul>
2222
*
23-
* <li>e
23+
* <li>e
2424
* </ul>
2525
*/
2626
int x;

0 commit comments

Comments
 (0)