Пример #1
0
        public Ust VisitCreator(JavaParser.CreatorContext context)
        {
            Ust result;

            JavaParser.CreatedNameContext      createdName      = context.createdName();
            JavaParser.ArrayCreatorRestContext arrayCreatorRest = context.arrayCreatorRest();
            if (arrayCreatorRest != null)
            {
                var initializer = (MultichildExpression)Visit(arrayCreatorRest.arrayInitializer());
                if (initializer != null)
                {
                    // new int[] { 1, 2 };
                    int dimensions = (arrayCreatorRest.ChildCount - 1) / 2; // number of square bracket pairs
                    var sizes      = Enumerable.Range(0, dimensions).Select(
                        _ => new IntLiteral(0, createdName.GetTextSpan())).ToList <Expression>();
                    var initializers = initializer.Expressions.Where(el => !(el is IdToken));
                    result = new ArrayCreationExpression(
                        new TypeToken(createdName.GetText(), createdName.GetTextSpan()), sizes,
                        initializers, context.GetTextSpan());
                }
                else
                {
                    // new int[3][4][];
                    int dimensions = (arrayCreatorRest.ChildCount - arrayCreatorRest.expression().Length) / 2;
                    var sizes      = Enumerable.Range(0, dimensions).Select(
                        i => i < arrayCreatorRest.expression().Length ?
                        (Expression)Visit(arrayCreatorRest.expression(i)) :
                        new IntLiteral(0, createdName.GetTextSpan())).ToList();
                    result = new ArrayCreationExpression(
                        new TypeToken(createdName.GetText(), createdName.GetTextSpan()), sizes,
                        null, context.GetTextSpan());
                }
            }
            else
            {
                JavaParser.ClassCreatorRestContext classCreatorRest = context.classCreatorRest();
                ArgsUst args = (ArgsUst)Visit(classCreatorRest?.arguments()) ?? new ArgsUst();

                // TODO: add classBody

                result = new ObjectCreateExpression(
                    new TypeToken(createdName.GetText(), createdName.GetTextSpan()), args,
                    context.GetTextSpan());
            }
            return(result);
        }
Пример #2
0
        public UstNode VisitCreator(JavaParser.CreatorContext context)
        {
            JavaParser.CreatedNameContext      createdName      = context.createdName();
            JavaParser.ClassCreatorRestContext classCreatorRest = context.classCreatorRest();
            ArgsNode args;

            if (classCreatorRest != null)
            {
                args = (ArgsNode)Visit(classCreatorRest.arguments());
            }
            else
            {
                args = new ArgsNode();
            }
            // TODO: add classBody

            var result = new ObjectCreateExpression(
                new TypeToken(createdName.GetText(), createdName.GetTextSpan(), FileNode), args,
                context.GetTextSpan(), FileNode);

            return(result);
        }