public interface Node
Important: Do not use outside of Soy code (treat as superpackage-private).
| Modifier and Type | Method and Description |
|---|---|
Node |
clone()
Copies this node.
|
boolean |
couldHaveSyntaxVersionAtLeast(SyntaxVersion syntaxVersionCutoff)
Returns false if we know that this node's syntax version must be lower than the given value.
|
<N extends Node> |
getNearestAncestor(Class<N> ancestorClass)
Finds and returns this node's nearest ancestor of the given type.
|
ParentNode<?> |
getParent()
Gets this node's parent.
|
SourceLocation |
getSourceLocation()
Returns the source location (file path and line number) for this node.
|
SyntaxVersionBound |
getSyntaxVersionBound()
Returns a pair (syntaxVersion, reasonStr), where the first item is the lowest known upper bound
(exclusive!) for the syntax version of this node, and the second item is a user-friendly
explanation of the reason for the bound.
|
boolean |
hasAncestor(Class<? extends Node> ancestorClass)
Determines whether this node has an ancestor of the given type.
|
void |
maybeSetSyntaxVersionBound(SyntaxVersionBound newSyntaxVersionBound)
Records a newly discovered upper bound for the syntax version of this node.
|
void |
setParent(ParentNode<?> parent)
Sets this node's parent.
|
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).
|
@Nullable SyntaxVersionBound getSyntaxVersionBound()
void maybeSetSyntaxVersionBound(SyntaxVersionBound newSyntaxVersionBound)
newSyntaxVersionBound - A newly discovered upper bound (exclusive!) for the syntax version
of this node.boolean couldHaveSyntaxVersionAtLeast(SyntaxVersion syntaxVersionCutoff)
syntaxVersionCutoff - The syntax version cutoff to check.SourceLocation getSourceLocation()
void setParent(ParentNode<?> parent)
parent - The parent node to set.ParentNode<?> getParent()
boolean hasAncestor(Class<? extends Node> ancestorClass)
ancestorClass - The type of ancestor to look for.<N extends Node> N getNearestAncestor(Class<N> ancestorClass)
N - The type of ancestor to retrieve.ancestorClass - The class object for the type of ancestor to retrieve.String toSourceString()
UnsupportedOperationException - If this node does not directly map to Soy source.String toTreeString(int indent)
indent - The indentation for each line of the tree string (usually pass 0).Node clone()
All clone() overrides should follow this contract:
{@literal @}Override public T clone() {
return new T(this);
}
NOTE: this means we do not ultimately delegate to Object.clone(), ever.
TODO(lukes): The usecases for a clone method are few and far between. Making the AST nodes immutable (or at least unmodifiable) would be preferable to maintaining our clone() methods.