public final class MsgNode extends AbstractSoyNode implements SoyNode.ExprHolderNode, SoyNode.MsgBlockNode
The AST will be one of the following
RawTextNode
RawTextNode and MsgPlaceholderNode
MsgPluralNode
MsgSelectNode
Important: Do not use outside of Soy code (treat as superpackage-private).
| Modifier and Type | Class and Description |
|---|---|
static class |
MsgNode.PlaceholderInfo |
SoyNode.BlockCommandNode, SoyNode.BlockNode, SoyNode.CommandNode, SoyNode.ConditionalBlockNode, SoyNode.ExprHolderNode, SoyNode.Kind, SoyNode.LocalVarBlockNode, SoyNode.LocalVarInlineNode, SoyNode.LocalVarNode, SoyNode.MsgBlockNode, SoyNode.MsgPlaceholderInitialNode, SoyNode.MsgSubstUnitNode, SoyNode.ParentSoyNode<N extends SoyNode>, SoyNode.RenderUnitNode, SoyNode.SplitLevelTopNode<N extends SoyNode>, SoyNode.StandaloneNode, SoyNode.StatementNode| Constructor and Description |
|---|
MsgNode(int id,
SourceLocation location,
String commandName,
List<CommandTagAttribute> attributes,
ErrorReporter errorReporter) |
| Modifier and Type | Method and Description |
|---|---|
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 |
calculateSubstitutionInfo(ErrorReporter reporter) |
void |
clearChildren()
Clears the list of children.
|
MsgNode |
copy(CopyState copyState)
Copies this node.
|
void |
ensureSubstUnitInfoHasNotBeenAccessed()
This class lazily allocates some datastructures for accessing data about nested placeholders.
|
List<ExprRootNode> |
getAndRemoveGenderExprs()
Returns the list of expressions for gender values and sets that field to null.
|
N |
getChild(int index)
Gets the child at the given index.
|
int |
getChildIndex(Node child)
Finds the index of the given child.
|
List<N> |
getChildren()
Gets the list of children.
|
String |
getCommandName()
Returns the Soy command name.
|
String |
getCommandText()
Returns the command text (may be the empty string).
|
String |
getContentType()
Returns the content type for the TC.
|
String |
getDesc()
Returns the description string for translators.
|
com.google.common.collect.ImmutableList<ExprRootNode> |
getExprList()
Returns the list of expressions in this node.
|
SoyNode.Kind |
getKind()
Returns this node's kind (corresponding to this node's specific type).
|
String |
getMeaning()
Returns the meaning string if set, otherwise null (usually null).
|
MsgNode.PlaceholderInfo |
getPlaceholder(MsgPlaceholderNode placeholderNode)
Gets the placeholder name for a given placeholder node.
|
String |
getPluralVarName(MsgPluralNode pluralNode)
Gets the variable name associated with a given plural node.
|
MsgPlaceholderNode |
getRepPlaceholderNode(String placeholderName)
Gets the representative placeholder node for a given placeholder name.
|
MsgPluralNode |
getRepPluralNode(String pluralVarName)
Gets the representative plural node for a given plural variable name.
|
MsgSelectNode |
getRepSelectNode(String selectVarName)
Gets the representative select node for a given select variable name.
|
String |
getSelectVarName(MsgSelectNode selectNode)
Gets the variable name associated with a given select node.
|
protected String |
getTagString() |
protected String |
getTagString(boolean selfEnding) |
com.google.common.collect.ImmutableMap<String,SoyNode.MsgSubstUnitNode> |
getVarNameToRepNodeMap()
Getter for the generated map from substitution unit var name to representative node.
|
boolean |
isHidden()
Returns whether the message should be added as 'hidden' in the TC.
|
boolean |
isPlrselMsg()
Returns whether this is a plural or select message.
|
boolean |
isPluralMsg()
Returns whether this is a plural message.
|
boolean |
isRawTextMsg()
Returns whether this is a raw text message.
|
boolean |
isSelectMsg()
Returns whether this is a select message.
|
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.
|
String |
toSourceString()
Builds a Soy source string that could be the source for this node.
|
getId, getParent, getSourceLocation, setId, toStringcouldHaveSyntaxVersionAtLeast, equals, getNearestAncestor, getSyntaxVersionUpperBound, hasAncestor, hashCode, maybeSetSyntaxVersionUpperBound, setParentclone, finalize, getClass, notify, notifyAll, wait, wait, waitaddChild, addChild, addChildren, addChildren, appendSourceStringForChildren, clearChildren, getChild, getChildIndex, getChildren, numChildren, removeChild, removeChild, replaceChild, replaceChildcouldHaveSyntaxVersionAtLeast, getNearestAncestor, getSourceLocation, getSyntaxVersionUpperBound, hasAncestor, maybeSetSyntaxVersionUpperBound, setParentgetCommandNamepublic MsgNode(int id,
SourceLocation location,
String commandName,
List<CommandTagAttribute> attributes,
ErrorReporter errorReporter)
public SoyNode.Kind getKind()
SoyNode@Nullable public List<ExprRootNode> getAndRemoveGenderExprs()
Note that this node's command text will still contain the substring genders="...". We think this is okay since the command text is only used for reporting errors (in fact, it might be good as a reminder of how the msg was originally written).
public void calculateSubstitutionInfo(ErrorReporter reporter)
public com.google.common.collect.ImmutableList<ExprRootNode> getExprList()
SoyNode.ExprHolderNodegetExprList in interface SoyNode.ExprHolderNode@Nullable public String getMeaning()
public String getDesc()
public boolean isHidden()
public String getContentType()
public boolean isPlrselMsg()
public boolean isSelectMsg()
public boolean isPluralMsg()
public boolean isRawTextMsg()
public void ensureSubstUnitInfoHasNotBeenAccessed()
public MsgPlaceholderNode getRepPlaceholderNode(String placeholderName)
placeholderName - The placeholder name.public MsgNode.PlaceholderInfo getPlaceholder(MsgPlaceholderNode placeholderNode)
placeholderNode - The placeholder node.public MsgPluralNode getRepPluralNode(String pluralVarName)
pluralVarName - The plural variable name.public String getPluralVarName(MsgPluralNode pluralNode)
pluralNode - The plural node.public MsgSelectNode getRepSelectNode(String selectVarName)
selectVarName - The select variable name.public String getSelectVarName(MsgSelectNode selectNode)
selectNode - The select node.public com.google.common.collect.ImmutableMap<String,SoyNode.MsgSubstUnitNode> getVarNameToRepNodeMap()
public String getCommandText()
SoyNode.CommandNodegetCommandText in interface SoyNode.CommandNodepublic String toSourceString()
NodeNote: 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.
toSourceString in interface Nodepublic MsgNode copy(CopyState copyState)
SoyNodeAll copy() overrides should follow this contract:
{@literal @}Override public T copy(CopyState copyState) {
return new T(this, copyState);
}
TODO(lukes): The usecases for a copy method are few and far between. Making the AST nodes immutable (or at least unmodifiable) would be preferable to maintaining our copy() methods.
Don't clone nodes unless you know what you're doing. The Soy AST is not actually a tree (it contains back edges from variables to their definitions), and naively copying nodes can result in pointers into stale ASTs
The copied nodes will have the same ids as the original nodes. If you need to copy a subtree
with new ids assigned to the copied nodes, use SoyTreeUtils.cloneWithNewIds(T, com.google.template.soy.base.internal.IdGenerator).
public int numChildren()
ParentNodenumChildren in interface ParentNode<N extends SoyNode>public N getChild(int index)
ParentNodegetChild in interface ParentNode<N extends SoyNode>index - The index of the child to get.public int getChildIndex(Node child)
ParentNodegetChildIndex in interface ParentNode<N extends SoyNode>child - The child to find the index of.public List<N> getChildren()
ParentNodeNote: 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.
getChildren in interface ParentNode<N extends SoyNode>public void addChild(N child)
ParentNodeaddChild in interface ParentNode<N extends SoyNode>child - The child to add.public void addChild(int index,
N child)
ParentNodeaddChild in interface ParentNode<N extends SoyNode>index - The index to add the child at.child - The child to add.public void removeChild(int index)
ParentNoderemoveChild in interface ParentNode<N extends SoyNode>index - The index of the child to remove.public void removeChild(N child)
ParentNoderemoveChild in interface ParentNode<N extends SoyNode>child - The child to remove.public void replaceChild(int index,
N newChild)
ParentNodereplaceChild in interface ParentNode<N extends SoyNode>index - The index of the child to replace.newChild - The new child.public void replaceChild(N currChild,
N newChild)
ParentNodereplaceChild in interface ParentNode<N extends SoyNode>currChild - The current child to be replaced.newChild - The new child.public void clearChildren()
ParentNodeclearChildren in interface ParentNode<N extends SoyNode>public void addChildren(List<? extends N> children)
ParentNodeaddChildren in interface ParentNode<N extends SoyNode>children - The children to add.public void addChildren(int index,
List<? extends N> children)
ParentNodeaddChildren in interface ParentNode<N extends SoyNode>index - The index to add the children at.children - The children to add.public void appendSourceStringForChildren(StringBuilder sb)
ParentNodeappendSourceStringForChildren in interface ParentNode<N extends SoyNode>sb - The StringBuilder to which to append the children's source strings.public String getCommandName()
SoyNode.CommandNodegetCommandName in interface SoyNode.CommandNodeprotected String getTagString()
protected final String getTagString(boolean selfEnding)