public interface Node
The top level definition is the base node interface.
Important: Do not use outside of Soy code (treat as superpackage-private).
| Modifier and Type | Method and Description |
|---|---|
Node |
copy(CopyState copyState)
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.
|
SyntaxVersionUpperBound |
getSyntaxVersionUpperBound()
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 |
maybeSetSyntaxVersionUpperBound(SyntaxVersionUpperBound 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.
|
@Nullable SyntaxVersionUpperBound getSyntaxVersionUpperBound()
void maybeSetSyntaxVersionUpperBound(SyntaxVersionUpperBound 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()
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.
UnsupportedOperationException - If this node does not directly map to Soy source.Node copy(CopyState copyState)
All 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