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 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.
Modifier and Type | Class and Description |
---|---|
private static class |
TagParser.Point
Represents current position in the text.
|
Modifier and Type | Field and Description |
---|---|
private java.util.List<HtmlTag> |
tags
List of HtmlTags found on the input line of text.
|
Constructor and Description |
---|
TagParser(java.lang.String[] text,
int lineNo)
Constructs a TagParser and finds the first tag if any.
|
Modifier and Type | Method and Description |
---|---|
private void |
add(HtmlTag tag)
Performs lazy initialization on the internal tags List
and adds the tag.
|
private static TagParser.Point |
findChar(java.lang.String[] text,
char character,
TagParser.Point from)
Finds next occurrence of given character.
|
private static TagParser.Point |
getNextCharPos(java.lang.String[] text,
TagParser.Point from)
Returns position of next comment character, skips
whitespaces and asterisks.
|
private static java.lang.String |
getTagId(java.lang.String[] javadocText,
TagParser.Point tagStart)
Parse tag id.
|
boolean |
hasNextTag()
Indicates if there are any more HtmlTag to retrieve.
|
private static boolean |
isCommentTag(java.lang.String[] text,
TagParser.Point pos)
If this is a HTML-comments.
|
private static boolean |
isTag(java.lang.String[] javadocText,
TagParser.Point pos)
Checks if the given position is start one for HTML tag.
|
HtmlTag |
nextTag()
Returns the next available HtmlTag.
|
private TagParser.Point |
parseTag(java.lang.String[] text,
int lineNo,
int nLines,
TagParser.Point position)
Parses the tag and return position after it.
|
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.
|
private static TagParser.Point |
skipHtmlComment(java.lang.String[] text,
TagParser.Point fromPoint)
Skips HTML comments.
|
private final java.util.List<HtmlTag> tags
TagParser(java.lang.String[] text, int lineNo)
text
- the line of text to parse.lineNo
- the source line number.public HtmlTag nextTag()
null
if none available.java.lang.IndexOutOfBoundsException
- if there are no HtmlTags
left to return.public boolean hasNextTag()
true
if there are more tags.private void add(HtmlTag tag)
tag
- the HtmlTag to add.private void parseTags(java.lang.String[] text, int lineNo)
text
- the source line to parse.lineNo
- the source line number.private TagParser.Point parseTag(java.lang.String[] text, int lineNo, int nLines, TagParser.Point position)
text
- the source line to parse.lineNo
- the source line number.nLines
- line lengthposition
- start position for parsingprivate static boolean isTag(java.lang.String[] javadocText, TagParser.Point pos)
javadocText
- text of javadoc comments.pos
- position to check.true
some HTML tag starts from given position.private static java.lang.String getTagId(java.lang.String[] javadocText, TagParser.Point tagStart)
javadocText
- text of javadoc comments.tagStart
- start position of the tagprivate static boolean isCommentTag(java.lang.String[] text, TagParser.Point pos)
text
- text of javadoc commentspos
- position to checktrue
if HTML-comments
starts form given position.private static TagParser.Point skipHtmlComment(java.lang.String[] text, TagParser.Point fromPoint)
text
- text of javadoc comments.fromPoint
- start position of HTML-commentsprivate static TagParser.Point findChar(java.lang.String[] text, char character, TagParser.Point from)
text
- text to searchcharacter
- character to searchfrom
- position to start searchprivate static TagParser.Point getNextCharPos(java.lang.String[] text, TagParser.Point from)
text
- to search.from
- location to search from