Class ParseTree

java.lang.Object
gw.internal.gosu.parser.ParseTree
All Implemented Interfaces:
IParseTree, Serializable

public final class ParseTree extends Object implements IParseTree
Intended to specify the location of a parsed element within the source.
See Also:
  • Field Details

  • Constructor Details

  • Method Details

    • getEnclosingType

      public IType getEnclosingType()
      Specified by:
      getEnclosingType in interface IParseTree
    • getScriptPartId

      public IScriptPartId getScriptPartId()
      Specified by:
      getScriptPartId in interface IParseTree
    • 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
    • getParsedElement

      public ParsedElement getParsedElement()
      Specified by:
      getParsedElement in interface IParseTree
      Returns:
      The parsed element to which this location corresponds.
    • 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

      public boolean containsOrBorders(IParseTree l, 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
    • isAncestorOf

      public boolean isAncestorOf(IParseTree l)
      Specified by:
      isAncestorOf 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, 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)
    • removeChild

      public void removeChild(IParseTree l)
      Specified by:
      removeChild in interface IParseTree
    • getChildren

      public 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 String toString()
      Specified by:
      toString in interface IParseTree
      Overrides:
      toString in class Object
    • initLocation

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

      public void compactParseTree()
    • clearParseTreeInformation

      public void clearParseTreeInformation()
      Specified by:
      clearParseTreeInformation in interface IParseTree
    • areAllChildrenAfterPosition

      public boolean areAllChildrenAfterPosition(int caret)
      Specified by:
      areAllChildrenAfterPosition in interface IParseTree
    • getDominatingLocationList

      public List<IParseTree> getDominatingLocationList()
      Specified by:
      getDominatingLocationList in interface IParseTree
    • getChildrenBefore

      public List<IParseTree> getChildrenBefore(IParseTree parseTree)
      Specified by:
      getChildrenBefore in interface IParseTree
    • isSiblingOf

      public boolean isSiblingOf(IParseTree deepestAtEnd)
      Specified by:
      isSiblingOf in interface IParseTree
    • getChildAfter

      public ParseTree getChildAfter(int point)
      Specified by:
      getChildAfter in interface IParseTree
    • getChildBefore

      public ParseTree getChildBefore(int point)
      Specified by:
      getChildBefore in interface IParseTree
    • getChildBefore

      public ParseTree getChildBefore(IParseTree child)
      Specified by:
      getChildBefore in interface IParseTree
    • getChildAfter

      public ParseTree getChildAfter(IParseTree child)
      Specified by:
      getChildAfter in interface IParseTree
    • getFirstChildWithParsedElementType

      public ParseTree getFirstChildWithParsedElementType(Class<? extends IParsedElement> aClass)
      Specified by:
      getFirstChildWithParsedElementType in interface IParseTree
    • getLastChildWithParsedElementType

      public ParseTree getLastChildWithParsedElementType(Class<? extends IParsedElement> aClass)
      Specified by:
      getLastChildWithParsedElementType in interface IParseTree
    • getLastChild

      public ParseTree getLastChild()
      Specified by:
      getLastChild in interface IParseTree
    • getNextSibling

      public ParseTree getNextSibling()
      Specified by:
      getNextSibling in interface IParseTree
    • getPreviousSibling

      public ParseTree getPreviousSibling()
      Specified by:
      getPreviousSibling in interface IParseTree
    • getDeepestFirstChild

      public ParseTree getDeepestFirstChild()
      Specified by:
      getDeepestFirstChild in interface IParseTree
    • findDescendantsWithParsedElementType

      public Collection<IParseTree> findDescendantsWithParsedElementType(Class type)
      Specified by:
      findDescendantsWithParsedElementType in interface IParseTree
    • addUnder

      public void addUnder(IParseTree parent)
      Specified by:
      addUnder in interface IParseTree
    • adjustOffset

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

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

      private void findDescendantsWithParsedElementType(ArrayList<IParseTree> matches, Class type)
    • getEnclosingFunctionStatement

      public IFunctionStatement getEnclosingFunctionStatement()
      Specified by:
      getEnclosingFunctionStatement in interface IParseTree
    • getMatchingElement

      public final IParseTree getMatchingElement(int iStart, int iLength)
      Specified by:
      getMatchingElement in interface IParseTree
    • getTreeOutline

      public String getTreeOutline()
    • getTreeOutline

      private String getTreeOutline(String strIndent)
    • appendTokensForOutline

      private void appendTokensForOutline(ParseTree child, List<IToken> tokens, StringBuilder source)
    • getTextFromTokens

      public String getTextFromTokens()
      Specified by:
      getTextFromTokens in interface IParseTree
    • addTokens

      private void addTokens(ParseTree after, List<IToken> tokens, StringBuilder source)
    • getChildrenSorted

      public List<IParseTree> getChildrenSorted()
    • isAncestor

      public boolean isAncestor(IParseTree child)
      Specified by:
      isAncestor in interface IParseTree
    • getChild

      public ParseTree getChild(int index)