APIdia Launch Partner
Top Description Inners Fields Constructors Methods
com.sun.tools.javac.parser

public Class JavadocTokenizer

extends JavaTokenizer
Class Inheritance
Imports
com.sun.tools.javac.parser.Tokens.Comment, .Tokens.Comment.CommentStyle, com.sun.tools.javac.util.JCDiagnostic, .Position, java.nio.CharBuffer, java.util.Arrays

An extension to the base lexical analyzer (JavaTokenizer) that captures and processes the contents of doc comments. It does so by stripping the leading whitespace and comment stars from each line of the Javadoc comment.

This is NOT part of any supported API. If you write code that depends on this, you do so at your own risk. This code and its internal interfaces are subject to change or deletion without notice.

Nested and Inner Type Summary

Modifier and TypeClass and Description
protected static class
JavadocTokenizer.JavadocComment

An extension of BasicComment used to extract the relevant portion of a Javadoc comment.

pack-priv static class
JavadocTokenizer.OffsetMap

Build an int table to mapping positions in extracted Javadoc comment to positions in the JavaTokenizer source buffer.

pack-priv static class
JavadocTokenizer.StrippedComment

A Comment derived from a JavadocComment with leading whitespace removed from all lines.

Field Summary

Modifier and TypeField and Description
pack-priv final ScannerFactory
fac

Hides com.sun.tools.javac.parser.JavaTokenizer.fac.

The factory that created this Scanner.
Inherited from com.sun.tools.javac.parser.JavaTokenizer:
enableLineDocCommentserrPoshasEscapeSequencesisTextBlocklognameradixsbtk

Constructor Summary

AccessConstructor and Description
protected
JavadocTokenizer(ScannerFactory
the factory which created this Scanner.
fac
,
CharBuffer
the input character buffer.
cb
)

Create a tokenizer from the input character buffer.

protected
JavadocTokenizer(ScannerFactory
factory which created this Scanner
fac
,
char[]
input character array.
array
,
int
length of the meaningful content in the array.
length
)

Create a tokenizer from the input array.

Method Summary

Modifier and TypeMethod and Description
public Position.LineMap

Returns:

a LineMap
getLineMap
()

Overrides com.sun.tools.javac.parser.JavaTokenizer.getLineMap.

Build a map for translating between line numbers and positions in the input.

protected Tokens.Comment
processComment(int pos, int endPos, Tokens.Comment.CommentStyle style)

Overrides com.sun.tools.javac.parser.JavaTokenizer.processComment.

Called when a complete comment has been scanned.

Inherited from com.sun.tools.javac.parser.JavaTokenizer:
acceptOneOfThenPutacceptThenPutappendCommentcheckSourceLevelerrPoserrPoslexErrorprocessLineTerminatorprocessWhiteSpaceputputputputCodePointputThenNextreadToken

Field Detail

facback to summary
pack-priv final ScannerFactory fac

Hides com.sun.tools.javac.parser.JavaTokenizer.fac.

The factory that created this Scanner.

Constructor Detail

JavadocTokenizerback to summary
protected JavadocTokenizer(ScannerFactory fac, CharBuffer cb)

Create a tokenizer from the input character buffer. The input buffer content would typically be a Javadoc comment extracted by JavaTokenizer.

Parameters
fac:ScannerFactory

the factory which created this Scanner.

cb:CharBuffer

the input character buffer.

JavadocTokenizerback to summary
protected JavadocTokenizer(ScannerFactory fac, char[] array, int length)

Create a tokenizer from the input array. The input buffer content would typically be a Javadoc comment extracted by JavaTokenizer.

Parameters
fac:ScannerFactory

factory which created this Scanner

array:char[]

input character array.

length:int

length of the meaningful content in the array.

Method Detail

getLineMapback to summary
public Position.LineMap getLineMap()

Overrides com.sun.tools.javac.parser.JavaTokenizer.getLineMap.

Build a map for translating between line numbers and positions in the input. Overridden to expand tabs.

Returns:Position.LineMap

a LineMap

Annotations
@Override
processCommentback to summary
protected Tokens.Comment processComment(int pos, int endPos, Tokens.Comment.CommentStyle style)

Overrides com.sun.tools.javac.parser.JavaTokenizer.processComment.

Doc from com.sun.tools.javac.parser.JavaTokenizer.processComment.

Called when a complete comment has been scanned. pos and endPos will mark the comment boundary.

Annotations
@Override
com.sun.tools.javac.parser back to summary

protected Class JavadocTokenizer.JavadocComment

extends BasicComment
Class Inheritance

An extension of BasicComment used to extract the relevant portion of a Javadoc comment.

