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
| 40 | * </ul> |
| 41 | */ |
| 42 | public class ASTNode implements NodeMetaDataHandler { |
| 43 | |
| 44 | private int lineNumber = -1; |
| 45 | private int columnNumber = -1; |
| 46 | private int lastLineNumber = -1; |
| 47 | private int lastColumnNumber = -1; |
| 48 | |
| 49 | private volatile Map<?, ?> metaDataMap; |
| 50 | |
| 51 | /** |
| 52 | * Accepts a code visitor for AST traversal and transformation. |
| 53 | * Subclasses must implement this method to support visitor pattern-based processing. |
| 54 | * The visitor pattern enables decoupling of AST structure from processing logic. |
| 55 | * |
| 56 | * @param visitor the {@link GroovyCodeVisitor} to process this node |
| 57 | * @throws RuntimeException if visitor pattern support is not implemented for this node type |
| 58 | */ |
| 59 | public void visit(final GroovyCodeVisitor visitor) { |
| 60 | throw new RuntimeException("No visit() method implemented for class: " + getClass().getName()); |
| 61 | } |
| 62 | |
| 63 | /** |
| 64 | * Returns a human-readable text representation of this AST node. |
| 65 | * Used for debugging and error messages. Default implementation returns a message |
| 66 | * indicating the representation is not yet implemented for this node type. |
| 67 | * |
| 68 | * @return text representation of this node, or placeholder for unimplemented types |
| 69 | */ |
| 70 | public String getText() { |
| 71 | Class<?> nodeType = getClass(); |
| 72 | if (nodeType.isAnonymousClass()) nodeType = nodeType.getSuperclass(); |
| 73 | return "<not implemented yet for class: " + nodeType.getName() + ">"; |
| 74 | } |
| 75 | |
| 76 | /** |
| 77 | * Returns the line number where this AST node begins in the source file. |
| 78 | * Line numbers start from 1. Returns -1 if position information is not available |
| 79 | * (for synthetic or generated nodes). |
| 80 | * |
| 81 | * @return the starting line number, or -1 if not available |
| 82 | */ |
| 83 | public int getLineNumber() { |
| 84 | return lineNumber; |
| 85 | } |
| 86 | |
| 87 | /** |
| 88 | * Sets the starting line number for this AST node in the source file. |
| 89 | * Line numbers are 1-indexed. Use -1 to indicate unavailable position. |
| 90 | * |
| 91 | * @param lineNumber the starting line number to set |
| 92 | */ |
| 93 | public void setLineNumber(final int lineNumber) { |
| 94 | this.lineNumber = lineNumber; |
| 95 | } |
| 96 | |
| 97 | /** |
| 98 | * Returns the column number where this AST node begins in the source file. |
| 99 | * Column numbers are 0-indexed. Returns -1 if position information is unavailable |
nothing calls this directly
no outgoing calls
no test coverage detected