Example usage for org.antlr.v4.runtime.tree TerminalNode getParent

List of usage examples for org.antlr.v4.runtime.tree TerminalNode getParent

Introduction

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

Prototype

@Override
    ParseTree getParent();

Source Link

Usage

From source file:android.databinding.tool.ExpressionVisitor.java

License:Apache License

@Override
public Expr visitTerminal(@NotNull TerminalNode node) {
    try {//from w w  w .j  av  a 2  s.co m
        onEnter((ParserRuleContext) node.getParent().getRuleContext());
        final int type = node.getSymbol().getType();
        Class classType;
        switch (type) {
        case BindingExpressionParser.IntegerLiteral:
            classType = int.class;
            break;
        case BindingExpressionParser.FloatingPointLiteral:
            classType = float.class;
            break;
        case BindingExpressionParser.BooleanLiteral:
            classType = boolean.class;
            break;
        case BindingExpressionParser.CharacterLiteral:
            classType = char.class;
            break;
        case BindingExpressionParser.SingleQuoteString:
        case BindingExpressionParser.DoubleQuoteString:
            classType = String.class;
            break;
        case BindingExpressionParser.NullLiteral:
            classType = Object.class;
            break;
        default:
            throw new RuntimeException("cannot create expression from terminal node " + node.toString());
        }
        return mModel.symbol(node.getText(), classType);
    } finally {
        onExit((ParserRuleContext) node.getParent().getRuleContext());
    }
}

From source file:com.espertech.esper.epl.parse.EPLTreeWalkerListener.java

License:Open Source License

public void visitTerminal(@NotNull TerminalNode terminalNode) {
    if (terminalNode.getSymbol().getType() == EsperEPL2GrammarLexer.STAR) {
        int ruleIndex = ASTUtil.getRuleIndexIfProvided(terminalNode.getParent());
        if (ruleIndex == EsperEPL2GrammarParser.RULE_selectionListElement) {
            statementSpec.getSelectClauseSpec().add(new SelectClauseElementWildcard());
        }/*from   w w w . java  2s  . c  om*/
        if (ruleIndex == EsperEPL2GrammarParser.STAR
                || ruleIndex == EsperEPL2GrammarParser.RULE_expressionWithTime) {
            ExprWildcardImpl exprNode = new ExprWildcardImpl();
            ASTExprHelper.exprCollectAddSubNodesAddParentNode(exprNode, terminalNode, astExprNodeMap);
        }
    }
}

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

License:Open Source License

