Ejemplo n.º 1
0
        private IList <StatementNode> convertBlockStatementList(BlockStatementListContext blockStatementListContext)
        {
            if (blockStatementListContext == null)
            {
                return(CollectionUtils.emptyList <StatementNode>());
            }
            IList <StatementInBlockContext> statementsInBlock = blockStatementListContext._statements;

            StatementNode[] statements = new StatementNode[statementsInBlock.Count];

            for (var i = 0; i < statementsInBlock.Count; i++)
            {
                StatementContext statementContext = statementsInBlock[i].statement();
                if (statementContext != null)
                {
                    statements[i] = (StatementNode)VisitStatement(statementContext);
                }
                else
                {
                    LocalVariableDeclarationContext localVarCtx =
                        statementsInBlock[i].localVariableDeclaration();
                    statements[i] = (StatementNode)VisitLocalVariableDeclaration(localVarCtx);
                }
            }

            return(statements);
        }
        private void HandleLocalVariableDeclarationContext(CodeBlock inCodeBlock, LocalVariableDeclarationContext tmpVar)
        {
            var tmpVarDeclaration = new VariableDeclaration();

            if (tmpVar.typeType() != null)
            {
                tmpVarDeclaration.Type = JavaAntlrClassLoader.GetTypeContainer(tmpVar.typeType());
            }
            if (tmpVar.variableDeclarators() != null)
            {
                foreach (var tmpVariableDeclaration in tmpVar.variableDeclarators().variableDeclarator())
                {
                    var tmpVarDec = new VariableDeclaration()
                    {
                        Type = tmpVarDeclaration.Type,
                        Name = tmpVariableDeclaration.variableDeclaratorId().GetText(),
                    };
                    inCodeBlock.CodeEntries.Add(tmpVarDec);
                    if (tmpVariableDeclaration.variableInitializer() != null)
                    {
                        HandleArrayInizializer(inCodeBlock, tmpVariableDeclaration.variableInitializer().arrayInitializer(), tmpVarDec);
                        HandleExpressionContext(inCodeBlock, tmpVariableDeclaration.variableInitializer().expression(), tmpVarDec);
                    }
                }
            }
            if (tmpVar.variableModifier().Length > 0)
            {
                throw new NotImplementedException("Not done yet");
            }
        }
Ejemplo n.º 3
0
        public override Tree VisitLocalVariableDeclaration(LocalVariableDeclarationContext context)
        {
            VariableDeclaration localVariableDeclaration =
                (VariableDeclaration)VisitVariableDeclaration(context.variableDeclaration());

            localVariableDeclaration.endLine = context.Stop.Line;
            localVariableDeclaration.endCol  = context.Stop.Column;

            return(localVariableDeclaration);
        }