Class PositionConfigureUtils
java.lang.Object
org.apache.groovy.parser.antlr4.util.PositionConfigureUtils
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).
-
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionstatic <T extends ASTNode>
TconfigureAST(T astNode, org.antlr.v4.runtime.Token token) static <T extends ASTNode>
TconfigureAST(T astNode, org.antlr.v4.runtime.tree.TerminalNode terminalNode) static <T extends ASTNode>
TconfigureAST(T astNode, GroovyParser.GroovyParserRuleContext ctx) Sets location(lineNumber, colNumber, lastLineNumber, lastColumnNumber) for node using standard context information.static <T extends ASTNode>
TconfigureAST(T astNode, GroovyParser.GroovyParserRuleContext ctx, ASTNode initialStop) Sets the start fromctxand the end frominitialStopwhen that node has an authored end position.static <T extends ASTNode>
TconfigureAST(T astNode, ASTNode source) static <T extends ASTNode>
TconfigureAST(T astNode, ASTNode start, ASTNode stop) Sets the start fromstartand the end fromstopwhen that node has an authored end position.static <T extends ASTNode>
voidconfigureEndPosition(T astNode, org.antlr.v4.runtime.Token token) endPosition(org.antlr.v4.runtime.Token token)
-
Constructor Details
-
PositionConfigureUtils
public PositionConfigureUtils()
-
-
Method Details
-
configureAST
public static <T extends ASTNode> T configureAST(T astNode, GroovyParser.GroovyParserRuleContext ctx) 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.- Parameters:
astNode- Node to be modified.ctx- Context from which information is obtained.- Returns:
- Modified astNode.
-
endPosition
-
configureAST
public static <T extends ASTNode> T configureAST(T astNode, org.antlr.v4.runtime.tree.TerminalNode terminalNode) -
configureAST
-
configureAST
-
configureAST
public static <T extends ASTNode> T configureAST(T astNode, GroovyParser.GroovyParserRuleContext ctx, ASTNode initialStop) Sets the start fromctxand the end frominitialStopwhen that node has an authored end position. Otherwise the end comes fromctx's stop token.Groovy truth is non-null, so a synthetic
ConstantExpression(default-1coordinates) must not be treated as a stop: it would wipe the parent's end. The same applies toEmptyExpression.INSTANCE.- Parameters:
astNode- node to modifyctx- parse context supplying the start (and fallback end)initialStop- authored initializer whose end should be used, ornull/unpositioned to usectx's stop- Returns:
astNode
-
configureEndPosition
public static <T extends ASTNode> void configureEndPosition(T astNode, org.antlr.v4.runtime.Token token) -
configureAST
Sets the start fromstartand the end fromstopwhen that node has an authored end position. Otherwise the end is copied fromstart. SeeconfigureAST(ASTNode, GroovyParser.GroovyParserRuleContext, ASTNode).- Parameters:
astNode- node to modifystart- node supplying the start (and fallback end)stop- authored node whose end should be used, ornull/unpositioned to usestart's end- Returns:
astNode
-