static public String replacementForIdentifier(TerminalNode node) {
    String identifier = node.getText();
    if (!swiftKeywords.contains(identifier))
        return null;
    IdentifierContext usedFor = IdentifierContext.other;
    outer: for (RuleContext rc = (RuleContext) node.getParent(); null != rc; rc = rc.getParent()) {
        switch (rc.getRuleIndex()) {
        case Java8Parser.RULE_typeVariable:
        case Java8Parser.RULE_unannTypeVariable:
        case Java8Parser.RULE_typeParameter:
        case Java8Parser.RULE_expressionName:
        case Java8Parser.RULE_variableDeclaratorId:
        case Java8Parser.RULE_receiverParameter:
        case Java8Parser.RULE_enumConstant:
        case Java8Parser.RULE_enumConstantName:
        case Java8Parser.RULE_labeledStatement:
        case Java8Parser.RULE_labeledStatementNoShortIf:
        case Java8Parser.RULE_breakStatement:
        case Java8Parser.RULE_continueStatement:
        case Java8Parser.RULE_fieldAccess:
        case Java8Parser.RULE_fieldAccess_lf_primary:
        case Java8Parser.RULE_fieldAccess_lfno_primary:
        case Java8Parser.RULE_lambdaParameters:
        case Java8Parser.RULE_inferredFormalParameterList:
            usedFor = IdentifierContext.variable_name;
            break outer;

        case Java8Parser.RULE_packageOrTypeName:
        case Java8Parser.RULE_typeName:
        case Java8Parser.RULE_simpleTypeName:
        case Java8Parser.RULE_ambiguousName:
        case Java8Parser.RULE_enumDeclaration:
        case Java8Parser.RULE_normalClassDeclaration:
        case Java8Parser.RULE_normalInterfaceDeclaration:
        case Java8Parser.RULE_classType:
        case Java8Parser.RULE_classType_lf_classOrInterfaceType:
        case Java8Parser.RULE_classType_lfno_classOrInterfaceType:
        case Java8Parser.RULE_classInstanceCreationExpression:
        case Java8Parser.RULE_classInstanceCreationExpression_lf_primary:
        case Java8Parser.RULE_classInstanceCreationExpression_lfno_primary:
        case Java8Parser.RULE_unannClassType:
        case Java8Parser.RULE_unannClassType_lf_unannClassOrInterfaceType:
        case Java8Parser.RULE_unannClassType_lfno_unannClassOrInterfaceType:
            usedFor = IdentifierContext.type_name;
            break outer;

        case Java8Parser.RULE_methodName:
        case Java8Parser.RULE_methodDeclarator:
        case Java8Parser.RULE_methodInvocation:
        case Java8Parser.RULE_methodInvocation_lf_primary:
        case Java8Parser.RULE_methodInvocation_lfno_primary:
        case Java8Parser.RULE_methodReference:
        case Java8Parser.RULE_methodReference_lf_primary:
        case Java8Parser.RULE_methodReference_lfno_primary:
            usedFor = IdentifierContext.function_name;
            break outer;

        case Java8Parser.RULE_typeImportOnDemandDeclaration:
        case Java8Parser.RULE_singleStaticImportDeclaration:
        case Java8Parser.RULE_packageDeclaration:
        case Java8Parser.RULE_packageName:
        case Java8Parser.RULE_annotationTypeDeclaration:
        case Java8Parser.RULE_annotationTypeElementDeclaration:
        case Java8Parser.RULE_elementValuePair:
            return null; // package names need manual attention - leave untouched

        case Java8Parser.RULE_block:
        case Java8Parser.RULE_switchBlock:
        case Java8Parser.RULE_classBody:
        case Java8Parser.RULE_constructorBody:
        case Java8Parser.RULE_enumBody:
        case Java8Parser.RULE_interfaceBody:
        case Java8Parser.RULE_annotationTypeBody:
        case Java8Parser.RULE_elementValueArrayInitializer:
        case Java8Parser.RULE_arrayInitializer:
            return null; // stepping out of a scope without knowing what type of identifier -> ignore
        }//from  w w w.  j  a va  2 s.c o m
    }
    identifier = replacementForIdentifierInContext(identifier, usedFor);
    return identifier;
}

From source file:org.paltest.pal.parser.impl.java8.Java8MethodSpecificationListener.java

License:Apache License

@Override
public void visitTerminal(@NotNull TerminalNode node) {
    if (recordLine && !isInstanceOf(node.getParent(), Java8Parser.LiteralContext.class,
            Java8Parser.PrimaryContext.class) && !isSymbol(node.getText())) {
        specification.text().append(" ").append(sentencify(node.getText(), false));
    }//from  w w w  .  ja  v  a 2 s .c  o m
}

From source file:org.tinygroup.template.interpret.TemplateFromContext.java

License:GNU General Public License

/**
 * Trim ?Set ? ?/* ww w  .  jav  a 2  s. c o m*/
 * @param text 
 * @param nowTerminalNode 
 * @param trimWhileSpace ???
 * @return
 */
