APIdia Launch Partner
Top Description Inners Fields Constructors Methods
jdk.internal.markdown

public Class MarkdownTransformer

extends Object
implements DocCommentTreeTransformer
Class Inheritance
All Implemented Interfaces
com.sun.tools.javac.api.JavacTrees.DocCommentTreeTransformer
Imports
java.util.ArrayList, .Iterator, .List, java.util.regex.MatchResult, .Pattern, java.util.stream.Stream, com.sun.source.doctree.DocCommentTree, .DocTree, .DocTreeVisitor, .RawTextTree, com.sun.source.util.DocTreeScanner, .DocTrees, com.sun.tools.javac.api.JavacTrees, com.sun.tools.javac.parser.ReferenceParser, com.sun.tools.javac.tree.DCTree, .DocTreeMaker, com.sun.tools.javac.util.DefinedBy, jdk.internal.org.commonmark.ext.gfm.tables.TablesExtension, jdk.internal.org.commonmark.internal.InlineParserImpl, jdk.internal.org.commonmark.node.AbstractVisitor, .Link, .LinkReferenceDefinition, .Node, .Text, jdk.internal.org.commonmark.parser.IncludeSourceSpans, .InlineParser, .InlineParserContext, .InlineParserFactory, .Parser, jdk.internal.org.commonmark.parser.delimiter.DelimiterProcessor

A class to transform a DocTree node into a similar one with doc-comment "extensions" translated into equivalent standard DocTree nodes.

The primary extension is to allow references to program elements to be translated to {@link ...} or {@linkplain ...} tags.

Nested and Inner Type Summary

Modifier and TypeClass and Description
private static class
MarkdownTransformer.AutoRefInlineParserFactory

An InlineParserFactory that checks any unresolved link references in reference links.

private static class
private static class
MarkdownTransformer.Lower

A visitor to scan a Markdown document looking for any constructs that should be mapped to doc comment nodes.

Field Summary

Modifier and TypeField and Description
private static final DocTreeVisitor<Boolean, Void>
isMarkdownVisitor

A fast scanner for detecting Markdown nodes in documentation comment nodes.

private static final char

Constructor Summary

AccessConstructor and Description
public
MarkdownTransformer()

Public no-args constructor, suitable for use with java.util.ServiceLoader.

Method Summary

Modifier and TypeMethod and Description
private boolean
public String
name()

Implements com.sun.tools.javac.api.JavacTrees.DocCommentTreeTransformer.name.

Returns the name of this transformer.

public DocCommentTree
transform(DocTrees trees, DocCommentTree tree)

Implements com.sun.tools.javac.api.JavacTrees.DocCommentTreeTransformer.transform.

Transforms a documentation comment tree.

Inherited from java.lang.Object:
cloneequalsfinalizegetClasshashCodenotifynotifyAlltoStringwaitwaitwait

Field Detail

isMarkdownVisitorback to summary
private static final DocTreeVisitor<Boolean, Void> isMarkdownVisitor

A fast scanner for detecting Markdown nodes in documentation comment nodes. The scanner returns as soon as any Markdown node is found.

PLACEHOLDERback to summary
private static final char PLACEHOLDER

Constructor Detail

MarkdownTransformerback to summary
public MarkdownTransformer()

Public no-args constructor, suitable for use with java.util.ServiceLoader.

Method Detail

isMarkdownback to summary
private boolean isMarkdown(DocCommentTree node)
nameback to summary
public String name()

Implements com.sun.tools.javac.api.JavacTrees.DocCommentTreeTransformer.name.

Doc from com.sun.tools.javac.api.JavacTrees.DocCommentTreeTransformer.name.

Returns the name of this transformer.

transformback to summary
public DocCommentTree transform(DocTrees trees, DocCommentTree tree)

Implements com.sun.tools.javac.api.JavacTrees.DocCommentTreeTransformer.transform.

Doc from com.sun.tools.javac.api.JavacTrees.DocCommentTreeTransformer.transform.

Transforms a documentation comment tree.

Annotations
@Override
@DefinedBy:COMPILER_TREE
jdk.internal.markdown back to summary

private Class MarkdownTransformer.AutoRefInlineParserFactory

