Example usage for org.antlr.v4.runtime.tree ParseTree getSourceInterval

List of usage examples for org.antlr.v4.runtime.tree ParseTree getSourceInterval

Introduction

In this page you can find the example usage for org.antlr.v4.runtime.tree ParseTree getSourceInterval.

Prototype

Interval getSourceInterval();

Source Link

Document

Return an Interval indicating the index in the TokenStream of the first and last token associated with this subtree.

Usage

From source file:com.satisfyingstructures.J2S.J2SRewriter.java

License:Open Source License

public void insertComment(String comment, ParseTree pt, CommentWhere where) {
    int idx = where == CommentWhere.beforeToken || where == CommentWhere.beforeLineBreak
            ? pt.getSourceInterval().a
            : pt.getSourceInterval().b;/* w w  w. ja  v a2s.  co m*/
    insertComment(comment, idx, where);
}

From source file:com.satisfyingstructures.J2S.J2SRewriter.java

License:Open Source License

public void deleteAndAdjustWhitespace(ParseTree pt) {
    Interval interval = pt.getSourceInterval();
    deleteAndAdjustWhitespace(interval.a, interval.b);
}

From source file:com.satisfyingstructures.J2S.J2SRewriter.java

License:Open Source License

public void replaceAndAdjustWhitespace(ParseTree pt, String text) {
    Interval interval = pt.getSourceInterval();
    replaceAndAdjustWhitespace(interval.a, interval.b, text);
}

From source file:com.satisfyingstructures.J2S.ParseTreeRewriter.java

License:Open Source License

public void insertAfter(String programName, ParseTree pt, Object text) {
    insertAfter(programName, pt.getSourceInterval(), text);
}

From source file:com.satisfyingstructures.J2S.ParseTreeRewriter.java

License:Open Source License

public void insertBefore(String programName, ParseTree pt, Object text) {
    insertBefore(programName, pt.getSourceInterval(), text);
}

From source file:com.satisfyingstructures.J2S.ParseTreeRewriter.java

License:Open Source License

public void replace(String programName, ParseTree pt, Object text) {
    replace(programName, pt.getSourceInterval(), text);
}

From source file:com.satisfyingstructures.J2S.ParseTreeRewriter.java

License:Open Source License

public void delete(String programName, ParseTree pt) {
    replace(programName, pt.getSourceInterval(), null);
}

From source file:com.satisfyingstructures.J2S.ParseTreeRewriter.java

License:Open Source License

public String getText(String programName, ParseTree pt) {
    return getText(programName, pt.getSourceInterval());
}

From source file:info.fulloo.trygve.parser.Pass1Listener.java

License:Open Source License

private Expression processIndexedArrayElement(final ParseTree arrayExprCtx,
        final KantParser.ExprContext sexpCtx, final TerminalNode ABELIAN_INCREMENT_OPCtx) {
    // | abelian_expr '[' expr ']' ABELIAN_INCREMENT_OP
    // | ABELIAN_INCREMENT_OP expr '[' expr ']'

    Expression retval = null;//  w  ww. j a  va  2  s  . c  om
    final Expression indexExpr = parsingData_.popExpression();
    indexExpr.setResultIsConsumed(true);

    final Expression rawArrayBase = parsingData_.popExpression();
    final Type rawArrayBaseType = rawArrayBase.type();
    assert rawArrayBaseType instanceof ArrayType;
    final ArrayType arrayType = (ArrayType) rawArrayBaseType;
    final Type baseType = arrayType.baseType();
    final ArrayExpression arrayBase = new ArrayExpression(rawArrayBase, baseType);
    arrayBase.setResultIsConsumed(true);

    final Interval JavaIDInterval = arrayExprCtx.getSourceInterval();
    final Interval OperatorInterval = ABELIAN_INCREMENT_OPCtx.getSourceInterval();
    final UnaryopExpressionWithSideEffect.PreOrPost preOrPost = JavaIDInterval.startsAfter(OperatorInterval)
            ? UnaryopExpressionWithSideEffect.PreOrPost.Pre
            : UnaryopExpressionWithSideEffect.PreOrPost.Post;
    retval = new ArrayIndexExpressionUnaryOp(arrayBase, indexExpr, ABELIAN_INCREMENT_OPCtx.getText(), preOrPost,
            sexpCtx.getStart().getLine());
    return retval;
}

From source file:net.certiv.json.converter.BaseDescriptor.java

License:Open Source License

public int indexOfElement(ParserRuleContext ctx, ParseTree node) {
    buildElementAssociations(ctx);/*w  ww  .  j a  v a2  s .  com*/
    int index = node.getSourceInterval().a;
    for (int idx = 0; idx < assocElement.size(); idx++) {
        ElementAssoc e = assocElement.get(idx);
        if (e.index == index) {
            return idx;
        }
    }
    return -1;
}