private String trimCommentsDirectiveWhileSpaceNewLine(String text, TerminalNode nowTerminalNode,
        boolean trimWhileSpace) {
    if (text == null || text.length() == 0) {
        return "";
    }

    if (nowTerminalNode.getParent() instanceof TinyTemplateParser.TextContext) {
        // ??TextContext
        TinyTemplateParser.TextContext parseTree = (TinyTemplateParser.TextContext) nowTerminalNode.getParent();
        // ?Text Context?Block
        ParserRuleContext parentParserRuleContext = getParseTrreeParentButBlock(parseTree);
        if (isDirectiveNeedTrim(parentParserRuleContext)) {// ??Trim\r\n
            text = trimTextLeft(text);
            if (trimWhileSpace) {
                text = TemplateUtil.trimStart(text, stripWithSpaceChars);
                text = TemplateUtil.trimEnd(text, stripWithSpaceChars);
            }
        } else if (parentParserRuleContext instanceof TinyTemplateParser.BlockContext) {
            // ?Text ContextBlockContext?
            int parentChildrenIndex = getParentChildrenIndex(parseTree, parentParserRuleContext);
            // ?
            if (parentChildrenIndex > 0) {
                // ?
                ParseTree previousParseContext = parentParserRuleContext.getChild(parentChildrenIndex - 1);
                // text??
                if (previousParseContext instanceof TinyTemplateParser.CommentContext
                        || (previousParseContext instanceof TinyTemplateParser.DirectiveContext
                                && (previousParseContext
                                        .getChild(0) instanceof TinyTemplateParser.Set_directiveContext
                                        || previousParseContext.getChild(
                                                0) instanceof TinyTemplateParser.Blank_directiveContext
                                        || previousParseContext.getChild(
                                                0) instanceof TinyTemplateParser.Call_macro_directiveContext
                                        || previousParseContext.getChild(
                                                0) instanceof TinyTemplateParser.Call_macro_block_directiveContext
                                        || previousParseContext.getChild(
                                                0) instanceof TinyTemplateParser.Import_directiveContext
                                        || previousParseContext.getChild(
                                                0) instanceof TinyTemplateParser.If_directiveContext))) {
                    text = trimTextLeft(text);
                    if (trimWhileSpace) {
                        text = TemplateUtil.trimStart(text, stripWithSpaceChars);
                    }
                }

            }

            if (trimWhileSpace) {
                // ???
                if (parentChildrenIndex < parentParserRuleContext.getChildCount()) {
                    // ?
                    ParseTree previousParseContext = parentParserRuleContext.getChild(parentChildrenIndex + 1);
                    // text??
                    if (previousParseContext instanceof TinyTemplateParser.CommentContext
                            || (previousParseContext instanceof TinyTemplateParser.DirectiveContext
                                    && (previousParseContext
                                            .getChild(0) instanceof TinyTemplateParser.Set_directiveContext
                                            || previousParseContext.getChild(
                                                    0) instanceof TinyTemplateParser.Blank_directiveContext
                                            || previousParseContext.getChild(
                                                    0) instanceof TinyTemplateParser.Call_macro_directiveContext
                                            || previousParseContext.getChild(
                                                    0) instanceof TinyTemplateParser.Call_macro_block_directiveContext
                                            || previousParseContext.getChild(
                                                    0) instanceof TinyTemplateParser.Import_directiveContext
                                            || previousParseContext.getChild(
                                                    0) instanceof TinyTemplateParser.If_directiveContext))) {
                        text = TemplateUtil.trimEnd(text, stripWithSpaceChars);
                    }
                }
            }
        }
    }

    return text;
}

From source file:org.tvl.goworks.editor.go.semantics.SemanticAnalyzerListener.java

License:Open Source License

@Override
@RuleDependencies({/*from w w w. j  a  v a 2s.  c  om*/
        @RuleDependency(recognizer = GoParser.class, rule = GoParser.RULE_qualifiedIdentifier, version = 0),
        @RuleDependency(recognizer = GoParser.class, rule = GoParser.RULE_packageName, version = 0),
        @RuleDependency(recognizer = GoParser.class, rule = GoParser.RULE_typeSwitchGuard, version = 0),
        @RuleDependency(recognizer = GoParser.class, rule = GoParser.RULE_typeSwitchStmt, version = 0),
        @RuleDependency(recognizer = GoParser.class, rule = GoParser.RULE_typeCaseClause, version = 0),
        @RuleDependency(recognizer = GoParser.class, rule = GoParser.RULE_typeSwitchCase, version = 0),
        @RuleDependency(recognizer = GoParser.class, rule = GoParser.RULE_typeList, version = 0),
        @RuleDependency(recognizer = GoParser.class, rule = GoParser.RULE_type, version = 0, dependents = Dependents.SELF), })
