private async Task<Document> MakeLambdaExpressionAsync(Document document, AnonymousMethodExpressionSyntax anonMethod, CancellationToken cancellationToken)
        {
            
            var parent = anonMethod.Parent;

            var parameterList = anonMethod.ParameterList != null ? anonMethod.ParameterList : SyntaxFactory.ParameterList();

            SyntaxNode body;

            if (anonMethod.Block != null && anonMethod.Block.Statements.Count == 1)
            {
                body = anonMethod.Block.Statements.ElementAt(0).ChildNodes().ElementAt(0);
            }
            else if (anonMethod.Block != null)
            {
                body = anonMethod.Body;
            }
            else
            {
                body = SyntaxFactory.Block();
            }

            var lambdaExpr = SyntaxFactory.
                ParenthesizedLambdaExpression(parameterList, (CSharpSyntaxNode)body);

            var newParent = parent.ReplaceNode(anonMethod, lambdaExpr);

            var root = await document.GetSyntaxRootAsync(cancellationToken).ConfigureAwait(false);

            var newRoot = root.ReplaceNode(parent, newParent);

            return document.WithSyntaxRoot(newRoot);

        }
        public static void Go(OutputWriter writer, AnonymousMethodExpressionSyntax expression)
        {
            if (expression.ParameterList != null)
                Go(writer, expression.ParameterList.Parameters, expression.Block, TypeProcessor.GetTypeInfo(expression));
            else
                Go(writer, new SeparatedSyntaxList<ParameterSyntax>(), expression.Block, TypeProcessor.GetTypeInfo(expression));

        }
        private static SyntaxNode ReplaceWithLambda(AnonymousMethodExpressionSyntax anonymousMethod)
        {
            var parameterList = anonymousMethod.ParameterList;
            SyntaxNode lambdaExpression;

            if (parameterList == null)
            {
                parameterList = SyntaxFactory.ParameterList()
                    .WithLeadingTrivia(anonymousMethod.DelegateKeyword.LeadingTrivia)
                    .WithTrailingTrivia(anonymousMethod.DelegateKeyword.TrailingTrivia);
            }
            else
            {
                parameterList = parameterList.WithLeadingTrivia(anonymousMethod.DelegateKeyword.TrailingTrivia);
            }

            foreach (var parameter in parameterList.Parameters)
            {
                if (!IsValid(parameter))
                {
                    return anonymousMethod;
                }
            }

            var arrowToken = SyntaxFactory.Token(SyntaxKind.EqualsGreaterThanToken)
                .WithTrailingTrivia(SyntaxFactory.ElasticSpace);

            if (parameterList.Parameters.Count == 1)
            {
                var parameterSyntax = RemoveType(parameterList.Parameters[0]);

                var trailingTrivia = parameterSyntax.GetTrailingTrivia()
                    .Concat(parameterList.CloseParenToken.LeadingTrivia)
                    .Concat(parameterList.CloseParenToken.TrailingTrivia.WithoutTrailingWhitespace())
                    .Concat(new[] { SyntaxFactory.ElasticSpace });
                var leadingTrivia = parameterList.OpenParenToken.LeadingTrivia
                    .Concat(parameterList.OpenParenToken.TrailingTrivia)
                    .Concat(parameterSyntax.GetLeadingTrivia());

                parameterSyntax = parameterSyntax
                    .WithLeadingTrivia(leadingTrivia)
                    .WithTrailingTrivia(trailingTrivia);

                lambdaExpression = SyntaxFactory.SimpleLambdaExpression(anonymousMethod.AsyncKeyword, parameterSyntax, arrowToken, anonymousMethod.Body);
            }
            else
            {
                var parameterListSyntax = RemoveType(parameterList)
                    .WithTrailingTrivia(parameterList.GetTrailingTrivia().WithoutTrailingWhitespace().Add(SyntaxFactory.ElasticSpace));
                lambdaExpression = SyntaxFactory.ParenthesizedLambdaExpression(anonymousMethod.AsyncKeyword, parameterListSyntax, arrowToken, anonymousMethod.Body);
            }

            return lambdaExpression
                .WithAdditionalAnnotations(Formatter.Annotation);
        }
		public override SyntaxNode VisitAnonymousMethodExpression(AnonymousMethodExpressionSyntax node)
		{
			this.lambdaStack.Push(node);

			try
			{
				return base.VisitAnonymousMethodExpression(node);
			}
			finally
			{
				this.lambdaStack.Pop();
			}
		}
            public override SyntaxNode VisitAnonymousMethodExpression(AnonymousMethodExpressionSyntax node)
            {
                node = (AnonymousMethodExpressionSyntax)base.VisitAnonymousMethodExpression(node);

                // zipFile.FileExtracting += delegate (object sender, ProgressStatusEventArgs ea) { };
                if (node.DelegateKeyword.HasTrailingTrivia)
                {
                    this.addedAnnotations = true;
                    return node.WithDelegateKeyword(node.DelegateKeyword.WithTrailingTrivia(null));
                }

                return node;
            }
