Class MarkdownComment
java.lang.Object
com.github.javaparser.ast.Node
com.github.javaparser.ast.comments.Comment
com.github.javaparser.ast.comments.JavadocComment
com.github.javaparser.ast.comments.MarkdownComment
- All Implemented Interfaces:
NodeWithRange<Node>, NodeWithTokenRange<Node>, Observable, Visitable, HasParentNode<Node>, Cloneable
https://openjdk.org/jeps/467 added support for markdown JavaDoc comments
/// That are prefixed with ///
/// Support `markdown` markup and references
/// And supports substrings not allowed in regular block comments, e.g. *_no_space_here_/
While these comments could be seen as a series of single line comments, they are functionally block comments.
The MarkdownComment class adds support for this, although special handling is required for the content
of these comments, since the header is no longer only applied to the start of the comment, but rather to the
start of each line.
-
Nested Class Summary
Nested classes/interfaces inherited from class Node
Node.BreadthFirstIterator, Node.DirectChildrenIterator, Node.ObserverRegistrationMode, Node.ParentsVisitor, Node.Parsedness, Node.PostOrderIterator, Node.PreOrderIterator, Node.TreeTraversal -
Field Summary
FieldsFields inherited from class Node
ABSOLUTE_BEGIN_LINE, ABSOLUTE_END_LINE, LINE_SEPARATOR_KEY, NODE_BY_BEGIN_POSITION, PHANTOM_KEY, prettyPrinterNoCommentsConfiguration, PRINTER_KEY, SYMBOL_RESOLVER_KEY -
Constructor Summary
ConstructorsConstructorDescriptionMarkdownComment(TokenRange tokenRange, String content) This constructor is used by the parser and is considered private.MarkdownComment(String content) -
Method Summary
Modifier and TypeMethodDescription<R,A> R accept(GenericVisitor<R, A> v, A arg) Accept method for visitor support.<A> voidaccept(VoidVisitor<A> v, A arg) Accept method for visitor support.asString()clone()Markdown comments are not terminated by a specific character sequence, so just use the empty string as a footer.For other comment types, the header is the character sequence that starts the comment, i.e.Returns the Markdown content of this comment as defined in JEP 467: Because horizontal whitespace at the beginning and end of each line of Markdown text may be significant, the content of a Markdown documentation comment is determined as follows: -- Any leading whitespace and the three initial / characters are removed from each line.voidifMarkdownComment(Consumer<MarkdownComment> action) booleanMethods inherited from class JavadocComment
asJavadocComment, ifJavadocComment, isJavadocComment, parse, toJavadocCommentMethods inherited from class Comment
asBlockComment, asLineComment, asTraditionalJavadocComment, findRootNode, getCommentedNode, getContent, ifBlockComment, ifLineComment, ifTraditionalJavadocComment, isBlockComment, isLineComment, isOrphan, isTraditionalJavadocComment, remove, setComment, setCommentedNode, setContent, toBlockComment, toLineComment, toTraditionalJavadocCommentMethods inherited from class Node
addOrphanComment, containsData, createDefaultPrinter, createDefaultPrinter, customInitialization, equals, findAll, findAll, findAll, findByRange, findCompilationUnit, findData, findFirst, findFirst, findFirst, getAllContainedComments, getChildNodes, getChildNodesByType, getComment, getData, getDataKeys, getDefaultPrinterConfiguration, getLineEndingStyle, getLineEndingStyleOrDefault, getNodesByType, getOrphanComments, getParentNode, getParentNodeForChildren, getParsed, getPrinter, getPrinter, getRange, getSymbolResolver, getTokenRange, hashCode, hasScope, isAncestorOf, isPhantom, isRegistered, notifyPropertyChange, register, register, registerForSubtree, remove, removeComment, removeData, removeForced, removeOrphanComment, replace, replace, setAsParentNodeOf, setAsParentNodeOf, setBlockComment, setData, setLineComment, setParentNode, setParsed, setRange, setTokenRange, stream, stream, toString, toString, tryAddImportToParentCompilationUnit, unregister, walk, walk, walkMethods inherited from interface HasParentNode
findAncestor, findAncestor, findAncestor, hasParentNode, isDescendantOfMethods inherited from interface NodeWithRange
containsWithin, containsWithinRange, getBegin, getEnd, hasRange
-
Field Details
-
markdownLinePattern
-
-
Constructor Details
-
MarkdownComment
public MarkdownComment() -
MarkdownComment
-
MarkdownComment
This constructor is used by the parser and is considered private.
-
-
Method Details
-
getMarkdownContent
Returns the Markdown content of this comment as defined in JEP 467:Because horizontal whitespace at the beginning and end of each line of Markdown text may be significant, the content of a Markdown documentation comment is determined as follows: -- Any leading whitespace and the three initial / characters are removed from each line. -- The lines are shifted left, by removing leading whitespace characters, until the non-blank line with the least leading whitespace has no remaining leading whitespace. -- Additional leading whitespace and any trailing whitespace in each line is preserved, because it may be significant. For example, whitespace at the beginning of a line may indicate an indented code block or the continuation of a list item, and whitespace at the end of a line may indicate a hard line break.
-
getHeader
For other comment types, the header is the character sequence that starts the comment, i.e. /* for block comments and // for line comments and the footer is the character sequence that ends the comment, i.e. * / for block comments, but empty for line comments. These comments can then be reconstructed with c.getHeader() + c.getContent() + c.getFooter(). For Markdown comments, this model doesn't fit as well, since the header is now a character sequence that appears at the start of each line. For ease of use, the leading /// is now included in the comment content, returned by the getContent() method, while the getMarkdownContent() method returns the comment content with the leading /// stripped from each line. -
accept
Description copied from interface:VisitableAccept method for visitor support.- Type Parameters:
R- the type of the return value of the visitorA- the type the user argument passed to the visitor- Parameters:
v- the visitor implementationarg- the argument passed to the visitor (of type A)- Returns:
- the result of the visit (of type R)
-
accept
Description copied from interface:VisitableAccept method for visitor support.- Type Parameters:
A- the type the argument passed for the visitor- Parameters:
v- the visitor implementationarg- any value relevant for the visitor (of type A)
-
asString
-
isMarkdownComment
public boolean isMarkdownComment()- Overrides:
isMarkdownCommentin classComment
-
asMarkdownComment
- Overrides:
asMarkdownCommentin classComment
-
toMarkdownComment
- Overrides:
toMarkdownCommentin classComment
-
ifMarkdownComment
- Overrides:
ifMarkdownCommentin classComment
-
clone
- Overrides:
clonein classJavadocComment
-
getMetaModel
- Overrides:
getMetaModelin classJavadocComment- Returns:
- get JavaParser specific node introspection information.
-