public void enterQualifiedIdentifier(QualifiedIdentifierContext ctx) {
    if (ctx.packageName() != null) {
        if (ctx.IDENTIFIER() != null) {
            treeDecorator.putProperty(ctx.IDENTIFIER(), GoAnnotations.QUALIFIED_EXPR, true);
            treeDecorator.putProperty(ctx.IDENTIFIER(), GoAnnotations.QUALIFIER, ctx.packageName());
            unresolvedQualifiedIdentifiers.add(ctx.IDENTIFIER());
        }

        // check known imports
        if (ctx.packageName().IDENTIFIER() != null) {
            List<? extends TerminalNode> imports = ParseTrees
                    .emptyIfNull(importedPackages.get(ctx.packageName().IDENTIFIER().getSymbol().getText()));
            TerminalNode bestImport = null;
            boolean resolvedImport = false;
            for (TerminalNode importToken : imports) {
                if (bestImport == null || (!resolvedImport
                        && treeDecorator.getProperty(importToken, GoAnnotations.RESOLVED))) {
                    bestImport = importToken;
                    resolvedImport = treeDecorator.getProperty(importToken, GoAnnotations.RESOLVED);
                    break;
                }
            }

            if (bestImport != null) {
                treeDecorator.putProperty(ctx.packageName(), GoAnnotations.LOCAL_TARGET, bestImport);
                if (resolvedImport) {
                    treeDecorator.putProperty(ctx.packageName(), GoAnnotations.RESOLVED, true);
                }
            }
        }
    } else if (ctx.IDENTIFIER() != null) {
        assert ctx.packageName() == null;
        String text = ctx.IDENTIFIER().getText();
        switch (text) {
        case "true":
            treeDecorator.putProperty(ctx.IDENTIFIER(), GoAnnotations.UNEVALUATED_CONSTANT, "true");
            treeDecorator.putProperty(ctx.IDENTIFIER(), GoAnnotations.EVALUATED_CONSTANT, BigInteger.ONE);
            treeDecorator.putProperty(ctx.IDENTIFIER(), GoAnnotations.RESOLVED, true);
            treeDecorator.putProperty(ctx.IDENTIFIER(), GoAnnotations.NODE_TYPE, NodeType.CONST_REF);
            break;

        case "false":
            treeDecorator.putProperty(ctx.IDENTIFIER(), GoAnnotations.UNEVALUATED_CONSTANT, "false");
            treeDecorator.putProperty(ctx.IDENTIFIER(), GoAnnotations.EVALUATED_CONSTANT, BigInteger.ZERO);
            treeDecorator.putProperty(ctx.IDENTIFIER(), GoAnnotations.RESOLVED, true);
            treeDecorator.putProperty(ctx.IDENTIFIER(), GoAnnotations.NODE_TYPE, NodeType.CONST_REF);
            break;

        case "iota":
            treeDecorator.putProperty(ctx.IDENTIFIER(), GoAnnotations.UNEVALUATED_CONSTANT, "iota");
            treeDecorator.putProperty(ctx.IDENTIFIER(), GoAnnotations.EVALUATED_CONSTANT, _iota);
            treeDecorator.putProperty(ctx.IDENTIFIER(), GoAnnotations.RESOLVED, true);
            treeDecorator.putProperty(ctx.IDENTIFIER(), GoAnnotations.NODE_TYPE, NodeType.CONST_REF);
            break;
        }

        TerminalNode local = getVisibleLocal(ctx.IDENTIFIER());
        if (local != null) {
            treeDecorator.putProperty(ctx.IDENTIFIER(), GoAnnotations.NODE_TYPE, NodeType.VAR_REF);
            treeDecorator.putProperty(ctx.IDENTIFIER(), GoAnnotations.LOCAL_TARGET, local);
            treeDecorator.putProperty(ctx.IDENTIFIER(), GoAnnotations.RESOLVED, true);
            VarKind varType = treeDecorator.getProperty(local, GoAnnotations.VAR_TYPE);
            if (varType != VarKind.UNDEFINED) {
                treeDecorator.putProperty(ctx.IDENTIFIER(), GoAnnotations.VAR_TYPE, varType);
            }

            if (local.getParent().getRuleContext() instanceof TypeSwitchGuardContext) {
                TypeSwitchGuardContext typeSwitchGuardContext = (TypeSwitchGuardContext) local.getParent()
                        .getRuleContext();
                TypeSwitchStmtContext typeSwitchStmtContext = (TypeSwitchStmtContext) typeSwitchGuardContext
                        .getParent();
                for (TypeCaseClauseContext typeCaseClauseContext : typeSwitchStmtContext.typeCaseClause()) {
                    if (ParseTrees.isAncestorOf(typeCaseClauseContext, ctx)) {
                        TypeListContext typeListContext = typeCaseClauseContext.typeSwitchCase() != null
                                ? typeCaseClauseContext.typeSwitchCase().typeList()
                                : null;
                        if (typeListContext != null && typeListContext.type().size() == 1) {
                            treeDecorator.putProperty(ctx.IDENTIFIER(), GoAnnotations.EXPLICIT_TYPE,
                                    typeListContext.type(0));
                        }

                        break;
                    }
                }
            }

            return;
        }

        TerminalNode constant = getVisibleConstant(ctx.IDENTIFIER());
        if (constant != null) {
            treeDecorator.putProperty(ctx.IDENTIFIER(), GoAnnotations.NODE_TYPE, NodeType.CONST_REF);
            treeDecorator.putProperty(ctx.IDENTIFIER(), GoAnnotations.LOCAL_TARGET, constant);
            treeDecorator.putProperty(ctx.IDENTIFIER(), GoAnnotations.RESOLVED, true);
            return;
        }

        // check built-ins
        if (SemanticHighlighter.PREDEFINED_FUNCTIONS.contains(ctx.IDENTIFIER().getSymbol().getText())) {
            treeDecorator.putProperty(ctx.IDENTIFIER(), GoAnnotations.NODE_TYPE, NodeType.FUNC_REF);
            treeDecorator.putProperty(ctx.IDENTIFIER(), GoAnnotations.BUILTIN, true);
        } else if (SemanticHighlighter.PREDEFINED_TYPES.contains(ctx.IDENTIFIER().getSymbol().getText())) {
            treeDecorator.putProperty(ctx.IDENTIFIER(), GoAnnotations.NODE_TYPE, NodeType.TYPE_REF);
            treeDecorator.putProperty(ctx.IDENTIFIER(), GoAnnotations.TYPE_KIND, TypeKind.INTRINSIC);
            treeDecorator.putProperty(ctx.IDENTIFIER(), GoAnnotations.BUILTIN, true);
        } else if (SemanticHighlighter.PREDEFINED_CONSTANTS.contains(ctx.IDENTIFIER().getSymbol().getText())) {
            treeDecorator.putProperty(ctx.IDENTIFIER(), GoAnnotations.NODE_TYPE, NodeType.CONST_REF);
            treeDecorator.putProperty(ctx.IDENTIFIER(), GoAnnotations.BUILTIN, true);
        } else {
            unresolvedIdentifiers.add(ctx.IDENTIFIER());
        }
    }
}

