提交 25dcddbe 编写于 作者: C Cyrus Najmabadi

Simplify code.

上级 4425eb6a
......@@ -32,36 +32,42 @@ internal abstract partial class AbstractMoveDeclarationNearReferenceService<
protected abstract Task<bool> TypesAreCompatibleAsync(Document document, ILocalSymbol localSymbol, TLocalDeclarationStatementSyntax declarationStatement, SyntaxNode right, CancellationToken cancellationToken);
public async Task<bool> CanMoveDeclarationNearReferenceAsync(Document document, SyntaxNode node, CancellationToken cancellationToken)
{
var state = await ComputeStateAsync(document, node, cancellationToken).ConfigureAwait(false);
return state != null;
}
private async Task<State> ComputeStateAsync(Document document, SyntaxNode node, CancellationToken cancellationToken)
{
if (!(node is TLocalDeclarationStatementSyntax statement))
{
return false;
return null;
}
var state = await State.GenerateAsync((TService)this, document, statement, cancellationToken).ConfigureAwait(false);
if (state == null)
{
return false;
return null;
}
if (!CanMoveToBlock(state.LocalSymbol, state.OutermostBlock, state.InnermostBlock))
{
return false;
return null;
}
return true;
return state;
}
public async Task<Document> MoveDeclarationNearReferenceAsync(
Document document, SyntaxNode localDeclarationStatement, CancellationToken cancellationToken)
{
Debug.Assert(await CanMoveDeclarationNearReferenceAsync(document, localDeclarationStatement, cancellationToken));
var state = await ComputeStateAsync(document, localDeclarationStatement, cancellationToken);
if (state == null)
{
return document;
}
var statement = (TLocalDeclarationStatementSyntax)localDeclarationStatement;
var root = await document.GetSyntaxRootAsync(cancellationToken);
var state = await State.GenerateAsync((TService)this, document, statement, cancellationToken).ConfigureAwait(false);
var editor = new SyntaxEditor(root, document.Project.Solution.Workspace);
var crossesMeaningfulBlock = CrossesMeaningfulBlock(state);
......
......@@ -17,7 +17,8 @@ internal interface IMoveDeclarationNearReferenceService : ILanguageService
/// <summary>
/// Moves true if <paramref name="localDeclarationStatement"/> closer to its first
/// reference. Only applicable if <see cref="CanMoveDeclarationNearReferenceAsync"/>
/// returned <code>true</code>.
/// returned <code>true</code>. If not, then the original document will be returned
/// unchanged.
/// </summary>
Task<Document> MoveDeclarationNearReferenceAsync(Document document, SyntaxNode localDeclarationStatement, CancellationToken cancellationToken);
}
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册