Class SimpleNode
java.lang.Object
org.apache.velocity.runtime.parser.node.SimpleNode
- All Implemented Interfaces:
Cloneable,Node,Renderable
- Direct Known Subclasses:
ASTAssignment,ASTBinaryOperator,ASTBlock,ASTComment,ASTDirective,ASTDirectiveAssign,ASTElseIfStatement,ASTElseStatement,ASTEscape,ASTEscapedDirective,ASTExpression,ASTFalse,ASTFloatingPointLiteral,ASTIdentifier,ASTIfStatement,ASTIncludeStatement,ASTIndex,ASTIntegerLiteral,ASTIntegerRange,ASTMap,ASTMethod,ASTNegateNode,ASTNotNode,ASTObjectArray,ASTParameters,ASTprocess,ASTReference,ASTSetDirective,ASTStringLiteral,ASTText,ASTTextblock,ASTTrue,ASTVariable,ASTWord
-
Field Summary
FieldsModifier and TypeFieldDescriptionprotected Node[]protected intColumn number for this Node in the vm source file.protected Tokenprotected StringString image variable of the first Token element that was parsed and connected to this Node.protected intprotected intprotected booleanprotected Tokenprotected StringString image variable of the last Token element that was parsed and connected to this Node.protected intLine number for this Node in the vm source file.protected StringFor caching the literal value.protected org.slf4j.Loggerprotected Nodeprotected Parserprotected RuntimeServicesbooleanprotected Template -
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionchildrenAccept(StandardParserVisitor visitor, Object data) voidRemoves references to Parser and Tokens since they are not needed anymore at this point.Root node deep cloningprotected NodeChild node deep cloningfinal voidDumps nodes tree on System.out.final voiddump(String prefix, PrintStream out) Dumps nodes tree on System.out.voiddump(String prefix, PrintWriter out) Dumps nodes tree on System.out.booleanevaluate(InternalContextAdapter context) execute(Object o, InternalContextAdapter context) intintgetInfo()intgetLine()protected StringgetLocation(InternalContextAdapter context) Return a string that tells the current location of this node.intgetType()init(InternalContextAdapter context, Object data) booleanjjtAccept(StandardParserVisitor visitor, Object data) voidjjtAddChild(Node n, int i) This method tells the node to add its argument to the node's list of children.voidjjtClose()This method is called after all the child nodes have been added.jjtGetChild(int i) This method returns a child node.intReturn the number of children the node has.voidjjtOpen()This method is called after the node has been made the current node.voidjjtSetParent(Node n) This pair of methods are used to inform the node of its parent.literal()booleanrender(InternalContextAdapter context, Writer writer) voidCall before calling cleanupParserAndTokens() if you want to store image of the first and last token of this node.voidvoidsetInfo(int info) voidMark the node as invalid.toString()value(InternalContextAdapter context)
-
Field Details
-
rsvc
-
log
protected org.slf4j.Logger log -
parent
-
children
-
id
protected int id -
parser
-
info
protected int info -
state
public boolean state -
invalid
protected boolean invalid -
first
-
last
-
template
-
literal
For caching the literal value. -
line
protected int lineLine number for this Node in the vm source file. -
column
protected int columnColumn number for this Node in the vm source file. -
firstImage
String image variable of the first Token element that was parsed and connected to this Node. -
lastImage
String image variable of the last Token element that was parsed and connected to this Node.
-
-
Constructor Details
-
SimpleNode
public SimpleNode(int i) - Parameters:
i-
-
SimpleNode
- Parameters:
p-i-
-
-
Method Details
-
getRuntimeServices
-
jjtOpen
public void jjtOpen()Description copied from interface:NodeThis method is called after the node has been made the current node. It indicates that child nodes can now be added to it. -
jjtClose
public void jjtClose()Description copied from interface:NodeThis method is called after all the child nodes have been added. -
setFirstToken
- Parameters:
t-
-
getFirstToken
- Specified by:
getFirstTokenin interfaceNode- Returns:
- The first token.
- See Also:
-
getLastToken
- Specified by:
getLastTokenin interfaceNode- Returns:
- The last token.
- See Also:
-
jjtSetParent
Description copied from interface:NodeThis pair of methods are used to inform the node of its parent.- Specified by:
jjtSetParentin interfaceNode- Parameters:
n-- See Also:
-
jjtGetParent
- Specified by:
jjtGetParentin interfaceNode- Returns:
- The node parent.
- See Also:
-
jjtAddChild
Description copied from interface:NodeThis method tells the node to add its argument to the node's list of children.- Specified by:
jjtAddChildin interfaceNode- Parameters:
n-i-- See Also:
-
jjtGetChild
Description copied from interface:NodeThis method returns a child node. The children are numbered from zero, left to right.- Specified by:
jjtGetChildin interfaceNode- Parameters:
i-- Returns:
- A child node.
- See Also:
-
jjtGetNumChildren
public int jjtGetNumChildren()Description copied from interface:NodeReturn the number of children the node has.- Specified by:
jjtGetNumChildrenin interfaceNode- Returns:
- The number of children of this node.
- See Also:
-
jjtAccept
-
childrenAccept
- Specified by:
childrenAcceptin interfaceNode- Parameters:
visitor-data-- Returns:
- The node execution result.
- See Also:
-
toString
- Parameters:
prefix- display prefix- Returns:
- String representation of this node.
-
dump
Dumps nodes tree on System.out.
Override
dump(String, PrintWriter)if you want to customize how the node dumps out its children.- Parameters:
prefix-
-
dump
Dumps nodes tree on System.out.
Override
dump(String, PrintWriter)if you want to customize how the node dumps out its children.- Parameters:
prefix- display prefixout- output print stream
-
dump
Dumps nodes tree on System.out.
Override this method if you want to customize how the node dumps out its children.
- Parameters:
prefix- display prefixout- output print writer
-
getLocation
Return a string that tells the current location of this node.- Parameters:
context-- Returns:
- location
-
literal
-
init
- Specified by:
initin interfaceNode- Parameters:
context-data-- Returns:
- The init result.
- Throws:
TemplateInitException- See Also:
-
evaluate
- Specified by:
evaluatein interfaceNode- Parameters:
context-- Returns:
- The evaluation result.
- Throws:
MethodInvocationException- See Also:
-
value
- Specified by:
valuein interfaceNode- Parameters:
context-- Returns:
- The node value.
- Throws:
MethodInvocationException- See Also:
-
render
public boolean render(InternalContextAdapter context, Writer writer) throws IOException, MethodInvocationException, ParseErrorException, ResourceNotFoundException - Specified by:
renderin interfaceNode- Specified by:
renderin interfaceRenderable- Parameters:
context-writer-- Returns:
- True if the node rendered successfully.
- Throws:
IOExceptionMethodInvocationExceptionParseErrorExceptionResourceNotFoundException- See Also:
-
execute
- Specified by:
executein interfaceNode- Parameters:
o-context-- Returns:
- The execution result.
- Throws:
MethodInvocationException- See Also:
-
getType
public int getType() -
setInfo
public void setInfo(int info) -
getInfo
public int getInfo() -
setInvalid
public void setInvalid()Description copied from interface:NodeMark the node as invalid.- Specified by:
setInvalidin interfaceNode- See Also:
-
isInvalid
public boolean isInvalid() -
getLine
public int getLine() -
getColumn
public int getColumn() -
toString
-
getTemplateName
- Specified by:
getTemplateNamein interfaceNode- Returns:
- the file name of the template
-
saveTokenImages
public void saveTokenImages()Call before calling cleanupParserAndTokens() if you want to store image of the first and last token of this node. -
cleanupParserAndTokens
public void cleanupParserAndTokens()Removes references to Parser and Tokens since they are not needed anymore at this point. This allows us to save memory quite a bit. -
getFirstTokenImage
- Specified by:
getFirstTokenImagein interfaceNode- Returns:
- String image variable of the first Token element that was parsed and connected to this Node.
-
getLastTokenImage
- Specified by:
getLastTokenImagein interfaceNode- Returns:
- String image variable of the last Token element that was parsed and connected to this Node.
-
getTemplate
- Specified by:
getTemplatein interfaceNode- Returns:
- the template this node belongs to
-
getParser
-
clone
Root node deep cloning- Parameters:
template- owner template- Returns:
- cloned node
- Throws:
CloneNotSupportedException- Since:
- 2.4
-
clone
Child node deep cloning- Parameters:
template- owner templateparent- parent node- Returns:
- cloned node
- Throws:
CloneNotSupportedException- Since:
- 2.4
-