Field Summary

Modifier and TypeField and Description
private String
docComment

The relevant portion of the comment that is of interest to Javadoc.

private boolean
firstLine

Indicates if newline is required.

pack-priv JavadocTokenizer.OffsetMap
offsetMap

Map used to map the extracted Javadoc comment's character positions back to the original source.

private StringBuilder
sb

StringBuilder used to extract the relevant portion of the Javadoc comment.

Inherited from com.sun.tools.javac.parser.JavaTokenizer.BasicComment:
csdeprecatedFlagposscanned

Constructor Summary

AccessConstructor and Description
pack-priv
JavadocComment(Tokens.Comment.CommentStyle cs, UnicodeReader reader, int pos, int endPos)

Method Summary

Modifier and TypeMethod and Description
public int
getSourcePos(int pos)

Overrides com.sun.tools.javac.parser.JavaTokenizer.BasicComment.getSourcePos.

Implements com.sun.tools.javac.parser.Tokens.Comment.getSourcePos.

Return buffer position in original buffer mapped from buffer position in comment.

public String
getText()

Overrides com.sun.tools.javac.parser.JavaTokenizer.BasicComment.getText.

Implements com.sun.tools.javac.parser.Tokens.Comment.getText.

Return comment body text minus comment adornments or null if not scanned.

protected void
putLine(UnicodeReader
line reader
line
)

Overrides com.sun.tools.javac.parser.JavaTokenizer.BasicComment.putLine.

Add current character or code point from line to the extraction buffer.

protected void
public Tokens.Comment
stripIndent()

Overrides com.sun.tools.javac.parser.JavaTokenizer.BasicComment.stripIndent.

Implements com.sun.tools.javac.parser.Tokens.Comment.stripIndent.

Return a version of this comment with incidental whitespace removed, or this comment if the operation is not supported.

Inherited from com.sun.tools.javac.parser.JavaTokenizer.BasicComment:
getJavadocLineCommentIndentgetPosgetStyleisDeprecatedtrimEndOfCommenttrimJavadocCommenttrimJavadocLineComment

Field Detail

docCommentback to summary
private String docComment

The relevant portion of the comment that is of interest to Javadoc. Produced by invoking scanDocComment.

firstLineback to summary
private boolean firstLine

Indicates if newline is required.

offsetMapback to summary
pack-priv JavadocTokenizer.OffsetMap offsetMap

Map used to map the extracted Javadoc comment's character positions back to the original source.

sbback to summary
private StringBuilder sb

StringBuilder used to extract the relevant portion of the Javadoc comment.

Constructor Detail

JavadocCommentback to summary
pack-priv JavadocComment(Tokens.Comment.CommentStyle cs, UnicodeReader reader, int pos, int endPos)

Method Detail

getSourcePosback to summary
public int getSourcePos(int pos)

Overrides com.sun.tools.javac.parser.JavaTokenizer.BasicComment.getSourcePos.

Implements com.sun.tools.javac.parser.Tokens.Comment.getSourcePos.

Doc from com.sun.tools.javac.parser.JavaTokenizer.BasicComment.getSourcePos.

Return buffer position in original buffer mapped from buffer position in comment.

Annotations
@Override
getTextback to summary
public String getText()

Overrides com.sun.tools.javac.parser.JavaTokenizer.BasicComment.getText.

Implements com.sun.tools.javac.parser.Tokens.Comment.getText.

Doc from com.sun.tools.javac.parser.JavaTokenizer.BasicComment.getText.

Return comment body text minus comment adornments or null if not scanned.

Annotations
@Override
putLineback to summary
protected void putLine(UnicodeReader line)

Overrides com.sun.tools.javac.parser.JavaTokenizer.BasicComment.putLine.

Add current character or code point from line to the extraction buffer.

Parameters
line:UnicodeReader

line reader

scanDocCommentback to summary
protected void scanDocComment()

Overrides com.sun.tools.javac.parser.JavaTokenizer.BasicComment.scanDocComment.

Doc from com.sun.tools.javac.parser.JavaTokenizer.BasicComment.scanDocComment.

Scan document comment for content.

Annotations
@Override
stripIndentback to summary
public Tokens.Comment stripIndent()

Overrides com.sun.tools.javac.parser.JavaTokenizer.BasicComment.stripIndent.

Implements com.sun.tools.javac.parser.Tokens.Comment.stripIndent.

Doc from com.sun.tools.javac.parser.JavaTokenizer.BasicComment.stripIndent.

Return a version of this comment with incidental whitespace removed, or this comment if the operation is not supported.