Exemplo n.º 6
0
        public override SyntaxNode VisitAnonymousMethodExpression(AnonymousMethodExpressionSyntax node)
        {
            node = (AnonymousMethodExpressionSyntax)base.VisitAnonymousMethodExpression(node);

            if (transformKind == TransformKind.AnonMethodToLambda)
            {
                SyntaxToken arrowToken = SyntaxFactory.Token(SyntaxKind.EqualsGreaterThanToken);

                return SyntaxFactory.ParenthesizedLambdaExpression(default(SyntaxToken), node.ParameterList, arrowToken, node.Block);
            }

            return node;
        }
 public override void VisitAnonymousMethodExpression(Microsoft.CodeAnalysis.CSharp.Syntax.AnonymousMethodExpressionSyntax node)
 {
     base.VisitAnonymousMethodExpression(node);
     VisitBody("Delegate", node.DelegateKeyword, node.Body as StatementSyntax, null);
 }
 public override void VisitAnonymousMethodExpression(AnonymousMethodExpressionSyntax node)
 {
     // ignore anonymous methods
 }
 public override bool VisitAnonymousMethodExpression(AnonymousMethodExpressionSyntax node)
 {
     return false;
 }
Exemplo n.º 10
0
 /// <summary>
 /// 
 /// </summary>
 /// <param name="node"></param>
 public override sealed void VisitAnonymousMethodExpression(AnonymousMethodExpressionSyntax node)
 {
     this.OnNodeVisited(node);
     if (!this.traverseRootOnly) base.VisitAnonymousMethodExpression(node);
 }
 public override void VisitAnonymousMethodExpression(AnonymousMethodExpressionSyntax node)
 {
     base.VisitAnonymousMethodExpression(node);
     if (node.ParameterList != null)
         Analyze(node.ParameterList.Parameters, new[] { node.Block });
 }
            public override void VisitAnonymousMethodExpression(AnonymousMethodExpressionSyntax node)
            {
                var saveCurrentScope = currentScope;
                currentScope = new DeclarationScope(currentScope);

                Visit(node.Block);

                Debug.Assert(currentScope.Parent == saveCurrentScope);
                currentScope = saveCurrentScope;
            }
 /// <summary>
 /// 
 /// </summary>
 /// <param name="node"></param>
 public override sealed void VisitAnonymousMethodExpression(AnonymousMethodExpressionSyntax node)
 {
     this.OnNodeVisited(node, this.type.IsInstanceOfType(node));
     base.VisitAnonymousMethodExpression(node);
 }
Exemplo n.º 14
0
        public override void VisitAnonymousMethodExpression(AnonymousMethodExpressionSyntax node)
        {
            // Do not descend into a lambda unless it is a root node
            if (_root != node)
            {
                return;
            }

            VisitBlock(node.Block);
        }
 private SyntaxNode FixAnonymousMethod(AnonymousMethodExpressionSyntax method)
 {
     return method.WithAsyncKeyword(default(SyntaxToken)).WithPrependedLeadingTrivia(method.AsyncKeyword.LeadingTrivia);
 }
Exemplo n.º 16
0
 public override void VisitAnonymousMethodExpression(AnonymousMethodExpressionSyntax node)
 {
     base.VisitAnonymousMethodExpression(node);
 }
Exemplo n.º 17
0
        public override SyntaxNode VisitAnonymousMethodExpression(AnonymousMethodExpressionSyntax node)
        {
            _output.Write(node, "function ({0}) ", this.MakeParametersList(node.ParameterList));
            _output.TrivialWriteLine('{');

            _output.IncreaseIndent();
            this.Visit(node.Block);
            _output.DecreaseIndent();

            _output.TrivialWrite('}');
            return node;
        }
Exemplo n.º 18
0
 public override void VisitAnonymousMethodExpression(AnonymousMethodExpressionSyntax node)
 {
     VisitBlock(node.Block);
 }
Exemplo n.º 19
0
 private static SyntaxNode ConvertAnonymousMethodToAsync(AnonymousMethodExpressionSyntax anonymousMethod)
 {
     return SyntaxFactory.AnonymousMethodExpression(
                         SyntaxFactory.Token(SyntaxKind.AsyncKeyword),
                         anonymousMethod.DelegateKeyword,
                         anonymousMethod.ParameterList,
                         anonymousMethod.Block)
                         .WithTriviaFrom(anonymousMethod)
                         .WithAdditionalAnnotations(Formatter.Annotation);
 }
 private SyntaxNode FixAnonymousMethod(AnonymousMethodExpressionSyntax method)
 {
     return method.WithoutLeadingTrivia()
                  .WithAsyncKeyword(s_asyncToken.WithPrependedLeadingTrivia(method.GetLeadingTrivia()));
 }
Exemplo n.º 21
0
 public override void VisitAnonymousMethodExpression(AnonymousMethodExpressionSyntax node)
 {
     AnonymousDelegateWalker walker = this.CreateSyntaxWalker<AnonymousDelegateWalker>(node);
     walker.Visit(node);
     this.AnonymousMethods.Add(walker);
 }