public async Task <ExtractInterfaceResult> ExtractInterfaceFromAnalyzedTypeAsync(
            ExtractInterfaceTypeAnalysisResult refactoringResult,
            ExtractInterfaceOptionsResult extractInterfaceOptions,
            CancellationToken cancellationToken)
        {
            var solution = refactoringResult.DocumentToExtractFrom.Project.Solution;

            var extractedInterfaceSymbol = CodeGenerationSymbolFactory.CreateNamedTypeSymbol(
                attributes: default,
        public ExtractInterfaceResult ExtractInterfaceFromAnalyzedType(ExtractInterfaceTypeAnalysisResult refactoringResult, ExtractInterfaceOptionsResult extractInterfaceOptions, CancellationToken cancellationToken)
        {
            var solution = refactoringResult.DocumentToExtractFrom.Project.Solution;
            List<DocumentId> documentIds;
            SyntaxAnnotation typeNodeSyntaxAnnotation;

            var containingNamespaceDisplay = GetContainingNamespaceDisplay(refactoringResult.TypeToExtractFrom, refactoringResult.DocumentToExtractFrom.Project.CompilationOptions);

            var symbolToDeclarationAnnotationMap = CreateSymbolToDeclarationAnnotationMap(
                extractInterfaceOptions.IncludedMembers,
                ref solution,
                out documentIds,
                refactoringResult.TypeNode,
                out typeNodeSyntaxAnnotation,
                cancellationToken);

            var extractedInterfaceSymbol = CodeGenerationSymbolFactory.CreateNamedTypeSymbol(
                attributes: null,
                accessibility: ShouldIncludeAccessibilityModifier(refactoringResult.TypeNode) ? refactoringResult.TypeToExtractFrom.DeclaredAccessibility : Accessibility.NotApplicable,
                modifiers: new DeclarationModifiers(),
                typeKind: TypeKind.Interface,
                name: extractInterfaceOptions.InterfaceName,
                typeParameters: GetTypeParameters(refactoringResult.TypeToExtractFrom, extractInterfaceOptions.IncludedMembers),
                members: CreateInterfaceMembers(extractInterfaceOptions.IncludedMembers));

            var interfaceDocumentId = DocumentId.CreateNewId(refactoringResult.DocumentToExtractFrom.Project.Id, debugName: extractInterfaceOptions.FileName);

            var unformattedInterfaceDocument = GetUnformattedInterfaceDocument(
                solution,
                containingNamespaceDisplay,
                extractInterfaceOptions.FileName,
                refactoringResult.DocumentToExtractFrom.Folders,
                extractedInterfaceSymbol,
                interfaceDocumentId,
                cancellationToken);

            var solutionWithFormattedInterfaceDocument = GetSolutionWithFormattedInterfaceDocument(unformattedInterfaceDocument, cancellationToken);

            var completedSolution = GetSolutionWithOriginalTypeUpdated(
                solutionWithFormattedInterfaceDocument,
                documentIds,
                refactoringResult.DocumentToExtractFrom.Id,
                typeNodeSyntaxAnnotation,
                refactoringResult.TypeToExtractFrom,
                extractedInterfaceSymbol,
                extractInterfaceOptions.IncludedMembers,
                symbolToDeclarationAnnotationMap,
                cancellationToken);

            return new ExtractInterfaceResult(
                succeeded: true,
                updatedSolution: completedSolution,
                navigationDocumentId: interfaceDocumentId);
        }
        public ExtractInterfaceResult ExtractInterfaceFromAnalyzedType(ExtractInterfaceTypeAnalysisResult refactoringResult, ExtractInterfaceOptionsResult extractInterfaceOptions, CancellationToken cancellationToken)
        {
            var solution = refactoringResult.DocumentToExtractFrom.Project.Solution;
            List <DocumentId> documentIds;
            SyntaxAnnotation  typeNodeSyntaxAnnotation;

            var containingNamespaceDisplay = GetContainingNamespaceDisplay(refactoringResult.TypeToExtractFrom, refactoringResult.DocumentToExtractFrom.Project.CompilationOptions);

            var symbolToDeclarationAnnotationMap = CreateSymbolToDeclarationAnnotationMap(
                extractInterfaceOptions.IncludedMembers,
                ref solution,
                out documentIds,
                refactoringResult.TypeNode,
                out typeNodeSyntaxAnnotation,
                cancellationToken);

            var extractedInterfaceSymbol = CodeGenerationSymbolFactory.CreateNamedTypeSymbol(
                attributes: null,
                accessibility: ShouldIncludeAccessibilityModifier(refactoringResult.TypeNode) ? refactoringResult.TypeToExtractFrom.DeclaredAccessibility : Accessibility.NotApplicable,
                modifiers: new DeclarationModifiers(),
                typeKind: TypeKind.Interface,
                name: extractInterfaceOptions.InterfaceName,
                typeParameters: GetTypeParameters(refactoringResult.TypeToExtractFrom, extractInterfaceOptions.IncludedMembers),
                members: CreateInterfaceMembers(extractInterfaceOptions.IncludedMembers));

            var interfaceDocumentId = DocumentId.CreateNewId(refactoringResult.DocumentToExtractFrom.Project.Id, debugName: extractInterfaceOptions.FileName);

            var unformattedInterfaceDocument = GetUnformattedInterfaceDocument(
                solution,
                containingNamespaceDisplay,
                extractInterfaceOptions.FileName,
                refactoringResult.DocumentToExtractFrom.Folders,
                extractedInterfaceSymbol,
                interfaceDocumentId,
                cancellationToken);

            var solutionWithFormattedInterfaceDocument = GetSolutionWithFormattedInterfaceDocument(unformattedInterfaceDocument, cancellationToken);

            var completedSolution = GetSolutionWithOriginalTypeUpdated(
                solutionWithFormattedInterfaceDocument,
                documentIds,
                refactoringResult.DocumentToExtractFrom.Id,
                typeNodeSyntaxAnnotation,
                refactoringResult.TypeToExtractFrom,
                extractedInterfaceSymbol,
                extractInterfaceOptions.IncludedMembers,
                symbolToDeclarationAnnotationMap,
                cancellationToken);

            return(new ExtractInterfaceResult(
                       succeeded: true,
                       updatedSolution: completedSolution,
                       navigationDocumentId: interfaceDocumentId));
        }
Example #4
0
        public ExtractInterfaceResult ExtractInterfaceFromAnalyzedType(ExtractInterfaceTypeAnalysisResult refactoringResult, ExtractInterfaceOptionsResult extractInterfaceOptions, CancellationToken cancellationToken)
        {
            var solution = refactoringResult.DocumentToExtractFrom.Project.Solution;
            var containingNamespaceDisplay = GetContainingNamespaceDisplay(refactoringResult.TypeToExtractFrom, refactoringResult.DocumentToExtractFrom.Project.CompilationOptions);

            var symbolToDeclarationAnnotationMap = CreateSymbolToDeclarationAnnotationMap(
                extractInterfaceOptions.IncludedMembers,
                ref solution,
                out var documentIds,
                refactoringResult.TypeNode,
                out var typeNodeSyntaxAnnotation,
                cancellationToken);

            var extractedInterfaceSymbol = CodeGenerationSymbolFactory.CreateNamedTypeSymbol(
                attributes: default,