Пример #1
0
        public override void EnterFormalParameterList(JavaParser.FormalParameterListContext context)
        {
            FormalParameterListener formalParameterListener = new FormalParameterListener();

            foreach (JavaParser.FormalParameterContext formalParameterContext in context.formalParameter())
            {
                formalParameterContext.EnterRule(formalParameterListener);
                Arguments.Add(formalParameterListener.Argument);
            }
        }
        private MethodDeclaration ConvertMethodDeclaration(JavaParser.TypeTypeOrVoidContext type, ITerminalNode child0Terminal,
                                                           ITerminalNode identifier, JavaParser.FormalParametersContext formalParameters,
                                                           JavaParser.BlockContext methodBody, TextSpan textSpan)
        {
            TypeToken typeToken;

            if (type != null)
            {
                typeToken = (TypeToken)Visit(type);
            }
            else
            {
                var voidTerminal = child0Terminal;
                typeToken = new TypeToken(voidTerminal.GetText(), voidTerminal.GetTextSpan());
            }

            var id = (IdToken)Visit(identifier);

            // TODO: Fix with ParamsNode
            IEnumerable <ParameterDeclaration> parameters;

            JavaParser.FormalParameterListContext formalParameterList = formalParameters.formalParameterList();
            if (formalParameterList == null)
            {
                parameters = Enumerable.Empty <ParameterDeclaration>();
            }
            else
            {
                parameters = formalParameterList.formalParameter()
                             .Select(param => (ParameterDeclaration)Visit(param))
                             .Where(p => p != null).ToArray();
            }

            BlockStatement body = methodBody != null
                ? (BlockStatement)Visit(methodBody)

                                  /*: new BlockStatement(Enumerable.Empty<Statement>(),
                                   *  GetAndConvertTextSpan((ITerminalNode)context.GetChild(context.ChildCount - 1)), FileNode);*/
                : null;

            var result = new MethodDeclaration(id, parameters, body, textSpan);

            return(result);
        }
Пример #3
0
        public UstNode VisitConstructorDeclaration(JavaParser.ConstructorDeclarationContext context)
        {
            var id = (IdToken)Visit(context.IDENTIFIER());
            IEnumerable <ParameterDeclaration> parameters;

            JavaParser.FormalParameterListContext formalParameterList = context.formalParameters().formalParameterList();
            if (formalParameterList == null)
            {
                parameters = Enumerable.Empty <ParameterDeclaration>();
            }
            else
            {
                parameters = formalParameterList.formalParameter()
                             .Select(param => (ParameterDeclaration)Visit(param))
                             .Where(p => p != null).ToArray();
            }

            var body = (BlockStatement)Visit(context.constructorBody);

            var constructorDelaration = new ConstructorDeclaration(id, parameters, body, context.GetTextSpan(), FileNode);

            return(constructorDelaration);
        }