Annotations
@Override
com.sun.tools.javac.parser back to summary

pack-priv Class JavadocTokenizer.OffsetMap

extends Object
Class Inheritance

Build an int table to mapping positions in extracted Javadoc comment to positions in the JavaTokenizer source buffer. The array is organized as a series of pairs of integers: the first number in each pair specifies a position in the comment text, the second number in each pair specifies the corresponding position in the source buffer. The pairs are sorted in ascending order. Since the mapping function is generally continuous, with successive positions in the string corresponding to successive positions in the source buffer, the table only needs to record discontinuities in the mapping. The values of intermediate positions can be inferred. Discontinuities may occur in a number of places: when a newline is followed by whitespace and asterisks (which are ignored), when a tab is expanded into spaces, and when unicode escapes are used in the source buffer. Thus, to find the source position of any position, p, in the comment string, find the index, i, of the pair whose string offset (map[i * NOFFSETS + SB_OFFSET] ) is closest to but not greater than p. Then, sourcePos(p) = map[i * NOFFSETS + POS_OFFSET] + (p - map[i * NOFFSETS + SB_OFFSET]) .

Field Summary

Modifier and TypeField and Description
private int[]
map

Array storing entries in map.

private static final int
NOFFSETS

Number of elements in each entry.

private static final int
POS_OFFSET

map entry offset of input offset member of pair.

private static final int
SB_OFFSET

map entry offset for comment offset member of pair.

private int
size

Logical size of map.

Constructor Summary

AccessConstructor and Description
pack-priv
OffsetMap()

Constructor.

Method Summary

Modifier and TypeMethod and Description
pack-priv void
add(int
comment offset member of pair.
sbOffset
,
int
input offset member of pair.
posOffset
)

Adds entry pair if worthwhile.

private void
ensure(int
number of array slots needed.
need
)

Ensures there is enough space for a new entry.

pack-priv int
getSourcePos(int pos)

Binary search to find the entry for which the string index is less than pos.

private int

Returns:

the previous input offset.
lastPosOffset
()

Returns the previous input offset.

private int

Returns:

the previous comment offset.
lastSBOffset
()

Returns the previous comment offset.

pack-priv boolean

Returns:

true if it is worthwhile adding the entry pair.
shouldAdd
(int
comment offset member of pair.
sbOffset
,
int
input offset member of pair.
posOffset
)

Returns true if it is worthwhile adding the entry pair to the map.

pack-priv void
trim()

Reduce map to minimum size.

Inherited from java.lang.Object:
cloneequalsfinalizegetClasshashCodenotifynotifyAlltoStringwaitwaitwait

Field Detail

mapback to summary
private int[] map

Array storing entries in map.

NOFFSETSback to summary
private static final int NOFFSETS

Number of elements in each entry.

POS_OFFSETback to summary
private static final int POS_OFFSET

map entry offset of input offset member of pair.

SB_OFFSETback to summary
private static final int SB_OFFSET

map entry offset for comment offset member of pair.

sizeback to summary
private int size

Logical size of map. This is the number of occupied positions in map, and equals NOFFSETS multiplied by the number of entries.

Constructor Detail

OffsetMapback to summary
pack-priv OffsetMap()

Constructor.

Method Detail

addback to summary
pack-priv void add(int sbOffset, int posOffset)

Adds entry pair if worthwhile.

Parameters
sbOffset:int

comment offset member of pair.

posOffset:int

input offset member of pair.

ensureback to summary
private void ensure(int need)

Ensures there is enough space for a new entry.

Parameters
need:int

number of array slots needed.

getSourcePosback to summary
pack-priv int getSourcePos(int pos)

Binary search to find the entry for which the string index is less than pos. Since the map is a list of pairs of integers we must make sure the index is always NOFFSETS scaled. If we find an exact match for pos, the other item in the pair gives the source pos; otherwise, compute the source position relative to the best match found in the array.

lastPosOffsetback to summary
private int lastPosOffset()

Returns the previous input offset.

Returns:int

the previous input offset.

lastSBOffsetback to summary
private int lastSBOffset()

Returns the previous comment offset.

Returns:int

the previous comment offset.

shouldAddback to summary
pack-priv boolean shouldAdd(int sbOffset, int posOffset)

Returns true if it is worthwhile adding the entry pair to the map. That is if there is a change in relative offset.

Parameters
sbOffset:int

comment offset member of pair.

posOffset:int

input offset member of pair.

Returns:boolean

true if it is worthwhile adding the entry pair.

trimback to summary
pack-priv void trim()

Reduce map to minimum size.

com.sun.tools.javac.parser back to summary

pack-priv Class JavadocTokenizer.StrippedComment