extends Object
implements InlineParserFactory
Class Inheritance
  • java.lang.Object
  • jdk.internal.markdown.MarkdownTransformer.AutoRefInlineParserFactory
All Implemented Interfaces
jdk.internal.org.commonmark.parser.InlineParserFactory

An InlineParserFactory that checks any unresolved link references in reference links. If an unresolved link reference appears to be a reference to a program element, such as may be used in @see ... or {@link ...} tags, it generates a synthetic LinkReferenceDefinition. The reference is not validated to ensure it refers to any existing element. The primary function of this InlineParserFactory is to provide a custom implementation of an InlineParserContext via the create(InlineParserContext inlineParserContext) method. It is this InlineParserContext that actually manages the set of link reference definitions. This InlineParserFactory is intended to be registered with a Parser.Builder using setInlineParserFactory.

Field Summary

Modifier and TypeField and Description
private final String
private final ReferenceParser

Constructor Summary

AccessConstructor and Description
pack-priv

Method Summary

Modifier and TypeMethod and Description
public InlineParser

Returns:

the InlineParser
create
(InlineParserContext
the standard InlineParserContext
inlineParserContext
)

Implements jdk.internal.org.commonmark.parser.InlineParserFactory.create.

Creates a parser with a modified InlineParserContext that delegates to the standard InlineParserContext and also checks unresolved link references.

private boolean

Returns:

whether a string appears to be a reference to a program element
isReference
(String
the string
s
)

Returns whether a string appears to be a reference to a program element.

Inherited from java.lang.Object:
cloneequalsfinalizegetClasshashCodenotifynotifyAlltoStringwaitwaitwait

Field Detail

autorefSchemeback to summary
private final String autorefScheme
refParserback to summary
private final ReferenceParser refParser

Constructor Detail

AutoRefInlineParserFactoryback to summary
pack-priv AutoRefInlineParserFactory(ReferenceParser refParser, String autorefScheme)

Method Detail

createback to summary
public InlineParser create(InlineParserContext inlineParserContext)

Implements jdk.internal.org.commonmark.parser.InlineParserFactory.create.

Creates a parser with a modified InlineParserContext that delegates to the standard InlineParserContext and also checks unresolved link references.

Parameters
inlineParserContext:InlineParserContext

the standard InlineParserContext

Returns:InlineParser

the InlineParser

Annotations
@Override
isReferenceback to summary
private boolean isReference(String s)

Returns whether a string appears to be a reference to a program element.

Parameters
s:String

the string

Returns:boolean

whether a string appears to be a reference to a program element

jdk.internal.markdown back to summary

private Class MarkdownTransformer.DCTransformer

extends Object
Class Inheritance

Field Summary

Modifier and TypeField and Description
private final String
private final DocTreeMaker
m

private final ReferenceParser

Constructor Summary

AccessConstructor and Description
pack-priv

Method Summary

Modifier and TypeMethod and Description
private static <
the type of the items
T extends DocTree
>
boolean

Returns:

true if the items are reference-equal, and false otherwise
equal
(T
the first item
item1
,
T
the second item
item2
)

Shallow "equals" for two doc tree nodes.

private static <
the type of the items
T extends DocTree
>
boolean

Returns:

true if the items are reference-equal, and false otherwise
equal
(List<? extends T>
the first item
list1
,
List<? extends T>
the second item
list2
)

Shallow "equals" for two lists of doc tree nodes.

public DCTree

Returns:

a tree with any "extensions" converted into tags
transform
(DCTree
the tree node
tree
)

Transforms a doc tree node.

private List<? extends DCTree>

Returns:

the transformed list
transform
(List<? extends DCTree>
the list of tree nodes to be transformed
trees
)

Transforms a list of doc tree nodes.

private DCTree.DCAuthor
private DCTree.DCDeprecated
public DCTree.DCDocComment
private DCTree.DCHidden
private DCTree.DCIndex
private DCTree.DCParam
private DCTree.DCProvides
private DCTree.DCReturn
private DCTree.DCSee
private DCTree.DCSerial
private DCTree.DCSerialData
private DCTree.DCSerialField
pack-priv DCTree.DCSince
private DCTree.DCSpec
private DCTree.DCSummary
private DCTree.DCThrows
private DCTree.DCUnknownBlockTag
private DCTree.DCUnknownInlineTag
private DCTree.DCUses
private DCTree.DCVersion
Inherited from java.lang.Object:
cloneequalsfinalizegetClasshashCodenotifynotifyAlltoStringwaitwaitwait

