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
public class MarkdownComment extends JavadocComment
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
MarkdownCommentclass 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 com.github.javaparser.ast.Node
Node.BreadthFirstIterator, Node.DirectChildrenIterator, Node.ObserverRegistrationMode, Node.ParentsVisitor, Node.Parsedness, Node.PostOrderIterator, Node.PreOrderIterator, Node.TreeTraversal
-
-
Field Summary
-
Fields inherited from class com.github.javaparser.ast.Node
ABSOLUTE_BEGIN_LINE, ABSOLUTE_END_LINE, LINE_SEPARATOR_KEY, NODE_BY_BEGIN_POSITION, PHANTOM_KEY, prettyPrinterNoCommentsConfiguration, PRINTER_KEY, SYMBOL_RESOLVER_KEY
-
-
Constructor Summary
Constructors Constructor Description MarkdownComment()MarkdownComment(TokenRange tokenRange, String content)This constructor is used by the parser and is considered private.MarkdownComment(String content)
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description <R,A>
Raccept(GenericVisitor<R,A> v, A arg)Accept method for visitor support.<A> voidaccept(VoidVisitor<A> v, A arg)Accept method for visitor support.MarkdownCommentasMarkdownComment()StringasString()MarkdownCommentclone()StringgetFooter()Markdown comments are not terminated by a specific character sequence, so just use the empty string as a footer.StringgetHeader()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.StringgetMarkdownContent()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.MarkdownCommentMetaModelgetMetaModel()voidifMarkdownComment(Consumer<MarkdownComment> action)booleanisMarkdownComment()Optional<MarkdownComment>toMarkdownComment()-
Methods inherited from class com.github.javaparser.ast.comments.JavadocComment
asJavadocComment, ifJavadocComment, isJavadocComment, parse, toJavadocComment
-
Methods inherited from class com.github.javaparser.ast.comments.Comment
asBlockComment, asLineComment, asTraditionalJavadocComment, findRootNode, getCommentedNode, getContent, ifBlockComment, ifLineComment, ifTraditionalJavadocComment, isBlockComment, isLineComment, isOrphan, isTraditionalJavadocComment, remove, setComment, setCommentedNode, setContent, toBlockComment, toLineComment, toTraditionalJavadocComment
-
Methods inherited from class com.github.javaparser.ast.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, walk
-
Methods inherited from class java.lang.Object
finalize, getClass, notify, notifyAll, wait, wait, wait
-
Methods inherited from interface com.github.javaparser.HasParentNode
findAncestor, findAncestor, findAncestor, hasParentNode, isDescendantOf
-
Methods inherited from interface com.github.javaparser.ast.nodeTypes.NodeWithRange
containsWithin, containsWithinRange, getBegin, getEnd, hasRange
-
-
-
-
Constructor Detail
-
MarkdownComment
public MarkdownComment()
-
MarkdownComment
public MarkdownComment(String content)
-
MarkdownComment
public MarkdownComment(TokenRange tokenRange, String content)
This constructor is used by the parser and is considered private.
-
-
Method Detail
-
getMarkdownContent
public String 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
public String 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.
-
getFooter
public String getFooter()
Markdown comments are not terminated by a specific character sequence, so just use the empty string as a footer.
-
accept
public <R,A> R accept(GenericVisitor<R,A> v, A arg)
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
public <A> void accept(VoidVisitor<A> v, A arg)
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)
-
isMarkdownComment
public boolean isMarkdownComment()
- Overrides:
isMarkdownCommentin classComment
-
asMarkdownComment
public MarkdownComment asMarkdownComment()
- Overrides:
asMarkdownCommentin classComment
-
toMarkdownComment
public Optional<MarkdownComment> toMarkdownComment()
- Overrides:
toMarkdownCommentin classComment
-
ifMarkdownComment
public void ifMarkdownComment(Consumer<MarkdownComment> action)
- Overrides:
ifMarkdownCommentin classComment
-
clone
public MarkdownComment clone()
- Overrides:
clonein classJavadocComment
-
getMetaModel
public MarkdownCommentMetaModel getMetaModel()
- Overrides:
getMetaModelin classJavadocComment- Returns:
- get JavaParser specific node introspection information.
-
-