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 @@ -144,20 +144,20 @@ private static String render(List<Token> input, int blockIndent, boolean classic
* should include them as part of its own postprocessing? Or even the writer could make sense.
*/

private static Token standardizeBrToken(Token token) {
private static BrTag standardizeBrToken(BrTag token) {
return standardize(token, STANDARD_BR_TOKEN);
}

private static Token standardizePToken(Token token) {
private static ParagraphOpenTag standardizePToken(ParagraphOpenTag token) {
return standardize(token, STANDARD_P_TOKEN);
}

private static Token standardize(Token token, Token standardToken) {
private static <T extends Token> T standardize(T token, T standardToken) {
return SIMPLE_TAG_PATTERN.matcher(token.value()).matches() ? standardToken : token;
}

private static final Token STANDARD_BR_TOKEN = new BrTag("<br>");
private static final Token STANDARD_P_TOKEN = new ParagraphOpenTag("<p>");
private static final BrTag STANDARD_BR_TOKEN = new BrTag("<br>");
private static final ParagraphOpenTag STANDARD_P_TOKEN = new ParagraphOpenTag("<p>");
private static final Pattern SIMPLE_TAG_PATTERN = compile("^<\\w+\\s*/?\\s*>", CASE_INSENSITIVE);

private static final Pattern ONE_CONTENT_LINE_PATTERN = compile(" */[*][*]\n *[*] (.*)\n *[*]/");
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,25 @@
import static com.google.googlejavaformat.java.javadoc.JavadocWriter.RequestedWhitespace.NONE;
import static com.google.googlejavaformat.java.javadoc.JavadocWriter.RequestedWhitespace.WHITESPACE;

import com.google.googlejavaformat.java.javadoc.Token.CodeCloseTag;
import com.google.googlejavaformat.java.javadoc.Token.CodeOpenTag;
import com.google.googlejavaformat.java.javadoc.Token.FooterJavadocTagStart;
import com.google.googlejavaformat.java.javadoc.Token.HeaderCloseTag;
import com.google.googlejavaformat.java.javadoc.Token.HeaderOpenTag;
import com.google.googlejavaformat.java.javadoc.Token.HtmlComment;
import com.google.googlejavaformat.java.javadoc.Token.ListCloseTag;
import com.google.googlejavaformat.java.javadoc.Token.ListItemOpenTag;
import com.google.googlejavaformat.java.javadoc.Token.ListOpenTag;
import com.google.googlejavaformat.java.javadoc.Token.Literal;
import com.google.googlejavaformat.java.javadoc.Token.MoeBeginStripComment;
import com.google.googlejavaformat.java.javadoc.Token.MoeEndStripComment;
import com.google.googlejavaformat.java.javadoc.Token.PreCloseTag;
import com.google.googlejavaformat.java.javadoc.Token.PreOpenTag;
import com.google.googlejavaformat.java.javadoc.Token.SnippetBegin;
import com.google.googlejavaformat.java.javadoc.Token.SnippetEnd;
import com.google.googlejavaformat.java.javadoc.Token.StartOfLineToken;
import com.google.googlejavaformat.java.javadoc.Token.TableCloseTag;
import com.google.googlejavaformat.java.javadoc.Token.TableOpenTag;

/**
* Stateful object that accepts "requests" and "writes," producing formatted Javadoc.
Expand Down Expand Up @@ -73,7 +91,7 @@ private void requestWhitespace(RequestedWhitespace requestedWhitespace) {
this.requestedWhitespace = max(requestedWhitespace, this.requestedWhitespace);
}

void requestMoeBeginStripComment(Token token) {
void requestMoeBeginStripComment(MoeBeginStripComment token) {
// We queue this up so that we can put it after any requested whitespace.
requestedMoeBeginStripComment = checkNotNull(token);
}
Expand All @@ -100,7 +118,7 @@ void writeEndJavadoc() {
}
}

void writeFooterJavadocTagStart(Token token) {
void writeFooterJavadocTagStart(FooterJavadocTagStart token) {
// Close any unclosed lists (e.g., <li> without <ul>).
// TODO(cpovirk): Actually generate </ul>, etc.?
/*
Expand Down Expand Up @@ -132,7 +150,7 @@ void writeFooterJavadocTagStart(Token token) {
continuingFooterTag = true;
}

void writeSnippetBegin(Token token) {
void writeSnippetBegin(SnippetBegin token) {
requestBlankLine();
writeToken(token);
/*
Expand All @@ -146,7 +164,7 @@ void writeSnippetBegin(Token token) {
*/
}

void writeSnippetEnd(Token token) {
void writeSnippetEnd(SnippetEnd token) {
/*
* We don't request a newline here because we have preserved all newlines that existed in the
* input. TODO: b/323389829 - Improve upon that. Specifically:
Expand All @@ -164,7 +182,7 @@ void writeSnippetEnd(Token token) {
requestBlankLine();
}

void writeListOpen(Token token) {
void writeListOpen(ListOpenTag token) {
if (classicJavadoc) {
requestBlankLine();
}
Expand All @@ -178,7 +196,7 @@ void writeListOpen(Token token) {
requestNewline();
}

void writeListClose(Token token) {
void writeListClose(ListCloseTag token) {
if (classicJavadoc) {
requestNewline();
}
Expand All @@ -193,7 +211,7 @@ void writeListClose(Token token) {
}
}

void writeListItemOpen(Token token) {
void writeListItemOpen(ListItemOpenTag token) {
requestNewline();

if (continuingListItemOfInnermostList) {
Expand All @@ -206,15 +224,15 @@ void writeListItemOpen(Token token) {
continuingListItemStack.push(indent);
}

void writeHeaderOpen(Token token) {
void writeHeaderOpen(HeaderOpenTag token) {
if (wroteAnythingSignificant) {
requestBlankLine();
}

writeToken(token);
}

void writeHeaderClose(Token token) {
void writeHeaderClose(HeaderCloseTag token) {
writeToken(token);

requestBlankLine();
Expand Down Expand Up @@ -242,39 +260,39 @@ void writeBlockquoteOpenOrClose(Token token) {
requestBlankLine();
}

void writePreOpen(Token token) {
void writePreOpen(PreOpenTag token) {
requestBlankLine();

writeToken(token);
}

void writePreClose(Token token) {
void writePreClose(PreCloseTag token) {
writeToken(token);

requestBlankLine();
}

void writeCodeOpen(Token token) {
void writeCodeOpen(CodeOpenTag token) {
writeToken(token);
}

void writeCodeClose(Token token) {
void writeCodeClose(CodeCloseTag token) {
writeToken(token);
}

void writeTableOpen(Token token) {
void writeTableOpen(TableOpenTag token) {
requestBlankLine();

writeToken(token);
}

void writeTableClose(Token token) {
void writeTableClose(TableCloseTag token) {
writeToken(token);

requestBlankLine();
}

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

Expand All @@ -284,7 +302,7 @@ void writeMoeEndStripComment(Token token) {
requestNewline();
}

void writeHtmlComment(Token token) {
void writeHtmlComment(HtmlComment token) {
requestNewline();

writeToken(token);
Expand All @@ -302,7 +320,7 @@ void writeLineBreakNoAutoIndent() {
writeNewline(NO_AUTO_INDENT);
}

void writeLiteral(Token token) {
void writeLiteral(Literal token) {
writeToken(token);
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -94,7 +94,7 @@ void visit(Node node) {
Matcher matcher =
LIST_ITEM_START_PATTERN.matcher(input).region(startPosition, input.length());
verify(matcher.lookingAt());
Token openToken = new ListItemOpenTag(matcher.group(1));
ListItemOpenTag openToken = new ListItemOpenTag(matcher.group(1));
addSpan(positionToToken, listItem, openToken, LIST_ITEM_CLOSE_TOKEN);
if (listItem.getFirstChild() instanceof Paragraph paragraph) {
// A ListItem typically contains a Paragraph, but we don't want to visit that Paragraph
Expand Down Expand Up @@ -153,13 +153,13 @@ public String toString() {
private static final Parser PARSER =
Parser.builder().includeSourceSpans(IncludeSourceSpans.BLOCKS_AND_INLINES).build();

private static final Token HEADER_OPEN_TOKEN = new HeaderOpenTag("");
private static final Token HEADER_CLOSE_TOKEN = new HeaderCloseTag("");
private static final Token PARAGRAPH_OPEN_TOKEN = new ParagraphOpenTag("");
private static final Token PARAGRAPH_CLOSE_TOKEN = new ParagraphCloseTag("");
private static final Token LIST_OPEN_TOKEN = new ListOpenTag("");
private static final Token LIST_CLOSE_TOKEN = new ListCloseTag("");
private static final Token LIST_ITEM_CLOSE_TOKEN = new ListItemCloseTag("");
private static final HeaderOpenTag HEADER_OPEN_TOKEN = new HeaderOpenTag("");
private static final HeaderCloseTag HEADER_CLOSE_TOKEN = new HeaderCloseTag("");
private static final ParagraphOpenTag PARAGRAPH_OPEN_TOKEN = new ParagraphOpenTag("");
private static final ParagraphCloseTag PARAGRAPH_CLOSE_TOKEN = new ParagraphCloseTag("");
private static final ListOpenTag LIST_OPEN_TOKEN = new ListOpenTag("");
private static final ListCloseTag LIST_CLOSE_TOKEN = new ListCloseTag("");
private static final ListItemCloseTag LIST_ITEM_CLOSE_TOKEN = new ListItemCloseTag("");

// The leading \s here works around what appears to be a CommonMark bug. We shouldn't ever see
// space at the purported start of a list item?
Expand Down
Loading