Exemplo n.º 1
0
        public async Task <ExtractInterfaceResult> ExtractInterfaceFromAnalyzedTypeAsync(
            ExtractInterfaceTypeAnalysisResult refactoringResult,
            CancellationToken cancellationToken
            )
        {
            var containingNamespaceDisplay =
                refactoringResult.TypeToExtractFrom.ContainingNamespace.IsGlobalNamespace
                    ? string.Empty
                    : refactoringResult.TypeToExtractFrom.ContainingNamespace.ToDisplayString();

            var extractInterfaceOptions = await GetExtractInterfaceOptionsAsync(
                refactoringResult.DocumentToExtractFrom,
                refactoringResult.TypeToExtractFrom,
                refactoringResult.ExtractableMembers,
                containingNamespaceDisplay,
                cancellationToken
                )
                                          .ConfigureAwait(false);

            if (extractInterfaceOptions.IsCancelled)
            {
                return(new ExtractInterfaceResult(succeeded: false));
            }

            return(await ExtractInterfaceFromAnalyzedTypeAsync(
                       refactoringResult,
                       extractInterfaceOptions,
                       cancellationToken
                       )
                   .ConfigureAwait(false));
        }
Exemplo n.º 2
0
 public ExtractInterfaceCodeAction(
     AbstractExtractInterfaceService extractInterfaceService,
     ExtractInterfaceTypeAnalysisResult typeAnalysisResult
     )
 {
     _extractInterfaceService = extractInterfaceService;
     _typeAnalysisResult      = typeAnalysisResult;
 }
        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));
        }
Exemplo n.º 5
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,
        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, CancellationToken cancellationToken)
        {
            var containingNamespaceDisplay = refactoringResult.TypeToExtractFrom.ContainingNamespace.IsGlobalNamespace
                ? string.Empty
                : refactoringResult.TypeToExtractFrom.ContainingNamespace.ToDisplayString();

            var extractInterfaceOptions = GetExtractInterfaceOptions(
                refactoringResult.DocumentToExtractFrom,
                refactoringResult.TypeToExtractFrom,
                refactoringResult.ExtractableMembers,
                containingNamespaceDisplay,
                cancellationToken);

            if (extractInterfaceOptions.IsCancelled)
            {
                return new ExtractInterfaceResult(succeeded: false);
            }

            return ExtractInterfaceFromAnalyzedType(refactoringResult, extractInterfaceOptions, cancellationToken);
        }
 public ExtractInterfaceCodeAction(AbstractExtractInterfaceService extractInterfaceService, ExtractInterfaceTypeAnalysisResult typeAnalysisResult)
 {
     _extractInterfaceService = extractInterfaceService;
     _typeAnalysisResult = typeAnalysisResult;
 }