Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Share more code in extract method #76382

Merged
merged 1 commit into from
Dec 12, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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 @@ -389,5 +390,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
Loading