com.google.template.soy.soytree
Class AbstractParentCommandNode<N extends SoyNode>

java.lang.Object
  extended by com.google.template.soy.basetree.AbstractNode
      extended by com.google.template.soy.soytree.AbstractSoyNode
          extended by com.google.template.soy.soytree.AbstractCommandNode
              extended by com.google.template.soy.soytree.AbstractParentCommandNode<N>
All Implemented Interfaces:
Node, ParentNode<N>, SoyNode, SoyNode.CommandNode, SoyNode.ParentSoyNode<N>
Direct Known Subclasses:
AbstractBlockCommandNode, CallNode, ForeachNode, MsgPluralNode, MsgSelectNode, PrintNode, SwitchNode

public abstract class AbstractParentCommandNode<N extends SoyNode>
extends AbstractCommandNode
implements SoyNode.ParentSoyNode<N>

Abstract implementation of a ParentNode and CommandNode.

Important: Do not use outside of Soy code (treat as superpackage-private).


Nested Class Summary
 
Nested classes/interfaces inherited from interface com.google.template.soy.soytree.SoyNode
SoyNode.BlockCommandNode, SoyNode.BlockNode, SoyNode.CommandNode, SoyNode.ConditionalBlockNode, SoyNode.ExprHolderNode, SoyNode.Kind, SoyNode.LocalVarBlockNode, SoyNode.LocalVarInlineNode, SoyNode.LocalVarNode, SoyNode.LoopNode, SoyNode.MsgBlockNode, SoyNode.MsgPlaceholderInitialNode, SoyNode.ParentSoyNode<N extends SoyNode>, SoyNode.RenderUnitNode, SoyNode.SplitLevelTopNode<N extends SoyNode>, SoyNode.StandaloneNode, SoyNode.StatementNode, SoyNode.SyntaxVersion
 
Field Summary
 
Fields inherited from class com.google.template.soy.basetree.AbstractNode
SPACES
 
Constructor Summary
protected AbstractParentCommandNode(AbstractParentCommandNode<N> orig)
          Copy constructor.
  AbstractParentCommandNode(int id, String commandName, String commandText)
           
 
Method Summary
 void addChild(int index, N child)
          Adds the given child at the given index (shifting existing children if necessary).
 void addChild(N child)
          Adds the given child.
 void addChildren(int index, List<? extends N> children)
          Adds the given children at the given index (shifting existing children if necessary).
 void addChildren(List<? extends N> children)
          Adds the given children.
 void appendSourceStringForChildren(StringBuilder sb)
          Appends the source strings for all the children to the given StringBuilder.
 void appendTreeStringForChildren(StringBuilder sb, int indent)
          Appends the tree strings for all the children to the given StringBuilder, at one further indentation level (3 spaces) than the given current indentation level.
 void clearChildren()
          Clears the list of children.
 N getChild(int index)
          Gets the child at the given index.
 int getChildIndex(N child)
          Finds the index of the given child.
 List<N> getChildren()
          Gets the list of children.
 Boolean needsEnvFrameDuringInterp()
          Returns whether this node needs an env frame during interpretation, or null if unknown.
 int numChildren()
          Gets the number of children.
 void removeChild(int index)
          Removes the child at the given index.
 void removeChild(N child)
          Removes the given child.
 void replaceChild(int index, N newChild)
          Replaces the child at the given index with the given new child.
 void replaceChild(N currChild, N newChild)
          Replaces the given current child with the given new child.
 void setNeedsEnvFrameDuringInterp(Boolean needsEnvFrameDuringInterp)
          Sets whether this node needs an env frame when the template is being interpreted.
 String toSourceString()
          Builds a Soy source string that could be the source for this node.
 String toTreeString(int indent)
          Builds a string that visually shows the subtree rooted at this node (for debugging).
 
Methods inherited from class com.google.template.soy.soytree.AbstractCommandNode
buildTagStringHelper, buildTagStringHelper, getCommandName, getCommandText, getTagString
 
Methods inherited from class com.google.template.soy.soytree.AbstractSoyNode
clone, getId, getParent, getSourceLocation, getSyntaxVersion, maybeSetSyntaxVersion, setId, setSourceLocation, toString
 
Methods inherited from class com.google.template.soy.basetree.AbstractNode
getNearestAncestor, hasAncestor, setParent
 
Methods inherited from class java.lang.Object
equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
 
Methods inherited from interface com.google.template.soy.soytree.SoyNode
clone, getId, getKind, getParent, getSourceLocation, getSyntaxVersion, setId, setSourceLocation
 
Methods inherited from interface com.google.template.soy.basetree.Node
getNearestAncestor, hasAncestor, setParent
 

Constructor Detail

AbstractParentCommandNode

public AbstractParentCommandNode(int id,
                                 String commandName,
                                 String commandText)
Parameters:
id - The id for this node.
commandName - The name of the Soy command.
commandText - The command text, or empty string if none.

AbstractParentCommandNode

protected AbstractParentCommandNode(AbstractParentCommandNode<N> orig)
Copy constructor.

Parameters:
orig - The node to copy.
Method Detail

toSourceString

public String toSourceString()
Description copied from interface: Node
Builds a Soy source string that could be the source for this node. Note that this is not the actual original source string, but a (sort of) canonical equivalent. Note: Some nodes do not have a direct mapping to Soy source (such as nodes created during some optimization passes). Thus this method may not always be supported.

Specified by:
toSourceString in interface Node
Overrides:
toSourceString in class AbstractCommandNode
Returns:
A Soy string that could be the source for this node.

