Class ParseTree

  • All Implemented Interfaces:
    IParseTree, java.io.Serializable

    public final class ParseTree
    extends java.lang.Object
    implements IParseTree
    Intended to specify the location of a parsed element within the source.
    See Also:
    Serialized Form
    • Method Detail

      • getOffset

        public int getOffset()
        Specified by:
        getOffset in interface IParseTree
        Returns:
        The zero-based offset of the parsed element within the source.
      • getLength

        public int getLength()
        Specified by:
        getLength in interface IParseTree
        Returns:
        The length of the parsed element in the source.
      • setLength

        public void setLength​(int iLength)
        Specified by:
        setLength in interface IParseTree
      • getLineNum

        public int getLineNum()
        Specified by:
        getLineNum in interface IParseTree
        Returns:
        The one based line number of the beginning of the parsed element
      • getColumn

        public int getColumn()
        Specified by:
        getColumn in interface IParseTree
        Returns:
        The offset from the beginning of the line where the parsed element starts
      • getExtent

        public int getExtent()
        Specified by:
        getExtent in interface IParseTree
        Returns:
        The most distant position this location occupies i.e., offset + length - 1.
      • contains

        public boolean contains​(int iPosition)
        Specified by:
        contains in interface IParseTree
        Parameters:
        iPosition - Any position within the source.
        Returns:
        True if this location contains the position.
      • contains

        public boolean contains​(IParseTree l)
        Specified by:
        contains in interface IParseTree
        Parameters:
        l - A location to check.
        Returns:
        True if the space occupied by this location is a superset of the space occupied by the specified location.
      • contains

        private boolean contains​(int start,
                                 int end)
      • containsOrBorders

        public boolean containsOrBorders​(int iPosition,
                                         boolean strict)
        Specified by:
        containsOrBorders in interface IParseTree
      • containsOrBorders

        private boolean containsOrBorders​(int start,
                                          int end,
                                          boolean strict)
      • getDeepestLocation

        public ParseTree getDeepestLocation​(boolean statementsOnly,
                                            int iStart,
                                            int iEnd,
                                            boolean strict)
        Specified by:
        getDeepestLocation in interface IParseTree
      • getDeepestLocation

        private ParseTree getDeepestLocation​(boolean statementsOnly,
                                             int iPosition,
                                             boolean strict)
      • getDeepestLocation

        public ParseTree getDeepestLocation​(int iPosition,
                                            boolean strict)
        Specified by:
        getDeepestLocation in interface IParseTree
        Parameters:
        iPosition - The location to check.
        strict - Whether to match strictly or accept white spaces to the right
        Returns:
        The deepest descendent location containing the specified location.
      • getDeepestLocation

        public ParseTree getDeepestLocation​(int iStart,
                                            int iEnd,
                                            boolean strict)
        Specified by:
        getDeepestLocation in interface IParseTree
        Parameters:
        iStart - The start of the segment (inclusive)
        iEnd - The end of the segment (inclusive)
        strict - Whether to match strictly or accept white spaces to the right
        Returns:
        The deepest descendent location containing the segment.
      • getDeepestStatementLocation

        public ParseTree getDeepestStatementLocation​(int iPosition,
                                                     boolean strict)
        Specified by:
        getDeepestStatementLocation in interface IParseTree
        Parameters:
        iPosition - The location to check.
        strict - Whether to match strictly or accept white spaces to the right
        Returns:
        The deepest descendent statement location containing the specified location.
      • getStatementAtLine

        public ParseTree getStatementAtLine​(int iLineNum,
                                            java.lang.Class clsSkip)
        Specified by:
        getStatementAtLine in interface IParseTree
        Parameters:
        iLineNum - The one based line number to check.
        clsSkip - A statement sublcass to ignore. Optional.
        Returns:
        The first statement beginning at the specified line number, or null if no statements start at the line number.
      • addChild

        public void addChild​(IParseTree l)
        Adds a child location to this location. Note the location must cover only a subset of this locations area.
        Specified by:
        addChild in interface IParseTree
        Parameters:
        l - The location to add.
      • addChild

        public void addChild​(int iIndex,
                             IParseTree l)
      • getChildren

        public java.util.List<IParseTree> getChildren()
        Specified by:
        getChildren in interface IParseTree
        Returns:
        The list of child locations covered by this location.
      • getChildCount

        public int getChildCount()
      • setParent

        public void setParent​(IParseTree l)
        Sets the parent location. Note the parent location must cover a superset of the specified location's area.
        Specified by:
        setParent in interface IParseTree
        Parameters:
        l - The parent location.
      • getParent

        public IParseTree getParent()
        Specified by:
        getParent in interface IParseTree
        Returns:
        This location's parent location. Note the parent covers a superset of the this location's area.
      • getParentOtherThanThis

        public IParseTree getParentOtherThanThis()
        Like getParent, but won't infinitely recurse if the parent turns out to be equal to this, which can happen when the expression in question is a program (since the outer program has the same location as the main statement).
        Specified by:
        getParentOtherThanThis in interface IParseTree
      • areOffsetAndExtentEqual

        public boolean areOffsetAndExtentEqual​(IParseTree location)
        Is just the physical location equal?
        Specified by:
        areOffsetAndExtentEqual in interface IParseTree
        Parameters:
        location - Location to check
        Returns:
        True if the given physical location's offset and extents are equal to this one's
      • toString

        public java.lang.String toString()
        Specified by:
        toString in interface IParseTree
        Overrides:
        toString in class java.lang.Object
      • initLocation

        public void initLocation​(ParsedElement pe,
                                 int iOffset,
                                 int iLength)
      • compactParseTree

        public void compactParseTree()
      • adjustOffset

        void adjustOffset​(int offset,
                          int lineNumOffset,
                          int columnOffset)
      • recursivelyAdjustOffset

        private void recursivelyAdjustOffset​(int offset,
                                             int lineNumOffset,
                                             int columnOffset)
      • findDescendantsWithParsedElementType

        private void findDescendantsWithParsedElementType​(java.util.ArrayList<IParseTree> matches,
                                                          java.lang.Class type)
      • getTreeOutline

        public java.lang.String getTreeOutline()
      • getTreeOutline

        private java.lang.String getTreeOutline​(java.lang.String strIndent)
      • appendTokensForOutline

        private void appendTokensForOutline​(ParseTree child,
                                            java.util.List<IToken> tokens,
                                            java.lang.StringBuilder source)
      • addTokens

        private void addTokens​(ParseTree after,
                               java.util.List<IToken> tokens,
                               java.lang.StringBuilder source)
      • getChildrenSorted

        public java.util.List<IParseTree> getChildrenSorted()
      • getChild

        public ParseTree getChild​(int index)