Top Description Inners Fields Constructors Methods
com.google.escapevelocity

pack-priv abstract Class DirectiveNode

extends Node
Class Inheritance
Known Direct Subclasses
com.google.escapevelocity.DirectiveNode.SetNode, com.google.escapevelocity.DirectiveNode.DefineNode, com.google.escapevelocity.DirectiveNode.IfNode, com.google.escapevelocity.DirectiveNode.ForEachNode, com.google.escapevelocity.DirectiveNode.BreakNode, com.google.escapevelocity.DirectiveNode.MacroCallNode
Imports
com.google.common.collect.ImmutableList, java.util.Arrays, .Iterator, .Map

A node in the parse tree that is a directive such as #set ($x = $y) or #if ($x) y #end.
Author
[email protected] (Éamonn McManus)

Nested and Inner Type Summary

Modifier and TypeClass and Description
pack-priv static class
DirectiveNode.BreakNode

A node in the parse tree representing a #break directive.

pack-priv static class
DirectiveNode.DefineNode

A node in the parse tree representing a #define construct.

pack-priv static class
DirectiveNode.ForEachNode

A node in the parse tree representing a #foreach construct.

pack-priv static class
DirectiveNode.IfNode

A node in the parse tree representing an #if construct.

pack-priv static class
DirectiveNode.MacroCallNode

A node in the parse tree representing a macro call.

pack-priv static class
DirectiveNode.SetNode

A node in the parse tree representing a #set construct.

Field Summary

Inherited from com.google.escapevelocity.Node:
lineNumberresourceName

Constructor Summary

AccessConstructor and Description
pack-priv
DirectiveNode(String resourceName, int lineNumber)

Method Summary

Inherited from com.google.escapevelocity.Node:
consemptyNodeevaluationExceptionevaluationExceptionisHorizontalWhitespacerender

Constructor Detail

DirectiveNodeback to summary
pack-priv DirectiveNode(String resourceName, int lineNumber)
com.google.escapevelocity back to summary

pack-priv Class DirectiveNode.BreakNode

extends DirectiveNode
Class Inheritance

A node in the parse tree representing a #break directive. The directive has an optional scope argument, so you can write #break($foreach) to break from the nearest #foreach loop. That is in fact the only scope we support, so we just have a boolean that indicates if it is present. Otherwise we break from the nearest #foreach or #parse or from the whole template.

Field Summary

Modifier and TypeField and Description
private final ExpressionNode

Constructor Summary

AccessConstructor and Description
pack-priv
BreakNode(String resourceName, int lineNumber, ExpressionNode scope)

Method Summary

Modifier and TypeMethod and Description
pack-priv void
render(EvaluationContext context, StringBuilder output)

Implements abstract com.google.escapevelocity.Node.render.

Adds this node's contribution to the output.

Field Detail

scopeback to summary
private final ExpressionNode scope

Constructor Detail

BreakNodeback to summary
pack-priv BreakNode(String resourceName, int lineNumber, ExpressionNode scope)

Method Detail

renderback to summary
pack-priv void render(EvaluationContext context, StringBuilder output)

Implements abstract com.google.escapevelocity.Node.render.

Doc from com.google.escapevelocity.Node.render.

Adds this node's contribution to the output. Depending on the node type, this might be plain text from the template, or one branch of an #if, or the value of a $reference, etc.

Annotations
@Override
com.google.escapevelocity back to summary

pack-priv Class DirectiveNode.DefineNode

extends DirectiveNode
Class Inheritance

A node in the parse tree representing a #define construct. Evaluating #define ($x) foo $bar #end will set $x to the given sequence of nodes. It does not produce any text in the output.

Field Summary

Modifier and TypeField and Description
private final Node
private final String

Constructor Summary

AccessConstructor and Description
pack-priv
DefineNode(String var, Node body)

Method Summary

Modifier and TypeMethod and Description
pack-priv void
render(EvaluationContext context, StringBuilder output)

Implements abstract com.google.escapevelocity.Node.render.

Adds this node's contribution to the output.

Field Detail

bodyback to summary
private final Node body
varback to summary
private final String var

Constructor Detail

DefineNodeback to summary
pack-priv DefineNode(String var, Node body)

Method Detail

renderback to summary
pack-priv void render(EvaluationContext context, StringBuilder output)

Implements abstract com.google.escapevelocity.Node.render.

Doc from com.google.escapevelocity.Node.render.

Adds this node's contribution to the output. Depending on the node type, this might be plain text from the template, or one branch of an #if, or the value of a $reference, etc.

Annotations
@Override
com.google.escapevelocity back to summary

pack-priv Class DirectiveNode.ForEachNode

extends DirectiveNode
Class Inheritance