setNeedsEnvFrameDuringInterp

public void setNeedsEnvFrameDuringInterp(Boolean needsEnvFrameDuringInterp)
Description copied from interface: SoyNode.ParentSoyNode
Sets whether this node needs an env frame when the template is being interpreted.

Specified by:
setNeedsEnvFrameDuringInterp in interface SoyNode.ParentSoyNode<N extends SoyNode>
Parameters:
needsEnvFrameDuringInterp - Whether this node needs an env frame during interpretation, or null if unknown.

needsEnvFrameDuringInterp

public Boolean needsEnvFrameDuringInterp()
Description copied from interface: SoyNode.ParentSoyNode
Returns whether this node needs an env frame during interpretation, or null if unknown.

Specified by:
needsEnvFrameDuringInterp in interface SoyNode.ParentSoyNode<N extends SoyNode>

numChildren

public int numChildren()
Description copied from interface: ParentNode
Gets the number of children.

Specified by:
numChildren in interface ParentNode<N extends SoyNode>
Returns:
The number of children.

getChild

public N getChild(int index)
Description copied from interface: ParentNode
Gets the child at the given index.

Specified by:
getChild in interface ParentNode<N extends SoyNode>
Parameters:
index - The index of the child to get.
Returns:
The child at the given index.

getChildIndex

public int getChildIndex(N child)
Description copied from interface: ParentNode
Finds the index of the given child.

Specified by:
getChildIndex in interface ParentNode<N extends SoyNode>
Parameters:
child - The child to find the index of.
Returns:
The index of the given child, or -1 if the given child is not a child of this node.

getChildren

public List<N> getChildren()
Description copied from interface: ParentNode
Gets the list of children. Note: The returned list may not be a copy. Please do not modify the list directly. Instead, use the other methods in this class that are intended for modifying children. Also, if you're iterating over the children list as you're modifying it, then you should first make a copy of the children list to iterate over, in order to avoid ConcurrentModificationException.

Specified by:
getChildren in interface ParentNode<N extends SoyNode>
Returns:
The list of children.

addChild

public void addChild(N child)
Description copied from interface: ParentNode
Adds the given child.

Specified by:
addChild in interface ParentNode<N extends SoyNode>
Parameters:
child - The child to add.

addChild

public void addChild(int index,
                     N child)
Description copied from interface: ParentNode
Adds the given child at the given index (shifting existing children if necessary).

Specified by:
addChild in interface ParentNode<N extends SoyNode>
Parameters:
index - The index to add the child at.
child - The child to add.

removeChild

public void removeChild(int index)
Description copied from interface: ParentNode
Removes the child at the given index.

Specified by:
removeChild in interface ParentNode<N extends SoyNode>
Parameters:
index - The index of the child to remove.

removeChild

public void removeChild(N child)
Description copied from interface: ParentNode
Removes the given child.

Specified by:
removeChild in interface ParentNode<N extends SoyNode>
Parameters:
child - The child to remove.

replaceChild

public void replaceChild(int index,
                         N newChild)
Description copied from interface: ParentNode
Replaces the child at the given index with the given new child.

Specified by:
replaceChild in interface ParentNode<N extends SoyNode>
Parameters:
index - The index of the child to replace.
newChild - The new child.

replaceChild

public void replaceChild(N currChild,
                         N newChild)
Description copied from interface: ParentNode
Replaces the given current child with the given new child.

Specified by:
replaceChild in interface ParentNode<N extends SoyNode>
Parameters:
currChild - The current child to be replaced.
newChild - The new child.

clearChildren

public void clearChildren()
Description copied from interface: ParentNode
Clears the list of children.

Specified by:
clearChildren in interface ParentNode<N extends SoyNode>

addChildren

public void addChildren(List<? extends N> children)
Description copied from interface: ParentNode
Adds the given children.

Specified by:
addChildren in interface ParentNode<N extends SoyNode>
Parameters:
children - The children to add.

addChildren

public void addChildren(int index,
                        List<? extends N> children)
Description copied from interface: ParentNode
Adds the given children at the given index (shifting existing children if necessary).

Specified by:
addChildren in interface ParentNode<N extends SoyNode>
Parameters:
index - The index to add the children at.
children - The children to add.

appendSourceStringForChildren

public void appendSourceStringForChildren(StringBuilder sb)
Description copied from interface: ParentNode
Appends the source strings for all the children to the given StringBuilder.

Specified by:
appendSourceStringForChildren in interface ParentNode<N extends SoyNode>
Parameters:
sb - The StringBuilder to which to append the children's source strings.

appendTreeStringForChildren

public void appendTreeStringForChildren(StringBuilder sb,
                                        int indent)
Description copied from interface: ParentNode
Appends the tree strings for all the children to the given StringBuilder, at one further indentation level (3 spaces) than the given current indentation level.

Specified by:
appendTreeStringForChildren in interface ParentNode<N extends SoyNode>
Parameters:
sb - The StringBuilder to which to append the children's tree strings.
indent - The current indentation level of this parent node.

toTreeString

public String toTreeString(int indent)
Description copied from interface: Node
Builds a string that visually shows the subtree rooted at this node (for debugging). Each line of the string will be indented by the given indentation amount. You should pass an indentation of 0 unless this method is being called as part of building a larger tree string.

Specified by:
toTreeString in interface Node
Overrides:
toTreeString in class AbstractNode
Parameters:
indent - The indentation for each line of the tree string (usually pass 0).
Returns:
A string that visually shows the subtree rooted at this node.