public class Node extends Object implements Serializable
Modifier and Type | Class and Description |
---|---|
static class |
Node.AncestorIterable
Iterator to go up the ancestor tree.
|
static class |
Node.SideEffectFlags
A helper class for getting and setting the side-effect flags.
|
static class |
Node.TypeDeclarationNode
Represents a node in the type declaration AST.
|
Modifier and Type | Field and Description |
---|---|
static int |
ACCESS_MODIFIER |
static int |
ADDED_BLOCK |
static int |
ANALYZED_DURING_GTI |
static int |
ARROW_FN |
static int |
ASYNC_FN |
static int |
CHANGE_TIME |
static int |
COLUMN_BITS
COLUMN_BITS represents how many of the lower-order bits of
sourcePosition are reserved for storing the column number.
|
static int |
COLUMN_MASK
COLUMN_MASK stores a value where bits storing the column number
are set, and bits storing the line are not set.
|
static int |
COMPUTED_PROP_GETTER |
static int |
COMPUTED_PROP_METHOD |
static int |
COMPUTED_PROP_SETTER |
static int |
COMPUTED_PROP_VARIABLE |
static int |
CONSTANT_PROPERTY_DEF |
static int |
CONSTRUCT_SIGNATURE |
static int |
DECLARED_TYPE_EXPR |
static int |
DIRECT_EVAL |
static int |
DIRECTIVES |
static int |
EXPORT_ALL_FROM |
static int |
EXPORT_DEFAULT |
static int |
FEATURE_SET |
static int |
FLAG_ARGUMENTS_UNMODIFIED |
static int |
FLAG_GLOBAL_STATE_UNMODIFIED |
static int |
FLAG_LOCAL_RESULTS |
static int |
FLAG_NO_THROWS |
static int |
FLAG_THIS_UNMODIFIED |
static int |
FREE_CALL |
static int |
GENERATOR_FN |
static int |
GENERATOR_MARKER |
static int |
GENERATOR_SAFE |
static int |
GENERIC_TYPE_LIST |
static int |
GOOG_MODULE |
static int |
GOOG_MODULE_REQUIRE |
static int |
IMPLEMENTS |
static int |
INCRDECR_PROP |
static int |
INFERRED_FUNCTION |
static int |
INPUT_ID |
static int |
IS_CONSTANT_NAME |
static int |
IS_CONSTANT_VAR |
static int |
IS_ES6_CLASS |
static int |
IS_MODULE_NAME |
static int |
IS_NAMESPACE |
static int |
JSDOC_INFO_PROP |
static int |
MAX_COLUMN_NUMBER
MAX_COLUMN_NUMBER represents the maximum column number that can
be represented.
|
static int |
NO_SIDE_EFFECTS |
static int |
NON_INDEXABLE |
static int |
OPT_ARG_NAME |
static int |
OPT_ES6_TYPED |
static int |
ORIGINALNAME_PROP |
protected Node |
parent |
static int |
PARSE_RESULTS |
static int |
QUOTED_PROP |
static int |
RAW_STRING_VALUE |
static int |
REFLECTED_OBJECT |
static int |
SIDE_EFFECT_FLAGS |
static int |
SIDE_EFFECTS_ALL |
static int |
SIDE_EFFECTS_FLAGS_MASK |
static int |
SLASH_V |
static int |
STATIC_MEMBER |
static int |
STATIC_SOURCE_FILE |
static int |
SYNTHETIC_BLOCK_PROP |
static int |
TRANSPILED |
static int |
TYPE_BEFORE_CAST |
static int |
VAR_ARGS_NAME |
static int |
WAS_PREVIOUSLY_PROVIDED |
static int |
YIELD_FOR |
Constructor and Description |
---|
Node(Token nodeType) |
Node(Token nodeType,
int lineno,
int charno) |
Node(Token nodeType,
Node child) |
Node(Token nodeType,
Node child,
int lineno,
int charno) |
Node(Token nodeType,
Node left,
Node right) |
Node(Token nodeType,
Node left,
Node mid,
Node right) |
Modifier and Type | Method and Description |
---|---|
void |
addChildAfter(Node newChild,
Node node)
Add 'child' after 'node'.
|
void |
addChildBefore(Node newChild,
Node node)
Add 'child' before 'node'.
|
void |
addChildrenAfter(Node children,
Node node)
Add all children after 'node'.
|
void |
addChildrenToBack(Node children) |
void |
addChildrenToFront(Node children) |
void |
addChildToBack(Node child) |
void |
addChildToFront(Node child) |
void |
appendStringTree(Appendable appendable) |
String |
checkTreeEquals(Node actual)
Checks if the subtree under this node is the same as another subtree.
|
String |
checkTreeEqualsIncludingJsDoc(Node actual)
Checks if the subtree under this node is the same as another subtree.
|
Iterable<Node> |
children()
Return an iterable object that iterates over this node's children.
|
Node |
cloneNode() |
protected Node |
cloneNode(boolean cloneTypeExprs) |
Node |
clonePropsFrom(Node other)
Clone the properties from the provided node without copying
the property object.
|
Node |
cloneTree() |
Node |
cloneTree(boolean cloneTypeExprs) |
Node |
detach()
Removes this node from its parent.
|
void |
detachChildren()
Removes all children from this node and isolates the children from each
other.
|
Node |
detachFromParent()
Removes this node from its parent.
|
protected static int |
extractCharno(int lineCharNo)
Extracts the character number and character number from a merged line
char number (see
mergeLineCharNo(int, int) ). |
protected static int |
extractLineno(int lineCharNo)
Extracts the line number and character number from a merged line char
number (see
mergeLineCharNo(int, int) ). |
Node |
getAncestor(int level)
Gets the ancestor node relative to this.
|
Node.AncestorIterable |
getAncestors()
Iterates all of the node's ancestors excluding itself.
|
boolean |
getBooleanProp(int propType) |
int |
getChangeTime()
Returns the time of the last change for this node
|
int |
getCharno() |
Node |
getChildAtIndex(int i)
Gets the ith child, note that this is O(N) where N is the number of children.
|
Node |
getChildBefore(Node child) |
int |
getChildCount() |
Node.TypeDeclarationNode |
getDeclaredTypeExpression()
Returns the syntactical type specified on this node.
|
Set<String> |
getDirectives()
Returns the set of ES5 directives for this node.
|
double |
getDouble()
Can only be called when getType() == TokenStream.NUMBER
|
int |
getExistingIntProp(int propType) |
Node |
getFirstChild() |
Node |
getFirstFirstChild()
Get the first child of the first child.
|
Node |
getGrandparent() |
int |
getIndexOfChild(Node child)
Gets the index of a child, note that this is O(N) where N is the number of children.
|
InputId |
getInputId() |
int |
getIntProp(int propType)
Returns the integer value for the property, or 0 if the property
is not defined.
|
JSDocInfo |
getJSDocInfo()
Get the
JSDocInfo attached to this node. |
JSType |
getJSType()
Returns the compiled inferred type on this node.
|
JSType |
getJSTypeBeforeCast()
Returns the type of this node before casting.
|
Node |
getLastChild() |
int |
getLength() |
int |
getLineno() |
Node |
getNext() |
String |
getOriginalName()
The original name of this node, if the node has been renamed.
|
String |
getOriginalQualifiedName()
This function takes a set of GETPROP nodes and produces a string that is each property
separated by dots.
|
Node |
getParent() |
Node |
getPrevious() |
Object |
getProp(int propType) |
String |
getQualifiedName()
This function takes a set of GETPROP nodes and produces a string that is each property
separated by dots.
|
Node |
getSecondChild() |
int |
getSideEffectFlags()
Returns the side effects flags for this node.
|
String |
getSourceFileName() |
int |
getSourceOffset() |
int |
getSourcePosition() |
StaticSourceFile |
getStaticSourceFile()
Returns the source file associated with this input.
|
String |
getString()
Can only be called when node has String context.
|
Token |
getToken() |
TypeI |
getTypeI() |
TypeI |
getTypeIBeforeCast() |
TypeI |
getTypeIIfOld()
Gets the OTI
JSType associated with this node if any, and null otherwise. |
boolean |
hasChild(Node child) |
boolean |
hasChildren() |
boolean |
hasMoreThanOneChild()
Check for more than one child more efficiently than by iterating over all
the children as is done with Node.getChildCount().
|
boolean |
hasOneChild()
Check for one child more efficiently than by iterating over all the
children as is done with Node.getChildCount().
|
boolean |
hasProps() |
boolean |
hasTwoChildren()
Check for two children more efficiently than
getChildCount() == 2 |
boolean |
hasXChildren(int x)
Check for has exactly the number of specified children.
|
boolean |
hasZeroOrOneChild()
Check for zero or one child more efficiently than by iterating over all the
children as is done with Node.getChildCount().
|
boolean |
isAdd()
AST type check methods
|
boolean |
isAddedBlock()
Returns whether this is an added block that should not be considered
a real source block.
|
boolean |
isAnd() |
boolean |
isArrayLit() |
boolean |
isArrayPattern() |
boolean |
isArrowFunction()
Returns whether this node is a arrow function node.
|
boolean |
isAssign() |
boolean |
isAssignAdd() |
boolean |
isAsyncFunction()
Returns whether this is an async function node.
|
boolean |
isBreak() |
boolean |
isCall() |
boolean |
isCallSignature() |
boolean |
isCase() |
boolean |
isCast() |
boolean |
isCatch() |
boolean |
isClass() |
boolean |
isClassMembers() |
boolean |
isComma() |
boolean |
isComputedProp() |
boolean |
isConst() |
boolean |
isContinue() |
boolean |
isDebugger() |
boolean |
isDec() |
boolean |
isDefaultCase() |
boolean |
isDefaultValue() |
boolean |
isDelProp() |
boolean |
isDescendantOf(Node node) |
boolean |
isDestructuringLhs() |
boolean |
isDestructuringPattern() |
boolean |
isDo() |
boolean |
isEmpty() |
boolean |
isEquivalentTo(Node node)
Returns true if this node is equivalent semantically to another
|
boolean |
isEquivalentToShallow(Node node)
Checks equivalence without going into child nodes
|
boolean |
isEquivalentToTyped(Node node)
Returns true if this node is equivalent semantically to another and the types are equivalent.
|
boolean |
isEquivalentWithSideEffectsTo(Node node)
Returns true if this node is equivalent semantically to another including side efffects.
|
boolean |
isEquivalentWithSideEffectsToShallow(Node node)
Returns true if this node is equivalent semantically to another including side efffects.
|
boolean |
isExport() |
boolean |
isExprResult() |
boolean |
isFalse() |
boolean |
isFor()
Deprecated.
|
boolean |
isForIn() |
boolean |
isForOf() |
boolean |
isFromExterns() |
boolean |
isFunction() |
boolean |
isGeneratorFunction()
Returns whether this node is a generator function node.
|
boolean |
isGeneratorMarker()
Returns whether this node is a marker used in the translation of generators.
|
boolean |
isGeneratorSafe()
Used when translating ES6 generators.
|
boolean |
isGetElem() |
boolean |
isGetProp() |
boolean |
isGetterDef() |
boolean |
isHook() |
boolean |
isIf() |
boolean |
isImport() |
boolean |
isImportSpec() |
boolean |
isImportSpecs() |
boolean |
isImportStar() |
boolean |
isIn() |
boolean |
isInc() |
boolean |
isIndexable()
Whether this node should be indexed by static analysis / code indexing tools.
|
boolean |
isIndexSignature() |
boolean |
isInstanceOf() |
boolean |
isInterfaceMembers() |
boolean |
isLabel() |
boolean |
isLabelName() |
boolean |
isLet() |
boolean |
isLocalResultCall()
Returns true if this node is a function or constructor call that
returns a primitive or a local object (an object that has no other
references).
|
boolean |
isMemberFunctionDef() |
boolean |
isMemberVariableDef() |
boolean |
isModuleBody() |
boolean |
isName() |
boolean |
isNE() |
boolean |
isNew() |
boolean |
isNormalBlock() |
boolean |
isNoSideEffectsCall()
Returns true if this node is a function or constructor call that
has no side effects.
|
boolean |
isNot() |
boolean |
isNull() |
boolean |
isNumber() |
boolean |
isObjectLit() |
boolean |
isObjectPattern() |
boolean |
isOnlyModifiesArgumentsCall() |
boolean |
isOnlyModifiesThisCall() |
boolean |
isOptionalArg()
Returns whether this node is an optional argument node.
|
boolean |
isOptionalEs6Typed()
Returns whether this node is an optional node in the ES6 Typed syntax.
|
boolean |
isOr() |
boolean |
isParamList() |
boolean |
isQualifiedName()
Returns whether a node corresponds to a simple or a qualified name, such as
x or a.b.c or this.a . |
boolean |
isQuotedString()
This should only be called for STRING nodes children of OBJECTLIT.
|
boolean |
isRecordType() |
boolean |
isRegExp() |
boolean |
isRest() |
boolean |
isReturn() |
boolean |
isRoot() |
boolean |
isScript() |
boolean |
isSetterDef() |
boolean |
isSpread() |
boolean |
isStaticMember()
Returns whether this node is a static member node.
|
boolean |
isString() |
boolean |
isStringKey() |
boolean |
isSub() |
boolean |
isSuper() |
boolean |
isSwitch() |
boolean |
isSyntheticBlock()
Returns whether this is a synthetic block that should not be considered
a real source block.
|
boolean |
isTaggedTemplateLit() |
boolean |
isTemplateLit() |
boolean |
isTemplateLitSub() |
boolean |
isThis() |
boolean |
isThrow() |
boolean |
isTrue() |
boolean |
isTry() |
boolean |
isTypeOf() |
boolean |
isUnscopedQualifiedName()
Returns whether a node corresponds to a simple or a qualified name without
a "this" reference, such as
a.b.c , but not this.a
. |
boolean |
isValidAssignmentTarget() |
boolean |
isVanillaFor() |
boolean |
isVar() |
boolean |
isVarArgs()
Returns whether this node is a variable length argument node.
|
boolean |
isVoid() |
boolean |
isWhile() |
boolean |
isWith() |
boolean |
isYield() |
boolean |
isYieldFor()
Returns whether this node is a generator node.
|
void |
makeNonIndexable() |
boolean |
matchesQualifiedName(Node n)
Returns whether a node matches a simple or a qualified name, such as
x or
a.b.c or this.a . |
boolean |
matchesQualifiedName(String name)
Returns whether a node matches a simple or a qualified name, such as
x or a.b.c or this.a . |
boolean |
mayMutateArguments()
Returns true if this is a new/call that may mutate its arguments.
|
boolean |
mayMutateGlobalStateOrThrow()
Returns true if this is a new/call that may mutate global state or throw.
|
protected static int |
mergeLineCharNo(int lineno,
int charno)
Merges the line number and character number in one integer.
|
static Node |
newNumber(double number) |
static Node |
newNumber(double number,
int lineno,
int charno) |
static Node |
newString(String str) |
static Node |
newString(String str,
int lineno,
int charno) |
static Node |
newString(Token token,
String str) |
static Node |
newString(Token token,
String str,
int lineno,
int charno) |
void |
putBooleanProp(int propType,
boolean value) |
void |
putIntProp(int propType,
int value) |
void |
putProp(int propType,
Object value) |
void |
removeChild(Node child)
Detach a child from its parent and siblings.
|
Node |
removeChildAfter(Node prev) |
Node |
removeChildren() |
Node |
removeFirstChild()
Removes the first child of Node.
|
Node |
removeFirstOrChildAfter(Node prev)
Remove the child after the given child, or the first child if given null.
|
void |
removeProp(int propType) |
void |
replaceChild(Node child,
Node newChild)
Detaches child from Node and replaces it with newChild.
|
void |
replaceChildAfter(Node prevChild,
Node newChild) |
void |
replaceFirstOrChildAfter(Node prev,
Node newChild)
Detaches the child after the given child, or the first child if prev is null.
|
void |
replaceWith(Node newNode)
Detaches Node and replaces it with newNode.
|
void |
setChangeTime(int time)
This node was last changed at
time |
void |
setCharno(int charno) |
void |
setDeclaredTypeExpression(Node.TypeDeclarationNode typeExpression)
Sets the syntactical type specified on this node.
|
void |
setDirectives(Set<String> val)
Sets the ES5 directives on this node.
|
void |
setDouble(double value)
Can only be called when getType() == Token.NUMBER
|
void |
setGeneratorMarker(boolean isGeneratorMarker)
Sets whether this node is a marker used in the translation of generators.
|
void |
setGeneratorSafe(boolean isGeneratorSafe) |
void |
setInputId(InputId inputId) |
void |
setIsAddedBlock(boolean val)
Sets whether this is an added block that should not be considered
a real source block.
|
void |
setIsArrowFunction(boolean isArrow)
Sets whether this node is a arrow function node.
|
void |
setIsAsyncFunction(boolean isAsync)
Sets whether this node is an async function node.
|
void |
setIsGeneratorFunction(boolean isGenerator)
Sets whether this node is a generator node.
|
void |
setIsSyntheticBlock(boolean val)
Sets whether this is a synthetic block that should not be considered
a real source block.
|
Node |
setJSDocInfo(JSDocInfo info)
Sets the
JSDocInfo attached to this node. |
void |
setJSType(JSType jsType) |
void |
setLength(int length) |
void |
setLineno(int lineno) |
void |
setOptionalArg(boolean optionalArg)
Sets whether this node is an optional argument node.
|
void |
setOriginalName(String originalName) |
void |
setQuotedString()
This should only be called for STRING nodes children of OBJECTLIT.
|
void |
setSideEffectFlags(int flags)
Marks this function or constructor call's side effect flags.
|
void |
setSideEffectFlags(Node.SideEffectFlags flags) |
void |
setSourceEncodedPosition(int sourcePosition) |
void |
setSourceEncodedPositionForTree(int sourcePosition) |
void |
setSourceFileForTesting(String name)
Sets the source file to a non-extern file of the given name.
|
void |
setStaticMember(boolean isStatic)
Sets whether this node is a static member node.
|
void |
setStaticSourceFile(StaticSourceFile file) |
void |
setString(String value)
Can only be called for a Token.STRING or Token.NAME.
|
void |
setToken(Token token) |
void |
setTypeI(TypeI type) |
void |
setVarArgs(boolean varArgs)
Sets whether this node is a variable length argument node.
|
void |
setYieldFor(boolean isGenerator)
Sets whether this node is a generator node.
|
Iterable<Node> |
siblings()
Return an iterable object that iterates over this node's siblings,
including this Node but not any siblings that are before this one.
|
Node |
srcref(Node other) |
Node |
srcrefTree(Node other) |
String |
toString() |
String |
toString(boolean printSource,
boolean printAnnotations,
boolean printType) |
String |
toStringTree() |
Node |
useSourceInfoFrom(Node other)
Overwrite all the source information in this node with
that of
other . |
Node |
useSourceInfoFromForTree(Node other)
Overwrite all the source information in this node and its subtree with
that of
other . |
Node |
useSourceInfoIfMissingFrom(Node other)
Overwrite all the source information in this node with
that of
other iff the source info is missing. |
Node |
useSourceInfoIfMissingFromForTree(Node other)
Overwrite all the source information in this node and its subtree with
that of
other iff the source info is missing. |
Node |
useSourceInfoWithoutLengthIfMissingFrom(Node other)
Deprecated.
|
Node |
useSourceInfoWithoutLengthIfMissingFromForTree(Node other)
Deprecated.
|
public static final int JSDOC_INFO_PROP
public static final int VAR_ARGS_NAME
public static final int INCRDECR_PROP
public static final int QUOTED_PROP
public static final int OPT_ARG_NAME
public static final int SYNTHETIC_BLOCK_PROP
public static final int ADDED_BLOCK
public static final int ORIGINALNAME_PROP
public static final int SIDE_EFFECT_FLAGS
public static final int IS_CONSTANT_NAME
public static final int IS_NAMESPACE
public static final int DIRECTIVES
public static final int DIRECT_EVAL
public static final int FREE_CALL
public static final int STATIC_SOURCE_FILE
public static final int INPUT_ID
public static final int SLASH_V
public static final int INFERRED_FUNCTION
public static final int CHANGE_TIME
public static final int REFLECTED_OBJECT
public static final int STATIC_MEMBER
public static final int GENERATOR_FN
public static final int ARROW_FN
public static final int ASYNC_FN
public static final int YIELD_FOR
public static final int EXPORT_DEFAULT
public static final int EXPORT_ALL_FROM
public static final int IS_CONSTANT_VAR
public static final int GENERATOR_MARKER
public static final int GENERATOR_SAFE
public static final int RAW_STRING_VALUE
public static final int COMPUTED_PROP_METHOD
public static final int COMPUTED_PROP_GETTER
public static final int COMPUTED_PROP_SETTER
public static final int COMPUTED_PROP_VARIABLE
public static final int ANALYZED_DURING_GTI
public static final int CONSTANT_PROPERTY_DEF
public static final int DECLARED_TYPE_EXPR
public static final int TYPE_BEFORE_CAST
public static final int OPT_ES6_TYPED
public static final int GENERIC_TYPE_LIST
public static final int IMPLEMENTS
public static final int CONSTRUCT_SIGNATURE
public static final int ACCESS_MODIFIER
public static final int NON_INDEXABLE
public static final int PARSE_RESULTS
public static final int GOOG_MODULE
public static final int GOOG_MODULE_REQUIRE
public static final int FEATURE_SET
public static final int IS_MODULE_NAME
public static final int WAS_PREVIOUSLY_PROVIDED
public static final int IS_ES6_CLASS
public static final int TRANSPILED
public static final int COLUMN_BITS
public static final int MAX_COLUMN_NUMBER
public static final int COLUMN_MASK
public static final int FLAG_GLOBAL_STATE_UNMODIFIED
public static final int FLAG_THIS_UNMODIFIED
public static final int FLAG_ARGUMENTS_UNMODIFIED
public static final int FLAG_NO_THROWS
public static final int FLAG_LOCAL_RESULTS
public static final int SIDE_EFFECTS_FLAGS_MASK
public static final int SIDE_EFFECTS_ALL
public static final int NO_SIDE_EFFECTS
public Node(Token nodeType)
public Node(Token nodeType, int lineno, int charno)
public static Node newNumber(double number)
public static Node newNumber(double number, int lineno, int charno)
public final Token getToken()
public void setToken(Token token)
public boolean hasChildren()
@Nullable public Node getFirstFirstChild()
public Node getChildAtIndex(int i)
i
- The indexpublic int getIndexOfChild(Node child)
child
- The childpublic void addChildToFront(Node child)
public void addChildToBack(Node child)
public void addChildrenToFront(Node children)
public void addChildrenToBack(Node children)
public void addChildrenAfter(@Nullable Node children, @Nullable Node node)
public void removeChild(Node child)
public void replaceWith(Node newNode)
public void replaceChild(Node child, Node newChild)
public void replaceFirstOrChildAfter(@Nullable Node prev, Node newChild)
public Node clonePropsFrom(Node other)
other
- The node to clone properties from.public void removeProp(int propType)
public boolean hasProps()
public boolean getBooleanProp(int propType)
public int getIntProp(int propType)
public int getExistingIntProp(int propType)
public void putBooleanProp(int propType, boolean value)
public void putIntProp(int propType, int value)
public void setDeclaredTypeExpression(Node.TypeDeclarationNode typeExpression)
typeExpression
- @Nullable public Node.TypeDeclarationNode getDeclaredTypeExpression()
getJSType()
which returns the compiler-inferred type.@Nullable public JSType getJSTypeBeforeCast()
public double getDouble()
public void setDouble(double value)
value
- value to set.public String getString()
public void setString(String value)
value
- the value to set.public String toString(boolean printSource, boolean printAnnotations, boolean printType)
@CheckReturnValue public String toStringTree()
public void appendStringTree(Appendable appendable) throws IOException
IOException
public void setStaticSourceFile(@Nullable StaticSourceFile file)
public void setSourceFileForTesting(String name)
@Nullable public StaticSourceFile getStaticSourceFile()
public void setInputId(InputId inputId)
inputId
- @Nullable public InputId getInputId()
@Nullable public String getOriginalName()
public void setOriginalName(String originalName)
public boolean isIndexable()
public void makeNonIndexable()
public boolean isFromExterns()
public int getLength()
public void setLength(int length)
public int getLineno()
public int getCharno()
public int getSourceOffset()
public int getSourcePosition()
public void setLineno(int lineno)
public void setCharno(int charno)
public void setSourceEncodedPosition(int sourcePosition)
public void setSourceEncodedPositionForTree(int sourcePosition)
protected static int mergeLineCharNo(int lineno, int charno)
212-1
it is
adjusted to 212-1
.protected static int extractLineno(int lineCharNo)
mergeLineCharNo(int, int)
).protected static int extractCharno(int lineCharNo)
mergeLineCharNo(int, int)
).public Iterable<Node> children()
Return an iterable object that iterates over this node's children.
The iterator does not support the optional operation
Iterator.remove()
.
To iterate over a node's children, one can write
Node n = ...; for (Node child : n.children()) { ...
public Iterable<Node> siblings()
Return an iterable object that iterates over this node's siblings, including this Node but not any siblings that are before this one.
The iterator does not support the optional
operation Iterator.remove()
.
To iterate over a node's siblings including itself, one can write
Node n = ...; for (Node sibling : n.siblings()) { ...
@Nullable public Node getAncestor(int level)
level
- 0 = this, 1 = the parent, etc.public boolean isDescendantOf(Node node)
node
or a descendant of node
.public Node.AncestorIterable getAncestors()
public boolean hasOneChild()
public boolean hasTwoChildren()
getChildCount() == 2
public boolean hasZeroOrOneChild()
public boolean hasMoreThanOneChild()
public boolean hasXChildren(int x)
public int getChildCount()
public boolean hasChild(Node child)
@Nullable public String checkTreeEquals(Node actual)
this
as the
"expected" node and actual
as the "actual" node.@Nullable public String checkTreeEqualsIncludingJsDoc(Node actual)
this
as the "expected" node and actual
as the "actual" node.Object.equals(Object)
public final boolean isEquivalentTo(Node node)
public final boolean isEquivalentToShallow(Node node)
public final boolean isEquivalentWithSideEffectsTo(Node node)
public final boolean isEquivalentWithSideEffectsToShallow(Node node)
public final boolean isEquivalentToTyped(Node node)
@Nullable public String getQualifiedName()
@Nullable public String getOriginalQualifiedName()
public boolean isQualifiedName()
x
or a.b.c
or this.a
.public boolean matchesQualifiedName(String name)
x
or a.b.c
or this.a
.public boolean matchesQualifiedName(Node n)
x
or
a.b.c
or this.a
.public boolean isUnscopedQualifiedName()
a.b.c
, but not this.a
.public boolean isValidAssignmentTarget()
public Node detachFromParent()
public Node detach()
@Nullable public Node removeFirstChild()
@Nullable public Node removeChildren()
public void detachChildren()
public Node removeFirstOrChildAfter(@Nullable Node prev)
public Node cloneNode()
protected Node cloneNode(boolean cloneTypeExprs)
public Node cloneTree()
public Node cloneTree(boolean cloneTypeExprs)
@Deprecated public Node useSourceInfoWithoutLengthIfMissingFrom(Node other)
@Deprecated public Node useSourceInfoWithoutLengthIfMissingFromForTree(Node other)
public Node useSourceInfoFrom(Node other)
other
.public Node useSourceInfoFromForTree(Node other)
other
.public Node useSourceInfoIfMissingFrom(Node other)
other
iff the source info is missing.public Node useSourceInfoIfMissingFromForTree(Node other)
other
iff the source info is missing.@Nullable public JSType getJSType()
getDeclaredTypeExpression()
which returns the syntactically specified type.@Nullable public TypeI getTypeIIfOld()
JSType
associated with this node if any, and null otherwise.
NTI and OTI don't annotate the exact same AST nodes with types. (For example, OTI doesn't annotate dead code.) When OTI runs after NTI, the checks that use type information must only see the old types. They can call this method to avoid getting a new type for an AST node where OTI did not add a type. Calls to this method are intended to be temporary. As we migrate passes to support NTI natively, we will be replacing calls to this method with calls to getTypeI.
@Nullable public JSDocInfo getJSDocInfo()
JSDocInfo
attached to this node.null
if no JSDoc is attached to this nodepublic void setChangeTime(int time)
time
public int getChangeTime()
public void setVarArgs(boolean varArgs)
Token.NAME
nodes
used to define a Token.FUNCTION
's argument list.public boolean isVarArgs()
Token.NAME
nodes
used to define a Token.FUNCTION
's argument list.public void setOptionalArg(boolean optionalArg)
Token.NAME
nodes
used to define a Token.FUNCTION
's argument list.public boolean isOptionalArg()
Token.NAME
nodes
used to define a Token.FUNCTION
's argument list.public boolean isOptionalEs6Typed()
public void setIsSyntheticBlock(boolean val)
public boolean isSyntheticBlock()
@Nullable public Set<String> getDirectives()
public void setIsAddedBlock(boolean val)
public boolean isAddedBlock()
public void setStaticMember(boolean isStatic)
Token.GETTER_DEF
,
Token.SETTER_DEF
or Token.MEMBER_FUNCTION_DEF
nodes contained
within Token.CLASS
.public boolean isStaticMember()
Token.GETTER_DEF
,
Token.SETTER_DEF
or Token.MEMBER_FUNCTION_DEF
nodes contained
within Token.CLASS
.public void setIsGeneratorFunction(boolean isGenerator)
Token.FUNCTION
or
Token.MEMBER_FUNCTION_DEF
nodes.public boolean isGeneratorFunction()
public void setGeneratorMarker(boolean isGeneratorMarker)
public boolean isGeneratorMarker()
public void setGeneratorSafe(boolean isGeneratorSafe)
isGeneratorSafe()
public boolean isGeneratorSafe()
public void setIsArrowFunction(boolean isArrow)
Token.FUNCTION
public boolean isArrowFunction()
public void setIsAsyncFunction(boolean isAsync)
Token.FUNCTION
public boolean isAsyncFunction()
public void setYieldFor(boolean isGenerator)
Token.FUNCTION
or
Token.MEMBER_FUNCTION_DEF
nodes.public boolean isYieldFor()
Token.FUNCTION
or
Token.MEMBER_FUNCTION_DEF
nodes.public void setSideEffectFlags(int flags)
Token.CALL
and
Token.NEW
nodes.public void setSideEffectFlags(Node.SideEffectFlags flags)
public int getSideEffectFlags()
public boolean isOnlyModifiesThisCall()
public boolean isOnlyModifiesArgumentsCall()
public boolean isNoSideEffectsCall()
public boolean isLocalResultCall()
public boolean mayMutateArguments()
public boolean mayMutateGlobalStateOrThrow()
public boolean isQuotedString()
public void setQuotedString()
public boolean isAdd()
public boolean isSub()
public boolean isAnd()
public boolean isArrayLit()
public boolean isArrayPattern()
public boolean isAssign()
public boolean isAssignAdd()
public boolean isNormalBlock()
public boolean isRoot()
public boolean isBreak()
public boolean isCall()
public boolean isCase()
public boolean isCast()
public boolean isCatch()
public boolean isClass()
public boolean isClassMembers()
public boolean isComma()
public boolean isComputedProp()
public boolean isContinue()
public boolean isConst()
public boolean isDebugger()
public boolean isDec()
public boolean isDefaultCase()
public boolean isDefaultValue()
public boolean isDelProp()
public boolean isDestructuringLhs()
public boolean isDestructuringPattern()
public boolean isDo()
public boolean isEmpty()
public boolean isExport()
public boolean isExprResult()
public boolean isFalse()
@Deprecated public boolean isFor()
public boolean isVanillaFor()
public boolean isForIn()
public boolean isForOf()
public boolean isFunction()
public boolean isGetterDef()
public boolean isGetElem()
public boolean isGetProp()
public boolean isHook()
public boolean isIf()
public boolean isImport()
public boolean isImportStar()
public boolean isImportSpec()
public boolean isImportSpecs()
public boolean isIn()
public boolean isInc()
public boolean isInstanceOf()
public boolean isInterfaceMembers()
public boolean isRecordType()
public boolean isCallSignature()
public boolean isIndexSignature()
public boolean isLabel()
public boolean isLabelName()
public boolean isLet()
public boolean isMemberFunctionDef()
public boolean isMemberVariableDef()
public boolean isModuleBody()
public boolean isName()
public boolean isNE()
public boolean isNew()
public boolean isNot()
public boolean isNull()
public boolean isNumber()
public boolean isObjectLit()
public boolean isObjectPattern()
public boolean isOr()
public boolean isParamList()
public boolean isRegExp()
public boolean isRest()
public boolean isReturn()
public boolean isScript()
public boolean isSetterDef()
public boolean isSpread()
public boolean isString()
public boolean isStringKey()
public boolean isSuper()
public boolean isSwitch()
public boolean isTaggedTemplateLit()
public boolean isTemplateLit()
public boolean isTemplateLitSub()
public boolean isThis()
public boolean isThrow()
public boolean isTrue()
public boolean isTry()
public boolean isTypeOf()
public boolean isVar()
public boolean isVoid()
public boolean isWhile()
public boolean isWith()
public boolean isYield()
Copyright © 2009-2017 Google. All Rights Reserved.