From source file:org.tvl.goworks.editor.go.semantics.SemanticAnalyzerListener.java

License:Open Source License

@Override
@RuleDependencies({/*w  ww.j av  a 2s. c o  m*/
        @RuleDependency(recognizer = GoParser.class, rule = GoParser.RULE_builtinCall, version = 0, dependents = Dependents.PARENTS),
        @RuleDependency(recognizer = GoParser.class, rule = GoParser.RULE_builtinArgs, version = 3, dependents = Dependents.SELF),
        @RuleDependency(recognizer = GoParser.class, rule = GoParser.RULE_builtinTypeArgs, version = 3, dependents = Dependents.SELF),
        @RuleDependency(recognizer = GoParser.class, rule = GoParser.RULE_type, version = 0, dependents = Dependents.SELF),
        @RuleDependency(recognizer = GoParser.class, rule = GoParser.RULE_argumentList, version = 0, dependents = Dependents.SELF),
        @RuleDependency(recognizer = GoParser.class, rule = GoParser.RULE_expressionList, version = 1, dependents = Dependents.SELF),
        @RuleDependency(recognizer = GoParser.class, rule = GoParser.RULE_expression, version = 0, dependents = Dependents.SELF),
        @RuleDependency(recognizer = GoParser.class, rule = GoParser.RULE_typeSwitchGuard, version = 0, dependents = Dependents.PARENTS),
        @RuleDependency(recognizer = GoParser.class, rule = GoParser.RULE_typeSwitchStmt, version = 0, dependents = Dependents.PARENTS),
        @RuleDependency(recognizer = GoParser.class, rule = GoParser.RULE_typeCaseClause, version = 3, dependents = {
                Dependents.SELF, Dependents.DESCENDANTS }),
        @RuleDependency(recognizer = GoParser.class, rule = GoParser.RULE_typeSwitchCase, version = 0, dependents = Dependents.SELF),
        @RuleDependency(recognizer = GoParser.class, rule = GoParser.RULE_typeList, version = 0, dependents = Dependents.SELF), })
