提交 b1265560 编写于 作者: C Cyrus Najmabadi

NRT and immutable array

上级 e666b945
......@@ -2,8 +2,10 @@
// The .NET Foundation licenses this file to you under the MIT license.
// See the LICENSE file in the project root for more information.
#nullable enable
using System;
using System.Collections.Generic;
using System.Collections.Immutable;
using System.Composition;
using System.Linq;
using System.Threading;
......@@ -16,7 +18,9 @@
using Microsoft.CodeAnalysis.Formatting;
using Microsoft.CodeAnalysis.Host.Mef;
using Microsoft.CodeAnalysis.Options;
using Microsoft.CodeAnalysis.PooledObjects;
using Microsoft.CodeAnalysis.ReplacePropertyWithMethods;
using Microsoft.CodeAnalysis.Shared.Extensions;
using Roslyn.Utilities;
namespace Microsoft.CodeAnalysis.CSharp.ReplacePropertyWithMethods
......@@ -31,7 +35,7 @@ public CSharpReplacePropertyWithMethodsService()
{
}
public override async Task<IList<SyntaxNode>> GetReplacementMembersAsync(
public override async Task<ImmutableArray<SyntaxNode>> GetReplacementMembersAsync(
Document document,
IPropertySymbol property,
SyntaxNode propertyDeclarationNode,
......@@ -41,12 +45,10 @@ public CSharpReplacePropertyWithMethodsService()
CancellationToken cancellationToken)
{
if (!(propertyDeclarationNode is PropertyDeclarationSyntax propertyDeclaration))
{
return SpecializedCollections.EmptyList<SyntaxNode>();
}
return ImmutableArray<SyntaxNode>.Empty;
var documentOptions = await document.GetOptionsAsync(cancellationToken).ConfigureAwait(false);
var syntaxTree = await document.GetSyntaxTreeAsync(cancellationToken).ConfigureAwait(false);
var syntaxTree = await document.GetRequiredSyntaxTreeAsync(cancellationToken).ConfigureAwait(false);
var parseOptions = syntaxTree.Options;
return ConvertPropertyToMembers(
......@@ -57,18 +59,18 @@ public CSharpReplacePropertyWithMethodsService()
cancellationToken);
}
private static List<SyntaxNode> ConvertPropertyToMembers(
private static ImmutableArray<SyntaxNode> ConvertPropertyToMembers(
DocumentOptionSet documentOptions,
ParseOptions parseOptions,
SyntaxGenerator generator,
IPropertySymbol property,
PropertyDeclarationSyntax propertyDeclaration,
IFieldSymbol propertyBackingField,
IFieldSymbol? propertyBackingField,
string desiredGetMethodName,
string desiredSetMethodName,
CancellationToken cancellationToken)
{
var result = new List<SyntaxNode>();
using var _ = ArrayBuilder<SyntaxNode>.GetInstance(out var result);
if (propertyBackingField != null)
{
......@@ -96,7 +98,7 @@ public CSharpReplacePropertyWithMethodsService()
cancellationToken: cancellationToken));
}
return result;
return result.ToImmutable();
}
private static SyntaxNode GetSetMethod(
......@@ -104,7 +106,7 @@ public CSharpReplacePropertyWithMethodsService()
ParseOptions parseOptions,
SyntaxGenerator generator,
PropertyDeclarationSyntax propertyDeclaration,
IFieldSymbol propertyBackingField,
IFieldSymbol? propertyBackingField,
IMethodSymbol setMethod,
string desiredSetMethodName,
CancellationToken cancellationToken)
......@@ -125,7 +127,7 @@ public CSharpReplacePropertyWithMethodsService()
private static MethodDeclarationSyntax GetSetMethodWorker(
SyntaxGenerator generator,
PropertyDeclarationSyntax propertyDeclaration,
IFieldSymbol propertyBackingField,
IFieldSymbol? propertyBackingField,
IMethodSymbol setMethod,
string desiredSetMethodName,
CancellationToken cancellationToken)
......@@ -168,7 +170,7 @@ public CSharpReplacePropertyWithMethodsService()
ParseOptions parseOptions,
SyntaxGenerator generator,
PropertyDeclarationSyntax propertyDeclaration,
IFieldSymbol propertyBackingField,
IFieldSymbol? propertyBackingField,
IMethodSymbol getMethod,
string desiredGetMethodName,
CancellationToken cancellationToken)
......@@ -207,8 +209,9 @@ private static SyntaxTrivia ConvertTrivia(SyntaxTrivia trivia, CSharpSyntaxRewri
private static SyntaxTrivia ConvertDocumentationComment(SyntaxTrivia trivia, CSharpSyntaxRewriter rewriter)
{
var structure = trivia.GetStructure();
var updatedStructure = (StructuredTriviaSyntax)rewriter.Visit(structure);
return SyntaxFactory.Trivia(updatedStructure);
var rewritten = rewriter.Visit(structure);
Contract.ThrowIfNull(rewritten);
return SyntaxFactory.Trivia((StructuredTriviaSyntax)rewritten);
}
private static SyntaxNode UseExpressionOrBlockBodyIfDesired(
......@@ -216,7 +219,7 @@ private static SyntaxTrivia ConvertDocumentationComment(SyntaxTrivia trivia, CSh
MethodDeclarationSyntax methodDeclaration, bool createReturnStatementForExpression)
{
var expressionBodyPreference = documentOptions.GetOption(CSharpCodeStyleOptions.PreferExpressionBodiedMethods).Value;
if (methodDeclaration?.Body != null && expressionBodyPreference != ExpressionBodyPreference.Never)
if (methodDeclaration.Body != null && expressionBodyPreference != ExpressionBodyPreference.Never)
{
if (methodDeclaration.Body.TryConvertToArrowExpressionBody(
methodDeclaration.Kind(), parseOptions, expressionBodyPreference,
......@@ -228,7 +231,7 @@ private static SyntaxTrivia ConvertDocumentationComment(SyntaxTrivia trivia, CSh
.WithAdditionalAnnotations(Formatter.Annotation);
}
}
else if (methodDeclaration?.ExpressionBody != null && expressionBodyPreference == ExpressionBodyPreference.Never)
else if (methodDeclaration.ExpressionBody != null && expressionBodyPreference == ExpressionBodyPreference.Never)
{
if (methodDeclaration.ExpressionBody.TryConvertToBlock(
methodDeclaration.SemicolonToken, createReturnStatementForExpression, out var block))
......@@ -246,7 +249,7 @@ private static SyntaxTrivia ConvertDocumentationComment(SyntaxTrivia trivia, CSh
private static MethodDeclarationSyntax GetGetMethodWorker(
SyntaxGenerator generator,
PropertyDeclarationSyntax propertyDeclaration,
IFieldSymbol propertyBackingField,
IFieldSymbol? propertyBackingField,
IMethodSymbol getMethod,
string desiredGetMethodName,
CancellationToken cancellationToken)
......@@ -305,10 +308,10 @@ public override SyntaxNode GetPropertyNodeToReplace(SyntaxNode propertyDeclarati
return propertyDeclaration;
}
protected override NameMemberCrefSyntax TryGetCrefSyntax(IdentifierNameSyntax identifierName)
protected override NameMemberCrefSyntax? TryGetCrefSyntax(IdentifierNameSyntax identifierName)
=> identifierName.Parent as NameMemberCrefSyntax;
protected override NameMemberCrefSyntax CreateCrefSyntax(NameMemberCrefSyntax originalCref, SyntaxToken identifierToken, SyntaxNode parameterType)
protected override NameMemberCrefSyntax CreateCrefSyntax(NameMemberCrefSyntax originalCref, SyntaxToken identifierToken, SyntaxNode? parameterType)
{
CrefParameterListSyntax parameterList;
if (parameterType is TypeSyntax typeSyntax)
......
......@@ -6,6 +6,7 @@
using System;
using System.Collections.Generic;
using System.Collections.Immutable;
using System.Threading;
using System.Threading.Tasks;
using Microsoft.CodeAnalysis.CodeActions;
......@@ -27,9 +28,9 @@ internal abstract class AbstractReplacePropertyWithMethodsService<TIdentifierNam
where TPropertySyntax : SyntaxNode
{
public abstract SyntaxNode GetPropertyNodeToReplace(SyntaxNode propertyDeclaration);
public abstract Task<IList<SyntaxNode>> GetReplacementMembersAsync(Document document, IPropertySymbol property, SyntaxNode propertyDeclaration, IFieldSymbol propertyBackingField, string desiredGetMethodName, string desiredSetMethodName, CancellationToken cancellationToken);
public abstract Task<ImmutableArray<SyntaxNode>> GetReplacementMembersAsync(Document document, IPropertySymbol property, SyntaxNode propertyDeclaration, IFieldSymbol propertyBackingField, string desiredGetMethodName, string desiredSetMethodName, CancellationToken cancellationToken);
protected abstract TCrefSyntax TryGetCrefSyntax(TIdentifierNameSyntax identifierName);
protected abstract TCrefSyntax? TryGetCrefSyntax(TIdentifierNameSyntax identifierName);
protected abstract TCrefSyntax CreateCrefSyntax(TCrefSyntax originalCref, SyntaxToken identifierToken, SyntaxNode? parameterType);
protected abstract TExpressionSyntax UnwrapCompoundAssignment(SyntaxNode compoundAssignment, TExpressionSyntax readExpression);
......@@ -85,7 +86,7 @@ protected static SyntaxNode GetFieldReference(SyntaxGenerator generator, IFieldS
private readonly TIdentifierNameSyntax _identifierName;
private readonly TExpressionSyntax _expression;
private readonly TCrefSyntax _cref;
private readonly TCrefSyntax? _cref;
private readonly CancellationToken _cancellationToken;
public ReferenceReplacer(
......@@ -95,7 +96,8 @@ protected static SyntaxNode GetFieldReference(SyntaxGenerator generator, IFieldS
ISemanticFactsService semanticFacts,
SyntaxEditor editor,
TIdentifierNameSyntax identifierName,
IPropertySymbol property, IFieldSymbol propertyBackingField,
IPropertySymbol property,
IFieldSymbol propertyBackingField,
string desiredGetMethodName,
string desiredSetMethodName,
CancellationToken cancellationToken)
......
......@@ -2,7 +2,7 @@
// The .NET Foundation licenses this file to you under the MIT license.
// See the LICENSE file in the project root for more information.
using System.Collections.Generic;
using System.Collections.Immutable;
using System.Threading;
using System.Threading.Tasks;
using Microsoft.CodeAnalysis.CodeRefactorings;
......@@ -22,7 +22,7 @@ internal interface IReplacePropertyWithMethodsService : ILanguageService
string desiredGetMethodName, string desiredSetMethodName,
CancellationToken cancellationToken);
Task<IList<SyntaxNode>> GetReplacementMembersAsync(
Task<ImmutableArray<SyntaxNode>> GetReplacementMembersAsync(
Document document,
IPropertySymbol property, SyntaxNode propertyDeclaration,
IFieldSymbol propertyBackingField,
......
......@@ -2,6 +2,8 @@
// The .NET Foundation licenses this file to you under the MIT license.
// See the LICENSE file in the project root for more information.
#nullable enable
using System;
using System.Collections.Generic;
using System.Collections.Immutable;
......@@ -17,6 +19,7 @@
using Microsoft.CodeAnalysis.Editing;
using Microsoft.CodeAnalysis.FindSymbols;
using Microsoft.CodeAnalysis.LanguageServices;
using Microsoft.CodeAnalysis.PooledObjects;
using Microsoft.CodeAnalysis.Shared.Extensions;
using Microsoft.CodeAnalysis.Shared.Utilities;
using Roslyn.Utilities;
......@@ -41,18 +44,16 @@ public override async Task ComputeRefactoringsAsync(CodeRefactoringContext conte
var (document, _, cancellationToken) = context;
var service = document.GetLanguageService<IReplacePropertyWithMethodsService>();
if (service == null)
{
return;
}
var propertyDeclaration = await service.GetPropertyDeclarationAsync(context).ConfigureAwait(false);
if (propertyDeclaration == null)
{
return;
}
var semanticModel = await document.GetSemanticModelAsync(cancellationToken).ConfigureAwait(false);
var semanticModel = await document.GetRequiredSemanticModelAsync(cancellationToken).ConfigureAwait(false);
var propertySymbol = semanticModel.GetDeclaredSymbol(propertyDeclaration) as IPropertySymbol;
Contract.ThrowIfNull(propertySymbol);
var propertyName = propertySymbol.Name;
var accessorCount =
......@@ -115,9 +116,9 @@ public override async Task ComputeRefactoringsAsync(CodeRefactoringContext conte
return updatedSolution;
}
private static Dictionary<IPropertySymbol, IFieldSymbol> CreateDefinitionToBackingFieldMap(IEnumerable<ReferencedSymbol> propertyReferences)
private static ImmutableDictionary<IPropertySymbol, IFieldSymbol?> CreateDefinitionToBackingFieldMap(IEnumerable<ReferencedSymbol> propertyReferences)
{
var definitionToBackingField = new Dictionary<IPropertySymbol, IFieldSymbol>(SymbolEquivalenceComparer.Instance);
var definitionToBackingField = ImmutableDictionary.CreateBuilder<IPropertySymbol, IFieldSymbol?>(SymbolEquivalenceComparer.Instance);
foreach (var reference in propertyReferences)
{
......@@ -128,7 +129,7 @@ public override async Task ComputeRefactoringsAsync(CodeRefactoringContext conte
}
}
return definitionToBackingField;
return definitionToBackingField.ToImmutable();
}
private static bool HasAnyMatchingGetOrSetMethods(IPropertySymbol property, string name)
......@@ -156,21 +157,17 @@ private static bool HasAnyMatchingSetMethods(IPropertySymbol property, string na
comparer.Equals(m.Parameters[0].Type, property.Type));
}
private static IFieldSymbol GetBackingField(IPropertySymbol property)
private static IFieldSymbol? GetBackingField(IPropertySymbol property)
{
var field = property.GetBackingFieldIfAny();
if (field == null)
{
return null;
}
// If the field is something can be referenced with the name it has, then just use
// it as the backing field we'll generate. This is the case in VB where the backing
// field can be referenced as is.
if (field.CanBeReferencedByName)
{
return field;
}
// Otherwise, generate a good name for the backing field we're generating. This is
// the case for C# where we have mangled names for the backing field and need something
......@@ -188,7 +185,7 @@ private static IFieldSymbol GetBackingField(IPropertySymbol property)
}
#pragma warning disable IDE0060 // Remove unused parameter - Method not completely implemented.
private static string GetDefinitionIssues(IEnumerable<ReferencedSymbol> getMethodReferences)
private static string? GetDefinitionIssues(IEnumerable<ReferencedSymbol> getMethodReferences)
#pragma warning restore IDE0060 // Remove unused parameter
{
// TODO: add things to be concerned about here. For example:
......@@ -201,7 +198,7 @@ private static string GetDefinitionIssues(IEnumerable<ReferencedSymbol> getMetho
private static async Task<Solution> UpdateReferencesAsync(
Solution updatedSolution,
ILookup<Document, (IPropertySymbol property, ReferenceLocation location)> referencesByDocument,
Dictionary<IPropertySymbol, IFieldSymbol> propertyToBackingField,
ImmutableDictionary<IPropertySymbol, IFieldSymbol?> propertyToBackingField,
string desiredGetMethodName, string desiredSetMethodName,
CancellationToken cancellationToken)
{
......@@ -220,14 +217,14 @@ private static string GetDefinitionIssues(IEnumerable<ReferencedSymbol> getMetho
Solution updatedSolution,
Document originalDocument,
IEnumerable<(IPropertySymbol property, ReferenceLocation location)> references,
Dictionary<IPropertySymbol, IFieldSymbol> propertyToBackingField,
ImmutableDictionary<IPropertySymbol, IFieldSymbol?> propertyToBackingField,
string desiredGetMethodName, string desiredSetMethodName,
CancellationToken cancellationToken)
{
var root = await originalDocument.GetSyntaxRootAsync(cancellationToken).ConfigureAwait(false);
var root = await originalDocument.GetRequiredSyntaxRootAsync(cancellationToken).ConfigureAwait(false);
var editor = new SyntaxEditor(root, originalDocument.Project.Solution.Workspace);
var service = originalDocument.GetLanguageService<IReplacePropertyWithMethodsService>();
var service = originalDocument.GetRequiredLanguageService<IReplacePropertyWithMethodsService>();
await ReplaceReferencesAsync(
originalDocument, references, propertyToBackingField, root, editor, service,
......@@ -241,7 +238,7 @@ private static string GetDefinitionIssues(IEnumerable<ReferencedSymbol> getMetho
private static async Task ReplaceReferencesAsync(
Document originalDocument,
IEnumerable<(IPropertySymbol property, ReferenceLocation location)> references,
IDictionary<IPropertySymbol, IFieldSymbol> propertyToBackingField,
IDictionary<IPropertySymbol, IFieldSymbol?> propertyToBackingField,
SyntaxNode root, SyntaxEditor editor,
IReplacePropertyWithMethodsService service,
string desiredGetMethodName, string desiredSetMethodName,
......@@ -249,33 +246,32 @@ private static string GetDefinitionIssues(IEnumerable<ReferencedSymbol> getMetho
{
if (references != null)
{
var syntaxFacts = originalDocument.GetLanguageService<ISyntaxFactsService>();
var syntaxFacts = originalDocument.GetRequiredLanguageService<ISyntaxFactsService>();
foreach (var tuple in references)
foreach (var (property, referenceLocation) in references)
{
cancellationToken.ThrowIfCancellationRequested();
var property = tuple.property;
var referenceLocation = tuple.location;
var location = referenceLocation.Location;
var nameToken = root.FindToken(location.SourceSpan.Start, findInsideTrivia: true);
var parent = nameToken.Parent;
Contract.ThrowIfNull(parent);
if (referenceLocation.IsImplicit || !syntaxFacts.IsIdentifierName(parent))
{
// Warn the user that we can't properly replace this property with a method.
editor.ReplaceNode(parent, nameToken.Parent.WithAdditionalAnnotations(
editor.ReplaceNode(parent, parent.WithAdditionalAnnotations(
ConflictAnnotation.Create(FeaturesResources.Property_referenced_implicitly)));
}
else if (syntaxFacts.IsObjectInitializerNamedAssignmentIdentifier(parent))
{
editor.ReplaceNode(parent, nameToken.Parent.WithAdditionalAnnotations(
editor.ReplaceNode(parent, parent.WithAdditionalAnnotations(
ConflictAnnotation.Create(FeaturesResources.Property_reference_cannot_be_updated)));
}
else
{
var fieldSymbol = propertyToBackingField.GetValueOrDefault(tuple.property);
var fieldSymbol = propertyToBackingField.GetValueOrDefault(property);
await service.ReplaceReferenceAsync(
originalDocument, editor, parent,
property, fieldSymbol,
......@@ -289,7 +285,7 @@ private static string GetDefinitionIssues(IEnumerable<ReferencedSymbol> getMetho
Solution originalSolution,
Solution updatedSolution,
IEnumerable<ReferencedSymbol> references,
IDictionary<IPropertySymbol, IFieldSymbol> definitionToBackingField,
ImmutableDictionary<IPropertySymbol, IFieldSymbol?> definitionToBackingField,
string desiredGetMethodName, string desiredSetMethodName,
CancellationToken cancellationToken)
{
......@@ -339,21 +335,20 @@ private static string GetDefinitionIssues(IEnumerable<ReferencedSymbol> getMetho
Solution updatedSolution,
DocumentId documentId,
MultiDictionary<DocumentId, IPropertySymbol>.ValueSet originalDefinitions,
IDictionary<IPropertySymbol, IFieldSymbol> definitionToBackingField,
IDictionary<IPropertySymbol, IFieldSymbol?> definitionToBackingField,
string desiredGetMethodName, string desiredSetMethodName,
CancellationToken cancellationToken)
{
var updatedDocument = updatedSolution.GetDocument(documentId);
var compilation = await updatedDocument.Project.GetCompilationAsync(cancellationToken).ConfigureAwait(false);
var updatedDocument = updatedSolution.GetRequiredDocument(documentId);
var semanticModel = await updatedDocument.GetRequiredSemanticModelAsync(cancellationToken).ConfigureAwait(false);
// We've already gone and updated all references. So now re-resolve all the definitions
// in the current compilation to find their updated location.
var currentDefinitions = await GetCurrentPropertiesAsync(
updatedSolution, compilation, documentId, originalDefinitions, cancellationToken).ConfigureAwait(false);
updatedSolution, semanticModel.Compilation, documentId, originalDefinitions, cancellationToken).ConfigureAwait(false);
var service = updatedDocument.GetLanguageService<IReplacePropertyWithMethodsService>();
var service = updatedDocument.GetRequiredLanguageService<IReplacePropertyWithMethodsService>();
var semanticModel = await updatedDocument.GetSemanticModelAsync(cancellationToken).ConfigureAwait(false);
var root = await updatedDocument.GetSyntaxRootAsync(cancellationToken).ConfigureAwait(false);
var editor = new SyntaxEditor(root, updatedSolution.Workspace);
......@@ -376,7 +371,7 @@ private static string GetDefinitionIssues(IEnumerable<ReferencedSymbol> getMetho
{
members = members.Select(editor.Generator.AsInterfaceMember)
.WhereNotNull()
.ToList();
.ToImmutableArray();
}
var nodeToReplace = service.GetPropertyNodeToReplace(declaration);
......@@ -387,14 +382,14 @@ private static string GetDefinitionIssues(IEnumerable<ReferencedSymbol> getMetho
return updatedSolution.WithDocumentSyntaxRoot(documentId, editor.GetChangedRoot());
}
private static async Task<List<(IPropertySymbol property, SyntaxNode declaration)>> GetCurrentPropertiesAsync(
private static async Task<ImmutableArray<(IPropertySymbol property, SyntaxNode declaration)>> GetCurrentPropertiesAsync(
Solution updatedSolution,
Compilation compilation,
DocumentId documentId,
MultiDictionary<DocumentId, IPropertySymbol>.ValueSet originalDefinitions,
CancellationToken cancellationToken)
{
var result = new List<(IPropertySymbol property, SyntaxNode declaration)>();
using var _ = ArrayBuilder<(IPropertySymbol property, SyntaxNode declaration)>.GetInstance(out var result);
foreach (var originalDefinition in originalDefinitions)
{
cancellationToken.ThrowIfCancellationRequested();
......@@ -402,29 +397,25 @@ private static string GetDefinitionIssues(IEnumerable<ReferencedSymbol> getMetho
var property = GetSymbolInCurrentCompilation(compilation, originalDefinition, cancellationToken);
var declaration = await GetPropertyDeclarationAsync(property, cancellationToken).ConfigureAwait(false);
if (declaration != null && updatedSolution.GetDocument(declaration.SyntaxTree)?.Id == documentId)
{
if (property != null && declaration != null && updatedSolution.GetDocument(declaration.SyntaxTree)?.Id == documentId)
result.Add((property, declaration));
}
}
return result;
return result.ToImmutable();
}
private static async Task<SyntaxNode> GetPropertyDeclarationAsync(
IPropertySymbol property, CancellationToken cancellationToken)
private static async Task<SyntaxNode?> GetPropertyDeclarationAsync(
IPropertySymbol? property, CancellationToken cancellationToken)
{
if (property == null)
{
return null;
}
Debug.Assert(property.DeclaringSyntaxReferences.Length == 1);
var reference = property.DeclaringSyntaxReferences[0];
return await reference.GetSyntaxAsync(cancellationToken).ConfigureAwait(false);
}
private static TSymbol GetSymbolInCurrentCompilation<TSymbol>(Compilation compilation, TSymbol originalDefinition, CancellationToken cancellationToken)
private static TSymbol? GetSymbolInCurrentCompilation<TSymbol>(Compilation compilation, TSymbol originalDefinition, CancellationToken cancellationToken)
where TSymbol : class, ISymbol
{
return originalDefinition.GetSymbolKey(cancellationToken).Resolve(compilation, cancellationToken: cancellationToken).GetAnySymbol() as TSymbol;
......
......@@ -2,12 +2,14 @@
' The .NET Foundation licenses this file to you under the MIT license.
' See the LICENSE file in the project root for more information.
Imports System.Collections.Immutable
Imports System.Composition
Imports System.Threading
Imports Microsoft.CodeAnalysis.CodeGeneration
Imports Microsoft.CodeAnalysis.Editing
Imports Microsoft.CodeAnalysis.Formatting
Imports Microsoft.CodeAnalysis.Host.Mef
Imports Microsoft.CodeAnalysis.PooledObjects
Imports Microsoft.CodeAnalysis.ReplacePropertyWithMethods
Imports Microsoft.CodeAnalysis.VisualBasic.Syntax
......@@ -28,11 +30,11 @@ Namespace Microsoft.CodeAnalysis.VisualBasic.CodeRefactorings.ReplaceMethodWithP
propertyBackingField As IFieldSymbol,
desiredGetMethodName As String,
desiredSetMethodName As String,
cancellationToken As CancellationToken) As Task(Of IList(Of SyntaxNode))
cancellationToken As CancellationToken) As Task(Of ImmutableArray(Of SyntaxNode))
Dim propertyStatement = TryCast(propertyDeclarationNode, PropertyStatementSyntax)
If propertyStatement Is Nothing Then
Return Task.FromResult(SpecializedCollections.EmptyList(Of SyntaxNode))
Return SpecializedTasks.EmptyImmutableArray(Of SyntaxNode)
End If
Return Task.FromResult(ConvertPropertyToMembers(
......@@ -49,10 +51,9 @@ Namespace Microsoft.CodeAnalysis.VisualBasic.CodeRefactorings.ReplaceMethodWithP
propertyBackingField As IFieldSymbol,
desiredGetMethodName As String,
desiredSetMethodName As String,
cancellationToken As CancellationToken) As IList(Of SyntaxNode)
Dim result = New List(Of SyntaxNode)()
cancellationToken As CancellationToken) As ImmutableArray(Of SyntaxNode)
Dim result = ArrayBuilder(Of SyntaxNode).GetInstance()
If propertyBackingField IsNot Nothing Then
Dim initializer = propertyStatement.Initializer?.Value
result.Add(generator.FieldDeclaration(propertyBackingField, initializer))
......@@ -72,7 +73,7 @@ Namespace Microsoft.CodeAnalysis.VisualBasic.CodeRefactorings.ReplaceMethodWithP
setMethod, desiredSetMethodName, cancellationToken:=cancellationToken))
End If
Return result
Return result.ToImmutableAndFree()
End Function
Private Shared Function GetGetMethod(
......@@ -155,7 +156,7 @@ Namespace Microsoft.CodeAnalysis.VisualBasic.CodeRefactorings.ReplaceMethodWithP
' To do this we make the new method using the information from the implicit getter
' Function. However, we need to update the 'explicit interface implementations'
' of the implicit getter function so that they point to the updated interface method
' and not hte old implicit interface method.
' and not the old implicit interface method.
Dim updatedImplementations = method.ExplicitInterfaceImplementations.SelectAsArray(
Function(i) UpdateExplicitInterfaceImplementation([property], i, desiredName))
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册