Field Detail

autorefSchemeback to summary
private final String autorefScheme
mback to summary
private final DocTreeMaker m
refParserback to summary
private final ReferenceParser refParser

Constructor Detail

DCTransformerback to summary
pack-priv DCTransformer(JavacTrees t)

Method Detail

equalback to summary
private static <T extends DocTree> boolean equal(T item1, T item2)

Shallow "equals" for two doc tree nodes.

Parameters
<T>
the type of the items
item1:T

the first item

item2:T

the second item

Returns:boolean

true if the items are reference-equal, and false otherwise

equalback to summary
private static <T extends DocTree> boolean equal(List<? extends T> list1, List<? extends T> list2)

Shallow "equals" for two lists of doc tree nodes.

Parameters
<T>
the type of the items
list1:List<? extends T>

the first item

list2:List<? extends T>

the second item

Returns:boolean

true if the items are reference-equal, and false otherwise

transformback to summary
public DCTree transform(DCTree tree)

Transforms a doc tree node. This node dispatches to a more specific overload, based on the kind of the node. The result may be the same as the argument if no transformations were made.

Parameters
tree:DCTree

the tree node

Returns:DCTree

a tree with any "extensions" converted into tags

transformback to summary
private List<? extends DCTree> transform(List<? extends DCTree> trees)

Transforms a list of doc tree nodes. If any of the nodes contain Markdown, the Markdown source is parsed and analyzed for any transformations. Any non-Markdown nodes are individually transformed.

Parameters
trees:List<? extends DCTree>

the list of tree nodes to be transformed

Returns:List<? extends DCTree>

the transformed list

transformback to summary
private DCTree.DCAuthor transform(DCTree.DCAuthor tree)
transformback to summary
private DCTree.DCDeprecated transform(DCTree.DCDeprecated tree)
transformback to summary
public DCTree.DCDocComment transform(DCTree.DCDocComment tree)
transformback to summary
private DCTree.DCHidden transform(DCTree.DCHidden tree)
transformback to summary
private DCTree.DCIndex transform(DCTree.DCIndex tree)
transformback to summary
private DCTree.DCParam transform(DCTree.DCParam tree)
transformback to summary
private DCTree.DCProvides transform(DCTree.DCProvides tree)
transformback to summary
private DCTree.DCReturn transform(DCTree.DCReturn tree)
transformback to summary
private DCTree.DCSee transform(DCTree.DCSee tree)
transformback to summary
private DCTree.DCSerial transform(DCTree.DCSerial tree)
transformback to summary
private DCTree.DCSerialData transform(DCTree.DCSerialData tree)
transformback to summary
private DCTree.DCSerialField transform(DCTree.DCSerialField tree)
transformback to summary
pack-priv DCTree.DCSince transform(DCTree.DCSince tree)
transformback to summary
private DCTree.DCSpec transform(DCTree.DCSpec tree)
transformback to summary
private DCTree.DCSummary transform(DCTree.DCSummary tree)
transformback to summary
private DCTree.DCThrows transform(DCTree.DCThrows tree)
transformback to summary
private DCTree.DCUnknownBlockTag transform(DCTree.DCUnknownBlockTag tree)
transformback to summary
private DCTree.DCUnknownInlineTag transform(DCTree.DCUnknownInlineTag tree)
transformback to summary
private DCTree.DCUses transform(DCTree.DCUses tree)
transformback to summary
private DCTree.DCVersion transform(DCTree.DCVersion tree)
jdk.internal.markdown back to summary

private Class MarkdownTransformer.Lower

extends AbstractVisitor
Class Inheritance

