Package com.javacc.parser
Interface Node
-
- All Superinterfaces:
Comparable<Node>,freemarker.template.TemplateModel,freemarker.template.TemplateNodeModel,freemarker.template.TemplateScalarModel
- All Known Subinterfaces:
Annotation,ClassOrInterfaceBodyDeclaration,Expression,Type,TypeDeclaration
- All Known Implementing Classes:
AdditiveExpression,AllocationExpression,AndExpression,AnnotationMethodDeclaration,AnnotationTypeBody,AnnotationTypeDeclaration,AnnotationTypeMemberDeclaration,ANY_CHAR,ArrayAccess,ArrayDimsAndInits,ArrayInitializer,Assertion,AssertStatement,AssignmentExpression,AttemptBlock,Backslash,BaseNode,BasicForStatement,BlockStatement,BNFProduction,BooleanLiteral,BreakStatement,CatchBlock,CharacterList,CharacterLiteral,CharacterRange,ClassDeclaration,ClassicCaseStatement,ClassicSwitchLabel,ClassicSwitchStatement,ClassicTryStatement,ClassLiteral,ClassOrInterfaceBody,CodeBlock,CodeInjection,CodeInjection2,Comment,CompactConstructorDeclaration,CompilationUnit,ConditionalAndExpression,ConditionalOrExpression,ConstructorDeclaration,ContinueStatement,DefaultValue,Delimiter,DiamondOperator,DoStatement,DotName,DotNew,DotSuper,DotThis,EmptyDeclaration,EmptyExpansion,EmptyStatement,EndOfFile,EnhancedForStatement,EnumBody,EnumConstant,EnumDeclaration,EqualityExpression,ExceptionType,ExclusiveOrExpression,Expansion,ExpansionChoice,ExpansionSequence,ExpansionUnit,ExpansionWithParentheses,ExplicitConstructorInvocation,ExpressionStatement,ExtendsList,Failure,FieldDeclaration,FinallyBlock,FloatingPointLiteral,ForInit,FormalParameter,FormalParameters,ForStatement,Grammar,GrammarFile,GrammarInclusion,HASH,Identifier,IfStatement,ImplementsList,ImportDeclaration,InclusiveOrExpression,Initializer,InstanceOfExpression,IntegerLiteral,InterfaceDeclaration,InvalidToken,InvocationArguments,JavaCCKeyWord,KeyWord,Label,LambdaExpression,LambdaLHS,LambdaParameter,LambdaParameters,LegacyLookahead,LexicalStateSwitch,Literal,LiteralExpression,LocalVariableDeclaration,LongLiteral,Lookahead,LookBehind,MarkerAnnotation,MemberValue,MemberValueArrayInitializer,MemberValuePair,MemberValuePairs,MethodCall,MethodDeclaration,MethodReference,MULTI_LINE_COMMENT_START,MultiLineComment,MultiplicativeExpression,Name,NewCaseStatement,NewSwitchLabel,NewSwitchStatement,NonTerminal,NormalAnnotation,NullLiteral,NumericalLiteral,ObjectCastExpression,ObjectType,OneOrMore,OneOrMoreRegexp,Operator,Options,PackageDeclaration,Parentheses,ParserCodeDecls,PermitsList,PostfixExpression,PreDecrementExpression,PreIncrementExpression,Primitive,PrimitiveArrayType,PrimitiveCastExpression,PrimitiveType,RecordBody,RecordComponent,RecordDeclaration,RecordHeader,ReferenceType,RegexpChoice,RegexpRef,RegexpSequence,RegexpSpec,RegexpStringLiteral,RegularExpression,RelationalExpression,RepetitionRange,ReturnStatement,ReturnType,RightArrow,scan,Setting,ShiftExpression,SINGLE_LINE_COMMENT_START,SingleLineComment,SingleMemberAnnotation,Statement,StatementExpression,StatementExpressionList,StringLiteral,SwitchExpression,SwitchStatement,SynchronizedStatement,TernaryExpression,ThisLiteral,ThrowsList,ThrowStatement,Token,TokenActivation,TokenManagerDecls,TokenProduction,TreeBuildingAnnotation,TryBlock,TryStatement,TryWithResources,TypeArgument,TypeArguments,TypeBound,TypeParameter,TypeParameters,UnaryExpression,UnaryExpressionNotPlusMinus,UncacheTokens,UP_TO_HERE,VariableDeclarator,VariableDeclaratorId,VariableInitializer,WhileStatement,Whitespace,WildcardBounds,YieldStatement,ZeroOrMore,ZeroOrMoreRegexp,ZeroOrOne,ZeroOrOneRegexp
public interface Node extends Comparable<Node>, freemarker.template.TemplateNodeModel, freemarker.template.TemplateScalarModel
-
-
Nested Class Summary
Nested Classes Modifier and Type Interface Description static classNode.Visitor
-
Method Summary
All Methods Static Methods Instance Methods Abstract Methods Default Methods Modifier and Type Method Description voidaddChild(int i, Node n)inserts a child Node at a specific index, displacing the nodes after the index by 1.voidaddChild(Node n)appends a child node to this Nodedefault booleanappendChild(Node where, Node inserted)Insert a node right after a given Node.default List<Node>children()default List<Node>children(boolean includeUnparsedTokens)default <T extends Node>
List<T>childrenOfType(Class<T> clazz)voidclearChildren()Remove all the child nodesdefault voidclose()Life-cycle hook method called after all the child nodes have been added.default intcompareTo(Node n)Used to order Nodes by location.default voidcopyLocationInfo(Node from)Copy the location info from another Nodedefault voidcopyLocationInfo(Node start, Node end)Copy the location info given a start and end Nodedefault List<Node>descendants()default <T extends Node>
List<T>descendants(Class<T> clazz)default <T extends Node>
List<T>descendants(Class<T> clazz, Predicate<? super T> predicate)default List<Node>descendants(Predicate<? super Node> predicate)default <T extends Node>
List<T>descendantsOfType(Class<T> clazz)default voiddump()default voiddump(String prefix)default <T extends Node>
TfirstAncestorOfType(Class<T> clazz)default TokenfirstChildOfType(JavaCCConstants.TokenType tokenType)default <T extends Node>
TfirstChildOfType(Class<T> clazz)default <T extends Node>
TfirstChildOfType(Class<T> clazz, Predicate<T> pred)default TokenfirstDescendantOfType(JavaCCConstants.TokenType type)default <T extends Node>
TfirstDescendantOfType(Class<T> clazz)default List<Token>getAllTokens(boolean includeCommentTokens)default intgetBeginColumn()default intgetBeginLine()intgetBeginOffset()NodegetChild(int i)intgetChildCount()default intgetEndColumn()default intgetEndLine()intgetEndOffset()default NodegetFirstChild()Returns the first child of this node.default TokengetFirstToken()GrammargetGrammar()default StringgetInputSource()default NodegetLastChild()Returns the last child of the given node.default TokengetLastToken()default StringgetLocation()NodegetParent()default List<Token>getRealTokens()static List<Token>getRealTokens(Node n)default NodegetRoot()default StringgetSource()static List<Token>getTokens(Node node)JavaCCLexergetTokenSource()default JavaCCConstants.TokenTypegetTokenType()default booleanhasChildNodes()Returns whether this node has any children.default intindexOf(Node child)default booleanisUnparsed()default ListIterator<Node>iterator()default NodenextSibling()default voidopen()Life-cycle hook method called after the node has been made the current nodedefault booleanprependChild(Node where, Node inserted)Insert a Node right before a given Node.default NodepreviousSibling()NoderemoveChild(int i)Remove the node at index i.default booleanremoveChild(Node n)Removes the Node from this node's childrendefault voidreplace(Node toBeReplaced)default booleanreplaceChild(Node current, Node replacement)Replaces a child node with another one.voidsetBeginOffset(int beginOffset)Set the offset where the token begins, expressed in code units.voidsetChild(int i, Node n)Replace the node at index ivoidsetEndOffset(int endOffet)Set the offset where the token ends, actually the location where the very next token should begin.voidsetGrammar(Grammar grammar)voidsetParent(Node n)voidsetTokenSource(JavaCCLexer tokenSource)voidsetUnparsed(boolean b)Mark whether this Node is unparsed, i.e.
-
-
-
Method Detail
-
getGrammar
Grammar getGrammar()
-
setGrammar
void setGrammar(Grammar grammar)
-
open
default void open()
Life-cycle hook method called after the node has been made the current node
-
close
default void close()
Life-cycle hook method called after all the child nodes have been added.
-
getInputSource
default String getInputSource()
- Returns:
- the input source (usually a filename) from which this Node came from
-
hasChildNodes
default boolean hasChildNodes()
Returns whether this node has any children.- Returns:
- Returns
trueif this node has any children,falseotherwise.
-
setParent
void setParent(Node n)
- Parameters:
n- The Node to set as the parent. Mostly used internally. The various addChild or appendChild sorts of methods should use this to set the node's parent.
-
getParent
Node getParent()
- Returns:
- this node's parent Node
-
addChild
void addChild(Node n)
appends a child node to this Node- Parameters:
n- the Node to append
-
addChild
void addChild(int i, Node n)inserts a child Node at a specific index, displacing the nodes after the index by 1.- Parameters:
i- the (zero-based) index at which to insert the noden- the Node to insert
-
getChild
Node getChild(int i)
- Parameters:
i- the index of the Node to return- Returns:
- the Node at the specific offset
-
setChild
void setChild(int i, Node n)Replace the node at index i- Parameters:
i- the indexn- the node
-
removeChild
Node removeChild(int i)
Remove the node at index i. Any Nodes after i are shifted to the left.- Parameters:
i- the index at which to remove- Returns:
- the removed Node
-
removeChild
default boolean removeChild(Node n)
Removes the Node from this node's children- Parameters:
n- the Node to remove- Returns:
- whether the Node was present
-
replaceChild
default boolean replaceChild(Node current, Node replacement)
Replaces a child node with another one. It does nothing if the first parameter is not actually a child node.- Parameters:
current- the Node to be replacedreplacement- the Node to substitute- Returns:
- whether any replacement took place
-
prependChild
default boolean prependChild(Node where, Node inserted)
Insert a Node right before a given Node. It does nothing if the where Node is not actually a child node.- Parameters:
where- the Node that is the location where to prependinserted- the Node to prepend- Returns:
- whether a Node was prepended
-
appendChild
default boolean appendChild(Node where, Node inserted)
Insert a node right after a given Node. It does nothing if the where node is not actually a child node.- Parameters:
where- the Node after which to appendinserted- the Node to be inserted- Returns:
- whether a Node really was appended
-
indexOf
default int indexOf(Node child)
- Parameters:
child- the Node to get the index of- Returns:
- the index of the child Node. Or -1 if it is not a child Node.
-
previousSibling
default Node previousSibling()
-
nextSibling
default Node nextSibling()
-
compareTo
default int compareTo(Node n)
Used to order Nodes by location.- Specified by:
compareToin interfaceComparable<Node>- Parameters:
n- the Node to compare to- Returns:
- typical Comparator semantics
-
clearChildren
void clearChildren()
Remove all the child nodes
-
getChildCount
int getChildCount()
- Returns:
- the number of child nodes
-
children
default List<Node> children(boolean includeUnparsedTokens)
- Returns:
- a List containing this node's child nodes The default implementation returns a copy, so modifying the list that is returned has no effect on this object. Most implementations of this should similarly return a copy or possibly immutable wrapper around the list.
-
getAllTokens
default List<Token> getAllTokens(boolean includeCommentTokens)
- Parameters:
includeCommentTokens- Whether to include comment tokens- Returns:
- a List containing all the tokens in a Node
-
getRealTokens
default List<Token> getRealTokens()
- Returns:
- All the tokens in the node that are "real" (i.e. participate in parsing)
-
getTokenSource
JavaCCLexer getTokenSource()
- Returns:
- the #JavaCCLexer from which this Node object originated. There is no guarantee that this doesn't return null. Most likely that would simply be because you constructed the Node yourself, i.e. it didn't really come about via the parsing/tokenizing machinery.
-
setTokenSource
void setTokenSource(JavaCCLexer tokenSource)
-
getSource
default String getSource()
- Returns:
- the original source content this Node came from a reference to the #JavaCCLexer that stores the source code and the start/end location info stored in the Node object itself. This method could throw a NullPointerException if #getTokenSource returns null. Also, the return value could be spurious if the content of the source file was changed meanwhile. But this is just the default implementation of an API and it does not address this problem!
-
getBeginLine
default int getBeginLine()
- Returns:
- the (1-based) line location where this Node starts
-
getEndLine
default int getEndLine()
- Returns:
- the (1-based) line location where this Node ends
-
getBeginColumn
default int getBeginColumn()
- Returns:
- the (1-based) column where this Node starts
-
getEndColumn
default int getEndColumn()
- Returns:
- the (1-based) column offset where this Node ends
-
getBeginOffset
int getBeginOffset()
- Returns:
- the offset in the input source where the token begins, expressed in code units.
-
getEndOffset
int getEndOffset()
- Returns:
- the offset in the input source where the token ends, expressed in code units. This is actually the offset where the very next token would begin.
-
setBeginOffset
void setBeginOffset(int beginOffset)
Set the offset where the token begins, expressed in code units.
-
setEndOffset
void setEndOffset(int endOffet)
Set the offset where the token ends, actually the location where the very next token should begin.
-
getLocation
default String getLocation()
- Returns:
- a String that gives the starting location of this Node. This is a default implementation that could be overridden
-
isUnparsed
default boolean isUnparsed()
- Returns:
- whether this Node was created by regular operations of the parsing machinery.
-
setUnparsed
void setUnparsed(boolean b)
Mark whether this Node is unparsed, i.e. not the result of normal parsing- Parameters:
b- whether to set the Node as unparsed or parsed.
-
firstDescendantOfType
default Token firstDescendantOfType(JavaCCConstants.TokenType type)
-
firstChildOfType
default Token firstChildOfType(JavaCCConstants.TokenType tokenType)
-
getTokenType
default JavaCCConstants.TokenType getTokenType()
-
getFirstToken
default Token getFirstToken()
- Returns:
- the very first token that is part of this node. It may be an unparsed (i.e. special) token.
-
getLastToken
default Token getLastToken()
-
copyLocationInfo
default void copyLocationInfo(Node from)
Copy the location info from another Node- Parameters:
from- the Node to copy the info from
-
copyLocationInfo
default void copyLocationInfo(Node start, Node end)
Copy the location info given a start and end Node- Parameters:
start- the start nodeend- the end node
-
replace
default void replace(Node toBeReplaced)
-
getFirstChild
default Node getFirstChild()
Returns the first child of this node. If there is no such node, this returnsnull.- Returns:
- the first child of this node. If there is no such node, this returns
null.
-
getLastChild
default Node getLastChild()
Returns the last child of the given node. If there is no such node, this returnsnull.- Returns:
- the last child of the given node. If there is no such node, this
returns
null.
-
getRoot
default Node getRoot()
-
descendants
default <T extends Node> List<T> descendants(Class<T> clazz, Predicate<? super T> predicate)
-
dump
default void dump(String prefix)
-
dump
default void dump()
-
iterator
default ListIterator<Node> iterator()
-
-