A node in the parse tree representing a #foreach construct. While evaluating #foreach ($x in $things), {$code $x} will be set to each element of $things in turn. Once the loop completes, $x will go back to whatever value it had before, which might be undefined. During loop execution, the variable $foreach is also defined. Velocity defines a number of properties in this variable, but here we only support $foreach.hasNext and $foreach.index.

Nested and Inner Type Summary

Modifier and TypeClass and Description
private static class
private static class
DirectiveNode.ForEachNode.ForEachVar

This class is the type of the variable $foreach that is defined within #foreach loops.

Field Summary

Modifier and TypeField and Description
private final Node
private final ExpressionNode
private final String

Constructor Summary

AccessConstructor and Description
pack-priv
ForEachNode(String resourceName, int lineNumber, String var, ExpressionNode in, Node body)

Method Summary

Modifier and TypeMethod and Description
pack-priv void
render(EvaluationContext context, StringBuilder output)

Implements abstract com.google.escapevelocity.Node.render.

Adds this node's contribution to the output.

Field Detail

bodyback to summary
private final Node body
collectionback to summary
private final ExpressionNode collection
varback to summary
private final String var

Constructor Detail

ForEachNodeback to summary
pack-priv ForEachNode(String resourceName, int lineNumber, String var, ExpressionNode in, Node body)

Method Detail

renderback to summary
pack-priv void render(EvaluationContext context, StringBuilder output)

Implements abstract com.google.escapevelocity.Node.render.

Doc from com.google.escapevelocity.Node.render.

Adds this node's contribution to the output. Depending on the node type, this might be plain text from the template, or one branch of an #if, or the value of a $reference, etc.

Annotations
@Override
com.google.escapevelocity back to summary

private Class DirectiveNode.ForEachNode.CountingIterator

extends Object
implements Iterator<Object>
Class Inheritance
  • java.lang.Object
  • com.google.escapevelocity.DirectiveNode.ForEachNode.CountingIterator
All Implemented Interfaces
java.util.Iterator

Field Summary

Modifier and TypeField and Description
private int
private final Iterator<?>

Constructor Summary

AccessConstructor and Description
pack-priv

Method Summary

Modifier and TypeMethod and Description
public boolean
hasNext()

Implements java.util.Iterator.hasNext.

Returns true if the iteration has more elements.
pack-priv int
public Object
next()

Implements java.util.Iterator.next.

Returns the next element in the iteration.
Inherited from java.lang.Object:
cloneequalsfinalizegetClasshashCodenotifynotifyAlltoStringwaitwaitwait

Field Detail

indexback to summary
private int index
iteratorback to summary
private final Iterator<?> iterator

Constructor Detail

CountingIteratorback to summary
pack-priv CountingIterator(Iterator<?> iterator)

Method Detail

hasNextback to summary
public boolean hasNext()

Implements java.util.Iterator.hasNext.

Doc from java.util.Iterator.hasNext.

Returns true if the iteration has more elements. (In other words, returns true if next would return an element rather than throwing an exception.)

Returns:boolean

true if the iteration has more elements

Annotations
@Override
indexback to summary
pack-priv int index()
nextback to summary
public Object next()

Implements java.util.Iterator.next.

Doc from java.util.Iterator.next.

Returns the next element in the iteration.

Returns:Object

the next element in the iteration

Annotations
@Override
com.google.escapevelocity back to summary

private Class DirectiveNode.ForEachNode.ForEachVar

extends Object
Class Inheritance
  • java.lang.Object
  • com.google.escapevelocity.DirectiveNode.ForEachNode.ForEachVar
Annotations
@SuppressWarnings:unused

This class is the type of the variable $foreach that is defined within #foreach loops. Its getHasNext() method means that we can write #if ($foreach.hasNext) and likewise for getIndex() etc.

Field Summary

Modifier and TypeField and Description
private final DirectiveNode.ForEachNode.CountingIterator

Constructor Summary

AccessConstructor and Description
pack-priv

Method Summary

Modifier and TypeMethod and Description
public int
public boolean
public boolean
public int
public boolean
public String
toString()

Overrides java.lang.Object.toString.

Returns a string representation of the object.
Inherited from java.lang.Object:
cloneequalsfinalizegetClasshashCodenotifynotifyAllwaitwaitwait

Field Detail

iteratorback to summary
private final DirectiveNode.ForEachNode.CountingIterator iterator

Constructor Detail

ForEachVarback to summary
pack-priv ForEachVar(DirectiveNode.ForEachNode.CountingIterator iterator)

Method Detail

getCountback to summary
public int getCount()
getFirstback to summary
public boolean getFirst()
getHasNextback to summary
public boolean getHasNext()
getIndexback to summary
public int getIndex()
getLastback to summary
public boolean getLast()
toStringback to summary
public String toString()

Overrides java.lang.Object.toString.

Doc from java.lang.Object.toString.

Returns a string representation of the object.

Returns:String

a string representation of the object.

