public static async Task <Document> RefactorAsync( Document document, ClassDeclarationSyntax classDeclaration, CancellationToken cancellationToken) { SemanticModel semanticModel = await document.GetSemanticModelAsync(cancellationToken).ConfigureAwait(false); List <IMethodSymbol> constructors = GenerateBaseConstructorsAnalysis.GetMissingBaseConstructors(classDeclaration, semanticModel, cancellationToken); return(await GenerateBaseConstructorsRefactoring.RefactorAsync(document, classDeclaration, constructors.ToArray(), semanticModel, cancellationToken).ConfigureAwait(false)); }
public static async Task ComputeRefactoringsAsync(RefactoringContext context, RecordDeclarationSyntax recordDeclaration) { if (context.IsRefactoringEnabled(RefactoringDescriptors.AddGenericParameterToDeclaration)) { AddGenericParameterToDeclarationRefactoring.ComputeRefactoring(context, recordDeclaration); } if (context.IsRefactoringEnabled(RefactoringDescriptors.ExtractTypeDeclarationToNewFile)) { ExtractTypeDeclarationToNewFileRefactoring.ComputeRefactorings(context, recordDeclaration); } if (context.IsRefactoringEnabled(RefactoringDescriptors.GenerateBaseConstructors) && recordDeclaration.Identifier.Span.Contains(context.Span)) { SemanticModel semanticModel = await context.GetSemanticModelAsync().ConfigureAwait(false); List <IMethodSymbol> constructors = GenerateBaseConstructorsAnalysis.GetMissingBaseConstructors(recordDeclaration, semanticModel, context.CancellationToken); if (constructors?.Count > 0) { context.RegisterRefactoring( (constructors.Count == 1) ? "Generate base constructor" : "Generate base constructors", ct => GenerateBaseConstructorsRefactoring.RefactorAsync(context.Document, recordDeclaration, constructors.ToArray(), semanticModel, ct), RefactoringDescriptors.GenerateBaseConstructors); } } if (context.IsRefactoringEnabled(RefactoringDescriptors.ImplementCustomEnumerator) && context.Span.IsEmptyAndContainedInSpan(recordDeclaration.Identifier)) { SemanticModel semanticModel = await context.GetSemanticModelAsync().ConfigureAwait(false); ImplementCustomEnumeratorRefactoring.ComputeRefactoring(context, recordDeclaration, semanticModel); } if (context.IsRefactoringEnabled(RefactoringDescriptors.ExpandPositionalConstructor) && recordDeclaration.ParameterList != null && context.Span.IsEmptyAndContainedInSpanOrBetweenSpans(recordDeclaration.ParameterList.Parameters)) { ExpandPositionalConstructorRefactoring.ComputeRefactoring(context, recordDeclaration); } if (context.IsRefactoringEnabled(RefactoringDescriptors.SortMemberDeclarations) && recordDeclaration.BracesSpan().Contains(context.Span)) { SortMemberDeclarationsRefactoring.ComputeRefactoring(context, recordDeclaration); } }
public static async Task ComputeRefactoringsAsync(RefactoringContext context, ClassDeclarationSyntax classDeclaration) { if (context.IsRefactoringEnabled(RefactoringIdentifiers.AddTypeParameter)) { AddTypeParameterRefactoring.ComputeRefactoring(context, classDeclaration); } if (context.IsRefactoringEnabled(RefactoringIdentifiers.ExtractTypeDeclarationToNewFile)) { ExtractTypeDeclarationToNewFileRefactoring.ComputeRefactorings(context, classDeclaration); } if (context.IsRefactoringEnabled(RefactoringIdentifiers.GenerateBaseConstructors) && classDeclaration.Identifier.Span.Contains(context.Span)) { SemanticModel semanticModel = await context.GetSemanticModelAsync().ConfigureAwait(false); List <IMethodSymbol> constructors = GenerateBaseConstructorsAnalysis.GetMissingBaseConstructors(classDeclaration, semanticModel, context.CancellationToken); if (constructors?.Count > 0) { context.RegisterRefactoring( (constructors.Count == 1) ? "Generate base constructor" : "Generate base constructors", cancellationToken => GenerateBaseConstructorsRefactoring.RefactorAsync(context.Document, classDeclaration, constructors.ToArray(), semanticModel, cancellationToken), RefactoringIdentifiers.GenerateBaseConstructors); } } if (context.IsRefactoringEnabled(RefactoringIdentifiers.ImplementIEquatableOfT)) { await ImplementIEquatableOfTRefactoring.ComputeRefactoringAsync(context, classDeclaration).ConfigureAwait(false); } if (context.IsRefactoringEnabled(RefactoringIdentifiers.ImplementCustomEnumerator) && context.Span.IsEmptyAndContainedInSpan(classDeclaration.Identifier)) { SemanticModel semanticModel = await context.GetSemanticModelAsync().ConfigureAwait(false); ImplementCustomEnumeratorRefactoring.ComputeRefactoring(context, classDeclaration, semanticModel); } if (context.IsRefactoringEnabled(RefactoringIdentifiers.SortMemberDeclarations) && classDeclaration.BracesSpan().Contains(context.Span)) { SortMemberDeclarationsRefactoring.ComputeRefactoring(context, classDeclaration); } }
public static async Task ComputeRefactorings(RefactoringContext context, ClassDeclarationSyntax classDeclaration) { if (context.IsRefactoringEnabled(RefactoringIdentifiers.AddTypeParameter)) { AddTypeParameterRefactoring.ComputeRefactoring(context, classDeclaration); } if (context.IsRefactoringEnabled(RefactoringIdentifiers.ExtractTypeDeclarationToNewFile)) { ExtractTypeDeclarationToNewFileRefactoring.ComputeRefactorings(context, classDeclaration); } if (context.IsRefactoringEnabled(RefactoringIdentifiers.GenerateBaseConstructors) && classDeclaration.Identifier.Span.Contains(context.Span)) { SemanticModel semanticModel = await context.GetSemanticModelAsync().ConfigureAwait(false); ImmutableArray <IMethodSymbol> constructors = GenerateBaseConstructorsRefactoring.GetMissingBaseConstructors(classDeclaration, semanticModel, context.CancellationToken); if (!constructors.IsDefaultOrEmpty) { context.RegisterRefactoring( (constructors.Length == 1) ? "Generate base constructor" : "Generate base constructors", cancellationToken => GenerateBaseConstructorsRefactoring.RefactorAsync(context.Document, classDeclaration, constructors, semanticModel, context.CancellationToken)); } } if (context.IsRefactoringEnabled(RefactoringIdentifiers.ImplementIEquatableOfT)) { await ImplementIEquatableOfTRefactoring.ComputeRefactoringAsync(context, classDeclaration).ConfigureAwait(false); } if (context.IsRefactoringEnabled(RefactoringIdentifiers.SortMemberDeclarations) && classDeclaration.BracesSpan().Contains(context.Span)) { SortMemberDeclarationsRefactoring.ComputeRefactoring(context, classDeclaration); } }