提交 9fe084b5 编写于 作者: A Andrew Hall (METAL)

VB extract interface changes

上级 41a7c27a
......@@ -135,13 +135,16 @@ internal override bool ShouldIncludeAccessibilityModifier(SyntaxNode typeNode)
}
internal override Solution GetSolutionWithSameFileUpdated(
Solution solution,
INamedTypeSymbol extractedInterfaceSymbol,
Solution solution,
INamedTypeSymbol extractedInterfaceSymbol,
IEnumerable<ISymbol> includedMembers,
Dictionary<ISymbol, SyntaxAnnotation> symbolToDeclarationAnnotationMap,
List<DocumentId> documentIds,
SyntaxAnnotation typeNodeAnnotation,
DocumentId documentId,
DocumentId documentIdWithTypeNode,
CancellationToken cancellationToken)
{
var document = solution.GetDocument(documentId);
var document = solution.GetDocument(documentIdWithTypeNode);
var originalRoot = document.GetSyntaxRootSynchronously(cancellationToken);
var typeDeclaration = originalRoot.GetAnnotatedNodes<TypeDeclarationSyntax>(typeNodeAnnotation).Single();
......@@ -165,7 +168,7 @@ internal override bool ShouldIncludeAccessibilityModifier(SyntaxNode typeNode)
var newRoot = Formatter.Format(editor.GetChangedRoot(), solution.Workspace);
return solution.WithDocumentSyntaxRoot(documentId, newRoot, PreservationMode.PreserveIdentity);
return solution.WithDocumentSyntaxRoot(documentIdWithTypeNode, newRoot, PreservationMode.PreserveIdentity);
}
}
}
......@@ -43,8 +43,11 @@ internal abstract class AbstractExtractInterfaceService : ILanguageService
internal abstract Solution GetSolutionWithSameFileUpdated(
Solution solution,
INamedTypeSymbol extractedInterfaceSymbol,
IEnumerable<ISymbol> includedMembers,
Dictionary<ISymbol, SyntaxAnnotation> symbolToDeclarationAnnotationMap,
List<DocumentId> documentIds,
SyntaxAnnotation typeNodeAnnotation,
DocumentId documentId,
DocumentId documentIdWithTypeNode,
CancellationToken cancellationToken);
internal abstract string GetGeneratedNameTypeParameterSuffix(IList<ITypeParameterSymbol> typeParameters, Workspace workspace);
......@@ -180,9 +183,8 @@ public ExtractInterfaceResult ExtractInterfaceFromAnalyzedType(ExtractInterfaceT
private ExtractInterfaceResult ExtractInterfaceToNewFile(
Solution solution, string containingNamespaceDisplay, INamedTypeSymbol extractedInterfaceSymbol,
SyntaxNode typeNode,
ProjectId projectId, IReadOnlyList<string> documentFolders, DocumentId documentId, INamedTypeSymbol typeToExtractFrom,
string fileName, IEnumerable<ISymbol> includedMembers, CancellationToken cancellationToken)
SyntaxNode typeNode, ProjectId projectId, IReadOnlyList<string> documentFolders, DocumentId documentId,
INamedTypeSymbol typeToExtractFrom, string fileName, IEnumerable<ISymbol> includedMembers, CancellationToken cancellationToken)
{
var symbolToDeclarationAnnotationMap = CreateSymbolToDeclarationAnnotationMap(
includedMembers,
......@@ -223,9 +225,8 @@ public ExtractInterfaceResult ExtractInterfaceFromAnalyzedType(ExtractInterfaceT
}
private ExtractInterfaceResult ExtractInterfaceToSameFile(
Solution solution, INamedTypeSymbol extractedInterfaceSymbol,
SyntaxNode typeNode,
ProjectId projectId, DocumentId documentId, INamedTypeSymbol typeToExtractFrom, IEnumerable<ISymbol> includedMembers, CancellationToken cancellationToken)
Solution solution, INamedTypeSymbol extractedInterfaceSymbol, SyntaxNode typeNode, ProjectId projectId,
DocumentId documentId, INamedTypeSymbol typeToExtractFrom, IEnumerable<ISymbol> includedMembers, CancellationToken cancellationToken)
{
var symbolToDeclarationAnnotationMap = CreateSymbolToDeclarationAnnotationMap(
includedMembers,
......@@ -238,8 +239,11 @@ public ExtractInterfaceResult ExtractInterfaceFromAnalyzedType(ExtractInterfaceT
var completedSolution = GetSolutionWithSameFileUpdated(
solution: solution,
extractedInterfaceSymbol: extractedInterfaceSymbol,
includedMembers: includedMembers,
symbolToDeclarationAnnotationMap: symbolToDeclarationAnnotationMap,
documentIds: documentIds,
typeNodeAnnotation: typeNodeSyntaxAnnotation,
documentId: documentId,
documentIdWithTypeNode: documentId,
cancellationToken: cancellationToken);
return new ExtractInterfaceResult(
......
......@@ -9,6 +9,7 @@ Imports Microsoft.CodeAnalysis.Formatting
Imports Microsoft.CodeAnalysis.Host.Mef
Imports Microsoft.CodeAnalysis.Text
Imports Microsoft.CodeAnalysis.VisualBasic
Imports Microsoft.CodeAnalysis.VisualBasic.CodeGeneration
Imports Microsoft.CodeAnalysis.VisualBasic.Syntax
Namespace Microsoft.CodeAnalysis.VisualBasic.ExtractInterface
......@@ -201,8 +202,43 @@ Namespace Microsoft.CodeAnalysis.VisualBasic.ExtractInterface
Return typeDeclaration.GetModifiers().Any(Function(m) SyntaxFacts.IsAccessibilityModifier(m.Kind()))
End Function
Friend Overrides Function GetSolutionWithSameFileUpdated(solution As Solution, extractedInterfaceSymbol As INamedTypeSymbol, typeNodeAnnotation As SyntaxAnnotation, documentId As DocumentId, cancellationToken As CancellationToken) As Solution
Throw New NotImplementedException()
Friend Overrides Function GetSolutionWithSameFileUpdated(
solution As Solution,
extractedInterfaceSymbol As INamedTypeSymbol,
includedMembers As IEnumerable(Of ISymbol),
symbolToDeclarationAnnotationMap As Dictionary(Of ISymbol, SyntaxAnnotation),
documentIds As List(Of DocumentId),
typeNodeAnnotation As SyntaxAnnotation,
documentIdWithTypeNode As DocumentId,
cancellationToken As CancellationToken) As Solution
Dim updatedSolution = GetSolutionWithUpdatedOriginalType(solution,
extractedInterfaceSymbol,
includedMembers,
symbolToDeclarationAnnotationMap,
documentIds,
typeNodeAnnotation,
documentIdWithTypeNode,
cancellationToken)
Dim document = updatedSolution.GetDocument(documentIdWithTypeNode)
Dim originalRoot = document.GetSyntaxRootSynchronously(cancellationToken)
Dim typeDeclaration = originalRoot.GetAnnotatedNodes(typeNodeAnnotation).Single()
document = document.WithSyntaxRoot(originalRoot.TrackNodes(typeDeclaration))
Dim currentRoot = document.GetSyntaxRootSynchronously(cancellationToken)
Dim editor = New SyntaxEditor(currentRoot, VisualBasicSyntaxGenerator.Instance)
typeDeclaration = currentRoot.GetCurrentNode(typeDeclaration)
Dim codeGenService = updatedSolution.Workspace.Services.GetLanguageServices(LanguageNames.VisualBasic).GetService(Of ICodeGenerationService)
Dim interfaceNode = codeGenService.CreateNamedTypeDeclaration(extractedInterfaceSymbol)
editor.InsertBefore(typeDeclaration, interfaceNode)
Dim newRoot = Formatter.Format(editor.GetChangedRoot(), updatedSolution.Workspace)
Return updatedSolution.WithDocumentSyntaxRoot(documentIdWithTypeNode, newRoot, PreservationMode.PreserveIdentity)
End Function
End Class
End Namespace
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册