com.google.javascript.jscomp
Class NodeUtil

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

public final class NodeUtil
extends Object

NodeUtil contains utilities that get properties from the Node object.


Method Summary
static JSDocInfo getFunctionJSDocInfo(Node n)
          Get the JSDocInfo for a function.
static Node getFunctionParameters(Node fnNode)
           
static InputId getInputId(Node n)
           
static int getInverseOperator(int type)
          Returns the inverse of an operator if it is invertible.
static String getNearestFunctionName(Node n)
          Gets the function's name.
static Node getRootOfQualifiedName(Node qName)
          Gets the root node of a qualified name.
static StaticSourceFile getSourceFile(Node n)
           
static String getSourceName(Node n)
           
static Collection<Node> getVarsDeclaredInBranch(Node root)
          Retrieves vars declared in the current node tree, excluding descent scopes.
static boolean isRelationalOperation(Node n)
          Returns true if the operator on this node is relational.
static boolean isSymmetricOperation(Node n)
          Returns true if the operator on this node is symmetric
static Node newExpr(Node child)
          Creates an EXPR_RESULT.
static Node newFunctionNode(String name, List<Node> params, Node body, int lineno, int charno)
          Creates function name(params_0, ..., params_n) { body }.
static Node newQualifiedNameNode(CodingConvention convention, String name, int lineno, int charno)
          Creates a node representing a qualified name.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Method Detail

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

isSymmetricOperation

public static boolean isSymmetricOperation(Node n)
Returns true if the operator on this node is symmetric


isRelationalOperation

public static boolean isRelationalOperation(Node n)
Returns true if the operator on this node is relational. the returned set does not include the equalities.


getInverseOperator

public static int getInverseOperator(int type)
Returns the inverse of an operator if it is invertible. ex. '>' ==> '<'


newExpr

public static Node newExpr(Node child)
Creates an EXPR_RESULT.

Parameters:
child - The expression itself.
Returns:
Newly created EXPR node with the child as subexpression.

newFunctionNode

public static Node newFunctionNode(String name,
                                   List<Node> params,
                                   Node body,
                                   int lineno,
                                   int charno)
Creates function name(params_0, ..., params_n) { body }.


newQualifiedNameNode

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

Parameters:
name - A qualified name (e.g. "foo" or "foo.bar.baz")
lineno - The source line offset.
charno - The source character offset from start of the line.
Returns:
A NAME or GETPROP node

getRootOfQualifiedName

public static Node getRootOfQualifiedName(Node qName)
Gets the root node of a qualified name. Must be either NAME or THIS.


getVarsDeclaredInBranch

public static Collection<Node> getVarsDeclaredInBranch(Node root)
Retrieves vars declared in the current node tree, excluding descent scopes.


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.