Class TagParser
- java.lang.Object
-
- com.puppycrawl.tools.checkstyle.checks.javadoc.TagParser
-
class TagParser extends java.lang.Object
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
hasNextTagandnextTagmethods 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 Classes Modifier and Type Class Description private static classTagParser.PointRepresents current position in the text.
-
Constructor Summary
Constructors Constructor Description TagParser(java.lang.String[] text, int lineNo)Constructs a TagParser and finds the first tag if any.
-
Method Summary
All Methods Static Methods Instance Methods Concrete Methods Modifier and Type Method Description private voidadd(HtmlTag tag)Performs lazy initialization on the internal tags List and adds the tag.private static TagParser.PointfindChar(java.lang.String[] text, char character, TagParser.Point from)Finds next occurrence of given character.private static TagParser.PointgetNextCharPos(java.lang.String[] text, TagParser.Point from)Returns position of next comment character, skips whitespaces and asterisks.private static java.lang.StringgetTagId(java.lang.String[] javadocText, TagParser.Point tagStart)Parse tag id.booleanhasNextTag()Indicates if there are any more HtmlTag to retrieve.private static booleanisCommentTag(java.lang.String[] text, TagParser.Point pos)If this is a HTML-comments.private static booleanisTag(java.lang.String[] javadocText, TagParser.Point pos)Checks if the given position is start one for HTML tag.HtmlTagnextTag()Returns the next available HtmlTag.private TagParser.PointparseTag(java.lang.String[] text, int lineNo, int nLines, TagParser.Point position)Parses the tag and return position after it.private voidparseTags(java.lang.String[] text, int lineNo)Parses the text line for any HTML tags and adds them to the internal List of tags.private static TagParser.PointskipHtmlComment(java.lang.String[] text, TagParser.Point fromPoint)Skips HTML comments.
-
-
-
Constructor Detail
-
TagParser
TagParser(java.lang.String[] text, int lineNo)
Constructs a TagParser and finds the first tag if any.- Parameters:
text- the line of text to parse.lineNo- the source line number.
-
-
Method Detail
-
nextTag
public HtmlTag nextTag()
Returns the next available HtmlTag.- Returns:
- a HtmlTag or
nullif none available. - Throws:
java.lang.IndexOutOfBoundsException- if there are no HtmlTags left to return.
-
hasNextTag
public boolean hasNextTag()
Indicates if there are any more HtmlTag to retrieve.- Returns:
trueif there are more tags.
-
add
private void add(HtmlTag tag)
Performs lazy initialization on the internal tags List and adds the tag.- Parameters:
tag- the HtmlTag to add.
-
parseTags
private void parseTags(java.lang.String[] text, int lineNo)
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
private TagParser.Point parseTag(java.lang.String[] text, int lineNo, int nLines, TagParser.Point position)
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
private static boolean isTag(java.lang.String[] javadocText, TagParser.Point pos)
Checks if the given position is start one for HTML tag.- Parameters:
javadocText- text of javadoc comments.pos- position to check.- Returns:
truesome HTML tag starts from given position.
-
getTagId
private static java.lang.String getTagId(java.lang.String[] javadocText, TagParser.Point tagStart)
Parse tag id.- Parameters:
javadocText- text of javadoc comments.tagStart- start position of the tag- Returns:
- id for given tag
-
isCommentTag
private static boolean isCommentTag(java.lang.String[] text, TagParser.Point pos)
If this is a HTML-comments.- Parameters:
text- text of javadoc commentspos- position to check- Returns:
trueif HTML-comments starts form given position.
-
skipHtmlComment
private static TagParser.Point skipHtmlComment(java.lang.String[] text, TagParser.Point fromPoint)
Skips HTML comments.- Parameters:
text- text of javadoc comments.fromPoint- start position of HTML-comments- Returns:
- position after HTML-comments
-
findChar
private static TagParser.Point findChar(java.lang.String[] text, char character, TagParser.Point from)
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
-
getNextCharPos
private static TagParser.Point getNextCharPos(java.lang.String[] text, TagParser.Point from)
Returns position of next comment character, skips whitespaces and asterisks.- Parameters:
text- to search.from- location to search from- Returns:
- location of the next character.
-
-