public void exitBuiltinCall(BuiltinCallContext ctx) {
    BuiltinArgsContext args = ctx.builtinArgs();
    if (ctx.IDENTIFIER() != null
            && !SemanticHighlighter.PREDEFINED_FUNCTIONS.contains(ctx.IDENTIFIER().getText())
            && (args == null || args.type() == null)) {
        // not a built in function, and no type was passed to it

        // HACK: copied from enterQualifiedIdentifier
        TerminalNode local = getVisibleLocal(ctx.IDENTIFIER());
        if (local != null) {
            treeDecorator.putProperty(ctx.IDENTIFIER(), GoAnnotations.NODE_TYPE, NodeType.VAR_REF);
            treeDecorator.putProperty(ctx.IDENTIFIER(), GoAnnotations.LOCAL_TARGET, local);
            treeDecorator.putProperty(ctx.IDENTIFIER(), GoAnnotations.RESOLVED, true);
            VarKind varType = treeDecorator.getProperty(local, GoAnnotations.VAR_TYPE);
            if (varType != VarKind.UNDEFINED) {
                treeDecorator.putProperty(ctx.IDENTIFIER(), GoAnnotations.VAR_TYPE, varType);
            }

            if (local.getParent().getRuleContext() instanceof TypeSwitchGuardContext) {
                TypeSwitchGuardContext typeSwitchGuardContext = (TypeSwitchGuardContext) local.getParent()
                        .getRuleContext();
                TypeSwitchStmtContext typeSwitchStmtContext = (TypeSwitchStmtContext) typeSwitchGuardContext
                        .getParent();
                for (TypeCaseClauseContext typeCaseClauseContext : typeSwitchStmtContext.typeCaseClause()) {
                    if (ParseTrees.isAncestorOf(typeCaseClauseContext, ctx)) {
                        TypeListContext typeListContext = typeCaseClauseContext.typeSwitchCase() != null
                                ? typeCaseClauseContext.typeSwitchCase().typeList()
                                : null;
                        if (typeListContext != null && typeListContext.type().size() == 1) {
                            treeDecorator.putProperty(ctx.IDENTIFIER(), GoAnnotations.EXPLICIT_TYPE,
                                    typeListContext.type(0));
                        }

                        break;
                    }
                }
            }
        } else {
            TerminalNode constant = getVisibleConstant(ctx.IDENTIFIER());
            if (constant != null) {
                treeDecorator.putProperty(ctx.IDENTIFIER(), GoAnnotations.NODE_TYPE, NodeType.CONST_REF);
                treeDecorator.putProperty(ctx.IDENTIFIER(), GoAnnotations.LOCAL_TARGET, constant);
                treeDecorator.putProperty(ctx.IDENTIFIER(), GoAnnotations.RESOLVED, true);
            } else {
                // check built-ins
                if (SemanticHighlighter.PREDEFINED_FUNCTIONS.contains(ctx.IDENTIFIER().getSymbol().getText())) {
                    treeDecorator.putProperty(ctx.IDENTIFIER(), GoAnnotations.NODE_TYPE, NodeType.FUNC_REF);
                    treeDecorator.putProperty(ctx.IDENTIFIER(), GoAnnotations.BUILTIN, true);
                } else if (SemanticHighlighter.PREDEFINED_TYPES
                        .contains(ctx.IDENTIFIER().getSymbol().getText())) {
                    treeDecorator.putProperty(ctx.IDENTIFIER(), GoAnnotations.NODE_TYPE, NodeType.TYPE_REF);
                    treeDecorator.putProperty(ctx.IDENTIFIER(), GoAnnotations.TYPE_KIND, TypeKind.INTRINSIC);
                    treeDecorator.putProperty(ctx.IDENTIFIER(), GoAnnotations.BUILTIN, true);
                } else if (SemanticHighlighter.PREDEFINED_CONSTANTS
                        .contains(ctx.IDENTIFIER().getSymbol().getText())) {
                    treeDecorator.putProperty(ctx.IDENTIFIER(), GoAnnotations.NODE_TYPE, NodeType.CONST_REF);
                    treeDecorator.putProperty(ctx.IDENTIFIER(), GoAnnotations.BUILTIN, true);
                } else {
                    unresolvedIdentifiers.add(ctx.IDENTIFIER());
                }
            }
        }

        treeDecorator.putProperty(ctx, GoAnnotations.EXPR_TYPE,
                new CallResultReference(new UnqualifiedIdentifierElementReference(ctx.IDENTIFIER())));
        return;
    }

    CodeElementReference typeArgument = CodeElementReference.UNKNOWN;
    if (args != null) {
        if (args.type() != null) {
            typeArgument = treeDecorator.getProperty(args.type(), GoAnnotations.CODE_CLASS);
        } else {
            ArgumentListContext argumentList = args.argumentList();
            ExpressionListContext exprList = argumentList != null ? argumentList.expressionList() : null;
            if (exprList != null) {
                List<? extends ExpressionContext> exprs = exprList.expression();
                if (exprs != null && !exprs.isEmpty()) {
                    typeArgument = treeDecorator.getProperty(exprs.get(0), GoAnnotations.EXPR_TYPE);
                    if (typeArgument == CodeElementReference.MISSING) {
                        typeArgument = treeDecorator.getProperty(exprs.get(0), GoAnnotations.CODE_CLASS);
                    }
                }
            }
        }
    }

    if (ctx.IDENTIFIER() != null) {
        treeDecorator.putProperty(ctx, GoAnnotations.EXPR_TYPE,
                new BuiltinCallResultReference(ctx.IDENTIFIER().getSymbol(), typeArgument));
    } else {
        treeDecorator.putProperty(ctx, GoAnnotations.EXPR_TYPE, CodeElementReference.UNKNOWN);
    }
}

From source file:tilda.grammar.TildaSQLTreePrinter.java

License:Apache License

@Override
public void visitTerminal(TerminalNode node) {
    _Path.get(node.getParent()).add(node.getText());
}