A visitor to scan a Markdown document looking for any constructs that should be mapped to doc comment nodes. The intended use is as follows:
Lower v = new Lower(document, source, replacements); document.accept(v); var result = v.getTrees();
Lower v = new Lower(document, source, replacements);
document.accept(v);
var result = v.getTrees();
On coordinates ... There are various position/coordinate systems in play in this code: 1. Tree positions, which correspond to positions in the original comment, represented as a 0-based character offset within the content of the comment. 2. Positions in the source string given to the Markdown parser, represented as a 0-based character offset within the source string. These differ from positions in the original comment if the source string contains U+FFFC characters representing embedded tree nodes. 3. Positions in the source string given to the Markdown parser, represented as (line, column) values within SourceSpan nodes. Both line and column are 0-based.

Note

SourceSpan objects never include newline characters. See Lower#toSourcePos(int, int) to convert from (line, column) coordinates to a source position. See Lower#sourcePosToTreePos(int) to convert from a source position to a position in the original comment, for use in tree nodes.

Field Summary

Modifier and TypeField and Description
private final String
private int
copyStartPos

The start of source text to be copied literally when required.

private final Node
document

The Markdown document being processed.

private static final Pattern
lineBreak

The pattern for a line break.

private final DocTreeMaker
m

private int
mainStartPos

The initial position in the enclosing comment of the source being transformed.

private static final int[]
private int
replaceAdjustPos

The current adjustment from positions in source to positions in the original comment, as used in doc tree nodes.

private final Iterator<?>
replaceIter

An iterator containing the values to be substituted into the generated tree when U+FFFC characters are encountered in the document.

private final String
source

The source for the Markdown document being processed.

private final int[]
sourceLineOffsets

An array giving the position of the first character after each newline in the source.

private final StringBuilder
text

The source text being accumulated, prior to being placed in a Markdown source node (RawTextTree with kind MARKDOWN).

private List<DCTree>
trees

The list of trees being built.

Constructor Summary

AccessConstructor and Description
public
Lower(DocTreeMaker docTreeMaker, Node
the document to be converted
document
,
String
the source of the document to be converted
source
,
int
the position in the enclosing comment of the source to be converted
sourcePos
,
List<?>
the objects to be substituted when U+FFFC is encountered
replacements
,
String
the scheme used for auto-generated references
autorefScheme
)

Creates an instance of the visitor, given a document, the source text for the document and objects to be substituted when U+FFFC characters are encountered.

Method Summary

Modifier and TypeMethod and Description
private void
copyTo(int
the end position
endPos
)

Copies source text from the saved copy-start position to the given end position using the saved source, to the list of trees.

private void
flushText(int pos)

Flushes any text in the text buffer, by creating a new Markdown source text node and adding it to the list of trees.

private int

Returns:

the end of this node, from the end of the last span
getEndPos
(Node
the node
node
)

Returns the end of this node, from the end of the last span.

private int

Returns:

the start of this node, from the start of the first span
getStartPos
(Node
the node
node
)

Returns the start of this node, from the start of the first span.

public List<DCTree>

Returns:

the trees that were built after using the visitor
getTrees
()

Returns the trees that were built after using the visitor.

private int

Returns:

the position in the original comment for a position in source, using replaceAdjustPos
sourcePosToTreePos
(int
the position in source
pos
)

Returns the position in the original comment for a position in source, using replaceAdjustPos.

private int

Returns:

