提交 7eb57f96 编写于 作者: S Shlomo Zach Cahlon

Undid some changes

上级 a91c6ee9
// Copyright (c) Microsoft. All Rights Reserved. Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information.
using System.Collections.Immutable;
using System.Composition;
using System.Threading;
using System.Threading.Tasks;
using Microsoft.CodeAnalysis.CodeActions;
using Microsoft.CodeAnalysis.CodeRefactorings;
using Microsoft.CodeAnalysis.CSharp.Syntax;
using Microsoft.CodeAnalysis.Editing;
using Microsoft.CodeAnalysis.InitializeParameter;
using Microsoft.CodeAnalysis.Operations;
namespace Microsoft.CodeAnalysis.CSharp.InitializeParameter
{
......
// Copyright (c) Microsoft. All Rights Reserved. Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information.
using System.Collections.Immutable;
using System.Composition;
using Microsoft.CodeAnalysis.CodeRefactorings;
using Microsoft.CodeAnalysis.CSharp.Syntax;
......
......@@ -10,7 +10,6 @@
using Microsoft.CodeAnalysis.Diagnostics.Analyzers.NamingStyles;
using Microsoft.CodeAnalysis.Editing;
using Microsoft.CodeAnalysis.Operations;
using Microsoft.CodeAnalysis.PooledObjects;
using Microsoft.CodeAnalysis.Shared.Extensions;
using Microsoft.CodeAnalysis.Shared.Naming;
using Microsoft.CodeAnalysis.Shared.Utilities;
......
......@@ -29,6 +29,23 @@ internal abstract partial class AbstractInitializeParameterCodeRefactoringProvid
protected abstract SyntaxNode GetBody(SyntaxNode functionDeclaration);
protected abstract SyntaxNode GetTypeBlock(SyntaxNode node);
protected abstract Task<ImmutableArray<CodeAction>> GetRefactoringsForAllParametersAsync(
Document document,
SyntaxNode functionDeclaration,
IMethodSymbol method,
IBlockOperation blockStatementOpt,
ImmutableArray<SyntaxNode> listOfParameterNodes,
int position,
CancellationToken cancellationToken);
protected abstract Task<ImmutableArray<CodeAction>> GetRefactoringsForSingleParameterAsync(
Document document,
IParameterSymbol parameter,
SyntaxNode functionDeclaration,
IMethodSymbol methodSymbol,
IBlockOperation blockStatementOpt,
CancellationToken cancellationToken);
protected abstract void InsertStatement(
SyntaxEditor editor, SyntaxNode functionDeclaration, IMethodSymbol method,
SyntaxNode statementToAddAfterOpt, TStatementSyntax statement);
......@@ -95,7 +112,6 @@ public override async Task ComputeRefactoringsAsync(CodeRefactoringContext conte
{
// Ok. Looks like the selected parameter could be refactored. Defer to subclass to
// actually determine if there are any viable refactorings here.
context.RegisterRefactorings(await GetRefactoringsForSingleParameterAsync(
document, parameter, functionDeclaration, methodSymbol, blockStatementOpt, cancellationToken).ConfigureAwait(false));
}
......@@ -117,44 +133,21 @@ public override async Task ComputeRefactoringsAsync(CodeRefactoringContext conte
{
// Looks like we can offer a refactoring for more than one parameter. Defer to subclass to
// actually determine if there are any viable refactorings here.
context.RegisterRefactorings(await GetRefactoringsForAllParametersAsync(
document, functionDeclaration, methodSymbol, blockStatementOpt, listOfPotentiallyValidParametersNodes.ToImmutableAndFree(), position, cancellationToken).ConfigureAwait(false));
}
bool TryGetParameterSymbol(
static bool TryGetParameterSymbol(
SyntaxNode parameterNode,
SemanticModel semanticModel,
out IParameterSymbol parameter,
CancellationToken cancellationToken)
{
parameter = (IParameterSymbol)semanticModel.GetDeclaredSymbol(parameterNode, cancellationToken);
if (parameter == null || parameter.Name == "")
{
return false;
}
return true;
return parameter.Name != "";
}
}
protected abstract Task<ImmutableArray<CodeAction>> GetRefactoringsForAllParametersAsync(
Document document,
SyntaxNode functionDeclaration,
IMethodSymbol method,
IBlockOperation blockStatementOpt,
ImmutableArray<SyntaxNode> listOfParameterNodes,
int position,
CancellationToken cancellationToken);
protected abstract Task<ImmutableArray<CodeAction>> GetRefactoringsForSingleParameterAsync(
Document document,
IParameterSymbol parameter,
SyntaxNode functionDeclaration,
IMethodSymbol methodSymbol,
IBlockOperation blockStatementOpt,
CancellationToken cancellationToken);
protected bool CanOfferRefactoring(SyntaxNode functionDeclaration, SemanticModel semanticModel, ISyntaxFactsService syntaxFacts, CancellationToken cancellationToken, out IBlockOperation blockStatementOpt)
{
blockStatementOpt = null;
......@@ -214,8 +207,8 @@ protected TParameterSyntax GetParameterNode(SyntaxToken token, int position)
}
protected static bool IsParameterReference(IOperation operation, IParameterSymbol parameter)
=> UnwrapImplicitConversion(operation) is IParameterReferenceOperation parameterReference &&
parameter.Equals(parameterReference.Parameter);
=> UnwrapImplicitConversion(operation) is IParameterReferenceOperation parameterReference &&
parameter.Equals(parameterReference.Parameter);
protected static IOperation UnwrapImplicitConversion(IOperation operation)
=> operation is IConversionOperation conversion && conversion.IsImplicit
......
' Copyright (c) Microsoft. All Rights Reserved. Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information.
Imports System.Collections.Immutable
Imports System.Composition
Imports System.Threading
Imports Microsoft.CodeAnalysis.CodeActions
Imports Microsoft.CodeAnalysis.CodeRefactorings
Imports Microsoft.CodeAnalysis.Editing
Imports Microsoft.CodeAnalysis.InitializeParameter
Imports Microsoft.CodeAnalysis.Operations
Imports Microsoft.CodeAnalysis.VisualBasic.Syntax
Namespace Microsoft.CodeAnalysis.VisualBasic.InitializeParameter
......@@ -47,6 +43,5 @@ Namespace Microsoft.CodeAnalysis.VisualBasic.InitializeParameter
Protected Overrides Function GetBody(functionDeclaration As SyntaxNode) As SyntaxNode
Return InitializeParameterHelpers.GetBody(functionDeclaration)
End Function
End Class
End Namespace
' Copyright (c) Microsoft. All Rights Reserved. Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information.
Imports System.Collections.Immutable
Imports System.Composition
Imports Microsoft.CodeAnalysis.CodeRefactorings
Imports Microsoft.CodeAnalysis.Editing
......@@ -55,6 +54,5 @@ Namespace Microsoft.CodeAnalysis.VisualBasic.InitializeParameter
Protected Overrides Function GetBody(functionDeclaration As SyntaxNode) As SyntaxNode
Return InitializeParameterHelpers.GetBody(functionDeclaration)
End Function
End Class
End Namespace
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册