public class PositionConfigureUtils
extends Object
Utilities for configuring AST source positions.
Line and column numbers are 1-based; the end column is exclusive.
-1 means the node is synthetic or generated and has no span in
the source. Authored nodes should be stamped through these helpers so
tooling can tell them apart (lineNumber > 0).
| Type Params | Return Type | Name and description |
|---|---|---|
<T extends ASTNode> |
public static T |
configureAST(T astNode, GroovyParserRuleContext ctx)Sets location(lineNumber, colNumber, lastLineNumber, lastColumnNumber) for node using standard context information. |
<T extends ASTNode> |
public static T |
configureAST(T astNode, TerminalNode terminalNode) |
<T extends ASTNode> |
public static T |
configureAST(T astNode, Token token) |
<T extends ASTNode> |
public static T |
configureAST(T astNode, ASTNode source) |
<T extends ASTNode> |
public static T |
configureAST(T astNode, GroovyParserRuleContext ctx, ASTNode initialStop)Sets the start from ctx and the end from initialStop
when that node has an authored end position. |
<T extends ASTNode> |
public static T |
configureAST(T astNode, ASTNode start, ASTNode stop)Sets the start from start and the end from stop when
that node has an authored end position. |
<T extends ASTNode> |
public static void |
configureEndPosition(T astNode, Token token) |
|
public static Tuple2<Integer, Integer> |
endPosition(Token token) |
Sets location(lineNumber, colNumber, lastLineNumber, lastColumnNumber) for node using standard context information. Note: this method is implemented to be closed over ASTNode. It returns same node as it received in arguments.
astNode - Node to be modified.ctx - Context from which information is obtained. Sets the start from ctx and the end from initialStop
when that node has an authored end position. Otherwise the end comes
from ctx's stop token.
Groovy truth is non-null, so a synthetic ConstantExpression
(default -1 coordinates) must not be treated as a stop: it
would wipe the parent's end. The same applies to
EmptyExpression.INSTANCE.
astNode - node to modifyctx - parse context supplying the start (and fallback end)initialStop - authored initializer whose end should be used, or
null/unpositioned to use ctx's stopastNode Sets the start from start and the end from stop when
that node has an authored end position. Otherwise the end is copied
from start. See configureAST(ASTNode, GroovyParser.GroovyParserRuleContext, ASTNode).
astNode - node to modifystart - node supplying the start (and fallback end)stop - authored node whose end should be used, or
null/unpositioned to use start's endastNode