the position in the source string for a given (line, column
toSourcePos
(int
the line index
lineIndex
,
int
the column index
columnIndex
)

Returns the position in the source string for a given (line, column.

protected void
visitChildren(Node
the node whose children should be visited
node
)

Overrides jdk.internal.org.commonmark.node.AbstractVisitor.visitChildren.

Processes a node and any children.

Inherited from jdk.internal.org.commonmark.node.AbstractVisitor:
visitvisitvisitvisitvisitvisitvisitvisitvisitvisitvisitvisitvisitvisitvisitvisitvisitvisitvisitvisitvisitvisit

Field Detail

autorefSchemeback to summary
private final String autorefScheme
copyStartPosback to summary
private int copyStartPos

The start of source text to be copied literally when required.

documentback to summary
private final Node document

The Markdown document being processed.

lineBreakback to summary
private static final Pattern lineBreak

The pattern for a line break. This is equivalent to the detection in the Markdown parser, so that (line, column) coordinates can be accurately converted back into source positions.

See Also
jdk.internal.org.commonmark.internal.DocumentParser#parse(String), jdk.internal.org.commonmark.internal.util.Parsing#findLineBreak(CharSequence, int)
mback to summary
private final DocTreeMaker m
mainStartPosback to summary
private int mainStartPos

The initial position in the enclosing comment of the source being transformed.

NOSPANback to summary
private static final int[] NOSPAN
replaceAdjustPosback to summary
private int replaceAdjustPos

The current adjustment from positions in source to positions in the original comment, as used in doc tree nodes. The difference arises because of the use of U+FFFC characters for embedded objects. As the document (and source) are scanned, this offset is updated when U+FFFC characters are encountered.

replaceIterback to summary
private final Iterator<?> replaceIter

An iterator containing the values to be substituted into the generated tree when U+FFFC characters are encountered in the document. There is a 1-1 correspondence between the values returned by the iterator and the U+FFFC characters in the document. The replacement objects may be either DCTree objects or U+FFFC characters that were found in the original document.

sourceback to summary
private final String source

The source for the Markdown document being processed. The document has "source spans" that indirectly point into this string using (line, column) coordinates.

See Also
toSourcePos(int, int)
sourceLineOffsetsback to summary
private final int[] sourceLineOffsets

An array giving the position of the first character after each newline in the source. Used to convert (line, column) coordinates to a character offset in source.

textback to summary
private final StringBuilder text

The source text being accumulated, prior to being placed in a Markdown source node (RawTextTree with kind MARKDOWN).

treesback to summary
private List<DCTree> trees

The list of trees being built. It may be temporarily replaced while visiting the children of Link codes.

Constructor Detail

Lowerback to summary
public Lower(DocTreeMaker docTreeMaker, Node document, String source, int sourcePos, List<?> replacements, String autorefScheme)

Creates an instance of the visitor, given a document, the source text for the document and objects to be substituted when U+FFFC characters are encountered. Note the document does not itself contain any source text: it just contains SourceSpan objects that point into the source text using line and column indices.

Parameters
document:Node

the document to be converted

source:String

the source of the document to be converted

sourcePos:int

the position in the enclosing comment of the source to be converted

replacements:List<?>

the objects to be substituted when U+FFFC is encountered

autorefScheme:String

the scheme used for auto-generated references

Method Detail

copyToback to summary
private void copyTo(int endPos)

Copies source text from the saved copy-start position to the given end position using the saved source, to the list of trees.

Parameters
endPos:int

the end position

flushTextback to summary
private void flushText(int pos)

Flushes any text in the text buffer, by creating a new Markdown source text node and adding it to the list of trees.

getEndPosback to summary
private int getEndPos(Node node)

Returns the end of this node, from the end of the last span. The end points to the first character not included in the span.

Parameters
node:Node

the node

Returns:int

the end of this node, from the end of the last span

getStartPosback to summary
private int getStartPos(Node node)

Returns the start of this node, from the start of the first span.

Parameters
node:Node

the node

Returns:int

the start of this node, from the start of the first span

getTreesback to summary
public List<DCTree> getTrees()

Returns the trees that were built after using the visitor.

Returns:List<DCTree>

the trees that were built after using the visitor

sourcePosToTreePosback to summary
private int sourcePosToTreePos(int pos)

Returns the position in the original comment for a position in source, using replaceAdjustPos.

Parameters
pos:int

the position in source

Returns:int

the position in the original comment for a position in source, using replaceAdjustPos

toSourcePosback to summary
private int toSourcePos(int lineIndex, int columnIndex)

Returns the position in the source string for a given (line, column.

Parameters
lineIndex:int

the line index

columnIndex:int

the column index

Returns:int

the position in the source string for a given (line, column

visitChildrenback to summary
protected void visitChildren(Node node)

Overrides jdk.internal.org.commonmark.node.AbstractVisitor.visitChildren.

Processes a node and any children. If the node has children, the children are each visited by calling their accept method, and then finally, if this is the top-level document node, any pending text is flushed. If the node does not have children, the source spans for the node are processed instead. Note that unlike the default implementation of visitChildren, the next child is not accessed until after the current child has been visited. This allows a child to peek at and possibly remove any child nodes that may follow it.

Parameters
node:Node

the node whose children should be visited

Annotations
@Override