Annotations
@Override
com.google.escapevelocity back to summary

pack-priv Class DirectiveNode.IfNode

extends DirectiveNode
Class Inheritance

A node in the parse tree representing an #if construct. All instances of this class have a true subtree and a false subtree. For a plain #if (cond) body #end, the false subtree will be empty. For #if (cond1) body1 #elseif (cond2) body2 #else body3 #end, the false subtree will contain a nested IfNode, as if #else #if had been used instead of #elseif.

Field Summary

Modifier and TypeField and Description
private final ExpressionNode
private final Node
private final Node

Constructor Summary

AccessConstructor and Description
pack-priv
IfNode(String resourceName, int lineNumber, ExpressionNode condition, Node trueNode, Node falseNode)

Method Summary

Modifier and TypeMethod and Description
pack-priv void
render(EvaluationContext context, StringBuilder output)

Implements abstract com.google.escapevelocity.Node.render.

Adds this node's contribution to the output.

Field Detail

conditionback to summary
private final ExpressionNode condition
falsePartback to summary
private final Node falsePart
truePartback to summary
private final Node truePart

Constructor Detail

IfNodeback to summary
pack-priv IfNode(String resourceName, int lineNumber, ExpressionNode condition, Node trueNode, Node falseNode)

Method Detail

renderback to summary
pack-priv void render(EvaluationContext context, StringBuilder output)

Implements abstract com.google.escapevelocity.Node.render.

Doc from com.google.escapevelocity.Node.render.

Adds this node's contribution to the output. Depending on the node type, this might be plain text from the template, or one branch of an #if, or the value of a $reference, etc.

Annotations
@Override
com.google.escapevelocity back to summary

pack-priv Class DirectiveNode.MacroCallNode

extends DirectiveNode
Class Inheritance

A node in the parse tree representing a macro call. If the template contains a definition like #macro (mymacro $x $y) ... #end, then a call of that macro looks like #mymacro (xvalue yvalue). The call is represented by an instance of this class. The definition itself does not appear in the parse tree.

Evaluating a macro involves temporarily setting the parameter variables ($x $y in the example) to thunks representing the argument expressions, evaluating the macro body, and restoring any previous values that the parameter variables had.

Field Summary

Modifier and TypeField and Description
private final Node
private final String
private final ImmutableList<ExpressionNode>

Constructor Summary

AccessConstructor and Description
pack-priv
MacroCallNode(String resourceName, int lineNumber, String name, ImmutableList<ExpressionNode> argumentNodes, Node bodyContent)

Method Summary

Modifier and TypeMethod and Description
pack-priv void
render(EvaluationContext context, StringBuilder output)

Implements abstract com.google.escapevelocity.Node.render.

Adds this node's contribution to the output.

Field Detail

bodyContentback to summary
private final Node bodyContent
nameback to summary
private final String name
thunksback to summary
private final ImmutableList<ExpressionNode> thunks

Constructor Detail

MacroCallNodeback to summary
pack-priv MacroCallNode(String resourceName, int lineNumber, String name, ImmutableList<ExpressionNode> argumentNodes, Node bodyContent)

Method Detail

renderback to summary
pack-priv void render(EvaluationContext context, StringBuilder output)

Implements abstract com.google.escapevelocity.Node.render.

Doc from com.google.escapevelocity.Node.render.

Adds this node's contribution to the output. Depending on the node type, this might be plain text from the template, or one branch of an #if, or the value of a $reference, etc.

Annotations
@Override
com.google.escapevelocity back to summary

pack-priv Class DirectiveNode.SetNode

extends DirectiveNode
Class Inheritance

A node in the parse tree representing a #set construct. Evaluating #set ($x = 23) will set $x to the value 23. It does not in itself produce any text in the output.

Velocity supports setting values within arrays or collections, with for example $set ($x[$i] = $y). That is not currently supported here.

Field Summary

Modifier and TypeField and Description
private final ExpressionNode
private final String

Constructor Summary

AccessConstructor and Description
pack-priv
SetNode(String var, ExpressionNode expression)

Method Summary

Modifier and TypeMethod and Description
pack-priv void
render(EvaluationContext context, StringBuilder output)

Implements abstract com.google.escapevelocity.Node.render.

Adds this node's contribution to the output.

Field Detail

expressionback to summary
private final ExpressionNode expression
varback to summary
private final String var

Constructor Detail

SetNodeback to summary
pack-priv SetNode(String var, ExpressionNode expression)

Method Detail

renderback to summary
pack-priv void render(EvaluationContext context, StringBuilder output)

Implements abstract com.google.escapevelocity.Node.render.

Doc from com.google.escapevelocity.Node.render.

Adds this node's contribution to the output. Depending on the node type, this might be plain text from the template, or one branch of an #if, or the value of a $reference, etc.

Annotations
@Override