public static Task <Document> RefactorAsync( Document document, InvocationExpressionSyntax invocationExpression, string newName, CancellationToken cancellationToken) { InvocationExpressionSyntax newInvocationExpression = RefactoringUtility.ChangeInvokedMethodName(invocationExpression, newName); return(document.ReplaceNodeAsync(invocationExpression, newInvocationExpression, cancellationToken)); }
private static ExpressionSyntax GetNewNode(PrefixUnaryExpressionSyntax logicalNot) { ExpressionSyntax operand = logicalNot.Operand; ExpressionSyntax expression = operand.WalkDownParentheses(); switch (expression.Kind()) { case SyntaxKind.TrueLiteralExpression: case SyntaxKind.FalseLiteralExpression: { LiteralExpressionSyntax newNode = BooleanLiteralExpression(expression.Kind() == SyntaxKind.FalseLiteralExpression); newNode = newNode.WithTriviaFrom(expression); return(operand.ReplaceNode(expression, newNode)); } case SyntaxKind.LogicalNotExpression: { return(((PrefixUnaryExpressionSyntax)expression).Operand); } case SyntaxKind.EqualsExpression: { var equalsExpression = (BinaryExpressionSyntax)expression; BinaryExpressionSyntax notEqualsExpression = NotEqualsExpression( equalsExpression.Left, SyntaxFactory.Token(SyntaxKind.ExclamationEqualsToken).WithTriviaFrom(equalsExpression.OperatorToken), equalsExpression.Right); return(operand.ReplaceNode(equalsExpression, notEqualsExpression)); } case SyntaxKind.InvocationExpression: { var invocationExpression = (InvocationExpressionSyntax)expression; var memberAccessExpression = (MemberAccessExpressionSyntax)invocationExpression.Expression; ExpressionSyntax lambdaExpression = invocationExpression.ArgumentList.Arguments.First().Expression.WalkDownParentheses(); SingleParameterLambdaExpressionInfo lambdaInfo = SyntaxInfo.SingleParameterLambdaExpressionInfo(lambdaExpression); var logicalNot2 = (PrefixUnaryExpressionSyntax)SimplifyLogicalNegationAnalyzer.GetReturnExpression(lambdaInfo.Body).WalkDownParentheses(); InvocationExpressionSyntax newNode = invocationExpression.ReplaceNode(logicalNot2, logicalNot2.Operand.WithTriviaFrom(logicalNot2)); return(RefactoringUtility.ChangeInvokedMethodName(newNode, (memberAccessExpression.Name.Identifier.ValueText == "All") ? "Any" : "All")); } } return(null); }
private static InvocationExpressionSyntax GetNewInvocation(InvocationExpressionSyntax invocation) { ArgumentListSyntax argumentList = invocation.ArgumentList; SeparatedSyntaxList <ArgumentSyntax> arguments = argumentList.Arguments; if (arguments.Count == 1) { ArgumentSyntax argument = arguments[0]; arguments = arguments.ReplaceAt(0, argument.WithExpression(CSharpFactory.StringLiteralExpression("").WithTriviaFrom(argument.Expression))); } else { arguments = arguments.RemoveAt(0); } return(RefactoringUtility.ChangeInvokedMethodName(invocation, "Fail") .WithArgumentList(argumentList.WithArguments(arguments))); }
private static Task <Document> SimplifyNullChckWithFirstOrDefault( Document document, SyntaxNode node, CancellationToken cancellationToken) { NullCheckExpressionInfo nullCheck = NullCheckExpressionInfo(node, NullCheckStyles.ComparisonToNull | NullCheckStyles.IsNull); var invocation = (InvocationExpressionSyntax)nullCheck.Expression; ExpressionSyntax newNode = RefactoringUtility.ChangeInvokedMethodName(invocation, "Any"); if (node.IsKind(SyntaxKind.EqualsExpression, SyntaxKind.IsPatternExpression)) { newNode = LogicalNotExpression(newNode.TrimTrivia().Parenthesize()); } newNode = newNode.WithTriviaFrom(node); return(document.ReplaceNodeAsync(node, newNode, cancellationToken)); }