extends Object
implements Comment
Class Inheritance
All Implemented Interfaces
com.sun.tools.javac.parser.Tokens.Comment

A Comment derived from a JavadocComment with leading whitespace removed from all lines. A new OffsetMap is used in combination with the OffsetMap of the original comment to translate comment locations to positions in the source file.

Note

This class assumes new lines are encoded as '\n', which is the case for comments created by JavadocTokenizer.

Field Summary

Modifier and TypeField and Description
pack-priv final boolean
pack-priv final JCDiagnostic.DiagnosticPosition
pack-priv final JavadocTokenizer.OffsetMap
pack-priv final JavadocTokenizer.OffsetMap
pack-priv final Tokens.Comment.CommentStyle
pack-priv String

Constructor Summary

AccessConstructor and Description
private

Method Summary

Modifier and TypeMethod and Description
pack-priv static int

Returns:

number of leading whitespace characters that can be reomved
getIndent
(Tokens.Comment
the original comment
comment
)

Determines the number of leading whitespace characters that can be removed from all non-blank lines of the original comment.

public JCDiagnostic.DiagnosticPosition
public int
public Tokens.Comment.CommentStyle
public String
public boolean
pack-priv static Tokens.Comment

Returns:

stripped or original comment
of
(JavadocTokenizer.JavadocComment
the original comment
comment
)

Returns a stripped version of the comment, or the comment itself if there is no whitespace that can be stripped.

private void
stripComment(JavadocTokenizer.JavadocComment
the original comment
comment
,
int
number of whitespace characters to remove from each non-blank line
indent
)

Strips indent whitespace characters from every line of the original comment and initializes an OffsetMap to translate positions to the original comment's OffsetMap.

public Tokens.Comment
Inherited from java.lang.Object:
cloneequalsfinalizegetClasshashCodenotifynotifyAlltoStringwaitwaitwait

Field Detail

deprecatedback to summary
pack-priv final boolean deprecated
diagPosback to summary
pack-priv final JCDiagnostic.DiagnosticPosition diagPos
sourceMapback to summary
pack-priv final JavadocTokenizer.OffsetMap sourceMap
strippedMapback to summary
pack-priv final JavadocTokenizer.OffsetMap strippedMap
styleback to summary
pack-priv final Tokens.Comment.CommentStyle style
textback to summary
pack-priv String text

Constructor Detail

StrippedCommentback to summary
private StrippedComment(JavadocTokenizer.JavadocComment comment, int indent)

Method Detail

getIndentback to summary
pack-priv static int getIndent(Tokens.Comment comment)

Determines the number of leading whitespace characters that can be removed from all non-blank lines of the original comment.

Parameters
comment:Tokens.Comment

the original comment

Returns:int

number of leading whitespace characters that can be reomved

getPosback to summary
public JCDiagnostic.DiagnosticPosition getPos()

Implements com.sun.tools.javac.parser.Tokens.Comment.getPos.

Annotations
@Override
getSourcePosback to summary
public int getSourcePos(int pos)

Implements com.sun.tools.javac.parser.Tokens.Comment.getSourcePos.

Annotations
@Override
getStyleback to summary
public Tokens.Comment.CommentStyle getStyle()

Implements com.sun.tools.javac.parser.Tokens.Comment.getStyle.

Annotations
@Override
getTextback to summary
public String getText()

Implements com.sun.tools.javac.parser.Tokens.Comment.getText.

Annotations
@Override
isDeprecatedback to summary
public boolean isDeprecated()

Implements com.sun.tools.javac.parser.Tokens.Comment.isDeprecated.

Annotations
@Override
ofback to summary
pack-priv static Tokens.Comment of(JavadocTokenizer.JavadocComment comment)

Returns a stripped version of the comment, or the comment itself if there is no whitespace that can be stripped.

Parameters
comment:JavadocTokenizer.JavadocComment

the original comment

Returns:Tokens.Comment

stripped or original comment

stripCommentback to summary
private void stripComment(JavadocTokenizer.JavadocComment comment, int indent)

Strips indent whitespace characters from every line of the original comment and initializes an OffsetMap to translate positions to the original comment's OffsetMap. This method does not distinguish between blank and non-blank lines except for the fact that blank lines are not required to contain the number of leading whitespace indicated by {@indent }.

Parameters
comment:JavadocTokenizer.JavadocComment

the original comment

indent:int

number of whitespace characters to remove from each non-blank line

stripIndentback to summary
public Tokens.Comment stripIndent()

Implements com.sun.tools.javac.parser.Tokens.Comment.stripIndent.

Annotations
@Override