public static SwitchSectionSyntax WithoutStatements(this SwitchSectionSyntax switchSection) { if (switchSection == null) { throw new ArgumentNullException(nameof(switchSection)); } return(switchSection.WithStatements(default(SyntaxList <StatementSyntax>))); }
public override SyntaxNode VisitSwitchSection(SwitchSectionSyntax node) { node = (SwitchSectionSyntax)base.VisitSwitchSection(node); SyntaxList <StatementSyntax> statements = node.Statements; statements = RewriteStatements(statements); return(node.WithStatements(statements)); }
public override SyntaxNode VisitSwitchSection(SwitchSectionSyntax node) { if (node != this.ContainerOfStatementsOrFieldToReplace) { // make sure we visit nodes under the switch section return(base.VisitSwitchSection(node)); } return(node.WithStatements(VisitList(ReplaceStatements(node.Statements)).ToSyntaxList())); }
public override SyntaxNode VisitSwitchSection(SwitchSectionSyntax node) { var resumeLocation = node.Statements.Count > 0 ? node.Statements[0].GetLocation().GetMappedLineSpan() : new FileLinePositionSpan(); node = (SwitchSectionSyntax)base.VisitSwitchSection(node); if (node.Statements.Count > 0) { node = node.WithStatements(node.Statements.Insert(0, Barricaded(resumeLocation.Path, resumeLocation.StartLinePosition, InstructionCounterCall()))); } return(node); }
public static Task <Document> RefactorAsync( Document document, SwitchSectionSyntax switchSection, CancellationToken cancellationToken = default(CancellationToken)) { var block = (BlockSyntax)switchSection.Statements[0]; SwitchSectionSyntax newSwitchSection = switchSection .WithStatements(block.Statements) .WithFormatterAnnotation(); return(document.ReplaceNodeAsync(switchSection, newSwitchSection, cancellationToken)); }
public static Task <Document> RefactorAsync( Document document, SwitchSectionSyntax switchSection, CancellationToken cancellationToken = default(CancellationToken)) { SwitchSectionSyntax newNode = switchSection .WithStatements( List <StatementSyntax>( SingletonList( Block(switchSection.Statements)))) .WithFormatterAnnotation(); return(document.ReplaceNodeAsync(switchSection, newNode, cancellationToken)); }
private static async Task <Document> AddBracesToSwitchSectionAsync( Document document, SwitchSectionSyntax switchSection, CancellationToken cancellationToken) { SyntaxNode oldRoot = await document.GetSyntaxRootAsync(cancellationToken); SwitchSectionSyntax newNode = switchSection .WithStatements(List <StatementSyntax>(SingletonList(Block(switchSection.Statements)))) .WithAdditionalAnnotations(Formatter.Annotation); SyntaxNode newRoot = oldRoot.ReplaceNode(switchSection, newNode); return(document.WithSyntaxRoot(newRoot)); }
private static async Task <Document> RemoveBracesAsync( Document document, SwitchSectionSyntax switchSection, CancellationToken cancellationToken) { SyntaxNode oldRoot = await document.GetSyntaxRootAsync(cancellationToken); var block = (BlockSyntax)switchSection.Statements[0]; SwitchSectionSyntax newSwitchSection = switchSection .WithStatements(block.Statements) .WithAdditionalAnnotations(Formatter.Annotation); SyntaxNode newRoot = oldRoot.ReplaceNode(switchSection, newSwitchSection); return(document.WithSyntaxRoot(newRoot)); }
public static async Task <Document> RefactorAsync( Document document, SwitchSectionSyntax switchSection, CancellationToken cancellationToken = default(CancellationToken)) { SyntaxNode root = await document.GetSyntaxRootAsync(cancellationToken).ConfigureAwait(false); var block = (BlockSyntax)switchSection.Statements[0]; SwitchSectionSyntax newSwitchSection = switchSection .WithStatements(block.Statements) .WithFormatterAnnotation(); SyntaxNode newRoot = root.ReplaceNode(switchSection, newSwitchSection); return(document.WithSyntaxRoot(newRoot)); }
public static async Task <Document> RefactorAsync( Document document, SwitchSectionSyntax switchSection, CancellationToken cancellationToken = default(CancellationToken)) { SyntaxNode root = await document.GetSyntaxRootAsync(cancellationToken).ConfigureAwait(false); SwitchSectionSyntax newNode = switchSection .WithStatements( List <StatementSyntax>( SingletonList( Block(switchSection.Statements)))) .WithFormatterAnnotation(); SyntaxNode newRoot = root.ReplaceNode(switchSection, newNode); return(document.WithSyntaxRoot(newRoot)); }
public override SyntaxNode VisitSwitchSection(SwitchSectionSyntax node) { node = (SwitchSectionSyntax)base.VisitSwitchSection(node); var oldStatements = node.Statements; if (oldStatements.Count == 0) //empty case - used for fall-through { return(node); } var caseTrailing = node.GetTrailingTrivia(); var caseLeading = node.GetLeadingTrivia(); var trueBlock = ToBlockSyntax(oldStatements, caseLeading, caseTrailing); node = node.WithStatements(trueBlock); return(node); }
private static SwitchSectionSyntax CreateSectionWithoutStatements(SwitchSectionSyntax section) { SwitchSectionSyntax newSection = section.WithStatements(List <StatementSyntax>()); if (newSection .GetTrailingTrivia() .All(f => f.IsWhitespaceTrivia())) { newSection = newSection.WithoutTrailingTrivia(); } if (section .SyntaxTree .IsSingleLineSpan(TextSpan.FromBounds(section.Labels.Last().SpanStart, section.Span.End))) { newSection = newSection.AppendToTrailingTrivia(section.GetTrailingTrivia()); } return(newSection); }
public override SyntaxNode NodeWithStatements(SyntaxList <StatementSyntax> statements) { return(_switchSection.WithStatements(statements)); }