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 ClassesNested classes/interfaces inherited from interface freemarker.template.TemplateModel
freemarker.template.TemplateModel.InvalidExpressionModel, freemarker.template.TemplateModel.JavaNull -
Field Summary
Fields inherited from interface freemarker.template.TemplateModel
INVALID_EXPRESSION, JAVA_NULL, NOTHINGFields inherited from interface freemarker.template.TemplateScalarModel
EMPTY_STRING -
Method Summary
Modifier and TypeMethodDescriptionvoidinserts a child Node at a specific index, displacing the nodes after the index by 1.voidappends a child node to this Nodedefault booleanappendChild(Node where, Node inserted) Insert a node right after a given Node.children()children(boolean includeUnparsedTokens) childrenOfType(Class<T> clazz) voidRemove all the child nodesdefault voidclose()Life-cycle hook method called after all the child nodes have been added.default intUsed 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 Nodedescendants(Class<T> clazz) descendants(Class<T> clazz, Predicate<? super T> predicate) descendants(Predicate<? super Node> predicate) descendantsOfType(Class<T> clazz) default voiddump()default voiddefault <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 Tokendefault <T extends Node>
TfirstDescendantOfType(Class<T> clazz) getAllTokens(boolean includeCommentTokens) default intdefault intintgetChild(int i) intdefault intdefault intintdefault NodeReturns the first child of this node.default Tokendefault Stringdefault NodeReturns the last child of the given node.default Tokendefault Stringdefault NodegetRoot()default Stringdefault JavaCCConstants.TokenTypedefault booleanReturns whether this node has any children.default intdefault booleandefault ListIterator<Node> iterator()default Nodedefault 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 NoderemoveChild(int i) Remove the node at index i.default booleanremoveChild(Node n) Removes the Node from this node's childrendefault voiddefault 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.voidReplace 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) voidvoidsetTokenSource(JavaCCLexer tokenSource) voidsetUnparsed(boolean b) Mark whether this Node is unparsed, i.e.Methods inherited from interface freemarker.template.TemplateNodeModel
getChildNodes, getNodeName, getNodeNamespace, getNodeType, getParentNodeMethods inherited from interface freemarker.template.TemplateScalarModel
getAsString
-
Method Details
-
getGrammar
Grammar getGrammar() -
setGrammar
-
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
- 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
- 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
appends a child node to this Node- Parameters:
n- the Node to append
-
addChild
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
- Parameters:
i- the index of the Node to return- Returns:
- the Node at the specific offset
-
setChild
Replace the node at index i- Parameters:
i- the indexn- the node
-
removeChild
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
Removes the Node from this node's children- Parameters:
n- the Node to remove- Returns:
- whether the Node was present
-
replaceChild
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
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
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
- 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
-
nextSibling
-
compareTo
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
- 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.
-
children
-
getAllTokens
- Parameters:
includeCommentTokens- Whether to include comment tokens- Returns:
- a List containing all the tokens in a Node
-
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
-
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
- 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.
-
firstChildOfType
-
firstChildOfType
-
firstDescendantOfType
-
firstChildOfType
-
firstDescendantOfType
-
childrenOfType
-
descendantsOfType
-
firstAncestorOfType
-
getTokenType
-
getFirstToken
- Returns:
- the very first token that is part of this node. It may be an unparsed (i.e. special) token.
-
getLastToken
-
copyLocationInfo
Copy the location info from another Node- Parameters:
from- the Node to copy the info from
-
copyLocationInfo
Copy the location info given a start and end Node- Parameters:
start- the start nodeend- the end node
-
replace
-
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
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
-
getTokens
-
getRealTokens
-
descendants
-
descendants
-
descendants
-
descendants
-
dump
-
dump
default void dump() -
iterator
-