private async Task<Document> CorrectKindAsync(Document document, ArgumentListSyntax declaration, CancellationToken c) { SyntaxGenerator generator = SyntaxGenerator.GetGenerator(document); ArgumentSyntax argument = CodeFixNodeCreator.CreateSyntaxKindIfStatement(generator); SeparatedSyntaxList<ArgumentSyntax> arguments = declaration.Arguments; if (arguments.Count < 2) { arguments = arguments.Add(argument); } else { arguments = arguments.Replace(arguments[1], argument); } var argList = SyntaxFactory.ArgumentList(arguments); SyntaxNode newRegister = generator.IdentifierName("RegisterSyntaxNodeAction"); SyntaxNode newMemberExpr = generator.MemberAccessExpression(((declaration.Parent as InvocationExpressionSyntax).Expression as MemberAccessExpressionSyntax).Expression, newRegister); SyntaxNode newInvocationExpr = generator.InvocationExpression(newMemberExpr, argList.Arguments); SyntaxNode newExpression = generator.ExpressionStatement(newInvocationExpr); return await ReplaceNode(declaration.Ancestors().OfType<ExpressionStatementSyntax>().First(), newExpression.WithLeadingTrivia(SyntaxFactory.TriviaList(SyntaxFactory.Whitespace(" "), SyntaxFactory.ParseLeadingTrivia("// Calls the method (first argument) to perform analysis whenever this is a change to a SyntaxNode of kind IfStatement").ElementAt(0), SyntaxFactory.EndOfLine("\r\n"), SyntaxFactory.Whitespace(" "))), document); }
// corrects the kind argument of the register statement to be SyntaxKind.IfStatement private async Task<Document> CorrectKindAsync(Document document, ArgumentListSyntax declaration, CancellationToken c) { SyntaxGenerator generator = SyntaxGenerator.GetGenerator(document); ArgumentSyntax argument = CodeFixHelper.CreateSyntaxKindIfStatement(generator); SeparatedSyntaxList<ArgumentSyntax> arguments = declaration.Arguments; if (arguments.Count < 2) { arguments = arguments.Add(argument); } else { arguments = arguments.Replace(arguments[1], argument); } ArgumentListSyntax argList = SyntaxFactory.ArgumentList(arguments); string contextParameter = (((declaration.Parent as InvocationExpressionSyntax).Expression as MemberAccessExpressionSyntax).Expression as IdentifierNameSyntax).Identifier.Text; SyntaxNode newExpr = CodeFixHelper.BuildRegister(generator, contextParameter, "RegisterSyntaxNodeAction", argList); return await ReplaceNode(declaration.Ancestors().OfType<InvocationExpressionSyntax>().First(), newExpr.WithLeadingTrivia(SyntaxFactory.TriviaList(SyntaxFactory.Whitespace(" "), SyntaxFactory.ParseLeadingTrivia("// Calls the method (first argument) to perform analysis whenever a SyntaxNode of kind IfStatement is found").ElementAt(0), SyntaxFactory.EndOfLine("\r\n"), SyntaxFactory.Whitespace(" "))), document); }