com.google.javascript.jscomp
Class NodeUtil

java.lang.Object
  extended by com.google.javascript.jscomp.NodeUtil

public final class NodeUtil
extends Object

NodeUtil contains generally useful AST utilities.


Method Summary
static JSDocInfo getFunctionJSDocInfo(Node n)
          Get the JSDocInfo for a function.
static Node getFunctionParameters(Node fnNode)
           
static InputId getInputId(Node n)
           
static String getNearestFunctionName(Node n)
          Gets the function's name.
static StaticSourceFile getSourceFile(Node n)
           
static String getSourceName(Node n)
           
static boolean isLValue(Node n)
          Determines whether this node is used as an L-value.
static TernaryValue isStrWhiteSpaceChar(int c)
          Copied from Rhino's ScriptRuntime
static boolean isValidQualifiedName(String name)
          Determines whether the given name is a valid qualified name.
static Map<Node,Node> mapMainToClone(Node main, Node clone)
          Given an AST and its copy, map the root node of each scope of main to the corresponding root node of clone
static Node newQualifiedNameNode(CodingConvention convention, String name)
          Creates a node representing a qualified name.
static Node newQualifiedNameNodeDeclaration(CodingConvention convention, String name, Node value, JSDocInfo info)
          Creates a node representing a qualified name.
static void verifyScopeChanges(Map<Node,Node> map, Node main, boolean verifyUnchangedNodes)
          Checks that the scope roots marked as changed have indeed changed
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Method Detail

isStrWhiteSpaceChar

public static TernaryValue isStrWhiteSpaceChar(int c)
Copied from Rhino's ScriptRuntime


getNearestFunctionName

public static String getNearestFunctionName(Node n)
Gets the function's name. This method recognizes the forms:

Parameters:
n - a node whose type is Token.FUNCTION
Returns:
the function's name, or null if it has no name

isLValue

public static boolean isLValue(Node n)
Determines whether this node is used as an L-value. Notice that sometimes names are used as both L-values and R-values. We treat "var x;" as a pseudo-L-value, which kind of makes sense if you treat it as "assignment to 'undefined' at the top of the scope". But if we're honest with ourselves, it doesn't make sense, and we only do this because it makes sense to treat this as syntactically similar to "var x = 0;".

Parameters:
n - The node
Returns:
True if n is an L-value.

newQualifiedNameNode

public static Node newQualifiedNameNode(CodingConvention convention,
                                        String name)
Creates a node representing a qualified name.

Parameters:
name - A qualified name (e.g. "foo" or "foo.bar.baz")
Returns:
A NAME or GETPROP node

newQualifiedNameNodeDeclaration

public static Node newQualifiedNameNodeDeclaration(CodingConvention convention,
                                                   String name,
                                                   Node value,
                                                   JSDocInfo info)
Creates a node representing a qualified name.

Parameters:
name - A qualified name (e.g. "foo" or "foo.bar.baz")
Returns:
A NAME or GETPROP node

isValidQualifiedName

public static boolean isValidQualifiedName(String name)
Determines whether the given name is a valid qualified name.


getFunctionParameters

public static Node getFunctionParameters(Node fnNode)
Parameters:
fnNode - The function.
Returns:
The Node containing the Function parameters.

getFunctionJSDocInfo

public static JSDocInfo getFunctionJSDocInfo(Node n)
Get the JSDocInfo for a function.


getSourceName

public static String getSourceName(Node n)
Parameters:
n - The node.
Returns:
The source name property on the node or its ancestors.

getSourceFile

public static StaticSourceFile getSourceFile(Node n)
Parameters:
n - The node.
Returns:
The source name property on the node or its ancestors.

getInputId

public static InputId getInputId(Node n)
Parameters:
n - The node.
Returns:
The InputId property on the node or its ancestors.

mapMainToClone

public static Map<Node,Node> mapMainToClone(Node main,
                                            Node clone)
Given an AST and its copy, map the root node of each scope of main to the corresponding root node of clone


verifyScopeChanges

public static void verifyScopeChanges(Map<Node,Node> map,
                                      Node main,
                                      boolean verifyUnchangedNodes)
Checks that the scope roots marked as changed have indeed changed