提交 48f88547 编写于 作者: C CyrusNajmabadi

Support ref-returns with GenerateMethod.

上级 7f38544a
......@@ -277,6 +277,7 @@ private void GenerateAndAddEventHandler(ITextView textView, ITextBuffer subjectB
accessibility: Accessibility.Private,
modifiers: new DeclarationModifiers(isStatic: eventHookupExpression.IsInStaticContext()),
returnType: delegateType.DelegateInvokeMethod.ReturnType,
returnsByRef: delegateType.DelegateInvokeMethod.ReturnsByRef,
explicitInterfaceSymbol: null,
name: eventHandlerMethodName,
typeParameters: null,
......
......@@ -7358,6 +7358,34 @@ private object Issue(int i)
{
throw new NotImplementedException();
}
}");
}
[WorkItem(16398, "https://github.com/dotnet/roslyn/issues/16398")]
[Fact, Trait(Traits.Feature, Traits.Features.CodeActionsGenerateMethod)]
public async Task TestRefReturnType1()
{
await TestAsync(
@"class Class
{
void Method(int i)
{
ref int v = ref [|Issue|](i);
}
}",
@"using System;
class Class
{
void Method(int i)
{
ref int v = ref Issue(i);
}
private ref int Issue(int i)
{
throw new NotImplementedException();
}
}");
}
}
......
......@@ -55,6 +55,7 @@ Namespace Microsoft.CodeAnalysis.Editor.VisualBasic.NavigationBar
accessibility:=Accessibility.Private,
modifiers:=New DeclarationModifiers(),
returnType:=delegateInvokeMethod.ReturnType,
returnsByRef:=delegateInvokeMethod.ReturnsByRef,
explicitInterfaceSymbol:=Nothing,
name:=methodName,
typeParameters:=Nothing,
......
......@@ -44,6 +44,7 @@ Namespace Microsoft.CodeAnalysis.Editor.VisualBasic.NavigationBar
accessibility:=Accessibility.Protected,
modifiers:=New DeclarationModifiers(isOverride:=True),
returnType:=compilation.GetSpecialType(SpecialType.System_Void),
returnsByRef:=False,
explicitInterfaceSymbol:=Nothing,
name:=WellKnownMemberNames.DestructorName,
typeParameters:=Nothing,
......
......@@ -93,6 +93,7 @@ protected override OperationStatus<IMethodSymbol> GenerateMethodDefinition(Cance
accessibility: Accessibility.Private,
modifiers: CreateMethodModifiers(),
returnType: this.AnalyzerResult.ReturnType,
returnsByRef: false,
explicitInterfaceSymbol: null,
name: _methodName.ToString(),
typeParameters: CreateMethodTypeParameters(cancellationToken),
......
......@@ -38,7 +38,8 @@ protected override bool ContainingTypesOrSelfHasUnsafeKeyword(INamedTypeSymbol c
return containingType.ContainingTypesOrSelfHasUnsafeKeyword();
}
protected override AbstractInvocationInfo CreateInvocationMethodInfo(SemanticDocument document, AbstractGenerateParameterizedMemberService<CSharpGenerateConversionService, SimpleNameSyntax, ExpressionSyntax, InvocationExpressionSyntax>.State state)
protected override AbstractInvocationInfo CreateInvocationMethodInfo(
SemanticDocument document, AbstractGenerateParameterizedMemberService<CSharpGenerateConversionService, SimpleNameSyntax, ExpressionSyntax, InvocationExpressionSyntax>.State state)
{
return new CSharpGenerateParameterizedMemberService<CSharpGenerateConversionService>.InvocationExpressionInfo(document, state);
}
......@@ -196,7 +197,8 @@ protected override bool IsValidSymbol(ISymbol symbol, SemanticModel semanticMode
return true;
}
private static IMethodSymbol GenerateMethodSymbol(INamedTypeSymbol typeToGenerateIn, INamedTypeSymbol parameterSymbol)
private static IMethodSymbol GenerateMethodSymbol(
INamedTypeSymbol typeToGenerateIn, INamedTypeSymbol parameterSymbol)
{
// Remove any generic parameters
if (typeToGenerateIn.IsGenericType)
......@@ -205,15 +207,16 @@ private static IMethodSymbol GenerateMethodSymbol(INamedTypeSymbol typeToGenerat
}
return CodeGenerationSymbolFactory.CreateMethodSymbol(
attributes: SpecializedCollections.EmptyList<AttributeData>(),
accessibility: default(Accessibility),
modifiers: default(DeclarationModifiers),
returnType: typeToGenerateIn,
explicitInterfaceSymbol: null,
name: null,
typeParameters: SpecializedCollections.EmptyList<ITypeParameterSymbol>(),
parameters: new[] { CodeGenerationSymbolFactory.CreateParameterSymbol(parameterSymbol, "v") },
methodKind: MethodKind.Conversion);
attributes: SpecializedCollections.EmptyList<AttributeData>(),
accessibility: default(Accessibility),
modifiers: default(DeclarationModifiers),
returnType: typeToGenerateIn,
returnsByRef: false,
explicitInterfaceSymbol: null,
name: null,
typeParameters: SpecializedCollections.EmptyList<ITypeParameterSymbol>(),
parameters: new[] { CodeGenerationSymbolFactory.CreateParameterSymbol(parameterSymbol, "v") },
methodKind: MethodKind.Conversion);
}
protected override string GetImplicitConversionDisplayText(AbstractGenerateParameterizedMemberService<CSharpGenerateConversionService, SimpleNameSyntax, ExpressionSyntax, InvocationExpressionSyntax>.State state)
......
......@@ -21,19 +21,13 @@ internal partial class CSharpGenerateMethodService :
AbstractGenerateMethodService<CSharpGenerateMethodService, SimpleNameSyntax, ExpressionSyntax, InvocationExpressionSyntax>
{
protected override bool IsExplicitInterfaceGeneration(SyntaxNode node)
{
return node is MethodDeclarationSyntax;
}
=> node is MethodDeclarationSyntax;
protected override bool IsSimpleNameGeneration(SyntaxNode node)
{
return node is SimpleNameSyntax;
}
=> node is SimpleNameSyntax;
protected override bool ContainingTypesOrSelfHasUnsafeKeyword(INamedTypeSymbol containingType)
{
return containingType.ContainingTypesOrSelfHasUnsafeKeyword();
}
=> containingType.ContainingTypesOrSelfHasUnsafeKeyword();
protected override AbstractInvocationInfo CreateInvocationMethodInfo(SemanticDocument document, AbstractGenerateParameterizedMemberService<CSharpGenerateMethodService, SimpleNameSyntax, ExpressionSyntax, InvocationExpressionSyntax>.State state)
{
......@@ -41,14 +35,10 @@ protected override AbstractInvocationInfo CreateInvocationMethodInfo(SemanticDoc
}
protected override bool AreSpecialOptionsActive(SemanticModel semanticModel)
{
return CSharpCommonGenerationServiceMethods.AreSpecialOptionsActive(semanticModel);
}
=> CSharpCommonGenerationServiceMethods.AreSpecialOptionsActive(semanticModel);
protected override bool IsValidSymbol(ISymbol symbol, SemanticModel semanticModel)
{
return CSharpCommonGenerationServiceMethods.IsValidSymbol(symbol, semanticModel);
}
=> CSharpCommonGenerationServiceMethods.IsValidSymbol(symbol, semanticModel);
protected override bool TryInitializeExplicitInterfaceState(
SemanticDocument document,
......@@ -154,7 +144,7 @@ protected override bool IsValidSymbol(ISymbol symbol, SemanticModel semanticMode
return false;
}
protected override ITypeSymbol CanGenerateMethodForSimpleNameOrMemberAccessExpression(
protected override ITypeSymbol DetermineReturnTypeForSimpleNameOrMemberAccessExpression(
ITypeInferenceService typeInferenceService,
SemanticModel semanticModel,
ExpressionSyntax expression,
......
......@@ -36,11 +36,14 @@ protected override IList<ParameterName> DetermineParameterNames(CancellationToke
_invocationExpression.ArgumentList);
}
protected override bool DetermineReturnsByRef(CancellationToken cancellationToken)
=> _invocationExpression.IsParentKind(SyntaxKind.RefExpression);
protected override ITypeSymbol DetermineReturnTypeWorker(CancellationToken cancellationToken)
{
// Defer to the type inferrer to figure out what the return type of this new method
// should be.
var typeInference = this.Document.Project.LanguageServices.GetService<ITypeInferenceService>();
var typeInference = this.Document.Document.GetLanguageService<ITypeInferenceService>();
var inferredType = typeInference.InferType(
this.Document.SemanticModel, _invocationExpression, objectAsDefault: true,
nameOpt: this.State.IdentifierToken.ValueText, cancellationToken: cancellationToken);
......
......@@ -65,6 +65,7 @@ protected override async Task<ISymbol> GenerateMemberAsync(ISymbol member, IName
accessibility: Accessibility.NotApplicable,
modifiers: MemberInsertionCompletionItem.GetModifiers(item),
returnType: semanticModel.Compilation.GetSpecialType(SpecialType.System_Void),
returnsByRef: false,
explicitInterfaceSymbol: null,
name: member.Name,
typeParameters: ((IMethodSymbol)member).TypeParameters,
......
......@@ -347,6 +347,7 @@ private IList<ISymbol> CreateInterfaceMembers(IEnumerable<ISymbol> includedMembe
accessibility: Accessibility.Public,
modifiers: new DeclarationModifiers(isAbstract: true, isUnsafe: method.IsUnsafe()),
returnType: method.ReturnType,
returnsByRef: method.ReturnsByRef,
explicitInterfaceSymbol: null,
name: method.Name,
typeParameters: method.TypeParameters,
......
......@@ -150,7 +150,7 @@ internal new class State : AbstractGenerateParameterizedMemberService<TService,
}
else
{
var typeInference = document.Project.LanguageServices.GetService<ITypeInferenceService>();
var typeInference = document.Document.GetLanguageService<ITypeInferenceService>();
var delegateType = typeInference.InferDelegateType(semanticModel, this.SimpleNameOrMemberAccessExpression, cancellationToken);
if (delegateType != null && delegateType.DelegateInvokeMethod != null)
{
......@@ -160,7 +160,7 @@ internal new class State : AbstractGenerateParameterizedMemberService<TService,
{
// We don't have and invocation expression or a delegate, but we may have a special expression without parenthesis. Lets see
// if the type inference service can directly infer the type for our expression.
var expressionType = service.CanGenerateMethodForSimpleNameOrMemberAccessExpression(typeInference, semanticModel, this.SimpleNameOrMemberAccessExpression, cancellationToken);
var expressionType = service.DetermineReturnTypeForSimpleNameOrMemberAccessExpression(typeInference, semanticModel, this.SimpleNameOrMemberAccessExpression, cancellationToken);
if (expressionType == null)
{
return false;
......@@ -212,13 +212,15 @@ internal new class State : AbstractGenerateParameterizedMemberService<TService,
return true;
}
private static IMethodSymbol CreateMethodSymbolWithReturnType(ITypeSymbol expressionType)
private static IMethodSymbol CreateMethodSymbolWithReturnType(
ITypeSymbol expressionType)
{
return CodeGenerationSymbolFactory.CreateMethodSymbol(
attributes: SpecializedCollections.EmptyList<AttributeData>(),
accessibility: default(Accessibility),
modifiers: default(DeclarationModifiers),
returnType: expressionType,
returnsByRef: false,
explicitInterfaceSymbol: null,
name: null,
typeParameters: SpecializedCollections.EmptyList<ITypeParameterSymbol>(),
......
......@@ -22,7 +22,7 @@ internal abstract partial class AbstractGenerateMethodService<TService, TSimpleN
protected abstract bool IsExplicitInterfaceGeneration(SyntaxNode node);
protected abstract bool TryInitializeExplicitInterfaceState(SemanticDocument document, SyntaxNode node, CancellationToken cancellationToken, out SyntaxToken identifierToken, out IMethodSymbol methodSymbol, out INamedTypeSymbol typeToGenerateIn);
protected abstract bool TryInitializeSimpleNameState(SemanticDocument document, TSimpleNameSyntax simpleName, CancellationToken cancellationToken, out SyntaxToken identifierToken, out TExpressionSyntax simpleNameOrMemberAccessExpression, out TInvocationExpressionSyntax invocationExpressionOpt, out bool isInConditionalExpression);
protected abstract ITypeSymbol CanGenerateMethodForSimpleNameOrMemberAccessExpression(ITypeInferenceService typeInferenceService, SemanticModel semanticModel, TExpressionSyntax expression, CancellationToken cancellationToken);
protected abstract ITypeSymbol DetermineReturnTypeForSimpleNameOrMemberAccessExpression(ITypeInferenceService typeInferenceService, SemanticModel semanticModel, TExpressionSyntax expression, CancellationToken cancellationToken);
public async Task<ImmutableArray<CodeAction>> GenerateMethodAsync(
Document document,
......
......@@ -3,7 +3,6 @@
using System.Collections.Generic;
using System.Linq;
using System.Threading;
using Microsoft.CodeAnalysis.Shared.Extensions;
using Microsoft.CodeAnalysis.Utilities;
using Roslyn.Utilities;
......@@ -27,36 +26,27 @@ protected class MethodSignatureInfo : SignatureInfo
protected override ITypeSymbol DetermineReturnTypeWorker(CancellationToken cancellationToken)
=> _methodSymbol.ReturnType;
protected override bool DetermineReturnsByRef(CancellationToken cancellationToken)
=> _methodSymbol.ReturnsByRef;
protected override IList<ITypeParameterSymbol> DetermineTypeParametersWorker(CancellationToken cancellationToken)
{
return _methodSymbol.TypeParameters;
}
=> _methodSymbol.TypeParameters;
protected override IList<RefKind> DetermineParameterModifiers(CancellationToken cancellationToken)
{
return _methodSymbol.Parameters.Select(p => p.RefKind).ToList();
}
=> _methodSymbol.Parameters.Select(p => p.RefKind).ToList();
protected override IList<bool> DetermineParameterOptionality(CancellationToken cancellationToken)
{
return _methodSymbol.Parameters.Select(p => p.IsOptional).ToList();
}
=> _methodSymbol.Parameters.Select(p => p.IsOptional).ToList();
protected override IList<ITypeSymbol> DetermineParameterTypes(CancellationToken cancellationToken)
{
return _methodSymbol.Parameters.Select(p => p.Type).ToList();
}
=> _methodSymbol.Parameters.Select(p => p.Type).ToList();
protected override IList<ParameterName> DetermineParameterNames(CancellationToken cancellationToken)
{
return _methodSymbol.Parameters.Select(p => new ParameterName(p.Name, isFixed: true))
.ToList();
}
=> _methodSymbol.Parameters.Select(p => new ParameterName(p.Name, isFixed: true))
.ToList();
protected override IList<ITypeSymbol> DetermineTypeArguments(CancellationToken cancellationToken)
{
return SpecializedCollections.EmptyList<ITypeSymbol>();
}
=> SpecializedCollections.EmptyList<ITypeSymbol>();
}
}
}
}
\ No newline at end of file
......@@ -53,6 +53,7 @@ public ITypeSymbol DetermineReturnType(CancellationToken cancellationToken)
protected abstract IList<ITypeSymbol> DetermineTypeArguments(CancellationToken cancellationToken);
protected abstract ITypeSymbol DetermineReturnTypeWorker(CancellationToken cancellationToken);
protected abstract bool DetermineReturnsByRef(CancellationToken cancellationToken);
protected abstract IList<RefKind> DetermineParameterModifiers(CancellationToken cancellationToken);
protected abstract IList<ITypeSymbol> DetermineParameterTypes(CancellationToken cancellationToken);
protected abstract IList<bool> DetermineParameterOptionality(CancellationToken cancellationToken);
......@@ -90,6 +91,8 @@ public ITypeSymbol DetermineReturnType(CancellationToken cancellationToken)
{
var parameters = DetermineParameters(cancellationToken);
var returnType = DetermineReturnType(cancellationToken);
var returnsByRef = DetermineReturnsByRef(cancellationToken);
var isUnsafe = (parameters
.Any(p => p.Type.IsUnsafe()) || returnType.IsUnsafe()) &&
!State.IsContainedInUnsafeType;
......@@ -98,6 +101,7 @@ public ITypeSymbol DetermineReturnType(CancellationToken cancellationToken)
accessibility: DetermineAccessibility(isAbstract),
modifiers: new DeclarationModifiers(isStatic: State.IsStatic, isAbstract: isAbstract, isUnsafe: isUnsafe),
returnType: returnType,
returnsByRef: returnsByRef,
explicitInterfaceSymbol: null,
name: this.State.IdentifierToken.ValueText,
typeParameters: DetermineTypeParameters(cancellationToken),
......
......@@ -66,6 +66,7 @@ Namespace Microsoft.CodeAnalysis.VisualBasic.ExtractMethod
accessibility:=Accessibility.Private,
modifiers:=CreateMethodModifiers(),
returnType:=Me.AnalyzerResult.ReturnType,
returnsByRef:=False,
explicitInterfaceSymbol:=Nothing,
name:=_methodName.ToString(),
typeParameters:=CreateMethodTypeParameters(cancellationToken),
......
......@@ -8,7 +8,6 @@ Imports Microsoft.CodeAnalysis.GenerateMember.GenerateParameterizedMember
Imports Microsoft.CodeAnalysis.Host.Mef
Imports Microsoft.CodeAnalysis.VisualBasic.Syntax
Namespace Microsoft.CodeAnalysis.VisualBasic.GenerateMember.GenerateMethod
<ExportLanguageService(GetType(IGenerateConversionService), LanguageNames.VisualBasic), [Shared]>
Partial Friend Class VisualBasicGenerateConversionService
......@@ -138,18 +137,19 @@ Namespace Microsoft.CodeAnalysis.VisualBasic.GenerateMember.GenerateMethod
typeToGenerateIn = typeToGenerateIn.ConstructUnboundGenericType.ConstructedFrom
End If
Return CodeGenerationSymbolFactory.CreateMethodSymbol(
attributes:=SpecializedCollections.EmptyList(Of AttributeData),
accessibility:=Nothing,
modifiers:=Nothing,
returnType:=typeToGenerateIn,
explicitInterfaceSymbol:=Nothing,
name:=Nothing,
typeParameters:=SpecializedCollections.EmptyList(Of ITypeParameterSymbol),
parameters:={CodeGenerationSymbolFactory.CreateParameterSymbol(parameterSymbol, "v")},
statements:=Nothing,
handlesExpressions:=Nothing,
returnTypeAttributes:=Nothing,
methodKind:=MethodKind.Conversion)
attributes:=SpecializedCollections.EmptyList(Of AttributeData),
accessibility:=Nothing,
modifiers:=Nothing,
returnType:=typeToGenerateIn,
returnsByRef:=False,
explicitInterfaceSymbol:=Nothing,
name:=Nothing,
typeParameters:=SpecializedCollections.EmptyList(Of ITypeParameterSymbol),
parameters:={CodeGenerationSymbolFactory.CreateParameterSymbol(parameterSymbol, "v")},
statements:=Nothing,
handlesExpressions:=Nothing,
returnTypeAttributes:=Nothing,
methodKind:=MethodKind.Conversion)
End Function
Protected Overrides Function GetExplicitConversionDisplayText(state As AbstractGenerateParameterizedMemberService(Of VisualBasicGenerateConversionService, SimpleNameSyntax, ExpressionSyntax, InvocationExpressionSyntax).State) As String
......@@ -160,7 +160,4 @@ Namespace Microsoft.CodeAnalysis.VisualBasic.GenerateMember.GenerateMethod
Return String.Format(VBFeaturesResources.Generate_widening_conversion_in_0, state.TypeToGenerateIn.Name)
End Function
End Class
End Namespace
End Namespace
\ No newline at end of file
......@@ -152,7 +152,7 @@ Namespace Microsoft.CodeAnalysis.VisualBasic.GenerateMember.GenerateMethod
Return New VisualBasicGenerateParameterizedMemberService(Of VisualBasicGenerateMethodService).InvocationExpressionInfo(document, state)
End Function
Protected Overrides Function CanGenerateMethodForSimpleNameOrMemberAccessExpression(typeInferenceService As ITypeInferenceService, semanticModel As SemanticModel, expression As ExpressionSyntax, cancellationToken As CancellationToken) As ITypeSymbol
Protected Overrides Function DetermineReturnTypeForSimpleNameOrMemberAccessExpression(typeInferenceService As ITypeInferenceService, semanticModel As SemanticModel, expression As ExpressionSyntax, cancellationToken As CancellationToken) As ITypeSymbol
Return typeInferenceService.InferType(semanticModel, expression, True, cancellationToken)
End Function
End Class
......
......@@ -30,8 +30,12 @@ Namespace Microsoft.CodeAnalysis.VisualBasic.GenerateMember.GenerateMethod
Me.InvocationExpression.ArgumentList, reservedNames:=typeParametersNames)
End Function
Protected Overrides Function DetermineReturnsByRef(cancellationToken As CancellationToken) As Boolean
Return False
End Function
Protected Overrides Function DetermineReturnTypeWorker(cancellationToken As CancellationToken) As ITypeSymbol
Select Case CType(Me.State.IdentifierToken, SyntaxToken).GetTypeCharacter()
Select Case Me.State.IdentifierToken.GetTypeCharacter()
Case TypeCharacter.Integer
Return Me.Document.SemanticModel.Compilation.GetSpecialType(SpecialType.System_Int32)
Case TypeCharacter.Long
......
......@@ -187,6 +187,7 @@ public static string GetEventHandlerMemberId(Document document, string className
accessibility: Accessibility.Protected,
modifiers: new DeclarationModifiers(),
returnType: targetDocument.Project.GetCompilationAsync(cancellationToken).WaitAndGetResult_Venus(cancellationToken).GetSpecialType(SpecialType.System_Void),
returnsByRef: false,
explicitInterfaceSymbol: null,
name: eventHandlerName,
typeParameters: null,
......
......@@ -80,6 +80,7 @@ protected SyntaxNode CreateEventDeclaration(SyntaxNode containerNode, string nam
accessibility: Accessibility.NotApplicable,
modifiers: new DeclarationModifiers(),
returnType: null,
returnsByRef: false,
explicitInterfaceSymbol: null,
name: "add_" + name,
typeParameters: null,
......@@ -90,6 +91,7 @@ protected SyntaxNode CreateEventDeclaration(SyntaxNode containerNode, string nam
accessibility: Accessibility.NotApplicable,
modifiers: new DeclarationModifiers(),
returnType: null,
returnsByRef: false,
explicitInterfaceSymbol: null,
name: "remove_" + name,
typeParameters: null,
......@@ -136,6 +138,7 @@ protected SyntaxNode CreateMethodDeclaration(SyntaxNode containerNode, string na
accessibility: CodeModelService.GetAccessibility(access, SymbolKind.Method, destination),
modifiers: new DeclarationModifiers(),
returnType: returnType,
returnsByRef: false,
explicitInterfaceSymbol: null,
name: name,
typeParameters: null,
......@@ -158,6 +161,7 @@ protected SyntaxNode CreatePropertyDeclaration(SyntaxNode containerNode, string
accessibility: Accessibility.NotApplicable,
modifiers: new DeclarationModifiers(),
returnType: null,
returnsByRef: false,
explicitInterfaceSymbol: null,
name: "get_" + name,
typeParameters: null,
......@@ -173,6 +177,7 @@ protected SyntaxNode CreatePropertyDeclaration(SyntaxNode containerNode, string
accessibility: Accessibility.NotApplicable,
modifiers: new DeclarationModifiers(),
returnType: null,
returnsByRef: false,
explicitInterfaceSymbol: null,
name: "set_" + name,
typeParameters: null,
......
......@@ -87,7 +87,11 @@ private IEnumerable<TypeInferenceInfo> GetTypesComplex(ExpressionSyntax expressi
private IEnumerable<TypeInferenceInfo> GetTypesSimple(ExpressionSyntax expression)
{
if (expression != null)
if (expression is RefTypeSyntax refType)
{
return GetTypes(refType.Type);
}
else if (expression != null)
{
var typeInfo = SemanticModel.GetTypeInfo(expression, CancellationToken);
var symbolInfo = SemanticModel.GetSymbolInfo(expression, CancellationToken);
......@@ -154,6 +158,7 @@ private IEnumerable<TypeInferenceInfo> GetTypesSimple(ExpressionSyntax expressio
case ParenthesizedLambdaExpressionSyntax parenthesizedLambdaExpression: return InferTypeInParenthesizedLambdaExpression(parenthesizedLambdaExpression);
case PostfixUnaryExpressionSyntax postfixUnary: return InferTypeInPostfixUnaryExpression(postfixUnary);
case PrefixUnaryExpressionSyntax prefixUnary: return InferTypeInPrefixUnaryExpression(prefixUnary);
case RefExpressionSyntax refExpression: return InferTypeInRefExpression(refExpression);
case ReturnStatementSyntax returnStatement: return InferTypeForReturnStatement(returnStatement);
case SimpleLambdaExpressionSyntax simpleLambdaExpression: return InferTypeInSimpleLambdaExpression(simpleLambdaExpression);
case SwitchLabelSyntax switchLabel: return InferTypeInSwitchLabel(switchLabel);
......@@ -1802,6 +1807,9 @@ private static ITypeSymbol GetMemberType(ISymbol memberSymbol)
return null;
}
private IEnumerable<TypeInferenceInfo> InferTypeInRefExpression(RefExpressionSyntax refExpression)
=> InferTypes(refExpression);
private IEnumerable<TypeInferenceInfo> InferTypeForReturnStatement(ReturnStatementSyntax returnStatement, SyntaxToken? previousToken = null)
{
InferTypeForReturnStatement(returnStatement, previousToken,
......
......@@ -116,7 +116,21 @@ public static IMethodSymbol CreateDestructorSymbol(IList<AttributeData> attribut
return result;
}
internal static IMethodSymbol CreateMethodSymbol(INamedTypeSymbol containingType, IList<AttributeData> attributes, Accessibility accessibility, DeclarationModifiers modifiers, ITypeSymbol returnType, IMethodSymbol explicitInterfaceSymbol, string name, IList<ITypeParameterSymbol> typeParameters, IList<IParameterSymbol> parameters, IList<SyntaxNode> statements = null, IList<SyntaxNode> handlesExpressions = null, IList<AttributeData> returnTypeAttributes = null, MethodKind methodKind = MethodKind.Ordinary, bool returnsByRef = false)
internal static IMethodSymbol CreateMethodSymbol(
INamedTypeSymbol containingType,
IList<AttributeData> attributes,
Accessibility accessibility,
DeclarationModifiers modifiers,
ITypeSymbol returnType,
bool returnsByRef,
IMethodSymbol explicitInterfaceSymbol,
string name,
IList<ITypeParameterSymbol> typeParameters,
IList<IParameterSymbol> parameters,
IList<SyntaxNode> statements = null,
IList<SyntaxNode> handlesExpressions = null,
IList<AttributeData> returnTypeAttributes = null,
MethodKind methodKind = MethodKind.Ordinary)
{
var result = new CodeGenerationMethodSymbol(containingType, attributes, accessibility, modifiers, returnType, returnsByRef, explicitInterfaceSymbol, name, typeParameters, parameters, returnTypeAttributes, methodKind);
CodeGenerationMethodInfo.Attach(result, modifiers.IsNew, modifiers.IsUnsafe, modifiers.IsPartial, modifiers.IsAsync, statements, handlesExpressions);
......@@ -126,9 +140,25 @@ internal static IMethodSymbol CreateMethodSymbol(INamedTypeSymbol containingType
/// <summary>
/// Creates a method symbol that can be used to describe a method declaration.
/// </summary>
public static IMethodSymbol CreateMethodSymbol(IList<AttributeData> attributes, Accessibility accessibility, DeclarationModifiers modifiers, ITypeSymbol returnType, IMethodSymbol explicitInterfaceSymbol, string name, IList<ITypeParameterSymbol> typeParameters, IList<IParameterSymbol> parameters, IList<SyntaxNode> statements = null, IList<SyntaxNode> handlesExpressions = null, IList<AttributeData> returnTypeAttributes = null, MethodKind methodKind = MethodKind.Ordinary)
public static IMethodSymbol CreateMethodSymbol(
IList<AttributeData> attributes,
Accessibility accessibility,
DeclarationModifiers modifiers,
ITypeSymbol returnType,
bool returnsByRef,
IMethodSymbol explicitInterfaceSymbol,
string name,
IList<ITypeParameterSymbol> typeParameters,
IList<IParameterSymbol> parameters,
IList<SyntaxNode> statements = null,
IList<SyntaxNode> handlesExpressions = null,
IList<AttributeData> returnTypeAttributes = null,
MethodKind methodKind = MethodKind.Ordinary)
{
return CreateMethodSymbol(null, attributes, accessibility, modifiers, returnType, explicitInterfaceSymbol, name, typeParameters, parameters, statements, handlesExpressions, returnTypeAttributes, methodKind);
return CreateMethodSymbol(
null, attributes, accessibility, modifiers, returnType, returnsByRef,
explicitInterfaceSymbol, name, typeParameters, parameters,
statements, handlesExpressions, returnTypeAttributes, methodKind);
}
/// <summary>
......@@ -223,6 +253,7 @@ public static IArrayTypeSymbol CreateArrayTypeSymbol(ITypeSymbol elementType, in
accessibility ?? accessor.DeclaredAccessibility,
accessor.GetSymbolModifiers().WithIsAbstract(statements == null),
accessor.ReturnType,
false,
explicitInterfaceSymbol ?? accessor.ExplicitInterfaceImplementations.FirstOrDefault(),
accessor.Name,
accessor.TypeParameters,
......@@ -243,7 +274,7 @@ public static IArrayTypeSymbol CreateArrayTypeSymbol(ITypeSymbol elementType, in
attributes,
accessibility,
new DeclarationModifiers(isAbstract: statements == null),
null, null,
null, false, null,
string.Empty,
null, null,
statements: statements);
......@@ -292,6 +323,7 @@ public static INamedTypeSymbol CreateNamedTypeSymbol(IList<AttributeData> attrib
accessibility: Accessibility.Public,
modifiers: new DeclarationModifiers(),
returnType: returnType,
returnsByRef: false,
explicitInterfaceSymbol: null,
name: "Invoke",
typeParameters: null,
......@@ -337,6 +369,7 @@ public static INamespaceSymbol CreateNamespaceSymbol(string name, IList<ISymbol>
accessibility ?? method.DeclaredAccessibility,
modifiers ?? method.GetSymbolModifiers(),
method.ReturnType,
method.ReturnsByRef,
explicitInterfaceSymbol,
name ?? method.Name,
method.TypeParameters,
......
......@@ -31,6 +31,7 @@ internal static partial class ICodeDefinitionFactoryExtensions
accessibility: Accessibility.Public,
modifiers: new DeclarationModifiers(isOverride: true),
returnType: compilation.GetSpecialType(SpecialType.System_Boolean),
returnsByRef: false,
explicitInterfaceSymbol: null,
name: EqualsName,
typeParameters: null,
......
......@@ -25,6 +25,7 @@ internal static partial class ICodeDefinitionFactoryExtensions
accessibility: Accessibility.Public,
modifiers: new DeclarationModifiers(isOverride: true),
returnType: compilation.GetSpecialType(SpecialType.System_Int32),
returnsByRef: false,
explicitInterfaceSymbol: null,
name: GetHashCodeName,
typeParameters: null,
......
......@@ -76,6 +76,7 @@ public static IMethodSymbol RenameTypeParameters(this IMethodSymbol method, ILis
method.DeclaredAccessibility,
method.GetSymbolModifiers(),
method.ReturnType.SubstituteTypes(mapping, typeGenerator),
method.ReturnsByRef,
method.ExplicitInterfaceImplementations.FirstOrDefault(),
method.Name,
updatedTypeParameters,
......@@ -84,7 +85,8 @@ public static IMethodSymbol RenameTypeParameters(this IMethodSymbol method, ILis
p.HasExplicitDefaultValue, p.HasExplicitDefaultValue ? p.ExplicitDefaultValue : null)).ToList());
}
public static IMethodSymbol RenameParameters(this IMethodSymbol method, IList<string> parameterNames)
public static IMethodSymbol RenameParameters(
this IMethodSymbol method, IList<string> parameterNames)
{
var parameterList = method.Parameters;
if (parameterList.Select(p => p.Name).SequenceEqual(parameterNames))
......@@ -100,6 +102,7 @@ public static IMethodSymbol RenameParameters(this IMethodSymbol method, IList<st
method.DeclaredAccessibility,
method.GetSymbolModifiers(),
method.ReturnType,
method.ReturnsByRef,
method.ExplicitInterfaceImplementations.FirstOrDefault(),
method.Name,
method.TypeParameters,
......@@ -199,6 +202,7 @@ public static IMethodSymbol RenameParameters(this IMethodSymbol method, IList<st
method.DeclaredAccessibility,
method.GetSymbolModifiers(),
method.ReturnType,
method.ReturnsByRef,
method.ExplicitInterfaceImplementations.FirstOrDefault(),
method.Name,
method.TypeParameters,
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册