Class JavadocLexer
- java.lang.Object
-
- com.google.googlejavaformat.java.javadoc.JavadocLexer
-
final class JavadocLexer extends java.lang.ObjectLexer for the Javadoc formatter.
-
-
Nested Class Summary
Nested Classes Modifier and Type Class Description (package private) static classJavadocLexer.LexException
-
Field Summary
Fields Modifier and Type Field Description private static java.util.regex.PatternBLOCKQUOTE_CLOSE_PATTERNprivate static java.util.regex.PatternBLOCKQUOTE_OPEN_PATTERNprivate static java.util.regex.PatternBR_PATTERNprivate NestingCounterbraceDepthprivate static java.util.regex.PatternCODE_CLOSE_PATTERNprivate static java.util.regex.PatternCODE_OPEN_PATTERNprivate NestingCountercodeDepthprivate static java.util.regex.PatternFOOTER_TAG_PATTERNprivate static java.util.regex.PatternHEADER_CLOSE_PATTERNprivate static java.util.regex.PatternHEADER_OPEN_PATTERNprivate static java.util.regex.PatternHTML_COMMENT_PATTERNprivate static java.util.regex.PatternINLINE_TAG_OPEN_PATTERNprivate CharStreaminputprivate static java.util.regex.PatternLIST_CLOSE_PATTERNprivate static java.util.regex.PatternLIST_ITEM_CLOSE_PATTERNprivate static java.util.regex.PatternLIST_ITEM_OPEN_PATTERNprivate static java.util.regex.PatternLIST_OPEN_PATTERNprivate static java.util.regex.PatternLITERAL_PATTERNprivate static java.util.regex.PatternMOE_BEGIN_STRIP_COMMENT_PATTERNprivate static java.util.regex.PatternMOE_END_STRIP_COMMENT_PATTERNprivate static com.google.common.base.CharMatcherNEWLINEprivate static java.util.regex.PatternNEWLINE_PATTERNprivate static java.util.regex.PatternNON_UNIX_LINE_ENDINGprivate static java.util.regex.PatternPARAGRAPH_CLOSE_PATTERNprivate static java.util.regex.PatternPARAGRAPH_OPEN_PATTERNprivate static java.util.regex.PatternPRE_CLOSE_PATTERNprivate static java.util.regex.PatternPRE_OPEN_PATTERNprivate NestingCounterpreDepthprivate booleansomethingSinceNewlineprivate static java.util.regex.PatternTABLE_CLOSE_PATTERNprivate static java.util.regex.PatternTABLE_OPEN_PATTERNprivate NestingCountertableDepth
-
Constructor Summary
Constructors Modifier Constructor Description privateJavadocLexer(CharStream input)
-
Method Summary
All Methods Static Methods Instance Methods Concrete Methods Modifier and Type Method Description private voidcheckMatchingTags()private static java.util.regex.PatterncloseTagPattern(java.lang.String namePattern)private Token.TypeconsumeToken()private static voiddeindentPreCodeBlock(com.google.common.collect.ImmutableList.Builder<Token> output, com.google.common.collect.PeekingIterator<Token> tokens)private static com.google.common.collect.ImmutableList<Token>deindentPreCodeBlocks(java.util.List<Token> input)Adjust indentation inside `private static java.util.regex.PatternfullCommentPattern()private com.google.common.collect.ImmutableList<Token>generateTokens()private static booleanhasMultipleNewlines(java.lang.String s)private static com.google.common.collect.ImmutableList<Token>inferParagraphTags(java.util.List<Token> input)Where the input has two consecutive line breaks between literals, insert a<p>tag between the literals.private static com.google.common.collect.ImmutableList<Token>joinAdjacentLiteralsAndAdjacentWhitespace(java.util.List<Token> input)Join together adjacent literal tokens, and join together adjacent whitespace tokens.(package private) static com.google.common.collect.ImmutableList<Token>lex(java.lang.String input)Takes a Javadoc comment, including ∕✱✱ and ✱∕, and returns tokens, including ∕✱✱ and ✱∕.private static java.lang.StringnormalizeLineEndings(java.lang.String input)The lexer crashes on windows line endings, so for now just normalize to `\n`.private static java.util.regex.PatternopenTagPattern(java.lang.String namePattern)private static com.google.common.collect.ImmutableList<Token>optionalizeSpacesAfterLinks(java.util.List<Token> input)Replaces whitespace after ahref=...>token with an "optional link break." This allows us to output either<a href=foo>foo</a>or<a href=foo>\nfoo</a>, depending on how much space we have left on the line.private booleanpreserveExistingFormatting()private TokenreadToken()private static java.lang.StringstripJavadocBeginAndEnd(java.lang.String input)
-
-
-
Field Detail
-
NON_UNIX_LINE_ENDING
private static final java.util.regex.Pattern NON_UNIX_LINE_ENDING
-
input
private final CharStream input
-
braceDepth
private final NestingCounter braceDepth
-
preDepth
private final NestingCounter preDepth
-
codeDepth
private final NestingCounter codeDepth
-
tableDepth
private final NestingCounter tableDepth
-
somethingSinceNewline
private boolean somethingSinceNewline
-
NEWLINE
private static final com.google.common.base.CharMatcher NEWLINE
-
NEWLINE_PATTERN
private static final java.util.regex.Pattern NEWLINE_PATTERN
-
FOOTER_TAG_PATTERN
private static final java.util.regex.Pattern FOOTER_TAG_PATTERN
-
MOE_BEGIN_STRIP_COMMENT_PATTERN
private static final java.util.regex.Pattern MOE_BEGIN_STRIP_COMMENT_PATTERN
-
MOE_END_STRIP_COMMENT_PATTERN
private static final java.util.regex.Pattern MOE_END_STRIP_COMMENT_PATTERN
-
HTML_COMMENT_PATTERN
private static final java.util.regex.Pattern HTML_COMMENT_PATTERN
-
PRE_OPEN_PATTERN
private static final java.util.regex.Pattern PRE_OPEN_PATTERN
-
PRE_CLOSE_PATTERN
private static final java.util.regex.Pattern PRE_CLOSE_PATTERN
-
CODE_OPEN_PATTERN
private static final java.util.regex.Pattern CODE_OPEN_PATTERN
-
CODE_CLOSE_PATTERN
private static final java.util.regex.Pattern CODE_CLOSE_PATTERN
-
TABLE_OPEN_PATTERN
private static final java.util.regex.Pattern TABLE_OPEN_PATTERN
-
TABLE_CLOSE_PATTERN
private static final java.util.regex.Pattern TABLE_CLOSE_PATTERN
-
LIST_OPEN_PATTERN
private static final java.util.regex.Pattern LIST_OPEN_PATTERN
-
LIST_CLOSE_PATTERN
private static final java.util.regex.Pattern LIST_CLOSE_PATTERN
-
LIST_ITEM_OPEN_PATTERN
private static final java.util.regex.Pattern LIST_ITEM_OPEN_PATTERN
-
LIST_ITEM_CLOSE_PATTERN
private static final java.util.regex.Pattern LIST_ITEM_CLOSE_PATTERN
-
HEADER_OPEN_PATTERN
private static final java.util.regex.Pattern HEADER_OPEN_PATTERN
-
HEADER_CLOSE_PATTERN
private static final java.util.regex.Pattern HEADER_CLOSE_PATTERN
-
PARAGRAPH_OPEN_PATTERN
private static final java.util.regex.Pattern PARAGRAPH_OPEN_PATTERN
-
PARAGRAPH_CLOSE_PATTERN
private static final java.util.regex.Pattern PARAGRAPH_CLOSE_PATTERN
-
BLOCKQUOTE_OPEN_PATTERN
private static final java.util.regex.Pattern BLOCKQUOTE_OPEN_PATTERN
-
BLOCKQUOTE_CLOSE_PATTERN
private static final java.util.regex.Pattern BLOCKQUOTE_CLOSE_PATTERN
-
BR_PATTERN
private static final java.util.regex.Pattern BR_PATTERN
-
INLINE_TAG_OPEN_PATTERN
private static final java.util.regex.Pattern INLINE_TAG_OPEN_PATTERN
-
LITERAL_PATTERN
private static final java.util.regex.Pattern LITERAL_PATTERN
-
-
Constructor Detail
-
JavadocLexer
private JavadocLexer(CharStream input)
-
-
Method Detail
-
lex
static com.google.common.collect.ImmutableList<Token> lex(java.lang.String input) throws JavadocLexer.LexException
Takes a Javadoc comment, including ∕✱✱ and ✱∕, and returns tokens, including ∕✱✱ and ✱∕.- Throws:
JavadocLexer.LexException
-
normalizeLineEndings
private static java.lang.String normalizeLineEndings(java.lang.String input)
The lexer crashes on windows line endings, so for now just normalize to `\n`.
-
stripJavadocBeginAndEnd
private static java.lang.String stripJavadocBeginAndEnd(java.lang.String input)
-
generateTokens
private com.google.common.collect.ImmutableList<Token> generateTokens() throws JavadocLexer.LexException
- Throws:
JavadocLexer.LexException
-
readToken
private Token readToken() throws JavadocLexer.LexException
- Throws:
JavadocLexer.LexException
-
consumeToken
private Token.Type consumeToken() throws JavadocLexer.LexException
- Throws:
JavadocLexer.LexException
-
preserveExistingFormatting
private boolean preserveExistingFormatting()
-
checkMatchingTags
private void checkMatchingTags() throws JavadocLexer.LexException- Throws:
JavadocLexer.LexException
-
joinAdjacentLiteralsAndAdjacentWhitespace
private static com.google.common.collect.ImmutableList<Token> joinAdjacentLiteralsAndAdjacentWhitespace(java.util.List<Token> input)
Join together adjacent literal tokens, and join together adjacent whitespace tokens.For literal tokens, this means something like
["<b>", "foo", "</b>"] => ["<b>foo</b>"]. SeeLITERAL_PATTERNfor discussion of why those tokens are separate to begin with.Whitespace tokens are treated analogously. We don't really "want" to join whitespace tokens, but in the course of joining literals, we incidentally join whitespace, too. We do take advantage of the joining later on: It simplifies
inferParagraphTags(java.util.List<com.google.googlejavaformat.java.javadoc.Token>).Note that we do not merge a literal token and a whitespace token together.
-
inferParagraphTags
private static com.google.common.collect.ImmutableList<Token> inferParagraphTags(java.util.List<Token> input)
Where the input has two consecutive line breaks between literals, insert a<p>tag between the literals.This method must be called after
joinAdjacentLiteralsAndAdjacentWhitespace(java.util.List<com.google.googlejavaformat.java.javadoc.Token>), as it assumes that adjacent whitespace tokens have already been joined.
-
optionalizeSpacesAfterLinks
private static com.google.common.collect.ImmutableList<Token> optionalizeSpacesAfterLinks(java.util.List<Token> input)
Replaces whitespace after ahref=...>token with an "optional link break." This allows us to output either<a href=foo>foo</a>or<a href=foo>\nfoo</a>, depending on how much space we have left on the line.This method must be called after
joinAdjacentLiteralsAndAdjacentWhitespace(java.util.List<com.google.googlejavaformat.java.javadoc.Token>), as it assumes that adjacent whitespace tokens have already been joined.
-
deindentPreCodeBlocks
private static com.google.common.collect.ImmutableList<Token> deindentPreCodeBlocks(java.util.List<Token> input)
Adjust indentation inside `` blocks. <p>Also trim leading and trailing blank lines, and move the trailing `` to its own line.
-
deindentPreCodeBlock
private static void deindentPreCodeBlock(com.google.common.collect.ImmutableList.Builder<Token> output, com.google.common.collect.PeekingIterator<Token> tokens)
-
hasMultipleNewlines
private static boolean hasMultipleNewlines(java.lang.String s)
-
fullCommentPattern
private static java.util.regex.Pattern fullCommentPattern()
-
openTagPattern
private static java.util.regex.Pattern openTagPattern(java.lang.String namePattern)
-
closeTagPattern
private static java.util.regex.Pattern closeTagPattern(java.lang.String namePattern)
-
-