public override void VisitSimpleLambdaExpression(SimpleLambdaExpressionSyntax node) { return; }
public override void VisitSimpleLambdaExpression(SimpleLambdaExpressionSyntax node) { VisitLambdaExpression(node); }
public override void VisitSimpleLambdaExpression(SimpleLambdaExpressionSyntax node) { VisitWithNesting(node, base.VisitSimpleLambdaExpression); }
public override void VisitSimpleLambdaExpression(SimpleLambdaExpressionSyntax node) { LambdaExpressionHandler(node); base.VisitSimpleLambdaExpression(node); }
public override SyntaxNode VisitSimpleLambdaExpression(SimpleLambdaExpressionSyntax node) { return(node); }
/* * private MemberExpression GetExpressionMethod(string methodName, Type[] parameterTypes) * { * var method = project.FindMethod(typeof(System.Linq.Expressions.Expression).GetMethod(methodName, parameterTypes)); * return SkJs.EntityMethodToJsFunctionRef(method); * } */ public override JsExpression VisitSimpleLambdaExpression(SimpleLambdaExpressionSyntax node) { return(VisitLambdaExpression(node, new[] { node.Parameter }, node.Body)); }
public override object VisitSimpleLambdaExpression(SimpleLambdaExpressionSyntax node) { Visit(node.Body); return(null); }
public override void VisitSimpleLambdaExpression(SimpleLambdaExpressionSyntax node) { _tracker.AddIdentifier(node.Parameter.Identifier); Visit(node.Body); _tracker.RemoveIdentifier(node.Parameter.Identifier); }
public static Lambda Create(ExpressionNodeInfo info, SimpleLambdaExpressionSyntax node) => new Lambda(info, node);
public override void VisitSimpleLambdaExpression(SimpleLambdaExpressionSyntax node) { // don't walk lambda }
Lambda(ExpressionNodeInfo info, SimpleLambdaExpressionSyntax node) : this(info.SetKind(ExprKind.LAMBDA), node.Body, Enumerators.Singleton(node.Parameter)) { }
public static bool TryFindMethodInvocation( SyntaxNode containerNode, ImmutableArray <string> methodNames, Func <SimpleLambdaExpressionSyntax, bool> lambdaPredicate, out InvocationExpressionSyntax invocation, out SimpleLambdaExpressionSyntax methodArgument, out int index) { invocation = null; methodArgument = null; index = -1; bool isFound = false; foreach (var node in containerNode.DescendantNodes()) { if (!node.IsKind(SyntaxKind.InvocationExpression)) { continue; } var currentInvocation = (InvocationExpressionSyntax)node; if (!currentInvocation.Expression.IsKind(SyntaxKind.SimpleMemberAccessExpression)) { continue; } var memberAccess = (MemberAccessExpressionSyntax)currentInvocation.Expression; index = methodNames.IndexOf(memberAccess.Name.Identifier.Text); if (index == -1) { continue; } if (currentInvocation.ArgumentList.Arguments.Count != 1) { continue; } var argument = currentInvocation.ArgumentList.Arguments[0]; if (!argument.Expression.IsKind(SyntaxKind.SimpleLambdaExpression)) { continue; } var lambda = (SimpleLambdaExpressionSyntax)argument.Expression; if (!lambdaPredicate(lambda)) { continue; } invocation = currentInvocation; methodArgument = lambda; isFound = true; break; } return(isFound); }
public override void VisitSimpleLambdaExpression(SimpleLambdaExpressionSyntax node) => OnlyOnParent(node, () => base.VisitSimpleLambdaExpression(node));
public override void VisitSimpleLambdaExpression(SimpleLambdaExpressionSyntax node) { Emit <SimpleLambdaExpressionBlock, SimpleLambdaExpressionSyntax>(node); }
private SyntaxNode FixSimpleLambda(SimpleLambdaExpressionSyntax lambda) { return(lambda.WithAsyncKeyword(default(SyntaxToken)).WithPrependedLeadingTrivia(lambda.AsyncKeyword.LeadingTrivia)); }
public override void VisitSimpleLambdaExpression(SimpleLambdaExpressionSyntax node) { Visit(node.Body); //base.VisitSimpleLambdaExpression(node); }
private static TypeSyntax GetCastType(SimpleLambdaExpressionSyntax lambda) { return(lambda?.Body?.As <CastExpressionSyntax>()?.Type); }
public override SyntaxNode VisitSimpleLambdaExpression(SimpleLambdaExpressionSyntax node) { node = (SimpleLambdaExpressionSyntax)base.VisitSimpleLambdaExpression(node); Classes.Add(node); return(node); }
public override void VisitSimpleLambdaExpression(SimpleLambdaExpressionSyntax node) { hasLambdasWithClosedVariables = hasLambdasWithClosedVariables || LambdaClosedVariablesChecker.HasClosedVariables(node); }
public override void VisitSimpleLambdaExpression(SimpleLambdaExpressionSyntax node) { // ignore lambdas }
public override LuaSyntaxNode VisitSimpleLambdaExpression(SimpleLambdaExpressionSyntax node) { return(VisitLambdaExpression(new ParameterSyntax[] { node.Parameter }, node.Body)); }
public override void VisitSimpleLambdaExpression(SimpleLambdaExpressionSyntax node) { _anonymousFunctionDepth++; base.VisitSimpleLambdaExpression(node); _anonymousFunctionDepth--; }
public override TypeSyntax VisitSimpleLambdaExpression(SimpleLambdaExpressionSyntax node) => GetInferredReturnTypeOfAnonymousFunctionSyntax(node);
public override void VisitSimpleLambdaExpression(SimpleLambdaExpressionSyntax node) { throw new NotImplementedException(); }
public override SyntaxNode VisitSimpleLambdaExpression(SimpleLambdaExpressionSyntax node) { FilterAndInstrument(node.Body); return(base.VisitSimpleLambdaExpression(node)); }
public static async Task <Document> RefactorAsync( Document document, ConditionalAccessExpressionSyntax conditionalAccess, CancellationToken cancellationToken) { ExpressionSyntax expression = conditionalAccess.Expression; SemanticModel semanticModel = await document.GetSemanticModelAsync().ConfigureAwait(false); int position = conditionalAccess.SpanStart; string localName = NameGenerator.Default.EnsureUniqueLocalName(DefaultNames.Variable, semanticModel, position); ITypeSymbol typeSymbol = semanticModel.GetTypeSymbol(expression, cancellationToken); TypeSyntax type = (typeSymbol?.SupportsExplicitDeclaration() == true) ? typeSymbol.ToMinimalTypeSyntax(semanticModel, position) : VarType(); LocalDeclarationStatementSyntax localStatement = LocalDeclarationStatement( type, Identifier(localName).WithRenameAnnotation(), expression); InvocationExpressionSyntax newExpression = CreateTaskFromResultExpression(document, conditionalAccess, semanticModel, cancellationToken); IfStatementSyntax ifStatement = IfStatement( CSharpSnippets.NotEqualsToNull(IdentifierName(localName)), Block(ReturnStatement(conditionalAccess.RemoveOperatorToken())), ElseClause(Block(ReturnStatement(newExpression)))); SyntaxList <StatementSyntax> statements = List(new StatementSyntax[] { localStatement, ifStatement }); SyntaxNode parent = conditionalAccess.Parent; if (parent is ReturnStatementSyntax returnStatement) { statements = statements.WithTriviaFrom(returnStatement); if (returnStatement.IsEmbedded()) { return(await document.ReplaceNodeAsync(returnStatement, Block(statements), cancellationToken).ConfigureAwait(false)); } else { return(await document.ReplaceNodeAsync(returnStatement, statements, cancellationToken).ConfigureAwait(false)); } } else if (parent is SimpleLambdaExpressionSyntax simpleLambda) { SimpleLambdaExpressionSyntax newNode = simpleLambda .WithBody(Block(statements)) .WithFormatterAnnotation(); return(await document.ReplaceNodeAsync(simpleLambda, newNode, cancellationToken).ConfigureAwait(false)); } else if (parent is ParenthesizedLambdaExpressionSyntax parenthesizedLambda) { ParenthesizedLambdaExpressionSyntax newNode = parenthesizedLambda .WithBody(Block(statements)) .WithFormatterAnnotation(); return(await document.ReplaceNodeAsync(parenthesizedLambda, newNode, cancellationToken).ConfigureAwait(false)); } else { var arrowExpressionClause = (ArrowExpressionClauseSyntax)parent; SyntaxNode node = arrowExpressionClause.Parent; SyntaxNode newNode = CreateNewNode(node).WithFormatterAnnotation(); return(await document.ReplaceNodeAsync(node, newNode, cancellationToken).ConfigureAwait(false)); } SyntaxNode CreateNewNode(SyntaxNode node) { switch (node) { case MethodDeclarationSyntax methodDeclaration: { return(methodDeclaration .WithExpressionBody(null) .WithBody(Block(statements))); } case LocalFunctionStatementSyntax localFunction: { return(localFunction .WithExpressionBody(null) .WithBody(Block(statements))); } case PropertyDeclarationSyntax propertyDeclaration: { return(propertyDeclaration .WithExpressionBody(null) .WithSemicolonToken(default(SyntaxToken)) .WithAccessorList(AccessorList(GetAccessorDeclaration(Block(statements))))); } case IndexerDeclarationSyntax indexerDeclaration: { return(indexerDeclaration .WithExpressionBody(null) .WithSemicolonToken(default(SyntaxToken)) .WithAccessorList(AccessorList(GetAccessorDeclaration(Block(statements))))); } case AccessorDeclarationSyntax accessorDeclaration: { return(accessorDeclaration .WithExpressionBody(null) .WithSemicolonToken(default(SyntaxToken)) .WithBody(Block(statements))); } default: { Debug.Fail(node.Kind().ToString()); return(node); } } } }
public SimpleLambdaExpressionTranslation(SimpleLambdaExpressionSyntax syntax, SyntaxTranslation parent) : base(syntax, parent) { Body = syntax.Body.Get <CSharpSyntaxTranslation>(this); Parameter = syntax.Parameter.Get <ParameterTranslation>(this); }
internal static SyntaxNode WithoutAsyncModifier(SimpleLambdaExpressionSyntax lambda) => lambda.WithAsyncKeyword(default).WithPrependedLeadingTrivia(lambda.AsyncKeyword.LeadingTrivia);
private static async Task <Document> RefactorAsync( Document document, SyntaxNode node, CancellationToken cancellationToken) { SemanticModel semanticModel = await document.GetSemanticModelAsync(cancellationToken).ConfigureAwait(false); switch (node) { case MethodDeclarationSyntax methodDeclaration: { IMethodSymbol methodSymbol = semanticModel.GetDeclaredSymbol(methodDeclaration, cancellationToken); UseAsyncAwaitRewriter rewriter = UseAsyncAwaitRewriter.Create(methodSymbol); var newNode = (MethodDeclarationSyntax)rewriter.VisitMethodDeclaration(methodDeclaration); newNode = ModifierList <MethodDeclarationSyntax> .Instance.Insert(newNode, SyntaxKind.AsyncKeyword); return(await document.ReplaceNodeAsync(methodDeclaration, newNode, cancellationToken).ConfigureAwait(false)); } case LocalFunctionStatementSyntax localFunction: { IMethodSymbol methodSymbol = semanticModel.GetDeclaredSymbol(localFunction, cancellationToken); UseAsyncAwaitRewriter rewriter = UseAsyncAwaitRewriter.Create(methodSymbol); var newBody = (BlockSyntax)rewriter.VisitBlock(localFunction.Body); LocalFunctionStatementSyntax newNode = localFunction.WithBody(newBody); newNode = ModifierList <LocalFunctionStatementSyntax> .Instance.Insert(newNode, SyntaxKind.AsyncKeyword); return(await document.ReplaceNodeAsync(localFunction, newNode, cancellationToken).ConfigureAwait(false)); } case SimpleLambdaExpressionSyntax lambda: { var methodSymbol = (IMethodSymbol)semanticModel.GetSymbol(lambda, cancellationToken); UseAsyncAwaitRewriter rewriter = UseAsyncAwaitRewriter.Create(methodSymbol); var newBody = (BlockSyntax)rewriter.VisitBlock((BlockSyntax)lambda.Body); SimpleLambdaExpressionSyntax newNode = lambda .WithBody(newBody) .WithAsyncKeyword(Token(SyntaxKind.AsyncKeyword)); return(await document.ReplaceNodeAsync(lambda, newNode, cancellationToken).ConfigureAwait(false)); } case ParenthesizedLambdaExpressionSyntax lambda: { var methodSymbol = (IMethodSymbol)semanticModel.GetSymbol(lambda, cancellationToken); UseAsyncAwaitRewriter rewriter = UseAsyncAwaitRewriter.Create(methodSymbol); var newBody = (BlockSyntax)rewriter.VisitBlock((BlockSyntax)lambda.Body); ParenthesizedLambdaExpressionSyntax newNode = lambda .WithBody(newBody) .WithAsyncKeyword(Token(SyntaxKind.AsyncKeyword)); return(await document.ReplaceNodeAsync(lambda, newNode, cancellationToken).ConfigureAwait(false)); } case AnonymousMethodExpressionSyntax anonymousMethod: { var methodSymbol = (IMethodSymbol)semanticModel.GetSymbol(anonymousMethod, cancellationToken); UseAsyncAwaitRewriter rewriter = UseAsyncAwaitRewriter.Create(methodSymbol); var newBody = (BlockSyntax)rewriter.VisitBlock((BlockSyntax)anonymousMethod.Body); AnonymousMethodExpressionSyntax newNode = anonymousMethod .WithBody(newBody) .WithAsyncKeyword(Token(SyntaxKind.AsyncKeyword)); return(await document.ReplaceNodeAsync(anonymousMethod, newNode, cancellationToken).ConfigureAwait(false)); } } throw new InvalidOperationException(); }
private SyntaxNode FixSimpleLambda(SimpleLambdaExpressionSyntax lambda) { return(lambda.WithoutLeadingTrivia() .WithAsyncKeyword(s_asyncToken.WithPrependedLeadingTrivia(lambda.GetLeadingTrivia()))); }
public void VisitSimpleLambdaExpression(SimpleLambdaExpressionSyntax node) { if (node == null) throw new ArgumentNullException("node"); node.Validate(); ExpressionStart(node); if (node.Modifiers != Modifiers.None) { _writer.WriteModifiers(node.Modifiers); _writer.WriteSpace(); } node.Parameter.Accept(this); if (_writer.Configuration.Spaces.Other.AroundLambdaArrow) _writer.WriteSpace(); _writer.WriteSyntax(Syntax.Arrow); if ( _writer.Configuration.Spaces.Other.AroundLambdaArrow && !(node.Body is BlockSyntax) ) _writer.WriteSpace(); _writer.PushBraceFormatting(_writer.Configuration.BracesLayout.Other, false); node.Body.Accept(this); _writer.PopBraceFormatting(); ExpressionEnd(node); }