public override object VisitLambdaExpression(CsharpSubsetParser.LambdaExpressionContext context) { string body = null; bool isTyped = false; if (context.lambdaBody() != null) { body = GetContextSource(context.lambdaBody()); isTyped = context.lambdaBody().returnStmnt() != null; } else { body = "\nreturn " + GetContextSource(context.mathExpression()) + ";\n"; isTyped = true; } var lambdaExpressionInterval = new Interval(context.Start.StartIndex, context.Stop.StopIndex); var argList = GetArgList(context); var classDefinitionContext = FindClassDefinitionContext(context); var clasStartIndex = classDefinitionContext.Start.StartIndex; RefactorData data = new RefactorData(argList, body, lambdaExpressionInterval, clasStartIndex, isTyped); RefactorDataList.Add(data); return(base.VisitLambdaExpression(context)); }
private string GetArgList(CsharpSubsetParser.LambdaExpressionContext context) { string argList; StringBuilder args = new StringBuilder(GetContextSource(context.lambdaArgs())); if (args[0] == '(') { args.Replace("(", ""); args.Replace(")", ""); } Console.WriteLine(context.lambdaArgs()); if (context.lambdaArgs().type().Length == 0 && context.lambdaArgs().NAME().Length != 0) { var arguments = args.ToString().Split(','); for (int i = 0; i < arguments.Length; i++) { arguments[i] = "int " + arguments[i]; } argList = string.Join(", ", arguments); } else { argList = args.ToString(); } return(argList); }
/// <summary> /// Exit a parse tree produced by <see cref="CsharpSubsetParser.lambdaExpression"/>. /// <para>The default implementation does nothing.</para> /// </summary> /// <param name="context">The parse tree.</param> public virtual void ExitLambdaExpression([NotNull] CsharpSubsetParser.LambdaExpressionContext context) { }
/// <summary> /// Visit a parse tree produced by <see cref="CsharpSubsetParser.lambdaExpression"/>. /// <para> /// The default implementation returns the result of calling <see cref="AbstractParseTreeVisitor{Result}.VisitChildren(IRuleNode)"/> /// on <paramref name="context"/>. /// </para> /// </summary> /// <param name="context">The parse tree.</param> /// <return>The visitor result.</return> public virtual Result VisitLambdaExpression([NotNull] CsharpSubsetParser.LambdaExpressionContext context) { return(VisitChildren(context)); }