Skip to content
Merged
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 @@ -81,8 +81,6 @@ private String render(List<Token> input, int blockIndent) {
case CODE_CLOSE_TAG -> output.writeCodeClose(token);
case TABLE_OPEN_TAG -> output.writeTableOpen(token);
case TABLE_CLOSE_TAG -> output.writeTableClose(token);
case MOE_BEGIN_STRIP_COMMENT -> output.requestMoeBeginStripComment(token);
case MOE_END_STRIP_COMMENT -> output.writeMoeEndStripComment(token);
case HTML_COMMENT -> output.writeHtmlComment(token);
case BR_TAG -> output.writeBr(standardizeBrToken(token));
case WHITESPACE -> output.requestWhitespace();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -37,8 +37,6 @@
import static com.palantir.javaformat.java.javadoc.Token.Type.LIST_ITEM_OPEN_TAG;
import static com.palantir.javaformat.java.javadoc.Token.Type.LIST_OPEN_TAG;
import static com.palantir.javaformat.java.javadoc.Token.Type.LITERAL;
import static com.palantir.javaformat.java.javadoc.Token.Type.MOE_BEGIN_STRIP_COMMENT;
import static com.palantir.javaformat.java.javadoc.Token.Type.MOE_END_STRIP_COMMENT;
import static com.palantir.javaformat.java.javadoc.Token.Type.OPTIONAL_LINE_BREAK;
import static com.palantir.javaformat.java.javadoc.Token.Type.PARAGRAPH_CLOSE_TAG;
import static com.palantir.javaformat.java.javadoc.Token.Type.PARAGRAPH_OPEN_TAG;
Expand Down Expand Up @@ -292,10 +290,6 @@ private Token.Type consumeToken() throws LexException {
return HEADER_CLOSE_TAG;
} else if (input.tryConsumeRegex(BR_PATTERN)) {
return BR_TAG;
} else if (input.tryConsumeRegex(MOE_BEGIN_STRIP_COMMENT_PATTERN)) {
return MOE_BEGIN_STRIP_COMMENT;
} else if (input.tryConsumeRegex(MOE_END_STRIP_COMMENT_PATTERN)) {
return MOE_END_STRIP_COMMENT;
} else if (input.tryConsumeRegex(HTML_COMMENT_PATTERN)) {
return HTML_COMMENT;
} else if (input.tryConsumeRegex(LITERAL_PATTERN)) {
Expand Down Expand Up @@ -611,9 +605,6 @@ private static boolean hasMultipleNewlines(String s) {
// annotations inside code blocks.
// Match "@param <T>" specially in case the <T> is a <P> or other HTML tag we treat specially.
private static final Pattern FOOTER_TAG_PATTERN = compile("^@(param\\s+<\\w+>|[a-z]\\w*)");
private static final Pattern MOE_BEGIN_STRIP_COMMENT_PATTERN =
compile("^<!--\\s*MOE:begin_intracomment_strip\\s*-->");
private static final Pattern MOE_END_STRIP_COMMENT_PATTERN = compile("^<!--\\s*MOE:end_intracomment_strip\\s*-->");
private static final Pattern HTML_COMMENT_PATTERN = fullCommentPattern();
private static final Pattern PRE_OPEN_PATTERN = openTagPattern("pre");
private static final Pattern PRE_CLOSE_PATTERN = closeTagPattern("pre");
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,6 @@

package com.palantir.javaformat.java.javadoc;

import static com.google.common.base.Preconditions.checkNotNull;
import static com.google.common.collect.Sets.immutableEnumSet;
import static com.palantir.javaformat.java.javadoc.JavadocWriter.AutoIndent.AUTO_INDENT;
import static com.palantir.javaformat.java.javadoc.JavadocWriter.AutoIndent.NO_AUTO_INDENT;
Expand All @@ -30,7 +29,6 @@
import com.google.common.collect.ImmutableSet;
import com.google.common.collect.Ordering;
import java.util.List;
import javax.annotation.Nullable;

/**
* Stateful object that accepts "requests" and "writes," producing formatted Javadoc.
Expand All @@ -56,11 +54,6 @@ final class JavadocWriter {
private int remainingOnLine;
private boolean atStartOfLine;
private RequestedWhitespace requestedWhitespace = NONE;

@Nullable
private Token requestedMoeBeginStripComment;

private int indentForMoeEndStripComment;
private boolean wroteAnythingSignificant;

JavadocWriter(int blockIndent, int maxLineLength) {
Expand All @@ -76,11 +69,6 @@ void requestWhitespace() {
requestWhitespace(WHITESPACE);
}

void requestMoeBeginStripComment(Token token) {
// We queue this up so that we can put it after any requested whitespace.
requestedMoeBeginStripComment = checkNotNull(token);
}

void writeBeginJavadoc() {
/*
* JavaCommentsHelper will make sure this is indented right. But it seems sensible enough that,
Expand Down Expand Up @@ -250,16 +238,6 @@ void writeTableClose(Token token) {
requestBlankLine();
}

void writeMoeEndStripComment(Token token) {
writeLineBreakNoAutoIndent();
appendSpaces(indentForMoeEndStripComment);

// Or maybe just "output.append(token.getValue())?" I'm kind of surprised this is so easy.
writeToken(token);

requestNewline();
}

void writeHtmlComment(Token token) {
requestNewline();

Expand Down Expand Up @@ -322,10 +300,6 @@ enum RequestedWhitespace {
}

private void writeToken(Token token) {
if (requestedMoeBeginStripComment != null) {
requestNewline();
}

if (!wroteAnythingSignificant) {
// Nothing precedes the first token but the opening ∕✱✱ and its newline, so no requested
// whitespace (e.g., the blank line a <pre> or <ul> asks for) belongs before it.
Expand Down Expand Up @@ -366,15 +340,6 @@ private void writeToken(Token token) {
remainingOnLine--;
}

if (requestedMoeBeginStripComment != null) {
output.append(requestedMoeBeginStripComment.getValue());
requestedMoeBeginStripComment = null;
indentForMoeEndStripComment = innerIndent();
requestNewline();
writeToken(token);
return;
}

output.append(token.getValue());

if (!START_OF_LINE_TOKENS.contains(token.getType())) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -60,10 +60,6 @@ enum Type {
CODE_CLOSE_TAG,
TABLE_OPEN_TAG,
TABLE_CLOSE_TAG,
/** {@code <!-- MOE:begin_intracomment_strip -->} */
MOE_BEGIN_STRIP_COMMENT,
/** {@code <!-- MOE:end_intracomment_strip -->} */
MOE_END_STRIP_COMMENT,
HTML_COMMENT,
// TODO(cpovirk): Support <hr> (probably a blank line before and after).
BR_TAG,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -115,7 +115,9 @@ void commentMostlyUntouched() {
}

@Test
void moeComments() {
void moeStripMarkersAreOrdinaryHtmlComments() {
// google/MOE is gone: its intracomment-strip markers are HTML comments like any other, each on a line of its
// own, indented like the text around it, with the blank line a <p> asks for staying with the <p>.
String[] input = {
"/**",
" * Deatomizes the given user.",
Expand Down Expand Up @@ -147,8 +149,8 @@ void moeComments() {
" * See go/deatomizer-v5 for the design doc.",
" * <!-- MOE:end_intracomment_strip -->",
" * To reatomize, call {@link reatomize}.",
" *",
" * <!-- MOE:begin_intracomment_strip -->",
" *",
" * <p>This method is used in the Google teleporter.",
" *",
" * <p>Yes, we have a teleporter.",
Expand All @@ -158,69 +160,9 @@ void moeComments() {
" * <!-- MOE:begin_intracomment_strip -->",
" * Users must sign go/deatomize-waiver ahead of time.",
" * <!-- MOE:end_intracomment_strip -->",
" * <!-- MOE:begin_intracomment_strip -->",
" * <!-- MOE:begin_intracomment_strip -->",
" * @deprecated Sometimes turns the user into a goat.",
" * <!-- MOE:end_intracomment_strip -->",
" */",
"class Test {}",
};
doFormatTest(input, expected);
}

@Test
void moeCommentBeginOnlyInMiddleOfDoc() {
// We don't really care what happens here so long as we don't explode.
String[] input = {
"/**", //
" * Foo.",
" * <!-- MOE:begin_intracomment_strip -->",
" * Bar.",
" */",
"class Test {}",
};
String[] expected = {
"/**", //
" * Foo.",
" * <!-- MOE:begin_intracomment_strip -->",
" * Bar.",
" */",
"class Test {}",
};
doFormatTest(input, expected);
}

@Test
void moeCommentBeginOnlyAtEndOfDoc() {
// We don't really care what happens here so long as we don't explode.
// TODO(cpovirk): OK, maybe try to leave it in....
String[] input = {
"/**", //
" * Foo.",
" * <!-- MOE:begin_intracomment_strip -->",
" */",
"class Test {}",
};
String[] expected = {
"/** Foo. */", //
"class Test {}",
};
doFormatTest(input, expected);
}

@Test
void moeCommentEndOnly() {
// We don't really care what happens here so long as we don't explode.
String[] input = {
"/**", //
" * Foo.",
" * <!-- MOE:end_intracomment_strip -->",
" */",
"class Test {}",
};
String[] expected = {
"/**", //
" * Foo.",
" * <!-- MOE:end_intracomment_strip -->",
" * <!-- MOE:end_intracomment_strip -->",
" */",
"class Test {}",
};
Expand Down
Loading