Class TagParser
java.lang.Object
com.puppycrawl.tools.checkstyle.checks.javadoc.TagParser
Helper class used to parse HTML tags or generic type identifiers
from a single-line of text. Just the beginning of the HTML tag
is located. No attempt is made to parse out the complete tag,
particularly since some of the tag parameters could be located
on the following line of text. The
hasNextTag
and
nextTag
methods are used to iterate through the HTML
tags or generic type identifiers that were found on the line of text.
This class isn't really specific to HTML tags. Currently, the only HTML
tag that this class looks specifically for is the HTML comment tag.
This class helps figure out if a tag exists and if it is well-formed.
It does not know whether it is valid HTML. This class is also used for
generics types which looks like opening HTML tags ex: <T>, <E>, <V>,
<MY_FOO_TYPE>
, etc. According to this class they are valid tags.
-
Nested Class Summary
Nested ClassesModifier and TypeClassDescriptionprivate static final class
Represents current position in the text. -
Field Summary
Fields -
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionprivate void
Performs lazy initialization on the internal tags List and adds the tag.private static TagParser.Point
findChar
(String[] text, char character, TagParser.Point from) Finds next occurrence of given character.private static TagParser.Point
getNextPoint
(String[] text, TagParser.Point from) Increments column number to be examined, moves onto the next line when no more characters are available.private static String
getTagId
(String[] javadocText, TagParser.Point tagStart) Parse tag id.boolean
Indicates if there are any more HtmlTag to retrieve.private static boolean
isCommentTag
(String[] text, TagParser.Point pos) If this is a HTML-comments.private static boolean
isTag
(String[] javadocText, TagParser.Point pos) Checks if the given position is start one for HTML tag.nextTag()
Returns the next available HtmlTag.private TagParser.Point
parseTag
(String[] text, int lineNo, int nLines, TagParser.Point position) Parses the tag and return position after it.private void
Parses the text line for any HTML tags and adds them to the internal List of tags.private static TagParser.Point
skipHtmlComment
(String[] text, TagParser.Point fromPoint) Skips HTML comments.
-
Field Details
-
tags
HtmlTags found on the input line of text.
-
-
Constructor Details
-
TagParser
Constructs a TagParser and finds the first tag if any.- Parameters:
text
- the line of text to parse.lineNo
- the source line number.
-
-
Method Details
-
nextTag
Returns the next available HtmlTag.- Returns:
- a HtmlTag or
null
if none available. - Throws:
IndexOutOfBoundsException
- if there are no HtmlTags left to return.
-
hasNextTag
Indicates if there are any more HtmlTag to retrieve.- Returns:
true
if there are more tags.
-
add
Performs lazy initialization on the internal tags List and adds the tag.- Parameters:
tag
- the HtmlTag to add.
-
parseTags
Parses the text line for any HTML tags and adds them to the internal List of tags.- Parameters:
text
- the source line to parse.lineNo
- the source line number.
-
parseTag
Parses the tag and return position after it.- Parameters:
text
- the source line to parse.lineNo
- the source line number.nLines
- line lengthposition
- start position for parsing- Returns:
- position after tag
-
isTag
Checks if the given position is start one for HTML tag.- Parameters:
javadocText
- text of javadoc comments.pos
- position to check.- Returns:
true
some HTML tag starts from given position.
-
getTagId
Parse tag id.- Parameters:
javadocText
- text of javadoc comments.tagStart
- start position of the tag- Returns:
- id for given tag
-
isCommentTag
If this is a HTML-comments.- Parameters:
text
- text of javadoc commentspos
- position to check- Returns:
true
if HTML-comments starts form given position.
-
skipHtmlComment
Skips HTML comments.- Parameters:
text
- text of javadoc comments.fromPoint
- start position of HTML-comments- Returns:
- position after HTML-comments
-
findChar
Finds next occurrence of given character.- Parameters:
text
- text to searchcharacter
- character to searchfrom
- position to start search- Returns:
- position of next occurrence of given character
-
getNextPoint
Increments column number to be examined, moves onto the next line when no more characters are available.- Parameters:
text
- to search.from
- location to search from- Returns:
- next point to be examined
-