Exemple #1
0
        public override void EnterMethodDeclaration([NotNull] JavaParser.MethodDeclarationContext context)
        {
            Logger.Debug("parsing method");

            var inputStream = context.Start.InputStream;

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

            var parameters = context.formalParameters()?.formalParameterList()?.formalParameter();

            Method methodModel = new Method(_currentClass, context.Identifier()?.GetText(), inputStream.GetText(interval));

            if (parameters != null)
            {
                foreach (var param in parameters)
                {
                    methodModel.AddParameter(param.GetText());
                }
            }

            if (_currentClass != null)
            {
                _currentClass.AddMethod(methodModel);
            }

            _statementListener.setCurrentMethod(methodModel);

            InvokeParseInfoUpdate("Parsing method: " + methodModel.Name);
        }
Exemple #2
0
        public override bool VisitMethodDeclaration([NotNull] JavaParser.MethodDeclarationContext context)
        {
            ++MethodCounter;
            Methods.Add(context.IDENTIFIER().GetText());

            return(true);
        }
Exemple #3
0
 public override void EnterMethodDeclaration(JavaParser.MethodDeclarationContext context)
 {
     ParseMethodFromContext(
         context.formalParameters(),
         context.typeTypeOrVoid(),
         context.qualifiedNameList(),
         context.IDENTIFIER().GetText(),
         context.GetFullText());
 }
Exemple #4
0
        public UstNode VisitMethodDeclaration(JavaParser.MethodDeclarationContext context)
        {
            JavaParser.TypeTypeOrVoidContext type = context.typeTypeOrVoid();
            ITerminalNode child0Terminal          = context.GetChild <ITerminalNode>(0);
            ITerminalNode identifier = context.IDENTIFIER();

            JavaParser.FormalParametersContext formalParameters = context.formalParameters();
            JavaParser.BlockContext            methodBody       = context.methodBody().block();

            MethodDeclaration result = ConvertMethodDeclaration(type, child0Terminal, identifier, formalParameters, methodBody,
                                                                context.GetTextSpan());

            return(result);
        }
Exemple #5
0
        public override void EnterMethodDeclaration(JavaParser.MethodDeclarationContext context)
        {
            var tokens     = context.GetTokens(JavaParser.Identifier);
            var parameters = context.GetRuleContexts <JavaParser.FormalParametersContext>();

            foreach (var token in tokens)
            {
                if (Process != null)
                {
                    //打印方法名
                    Process(this, "Method : " + token.Symbol.Text + "(");
                }
            }
            foreach (var param in parameters)
            {
                if (Process != null)
                {
                    var paramListCtxs = param.GetRuleContexts <JavaParser.FormalParameterListContext>();
                    foreach (var paramListCtx in paramListCtxs)
                    {
                        var fpcs = paramListCtx.GetRuleContexts <JavaParser.FormalParameterContext>();
                        foreach (var fpc in fpcs)
                        {
                            var varIdCtxs = fpc.GetRuleContexts <JavaParser.VariableDeclaratorIdContext>();
                            foreach (var varIdCtx in varIdCtxs)
                            {
                                var varTokens = varIdCtx.GetTokens(JavaParser.Identifier);
                                foreach (var token in varTokens)
                                {
                                    //打印参数名
                                    Process(this, "    " + token.Symbol.Text + ",");
                                }
                            }
                        }
                    }
                }
            }
            foreach (var token in tokens)
            {
                if (Process != null)
                {
                    Process(this, ")");
                }
            }
        }
Exemple #6
0
 public override void ExitMethodDeclaration([NotNull] JavaParser.MethodDeclarationContext context)
 {
     _methodListener.ExitMethodDeclaration(context);
 }
Exemple #7
0
 public override void ExitMethodDeclaration([NotNull] JavaParser.MethodDeclarationContext context)
 {
     _statementListener.resetCurrentMethod();
 }