Search in sources :

Example 1 with PostfixExprAltContext

use of org.apache.groovy.parser.antlr4.GroovyParser.PostfixExprAltContext in project groovy by apache.

the class SemanticPredicates method isFollowingArgumentsOrClosure.

/**
 * Check whether following a method name of command expression.
 * Method name should not end with "2: arguments" and "3: closure"
 *
 * @param context the preceding expression
 */
public static boolean isFollowingArgumentsOrClosure(ExpressionContext context) {
    if (context instanceof PostfixExprAltContext) {
        List<ParseTree> peacChildren = ((PostfixExprAltContext) context).children;
        try {
            ParseTree peacChild = peacChildren.get(0);
            List<ParseTree> pecChildren = ((PostfixExpressionContext) peacChild).children;
            ParseTree pecChild = pecChildren.get(0);
            PathExpressionContext pec = (PathExpressionContext) pecChild;
            int t = pec.t;
            return (2 == t || 3 == t);
        } catch (IndexOutOfBoundsException | ClassCastException e) {
            throw new GroovyBugError("Unexpected structure of expression context: " + context, e);
        }
    }
    return false;
}
Also used : PostfixExpressionContext(org.apache.groovy.parser.antlr4.GroovyParser.PostfixExpressionContext) PostfixExprAltContext(org.apache.groovy.parser.antlr4.GroovyParser.PostfixExprAltContext) GroovyBugError(org.codehaus.groovy.GroovyBugError) PathExpressionContext(org.apache.groovy.parser.antlr4.GroovyParser.PathExpressionContext) ParseTree(org.antlr.v4.runtime.tree.ParseTree)

Aggregations

ParseTree (org.antlr.v4.runtime.tree.ParseTree)1 PathExpressionContext (org.apache.groovy.parser.antlr4.GroovyParser.PathExpressionContext)1 PostfixExprAltContext (org.apache.groovy.parser.antlr4.GroovyParser.PostfixExprAltContext)1 PostfixExpressionContext (org.apache.groovy.parser.antlr4.GroovyParser.PostfixExpressionContext)1 GroovyBugError (org.codehaus.groovy.GroovyBugError)1