Ejemplo n.º 1
0
        public Ust VisitLocalVariableDeclaration(JavaParser.LocalVariableDeclarationContext context)
        {
            var type = (TypeToken)Visit(context.typeType());

            AssignmentExpression[] initializers = context.variableDeclarators().variableDeclarator()
                                                  .Select(varDec => (AssignmentExpression)Visit(varDec))
                                                  .Where(initializer => initializer != null).ToArray();

            if (initializers.Count() == 1 && initializers.First().Right is MultichildExpression multichildExpression)
            {
                var expressions = multichildExpression.Expressions;
                // is array?
                if (CommonUtils.TryCheckIdTokenValue(expressions.FirstOrDefault(), "{") &&
                    CommonUtils.TryCheckIdTokenValue(expressions.LastOrDefault(), "}"))
                {
                    int dimensions = multichildExpression.GetDepth(1);
                    var sizes      = Enumerable.Range(0, dimensions).Select(
                        _ => new IntLiteral(0, type.TextSpan)).ToList <Expression>();
                    var array_initializers     = expressions.Where(el => !(el is IdToken));
                    initializers.First().Right = new ArrayCreationExpression(
                        new TypeToken(type.TypeText, type.TextSpan), sizes,
                        array_initializers, multichildExpression.TextSpan);
                }
            }

            var result = new VariableDeclarationExpression(type, initializers, context.GetTextSpan());

            return(result);
        }
Ejemplo n.º 2
0
        public UstNode VisitLocalVariableDeclaration(JavaParser.LocalVariableDeclarationContext context)
        {
            var type = (TypeToken)Visit(context.typeType());

            AssignmentExpression[] initializers = context.variableDeclarators().variableDeclarator()
                                                  .Select(varDec => (AssignmentExpression)Visit(varDec))
                                                  .Where(initializer => initializer != null).ToArray();

            var result = new VariableDeclarationExpression(type, initializers, context.GetTextSpan(), FileNode);

            return(result);
        }
Ejemplo n.º 3
0
        public override void EnterLocalVariableDeclaration([NotNull] JavaParser.LocalVariableDeclarationContext context)
        {
            Logger.Debug("parsing local variable declaration");

            if (_currentMethod != null)
            {
                var inputStream = context.Start.InputStream;

                var interval = new Interval(context.Start.StartIndex, context.Stop.StopIndex);

                var text = context.GetText();

                _currentMethod.AddLocalField(text);
            }
        }
Ejemplo n.º 4
0
 public override void ExitLocalVariableDeclaration([NotNull] JavaParser.LocalVariableDeclarationContext context)
 {
     _statementListener.ExitLocalVariableDeclaration(context);
 }