Class NodeUtil

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

public final class NodeUtil extends Object
NodeUtil contains generally useful AST utilities.
  • Method Details

    • 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:
      • {'name': function() ...}
      • {name: function() ...}
      • function name() ...
      • var name = function() ...
      • qualified.name = function() ...
      • var name2 = function name1() ...
      • qualified.name2 = function name1() ...
      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
    • 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.