Class ASTNode

  • Direct Known Subclasses:
    AnnotatedNode, AnnotationNode, GenericsType, ModuleNode, Statement

    public class ASTNode
    extends Object
    Base class for any AST node. This class supports basic information used in all nodes of the AST:
    • line and column number information. Usually a node represents a certain area in a text file determined by a starting position and an ending position. For nodes that do not represent this, this information will be -1. A node can also be configured in its line/col information using another node through setSourcePosition(otherNode).
    • every node can store meta data. A phase operation or transform can use this to transport arbitrary information to another phase operation or transform. The only requirement is that the other phase operation or transform runs after the part storing the information. If the information transport is done it is strongly recommended to remove that meta data.
    • a text representation of this node trough getText(). This was in the past used for assertion messages. Since the usage of power asserts this method will not be called for this purpose anymore and might be removed in future versions of Groovy
    • Constructor Detail

      • ASTNode

        public ASTNode()
    • Method Detail

      • getText

        public String getText()
      • getLineNumber

        public int getLineNumber()
      • setLineNumber

        public void setLineNumber​(int lineNumber)
      • getColumnNumber

        public int getColumnNumber()
      • setColumnNumber

        public void setColumnNumber​(int columnNumber)
      • getLastLineNumber

        public int getLastLineNumber()
      • setLastLineNumber

        public void setLastLineNumber​(int lastLineNumber)
      • getLastColumnNumber

        public int getLastColumnNumber()
      • setLastColumnNumber

        public void setLastColumnNumber​(int lastColumnNumber)
      • setSourcePosition

        public void setSourcePosition​(ASTNode node)
        Sets the source position using another ASTNode. The sourcePosition consists of a line/column pair for the start and a line/column pair for the end of the expression or statement
        node - - the node used to configure the position information
      • getNodeMetaData

        public <T> T getNodeMetaData​(Object key)
        Gets the node meta data.
        key - - the meta data key
        the node meta data value for this key
      • copyNodeMetaData

        public void copyNodeMetaData​(ASTNode other)
        Copies all node meta data from the other node to this one
        other - - the other node
      • setNodeMetaData

        public void setNodeMetaData​(Object key,
                                    Object value)
        Sets the node meta data.
        key - - the meta data key
        value - - the meta data value
        GroovyBugError - if key is null or there is already meta data under that key
      • putNodeMetaData

        public Object putNodeMetaData​(Object key,
                                      Object value)
        Sets the node meta data but allows overwriting values.
        key - - the meta data key
        value - - the meta data value
        the old node meta data value for this key
        GroovyBugError - if key is null
      • removeNodeMetaData

        public void removeNodeMetaData​(Object key)
        Removes a node meta data entry.
        key - - the meta data key
        GroovyBugError - if the key is null
      • getNodeMetaData

        public Map<?,​?> getNodeMetaData()
        Returns an unmodifiable view of the current node metadata.
        the node metadata. Always not null.