Skip to content

Commit

Permalink
Share more code in extract method (#76382)
Browse files Browse the repository at this point in the history
  • Loading branch information
CyrusNajmabadi authored Dec 12, 2024
2 parents d06742d + 6a3b37c commit 591e9a4
Show file tree
Hide file tree
Showing 3 changed files with 15 additions and 24 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -701,19 +701,6 @@ private static TDeclarationNode TweakNewLinesInMethod<TDeclarationNode>(TDeclara
}
}

protected StatementSyntax GetStatementContainingInvocationToExtractedMethodWorker()
{
var callSignature = CreateCallSignature();

if (AnalyzerResult.HasReturnType)
{
Contract.ThrowIfTrue(AnalyzerResult.HasVariableToUseAsReturnValue);
return ReturnStatement(callSignature);
}

return ExpressionStatement(callSignature);
}

protected override async Task<SemanticDocument> UpdateMethodAfterGenerationAsync(
SemanticDocument originalDocument,
IMethodSymbol methodSymbol,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@
using Microsoft.CodeAnalysis;
using Microsoft.CodeAnalysis.CodeGeneration;
using Microsoft.CodeAnalysis.Diagnostics;
using Microsoft.CodeAnalysis.Editing;
using Microsoft.CodeAnalysis.LanguageService;
using Microsoft.CodeAnalysis.PooledObjects;
using Microsoft.CodeAnalysis.Shared.Extensions;
Expand Down Expand Up @@ -387,5 +388,19 @@ private static RefKind GetRefKind(ParameterBehavior parameterBehavior)
return parameterBehavior == ParameterBehavior.Ref ? RefKind.Ref :
parameterBehavior == ParameterBehavior.Out ? RefKind.Out : RefKind.None;
}

protected TStatementSyntax GetStatementContainingInvocationToExtractedMethodWorker()
{
var callSignature = CreateCallSignature();

var generator = this.SemanticDocument.Document.GetRequiredLanguageService<SyntaxGenerator>();
if (AnalyzerResult.HasReturnType)
{
Contract.ThrowIfTrue(AnalyzerResult.HasVariableToUseAsReturnValue);
return (TStatementSyntax)generator.ReturnStatement(callSignature);
}

return (TStatementSyntax)generator.ExpressionStatement(callSignature);
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -444,17 +444,6 @@ Namespace Microsoft.CodeAnalysis.VisualBasic.ExtractMethod

Return Await MyBase.CreateGeneratedCodeAsync(newDocument, cancellationToken).ConfigureAwait(False)
End Function

Protected Function GetStatementContainingInvocationToExtractedMethodWorker() As StatementSyntax
Dim callSignature = CreateCallSignature()

If Me.AnalyzerResult.HasReturnType Then
Contract.ThrowIfTrue(Me.AnalyzerResult.HasVariableToUseAsReturnValue)
Return SyntaxFactory.ReturnStatement(expression:=callSignature)
End If

Return SyntaxFactory.ExpressionStatement(expression:=callSignature)
End Function
End Class
End Class
End Namespace

0 comments on commit 591e9a4

Please sign in to comment.