Skip to content

Commit a13b036

Browse files
authored
Merge pull request #155 from openjavaformat/remove-moe-javadoc-markers
Format MOE strip markers in javadoc like any other HTML comment
2 parents 8f3a269 + cd40a92 commit a13b036

5 files changed

Lines changed: 6 additions & 114 deletions

File tree

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

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -81,8 +81,6 @@ private String render(List<Token> input, int blockIndent) {
8181
case CODE_CLOSE_TAG -> output.writeCodeClose(token);
8282
case TABLE_OPEN_TAG -> output.writeTableOpen(token);
8383
case TABLE_CLOSE_TAG -> output.writeTableClose(token);
84-
case MOE_BEGIN_STRIP_COMMENT -> output.requestMoeBeginStripComment(token);
85-
case MOE_END_STRIP_COMMENT -> output.writeMoeEndStripComment(token);
8684
case HTML_COMMENT -> output.writeHtmlComment(token);
8785
case BR_TAG -> output.writeBr(standardizeBrToken(token));
8886
case WHITESPACE -> output.requestWhitespace();

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

Lines changed: 0 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -37,8 +37,6 @@
3737
import static com.palantir.javaformat.java.javadoc.Token.Type.LIST_ITEM_OPEN_TAG;
3838
import static com.palantir.javaformat.java.javadoc.Token.Type.LIST_OPEN_TAG;
3939
import static com.palantir.javaformat.java.javadoc.Token.Type.LITERAL;
40-
import static com.palantir.javaformat.java.javadoc.Token.Type.MOE_BEGIN_STRIP_COMMENT;
41-
import static com.palantir.javaformat.java.javadoc.Token.Type.MOE_END_STRIP_COMMENT;
4240
import static com.palantir.javaformat.java.javadoc.Token.Type.OPTIONAL_LINE_BREAK;
4341
import static com.palantir.javaformat.java.javadoc.Token.Type.PARAGRAPH_CLOSE_TAG;
4442
import static com.palantir.javaformat.java.javadoc.Token.Type.PARAGRAPH_OPEN_TAG;
@@ -292,10 +290,6 @@ private Token.Type consumeToken() throws LexException {
292290
return HEADER_CLOSE_TAG;
293291
} else if (input.tryConsumeRegex(BR_PATTERN)) {
294292
return BR_TAG;
295-
} else if (input.tryConsumeRegex(MOE_BEGIN_STRIP_COMMENT_PATTERN)) {
296-
return MOE_BEGIN_STRIP_COMMENT;
297-
} else if (input.tryConsumeRegex(MOE_END_STRIP_COMMENT_PATTERN)) {
298-
return MOE_END_STRIP_COMMENT;
299293
} else if (input.tryConsumeRegex(HTML_COMMENT_PATTERN)) {
300294
return HTML_COMMENT;
301295
} else if (input.tryConsumeRegex(LITERAL_PATTERN)) {
@@ -611,9 +605,6 @@ private static boolean hasMultipleNewlines(String s) {
611605
// annotations inside code blocks.
612606
// Match "@param <T>" specially in case the <T> is a <P> or other HTML tag we treat specially.
613607
private static final Pattern FOOTER_TAG_PATTERN = compile("^@(param\\s+<\\w+>|[a-z]\\w*)");
614-
private static final Pattern MOE_BEGIN_STRIP_COMMENT_PATTERN =
615-
compile("^<!--\\s*MOE:begin_intracomment_strip\\s*-->");
616-
private static final Pattern MOE_END_STRIP_COMMENT_PATTERN = compile("^<!--\\s*MOE:end_intracomment_strip\\s*-->");
617608
private static final Pattern HTML_COMMENT_PATTERN = fullCommentPattern();
618609
private static final Pattern PRE_OPEN_PATTERN = openTagPattern("pre");
619610
private static final Pattern PRE_CLOSE_PATTERN = closeTagPattern("pre");

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

Lines changed: 0 additions & 35 deletions
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,6 @@
1414

1515
package com.palantir.javaformat.java.javadoc;
1616

17-
import static com.google.common.base.Preconditions.checkNotNull;
1817
import static com.google.common.collect.Sets.immutableEnumSet;
1918
import static com.palantir.javaformat.java.javadoc.JavadocWriter.AutoIndent.AUTO_INDENT;
2019
import static com.palantir.javaformat.java.javadoc.JavadocWriter.AutoIndent.NO_AUTO_INDENT;
@@ -30,7 +29,6 @@
3029
import com.google.common.collect.ImmutableSet;
3130
import com.google.common.collect.Ordering;
3231
import java.util.List;
33-
import javax.annotation.Nullable;
3432

3533
/**
3634
* Stateful object that accepts "requests" and "writes," producing formatted Javadoc.
@@ -56,11 +54,6 @@ final class JavadocWriter {
5654
private int remainingOnLine;
5755
private boolean atStartOfLine;
5856
private RequestedWhitespace requestedWhitespace = NONE;
59-
60-
@Nullable
61-
private Token requestedMoeBeginStripComment;
62-
63-
private int indentForMoeEndStripComment;
6457
private boolean wroteAnythingSignificant;
6558

6659
JavadocWriter(int blockIndent, int maxLineLength) {
@@ -76,11 +69,6 @@ void requestWhitespace() {
7669
requestWhitespace(WHITESPACE);
7770
}
7871

79-
void requestMoeBeginStripComment(Token token) {
80-
// We queue this up so that we can put it after any requested whitespace.
81-
requestedMoeBeginStripComment = checkNotNull(token);
82-
}
83-
8472
void writeBeginJavadoc() {
8573
/*
8674
* JavaCommentsHelper will make sure this is indented right. But it seems sensible enough that,
@@ -250,16 +238,6 @@ void writeTableClose(Token token) {
250238
requestBlankLine();
251239
}
252240

253-
void writeMoeEndStripComment(Token token) {
254-
writeLineBreakNoAutoIndent();
255-
appendSpaces(indentForMoeEndStripComment);
256-
257-
// Or maybe just "output.append(token.getValue())?" I'm kind of surprised this is so easy.
258-
writeToken(token);
259-
260-
requestNewline();
261-
}
262-
263241
void writeHtmlComment(Token token) {
264242
requestNewline();
265243

@@ -322,10 +300,6 @@ enum RequestedWhitespace {
322300
}
323301

324302
private void writeToken(Token token) {
325-
if (requestedMoeBeginStripComment != null) {
326-
requestNewline();
327-
}
328-
329303
if (!wroteAnythingSignificant) {
330304
// Nothing precedes the first token but the opening ∕✱✱ and its newline, so no requested
331305
// whitespace (e.g., the blank line a <pre> or <ul> asks for) belongs before it.
@@ -366,15 +340,6 @@ private void writeToken(Token token) {
366340
remainingOnLine--;
367341
}
368342

369-
if (requestedMoeBeginStripComment != null) {
370-
output.append(requestedMoeBeginStripComment.getValue());
371-
requestedMoeBeginStripComment = null;
372-
indentForMoeEndStripComment = innerIndent();
373-
requestNewline();
374-
writeToken(token);
375-
return;
376-
}
377-
378343
output.append(token.getValue());
379344

380345
if (!START_OF_LINE_TOKENS.contains(token.getType())) {

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

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -60,10 +60,6 @@ enum Type {
6060
CODE_CLOSE_TAG,
6161
TABLE_OPEN_TAG,
6262
TABLE_CLOSE_TAG,
63-
/** {@code <!-- MOE:begin_intracomment_strip -->} */
64-
MOE_BEGIN_STRIP_COMMENT,
65-
/** {@code <!-- MOE:end_intracomment_strip -->} */
66-
MOE_END_STRIP_COMMENT,
6763
HTML_COMMENT,
6864
// TODO(cpovirk): Support <hr> (probably a blank line before and after).
6965
BR_TAG,

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

Lines changed: 6 additions & 64 deletions
Original file line numberDiff line numberDiff line change
@@ -115,7 +115,9 @@ void commentMostlyUntouched() {
115115
}
116116

117117
@Test
118-
void moeComments() {
118+
void moeStripMarkersAreOrdinaryHtmlComments() {
119+
// google/MOE is gone: its intracomment-strip markers are HTML comments like any other, each on a line of its
120+
// own, indented like the text around it, with the blank line a <p> asks for staying with the <p>.
119121
String[] input = {
120122
"/**",
121123
" * Deatomizes the given user.",
@@ -147,8 +149,8 @@ void moeComments() {
147149
" * See go/deatomizer-v5 for the design doc.",
148150
" * <!-- MOE:end_intracomment_strip -->",
149151
" * To reatomize, call {@link reatomize}.",
150-
" *",
151152
" * <!-- MOE:begin_intracomment_strip -->",
153+
" *",
152154
" * <p>This method is used in the Google teleporter.",
153155
" *",
154156
" * <p>Yes, we have a teleporter.",
@@ -158,69 +160,9 @@ void moeComments() {
158160
" * <!-- MOE:begin_intracomment_strip -->",
159161
" * Users must sign go/deatomize-waiver ahead of time.",
160162
" * <!-- MOE:end_intracomment_strip -->",
161-
" * <!-- MOE:begin_intracomment_strip -->",
163+
" * <!-- MOE:begin_intracomment_strip -->",
162164
" * @deprecated Sometimes turns the user into a goat.",
163-
" * <!-- MOE:end_intracomment_strip -->",
164-
" */",
165-
"class Test {}",
166-
};
167-
doFormatTest(input, expected);
168-
}
169-
170-
@Test
171-
void moeCommentBeginOnlyInMiddleOfDoc() {
172-
// We don't really care what happens here so long as we don't explode.
173-
String[] input = {
174-
"/**", //
175-
" * Foo.",
176-
" * <!-- MOE:begin_intracomment_strip -->",
177-
" * Bar.",
178-
" */",
179-
"class Test {}",
180-
};
181-
String[] expected = {
182-
"/**", //
183-
" * Foo.",
184-
" * <!-- MOE:begin_intracomment_strip -->",
185-
" * Bar.",
186-
" */",
187-
"class Test {}",
188-
};
189-
doFormatTest(input, expected);
190-
}
191-
192-
@Test
193-
void moeCommentBeginOnlyAtEndOfDoc() {
194-
// We don't really care what happens here so long as we don't explode.
195-
// TODO(cpovirk): OK, maybe try to leave it in....
196-
String[] input = {
197-
"/**", //
198-
" * Foo.",
199-
" * <!-- MOE:begin_intracomment_strip -->",
200-
" */",
201-
"class Test {}",
202-
};
203-
String[] expected = {
204-
"/** Foo. */", //
205-
"class Test {}",
206-
};
207-
doFormatTest(input, expected);
208-
}
209-
210-
@Test
211-
void moeCommentEndOnly() {
212-
// We don't really care what happens here so long as we don't explode.
213-
String[] input = {
214-
"/**", //
215-
" * Foo.",
216-
" * <!-- MOE:end_intracomment_strip -->",
217-
" */",
218-
"class Test {}",
219-
};
220-
String[] expected = {
221-
"/**", //
222-
" * Foo.",
223-
" * <!-- MOE:end_intracomment_strip -->",
165+
" * <!-- MOE:end_intracomment_strip -->",
224166
" */",
225167
"class Test {}",
226168
};

0 commit comments

Comments
 (0)