Package gw.internal.gosu.parser
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:
- Serialized Form
-
-
Nested Class Summary
-
Nested classes/interfaces inherited from interface gw.lang.parser.IParseTree
IParseTree.Search
-
-
Constructor Summary
Constructors Constructor Description ParseTree(ParsedElement pe, int iOffset, int iLength, IScriptPartId scriptPart)
-
Method Summary
-
-
-
Constructor Detail
-
ParseTree
public ParseTree(ParsedElement pe, int iOffset, int iLength, IScriptPartId scriptPart)
-
-
Method Detail
-
getEnclosingType
public IType getEnclosingType()
- Specified by:
getEnclosingType
in interfaceIParseTree
-
getScriptPartId
public IScriptPartId getScriptPartId()
- Specified by:
getScriptPartId
in interfaceIParseTree
-
getOffset
public int getOffset()
- Specified by:
getOffset
in interfaceIParseTree
- Returns:
- The zero-based offset of the parsed element within the source.
-
getLength
public int getLength()
- Specified by:
getLength
in interfaceIParseTree
- Returns:
- The length of the parsed element in the source.
-
setLength
public void setLength(int iLength)
- Specified by:
setLength
in interfaceIParseTree
-
getLineNum
public int getLineNum()
- Specified by:
getLineNum
in interfaceIParseTree
- Returns:
- The one based line number of the beginning of the parsed element
-
getColumn
public int getColumn()
- Specified by:
getColumn
in interfaceIParseTree
- Returns:
- The offset from the beginning of the line where the parsed element starts
-
getParsedElement
public ParsedElement getParsedElement()
- Specified by:
getParsedElement
in interfaceIParseTree
- Returns:
- The parsed element to which this location corresponds.
-
getExtent
public int getExtent()
- Specified by:
getExtent
in interfaceIParseTree
- Returns:
- The most distant position this location occupies i.e., offset + length - 1.
-
contains
public boolean contains(int iPosition)
- Specified by:
contains
in interfaceIParseTree
- 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 interfaceIParseTree
- 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.
-
containsOrBorders
public boolean containsOrBorders(int iPosition, boolean strict)
- Specified by:
containsOrBorders
in interfaceIParseTree
-
containsOrBorders
public boolean containsOrBorders(IParseTree l, boolean strict)
- Specified by:
containsOrBorders
in interfaceIParseTree
-
getDeepestLocation
public ParseTree getDeepestLocation(boolean statementsOnly, int iStart, int iEnd, boolean strict)
- Specified by:
getDeepestLocation
in interfaceIParseTree
-
isAncestorOf
public boolean isAncestorOf(IParseTree l)
- Specified by:
isAncestorOf
in interfaceIParseTree
-
getDeepestLocation
public ParseTree getDeepestLocation(int iPosition, boolean strict)
- Specified by:
getDeepestLocation
in interfaceIParseTree
- 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 interfaceIParseTree
- 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 interfaceIParseTree
- 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 interfaceIParseTree
- 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 interfaceIParseTree
- Parameters:
l
- The location to add.
-
addChild
public void addChild(int iIndex, IParseTree l)
-
removeChild
public void removeChild(IParseTree l)
- Specified by:
removeChild
in interfaceIParseTree
-
getChildren
public List<IParseTree> getChildren()
- Specified by:
getChildren
in interfaceIParseTree
- 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 interfaceIParseTree
- Parameters:
l
- The parent location.
-
getParent
public IParseTree getParent()
- Specified by:
getParent
in interfaceIParseTree
- 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 interfaceIParseTree
-
areOffsetAndExtentEqual
public boolean areOffsetAndExtentEqual(IParseTree location)
Is just the physical location equal?- Specified by:
areOffsetAndExtentEqual
in interfaceIParseTree
- 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 interfaceIParseTree
- Overrides:
toString
in classObject
-
initLocation
public void initLocation(ParsedElement pe, int iOffset, int iLength)
-
compactParseTree
public void compactParseTree()
-
clearParseTreeInformation
public void clearParseTreeInformation()
- Specified by:
clearParseTreeInformation
in interfaceIParseTree
-
areAllChildrenAfterPosition
public boolean areAllChildrenAfterPosition(int caret)
- Specified by:
areAllChildrenAfterPosition
in interfaceIParseTree
-
getDominatingLocationList
public List<IParseTree> getDominatingLocationList()
- Specified by:
getDominatingLocationList
in interfaceIParseTree
-
getChildrenBefore
public List<IParseTree> getChildrenBefore(IParseTree parseTree)
- Specified by:
getChildrenBefore
in interfaceIParseTree
-
isSiblingOf
public boolean isSiblingOf(IParseTree deepestAtEnd)
- Specified by:
isSiblingOf
in interfaceIParseTree
-
getChildAfter
public ParseTree getChildAfter(int point)
- Specified by:
getChildAfter
in interfaceIParseTree
-
getChildBefore
public ParseTree getChildBefore(int point)
- Specified by:
getChildBefore
in interfaceIParseTree
-
getChildBefore
public ParseTree getChildBefore(IParseTree child)
- Specified by:
getChildBefore
in interfaceIParseTree
-
getChildAfter
public ParseTree getChildAfter(IParseTree child)
- Specified by:
getChildAfter
in interfaceIParseTree
-
getFirstChildWithParsedElementType
public ParseTree getFirstChildWithParsedElementType(Class<? extends IParsedElement> aClass)
- Specified by:
getFirstChildWithParsedElementType
in interfaceIParseTree
-
getLastChildWithParsedElementType
public ParseTree getLastChildWithParsedElementType(Class<? extends IParsedElement> aClass)
- Specified by:
getLastChildWithParsedElementType
in interfaceIParseTree
-
getLastChild
public ParseTree getLastChild()
- Specified by:
getLastChild
in interfaceIParseTree
-
getNextSibling
public ParseTree getNextSibling()
- Specified by:
getNextSibling
in interfaceIParseTree
-
getPreviousSibling
public ParseTree getPreviousSibling()
- Specified by:
getPreviousSibling
in interfaceIParseTree
-
getDeepestFirstChild
public ParseTree getDeepestFirstChild()
- Specified by:
getDeepestFirstChild
in interfaceIParseTree
-
findDescendantsWithParsedElementType
public Collection<IParseTree> findDescendantsWithParsedElementType(Class type)
- Specified by:
findDescendantsWithParsedElementType
in interfaceIParseTree
-
addUnder
public void addUnder(IParseTree parent)
- Specified by:
addUnder
in interfaceIParseTree
-
getEnclosingFunctionStatement
public IFunctionStatement getEnclosingFunctionStatement()
- Specified by:
getEnclosingFunctionStatement
in interfaceIParseTree
-
getMatchingElement
public final IParseTree getMatchingElement(int iStart, int iLength)
- Specified by:
getMatchingElement
in interfaceIParseTree
-
getTreeOutline
public String getTreeOutline()
-
getTextFromTokens
public String getTextFromTokens()
- Specified by:
getTextFromTokens
in interfaceIParseTree
-
getChildrenSorted
public List<IParseTree> getChildrenSorted()
-
isAncestor
public boolean isAncestor(IParseTree child)
- Specified by:
isAncestor
in interfaceIParseTree
-
getChild
public ParseTree getChild(int index)
-
-