Class Name

All Implemented Interfaces:
Comparable<AstNode>, Iterable<Node>

public class Name extends AstNode
AST node for a simple name. A simple name is an identifier that is not a keyword. Node type is Token.NAME.

This node type is also used to represent certain non-identifier names that are part of the language syntax. It's used for the "get" and "set" pseudo-keywords for object-initializer getter/setter properties, and it's also used for the "*" wildcard in E4X XML namespace and name expressions.

  • Constructor Details

    • Name

      public Name()
    • Name

      public Name(int pos)
    • Name

      public Name(int pos, int len)
    • Name

      public Name(int pos, int len, String name)
      Constructs a new Name
      Parameters:
      pos - node start position
      len - node length
      name - the identifier associated with this Name node
    • Name

      public Name(int pos, String name)
  • Method Details

    • getIdentifier

      public String getIdentifier()
      Returns the node's identifier
    • setIdentifier

      public void setIdentifier(String identifier)
      Sets the node's identifier
      Throws:
      IllegalArgumentException - if identifier is null
    • setScope

      public void setScope(Scope s)
      Set the Scope associated with this node. This method does not set the scope's ast-node field to this node. The field exists only for temporary storage by the code generator. Not every name has an associated scope - typically only function and variable names (but not property names) are registered in a scope.
      Overrides:
      setScope in class Node
      Parameters:
      s - the scope. Can be null. Doesn't set any fields in the scope.
    • getScope

      public Scope getScope()
      Return the Scope associated with this node. This is only used for (and set by) the code generator, so it will always be null in frontend AST-processing code. Use getDefiningScope() to find the lexical Scope in which this Name is defined, if any.
      Overrides:
      getScope in class Node
    • getDefiningScope

      public Scope getDefiningScope()
      Returns the Scope in which this Name is defined.
      Returns:
      the scope in which this name is defined, or null if it's not defined in the current lexical scope chain
    • isLocalName

      public boolean isLocalName()
      Return true if this node is known to be defined as a symbol in a lexical scope other than the top-level (global) scope.
      Returns:
      true if this name appears as local variable, a let-bound variable not in the global scope, a function parameter, a loop variable, the property named in a PropertyGet, or in any other context where the node is known not to resolve to the global scope. Returns false if the node is defined in the top-level scope (i.e., its defining scope is an AstRoot object), or if its name is not defined as a symbol in the symbol table, in which case it may be an external or built-in name (or just an error of some sort.)
    • length

      public int length()
      Return the length of this node's identifier, to let you pretend it's a String. Don't confuse this method with the AstNode.getLength() method, which returns the range of characters that this node overlaps in the source input.
    • toSource

      public String toSource(int depth)
      Description copied from class: AstNode
      Emits source code for this node. Callee is responsible for calling this function recursively on children, incrementing indent as appropriate.

      Note: if the parser was in error-recovery mode, some AST nodes may have null children that are expected to be non-null when no errors are present. In this situation, the behavior of the toSource method is undefined: toSource implementations may assume that the AST node is error-free, since it is intended to be invoked only at runtime after a successful parse.

      Specified by:
      toSource in class AstNode
      Parameters:
      depth - the current recursion depth, typically beginning at 0 when called on the root node.
    • visit

      public void visit(NodeVisitor v)
      Visits this node. There are no children to visit.
      Specified by:
      visit in class AstNode
      Parameters:
      v - the object to call with this node and its children