Class PositionConfigureUtils

java.lang.Object
org.apache.groovy.parser.antlr4.util.PositionConfigureUtils

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).

  • 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

      public static Tuple2<Integer,Integer> endPosition(org.antlr.v4.runtime.Token token)
    • configureAST

      public static <T extends ASTNode> T configureAST(T astNode, org.antlr.v4.runtime.tree.TerminalNode terminalNode)
    • configureAST

      public static <T extends ASTNode> T configureAST(T astNode, org.antlr.v4.runtime.Token token)
    • configureAST

      public static <T extends ASTNode> T configureAST(T astNode, ASTNode source)
    • configureAST

      public static <T extends ASTNode> T configureAST(T astNode, GroovyParser.GroovyParserRuleContext ctx, ASTNode initialStop)
      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.

      Parameters:
      astNode - node to modify
      ctx - parse context supplying the start (and fallback end)
      initialStop - authored initializer whose end should be used, or null/unpositioned to use ctx's stop
      Returns:
      astNode
    • configureEndPosition

      public static <T extends ASTNode> void configureEndPosition(T astNode, org.antlr.v4.runtime.Token token)
    • configureAST

      public static <T extends ASTNode> 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. Otherwise the end is copied from start. See configureAST(ASTNode, GroovyParser.GroovyParserRuleContext, ASTNode).
      Parameters:
      astNode - node to modify
      start - node supplying the start (and fallback end)
      stop - authored node whose end should be used, or null/unpositioned to use start's end
      Returns:
      astNode