public static void ComputeRefactorings(RefactoringContext context, MemberDeclarationSyntax member) { if (context.IsAnyRefactoringEnabled( RefactoringIdentifiers.SplitAttributes, RefactoringIdentifiers.MergeAttributes)) { SyntaxList <AttributeListSyntax> lists = member.GetAttributeLists(); if (lists.Count > 0) { var info = new SelectedNodesInfo <AttributeListSyntax>(lists, context.Span); if (context.IsRefactoringEnabled(RefactoringIdentifiers.SplitAttributes) && info.SelectedNodes().Any(f => f.Attributes.Count > 1)) { context.RegisterRefactoring( "Split attributes", cancellationToken => { return(SplitAsync( context.Document, member, info.SelectedNodes().ToArray(), cancellationToken)); }); } if (context.IsRefactoringEnabled(RefactoringIdentifiers.MergeAttributes) && info.AreManySelected) { context.RegisterRefactoring( "Merge attributes", cancellationToken => { return(MergeAsync( context.Document, member, info.SelectedNodes().ToArray(), cancellationToken)); }); } } } }
public static void ComputeRefactorings(RefactoringContext context, SwitchStatementSyntax switchStatement) { bool fRemoveStatements = context.IsRefactoringEnabled(RefactoringIdentifiers.RemoveStatementsFromSwitchSections); bool fAddBraces = context.IsRefactoringEnabled(RefactoringIdentifiers.AddBracesToSwitchSections); bool fRemoveBraces = context.IsRefactoringEnabled(RefactoringIdentifiers.RemoveBracesFromSwitchSections); if (fRemoveStatements || fAddBraces || fRemoveBraces) { SyntaxList <SwitchSectionSyntax> sections = switchStatement.Sections; if (sections.Any()) { var info = new SelectedNodesInfo <SwitchSectionSyntax>(sections, context.Span); if (info.IsAnySelected) { if (fAddBraces || fRemoveBraces) { var addBraces = new List <SwitchSectionSyntax>(); var removeBraces = new List <SwitchSectionSyntax>(); foreach (SwitchSectionSyntax section in info.SelectedNodes()) { if (addBraces.Count > 0 && removeBraces.Count > 0) { break; } switch (SwitchStatementAnalysis.AnalyzeSection(section)) { case SwitchSectionAnalysisResult.AddBraces: { addBraces.Add(section); break; } case SwitchSectionAnalysisResult.RemoveBraces: { removeBraces.Add(section); break; } } } if (fAddBraces && addBraces.Count > 0) { string title = AddBracesToSwitchSectionRefactoring.Title; if (addBraces.Count > 1) { title += "s"; } context.RegisterRefactoring( title, cancellationToken => { return(AddBracesToSwitchSectionsRefactoring.RefactorAsync( context.Document, switchStatement, addBraces.ToArray(), cancellationToken)); }); } if (fRemoveBraces && removeBraces.Count > 0) { string title = RemoveBracesFromSwitchSectionRefactoring.Title; if (removeBraces.Count > 1) { title += "s"; } context.RegisterRefactoring( title, cancellationToken => { return(RemoveBracesFromSwitchSectionsRefactoring.RefactorAsync( context.Document, switchStatement, removeBraces.ToArray(), cancellationToken)); }); } } if (fRemoveStatements) { string title = "Remove statements from section"; if (info.AreManySelected) { title += "s"; } context.RegisterRefactoring( title, cancellationToken => { return(RemoveStatementsFromSwitchSectionsRefactoring.RefactorAsync( context.Document, switchStatement, info.SelectedNodes().ToImmutableArray(), cancellationToken)); }); } } } } }