Class TagParser


  • class TagParser
    extends 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.

    • Field Detail

      • tags

        private final List<HtmlTag> tags
        HtmlTags found on the input line of text.
    • Constructor Detail

      • TagParser

        TagParser​(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 null if none available.
        Throws:
        IndexOutOfBoundsException - if there are no HtmlTags left to return.
      • hasNextTag

        public boolean hasNextTag()
        Indicates if there are any more HtmlTag to retrieve.
        Returns:
        true if 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​(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​(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 length
        position - start position for parsing
        Returns:
        position after tag
      • isTag

        private static boolean isTag​(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:
        true some HTML tag starts from given position.
      • getTagId

        private static String getTagId​(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​(String[] text,
                                            TagParser.Point pos)
        If this is a HTML-comments.
        Parameters:
        text - text of javadoc comments
        pos - position to check
        Returns:
        true if HTML-comments starts form given position.
      • skipHtmlComment

        private static TagParser.Point skipHtmlComment​(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​(String[] text,
                                                char character,
                                                TagParser.Point from)
        Finds next occurrence of given character.
        Parameters:
        text - text to search
        character - character to search
        from - position to start search
        Returns:
        position of next occurrence of given character
      • getNextPoint

        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.
        Parameters:
        text - to search.
        from - location to search from
        Returns:
        next point to be examined