Package gw.internal.gosu.parser
Class ParseTree
- java.lang.Object
-
- gw.internal.gosu.parser.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
-
-
Nested Class Summary
-
Nested classes/interfaces inherited from interface gw.lang.parser.IParseTree
IParseTree.Search
-
-
Field Summary
Fields Modifier and Type Field Description private DynamicArray<ParseTree>_childrenprivate int_iLengthprivate int_iOffsetprivate ParsedElement_peprivate IScriptPartId_scriptPartprivate static DynamicArray<ParseTree>EMPTY_PARSE_TREE_LIST
-
Constructor Summary
Constructors Constructor Description ParseTree(ParsedElement pe, int iOffset, int iLength, IScriptPartId scriptPart)
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description voidaddChild(int iIndex, IParseTree l)voidaddChild(IParseTree l)Adds a child location to this location.private voidaddTokens(ParseTree after, java.util.List<IToken> tokens, java.lang.StringBuilder source)voidaddUnder(IParseTree parent)(package private) voidadjustOffset(int offset, int lineNumOffset, int columnOffset)private voidappendTokensForOutline(ParseTree child, java.util.List<IToken> tokens, java.lang.StringBuilder source)booleanareAllChildrenAfterPosition(int caret)booleanareOffsetAndExtentEqual(IParseTree location)Is just the physical location equal?voidclearParseTreeInformation()voidcompactParseTree()booleancontains(int iPosition)private booleancontains(int start, int end)booleancontains(IParseTree l)booleancontainsOrBorders(int iPosition, boolean strict)private booleancontainsOrBorders(int start, int end, boolean strict)booleancontainsOrBorders(IParseTree l, boolean strict)java.util.Collection<IParseTree>findDescendantsWithParsedElementType(java.lang.Class type)private voidfindDescendantsWithParsedElementType(java.util.ArrayList<IParseTree> matches, java.lang.Class type)ParseTreegetChild(int index)ParseTreegetChildAfter(int point)ParseTreegetChildAfter(IParseTree child)ParseTreegetChildBefore(int point)ParseTreegetChildBefore(IParseTree child)intgetChildCount()java.util.List<IParseTree>getChildren()java.util.List<IParseTree>getChildrenBefore(IParseTree parseTree)java.util.List<IParseTree>getChildrenSorted()intgetColumn()ParseTreegetDeepestFirstChild()private ParseTreegetDeepestLocation(boolean statementsOnly, int iPosition, boolean strict)ParseTreegetDeepestLocation(boolean statementsOnly, int iStart, int iEnd, boolean strict)ParseTreegetDeepestLocation(int iPosition, boolean strict)ParseTreegetDeepestLocation(int iStart, int iEnd, boolean strict)ParseTreegetDeepestStatementLocation(int iPosition, boolean strict)java.util.List<IParseTree>getDominatingLocationList()IFunctionStatementgetEnclosingFunctionStatement()ITypegetEnclosingType()intgetExtent()ParseTreegetFirstChildWithParsedElementType(java.lang.Class<? extends IParsedElement> aClass)ParseTreegetLastChild()ParseTreegetLastChildWithParsedElementType(java.lang.Class<? extends IParsedElement> aClass)intgetLength()intgetLineNum()IParseTreegetMatchingElement(int iStart, int iLength)ParseTreegetNextSibling()intgetOffset()IParseTreegetParent()IParseTreegetParentOtherThanThis()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).ParsedElementgetParsedElement()ParseTreegetPreviousSibling()IScriptPartIdgetScriptPartId()ParseTreegetStatementAtLine(int iLineNum, java.lang.Class clsSkip)java.lang.StringgetTextFromTokens()java.lang.StringgetTreeOutline()private java.lang.StringgetTreeOutline(java.lang.String strIndent)voidinitLocation(ParsedElement pe, int iOffset, int iLength)booleanisAncestor(IParseTree child)booleanisAncestorOf(IParseTree l)booleanisSiblingOf(IParseTree deepestAtEnd)private voidrecursivelyAdjustOffset(int offset, int lineNumOffset, int columnOffset)voidremoveChild(IParseTree l)voidsetLength(int iLength)voidsetParent(IParseTree l)Sets the parent location.java.lang.StringtoString()
-
-
-
Field Detail
-
EMPTY_PARSE_TREE_LIST
private static final DynamicArray<ParseTree> EMPTY_PARSE_TREE_LIST
-
_pe
private transient ParsedElement _pe
-
_children
private DynamicArray<ParseTree> _children
-
_iOffset
private int _iOffset
-
_iLength
private int _iLength
-
_scriptPart
private transient IScriptPartId _scriptPart
-
-
Constructor Detail
-
ParseTree
public ParseTree(ParsedElement pe, int iOffset, int iLength, IScriptPartId scriptPart)
-
-
Method Detail
-
getEnclosingType
public IType getEnclosingType()
- Specified by:
getEnclosingTypein interfaceIParseTree
-
getScriptPartId
public IScriptPartId getScriptPartId()
- Specified by:
getScriptPartIdin interfaceIParseTree
-
getOffset
public int getOffset()
- Specified by:
getOffsetin interfaceIParseTree- Returns:
- The zero-based offset of the parsed element within the source.
-
getLength
public int getLength()
- Specified by:
getLengthin interfaceIParseTree- Returns:
- The length of the parsed element in the source.
-
setLength
public void setLength(int iLength)
- Specified by:
setLengthin interfaceIParseTree
-
getLineNum
public int getLineNum()
- Specified by:
getLineNumin interfaceIParseTree- Returns:
- The one based line number of the beginning of the parsed element
-
getColumn
public int getColumn()
- Specified by:
getColumnin interfaceIParseTree- Returns:
- The offset from the beginning of the line where the parsed element starts
-
getParsedElement
public ParsedElement getParsedElement()
- Specified by:
getParsedElementin interfaceIParseTree- Returns:
- The parsed element to which this location corresponds.
-
getExtent
public int getExtent()
- Specified by:
getExtentin interfaceIParseTree- Returns:
- The most distant position this location occupies i.e., offset + length - 1.
-
contains
public boolean contains(int iPosition)
- Specified by:
containsin interfaceIParseTree- Parameters:
iPosition- Any position within the source.- Returns:
- True if this location contains the position.
-
contains
public boolean contains(IParseTree l)
- Specified by:
containsin 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.
-
contains
private boolean contains(int start, int end)
-
containsOrBorders
public boolean containsOrBorders(int iPosition, boolean strict)- Specified by:
containsOrBordersin interfaceIParseTree
-
containsOrBorders
public boolean containsOrBorders(IParseTree l, boolean strict)
- Specified by:
containsOrBordersin interfaceIParseTree
-
containsOrBorders
private boolean containsOrBorders(int start, int end, boolean strict)
-
getDeepestLocation
public ParseTree getDeepestLocation(boolean statementsOnly, int iStart, int iEnd, boolean strict)
- Specified by:
getDeepestLocationin interfaceIParseTree
-
isAncestorOf
public boolean isAncestorOf(IParseTree l)
- Specified by:
isAncestorOfin interfaceIParseTree
-
getDeepestLocation
private ParseTree getDeepestLocation(boolean statementsOnly, int iPosition, boolean strict)
-
getDeepestLocation
public ParseTree getDeepestLocation(int iPosition, boolean strict)
- Specified by:
getDeepestLocationin 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:
getDeepestLocationin 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:
getDeepestStatementLocationin 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, java.lang.Class clsSkip)
- Specified by:
getStatementAtLinein 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:
addChildin interfaceIParseTree- Parameters:
l- The location to add.
-
addChild
public void addChild(int iIndex, IParseTree l)
-
removeChild
public void removeChild(IParseTree l)
- Specified by:
removeChildin interfaceIParseTree
-
getChildren
public java.util.List<IParseTree> getChildren()
- Specified by:
getChildrenin 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:
setParentin interfaceIParseTree- Parameters:
l- The parent location.
-
getParent
public IParseTree getParent()
- Specified by:
getParentin 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:
getParentOtherThanThisin interfaceIParseTree
-
areOffsetAndExtentEqual
public boolean areOffsetAndExtentEqual(IParseTree location)
Is just the physical location equal?- Specified by:
areOffsetAndExtentEqualin 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 java.lang.String toString()
- Specified by:
toStringin interfaceIParseTree- Overrides:
toStringin classjava.lang.Object
-
initLocation
public void initLocation(ParsedElement pe, int iOffset, int iLength)
-
compactParseTree
public void compactParseTree()
-
clearParseTreeInformation
public void clearParseTreeInformation()
- Specified by:
clearParseTreeInformationin interfaceIParseTree
-
areAllChildrenAfterPosition
public boolean areAllChildrenAfterPosition(int caret)
- Specified by:
areAllChildrenAfterPositionin interfaceIParseTree
-
getDominatingLocationList
public java.util.List<IParseTree> getDominatingLocationList()
- Specified by:
getDominatingLocationListin interfaceIParseTree
-
getChildrenBefore
public java.util.List<IParseTree> getChildrenBefore(IParseTree parseTree)
- Specified by:
getChildrenBeforein interfaceIParseTree
-
isSiblingOf
public boolean isSiblingOf(IParseTree deepestAtEnd)
- Specified by:
isSiblingOfin interfaceIParseTree
-
getChildAfter
public ParseTree getChildAfter(int point)
- Specified by:
getChildAfterin interfaceIParseTree
-
getChildBefore
public ParseTree getChildBefore(int point)
- Specified by:
getChildBeforein interfaceIParseTree
-
getChildBefore
public ParseTree getChildBefore(IParseTree child)
- Specified by:
getChildBeforein interfaceIParseTree
-
getChildAfter
public ParseTree getChildAfter(IParseTree child)
- Specified by:
getChildAfterin interfaceIParseTree
-
getFirstChildWithParsedElementType
public ParseTree getFirstChildWithParsedElementType(java.lang.Class<? extends IParsedElement> aClass)
- Specified by:
getFirstChildWithParsedElementTypein interfaceIParseTree
-
getLastChildWithParsedElementType
public ParseTree getLastChildWithParsedElementType(java.lang.Class<? extends IParsedElement> aClass)
- Specified by:
getLastChildWithParsedElementTypein interfaceIParseTree
-
getLastChild
public ParseTree getLastChild()
- Specified by:
getLastChildin interfaceIParseTree
-
getNextSibling
public ParseTree getNextSibling()
- Specified by:
getNextSiblingin interfaceIParseTree
-
getPreviousSibling
public ParseTree getPreviousSibling()
- Specified by:
getPreviousSiblingin interfaceIParseTree
-
getDeepestFirstChild
public ParseTree getDeepestFirstChild()
- Specified by:
getDeepestFirstChildin interfaceIParseTree
-
findDescendantsWithParsedElementType
public java.util.Collection<IParseTree> findDescendantsWithParsedElementType(java.lang.Class type)
- Specified by:
findDescendantsWithParsedElementTypein interfaceIParseTree
-
addUnder
public void addUnder(IParseTree parent)
- Specified by:
addUnderin interfaceIParseTree
-
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)
-
getEnclosingFunctionStatement
public IFunctionStatement getEnclosingFunctionStatement()
- Specified by:
getEnclosingFunctionStatementin interfaceIParseTree
-
getMatchingElement
public final IParseTree getMatchingElement(int iStart, int iLength)
- Specified by:
getMatchingElementin interfaceIParseTree
-
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)
-
getTextFromTokens
public java.lang.String getTextFromTokens()
- Specified by:
getTextFromTokensin interfaceIParseTree
-
addTokens
private void addTokens(ParseTree after, java.util.List<IToken> tokens, java.lang.StringBuilder source)
-
getChildrenSorted
public java.util.List<IParseTree> getChildrenSorted()
-
isAncestor
public boolean isAncestor(IParseTree child)
- Specified by:
isAncestorin interfaceIParseTree
-
getChild
public ParseTree getChild(int index)
-
-