提交 9863a95b 编写于 作者: C CyrusNajmabadi 提交者: GitHub

Merge pull request #16516 from CyrusNajmabadi/generateMethodRefReturns

Add support for generating methods that return-by-ref.
Fixes #16398
...@@ -277,6 +277,7 @@ private void GenerateAndAddEventHandler(ITextView textView, ITextBuffer subjectB ...@@ -277,6 +277,7 @@ private void GenerateAndAddEventHandler(ITextView textView, ITextBuffer subjectB
accessibility: Accessibility.Private, accessibility: Accessibility.Private,
modifiers: new DeclarationModifiers(isStatic: eventHookupExpression.IsInStaticContext()), modifiers: new DeclarationModifiers(isStatic: eventHookupExpression.IsInStaticContext()),
returnType: delegateType.DelegateInvokeMethod.ReturnType, returnType: delegateType.DelegateInvokeMethod.ReturnType,
returnsByRef: delegateType.DelegateInvokeMethod.ReturnsByRef,
explicitInterfaceSymbol: null, explicitInterfaceSymbol: null,
name: eventHandlerMethodName, name: eventHandlerMethodName,
typeParameters: null, typeParameters: null,
......
...@@ -7358,6 +7358,37 @@ private object Issue(int i) ...@@ -7358,6 +7358,37 @@ private object Issue(int i)
{ {
throw new NotImplementedException(); throw new NotImplementedException();
} }
}");
}
[WorkItem(16398, "https://github.com/dotnet/roslyn/issues/16398")]
[Fact, Trait(Traits.Feature, Traits.Features.CodeActionsGenerateMethod)]
public async Task TestReturnsByRef()
{
await TestAsync(
@"
using System;
class C
{
public void Foo()
{
ref int i = ref [|Bar|]();
}
}",
@"using System;
class C
{
public void Foo()
{
ref int i = ref Bar();
}
private ref int Bar()
{
throw new NotImplementedException();
}
}"); }");
} }
} }
......
...@@ -6815,6 +6815,44 @@ class Class : IComInterface ...@@ -6815,6 +6815,44 @@ class Class : IComInterface
public void X() { throw new NotImplementedException(); } public void X() { throw new NotImplementedException(); }
public void MOverload(int i) { throw new NotImplementedException(); } public void MOverload(int i) { throw new NotImplementedException(); }
public int Prop => throw new NotImplementedException(); public int Prop => throw new NotImplementedException();
}");
}
[Fact, Trait(Traits.Feature, Traits.Features.CodeActionsImplementInterface)]
public async Task TestRefReturns()
{
await TestAsync(
@"
using System;
interface I {
ref int IFoo();
ref int Foo { get; }
ref int this[int i] { get; }
}
class C : [|I|]
{
}",
@"
using System;
interface I {
ref int IFoo();
ref int Foo { get; }
ref int this[int i] { get; }
}
class C : I
{
public ref int this[int i] => throw new NotImplementedException();
public ref int Foo => throw new NotImplementedException();
public ref int IFoo()
{
throw new NotImplementedException();
}
}"); }");
} }
} }
......
...@@ -138,6 +138,7 @@ public partial class CodeGenerationTests ...@@ -138,6 +138,7 @@ public partial class CodeGenerationTests
accessibility, accessibility,
modifiers, modifiers,
GetTypeSymbol(returnType)(context.SemanticModel), GetTypeSymbol(returnType)(context.SemanticModel),
false,
explicitInterfaceSymbol, explicitInterfaceSymbol,
name, name,
typeParameters, typeParameters,
...@@ -317,6 +318,7 @@ public partial class CodeGenerationTests ...@@ -317,6 +318,7 @@ public partial class CodeGenerationTests
accessibility, accessibility,
modifiers, modifiers,
GetTypeSymbol(returnType)(context.SemanticModel), GetTypeSymbol(returnType)(context.SemanticModel),
false,
name, name,
typeParameters, typeParameters,
parameterSymbols); parameterSymbols);
...@@ -406,6 +408,7 @@ public partial class CodeGenerationTests ...@@ -406,6 +408,7 @@ public partial class CodeGenerationTests
defaultAccessibility, defaultAccessibility,
new DeclarationModifiers(isAbstract: getStatements == null), new DeclarationModifiers(isAbstract: getStatements == null),
typeSymbol, typeSymbol,
false,
null, null,
"get_" + name, "get_" + name,
null, null,
...@@ -416,6 +419,7 @@ public partial class CodeGenerationTests ...@@ -416,6 +419,7 @@ public partial class CodeGenerationTests
setterAccessibility, setterAccessibility,
new DeclarationModifiers(isAbstract: setStatements == null), new DeclarationModifiers(isAbstract: setStatements == null),
GetTypeSymbol(typeof(void))(context.SemanticModel), GetTypeSymbol(typeof(void))(context.SemanticModel),
false,
null, null,
"set_" + name, "set_" + name,
null, null,
...@@ -439,6 +443,7 @@ public partial class CodeGenerationTests ...@@ -439,6 +443,7 @@ public partial class CodeGenerationTests
defaultAccessibility, defaultAccessibility,
modifiers, modifiers,
typeSymbol, typeSymbol,
false,
explicitInterfaceSymbol, explicitInterfaceSymbol,
name, name,
getParameterSymbols, getParameterSymbols,
......
...@@ -55,6 +55,7 @@ Namespace Microsoft.CodeAnalysis.Editor.VisualBasic.NavigationBar ...@@ -55,6 +55,7 @@ Namespace Microsoft.CodeAnalysis.Editor.VisualBasic.NavigationBar
accessibility:=Accessibility.Private, accessibility:=Accessibility.Private,
modifiers:=New DeclarationModifiers(), modifiers:=New DeclarationModifiers(),
returnType:=delegateInvokeMethod.ReturnType, returnType:=delegateInvokeMethod.ReturnType,
returnsByRef:=delegateInvokeMethod.ReturnsByRef,
explicitInterfaceSymbol:=Nothing, explicitInterfaceSymbol:=Nothing,
name:=methodName, name:=methodName,
typeParameters:=Nothing, typeParameters:=Nothing,
......
...@@ -44,6 +44,7 @@ Namespace Microsoft.CodeAnalysis.Editor.VisualBasic.NavigationBar ...@@ -44,6 +44,7 @@ Namespace Microsoft.CodeAnalysis.Editor.VisualBasic.NavigationBar
accessibility:=Accessibility.Protected, accessibility:=Accessibility.Protected,
modifiers:=New DeclarationModifiers(isOverride:=True), modifiers:=New DeclarationModifiers(isOverride:=True),
returnType:=compilation.GetSpecialType(SpecialType.System_Void), returnType:=compilation.GetSpecialType(SpecialType.System_Void),
returnsByRef:=False,
explicitInterfaceSymbol:=Nothing, explicitInterfaceSymbol:=Nothing,
name:=WellKnownMemberNames.DestructorName, name:=WellKnownMemberNames.DestructorName,
typeParameters:=Nothing, typeParameters:=Nothing,
......
...@@ -93,6 +93,7 @@ protected override OperationStatus<IMethodSymbol> GenerateMethodDefinition(Cance ...@@ -93,6 +93,7 @@ protected override OperationStatus<IMethodSymbol> GenerateMethodDefinition(Cance
accessibility: Accessibility.Private, accessibility: Accessibility.Private,
modifiers: CreateMethodModifiers(), modifiers: CreateMethodModifiers(),
returnType: this.AnalyzerResult.ReturnType, returnType: this.AnalyzerResult.ReturnType,
returnsByRef: false,
explicitInterfaceSymbol: null, explicitInterfaceSymbol: null,
name: _methodName.ToString(), name: _methodName.ToString(),
typeParameters: CreateMethodTypeParameters(cancellationToken), typeParameters: CreateMethodTypeParameters(cancellationToken),
......
// Copyright (c) Microsoft. All Rights Reserved. Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information. // 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.Generic; using System.Collections.Generic;
using System.Collections.Immutable;
using System.Composition; using System.Composition;
using System.Linq; using System.Linq;
using System.Threading; using System.Threading;
...@@ -36,14 +37,14 @@ protected override bool IsClassDeclarationGeneration(SemanticDocument document, ...@@ -36,14 +37,14 @@ protected override bool IsClassDeclarationGeneration(SemanticDocument document,
protected override bool TryInitializeConstructorInitializerGeneration( protected override bool TryInitializeConstructorInitializerGeneration(
SemanticDocument document, SyntaxNode node, CancellationToken cancellationToken, SemanticDocument document, SyntaxNode node, CancellationToken cancellationToken,
out SyntaxToken token, out IList<ArgumentSyntax> arguments, out INamedTypeSymbol typeToGenerateIn) out SyntaxToken token, out ImmutableArray<ArgumentSyntax> arguments, out INamedTypeSymbol typeToGenerateIn)
{ {
var constructorInitializer = (ConstructorInitializerSyntax)node; var constructorInitializer = (ConstructorInitializerSyntax)node;
if (!constructorInitializer.ArgumentList.CloseParenToken.IsMissing) if (!constructorInitializer.ArgumentList.CloseParenToken.IsMissing)
{ {
token = constructorInitializer.ThisOrBaseKeyword; token = constructorInitializer.ThisOrBaseKeyword;
arguments = constructorInitializer.ArgumentList.Arguments.ToList(); arguments = constructorInitializer.ArgumentList.Arguments.ToImmutableArray();
var semanticModel = document.SemanticModel; var semanticModel = document.SemanticModel;
var currentType = semanticModel.GetEnclosingNamedType(constructorInitializer.SpanStart, cancellationToken); var currentType = semanticModel.GetEnclosingNamedType(constructorInitializer.SpanStart, cancellationToken);
...@@ -54,7 +55,7 @@ protected override bool IsClassDeclarationGeneration(SemanticDocument document, ...@@ -54,7 +55,7 @@ protected override bool IsClassDeclarationGeneration(SemanticDocument document,
} }
token = default(SyntaxToken); token = default(SyntaxToken);
arguments = null; arguments = default(ImmutableArray<ArgumentSyntax>);
typeToGenerateIn = null; typeToGenerateIn = null;
return false; return false;
} }
...@@ -93,7 +94,7 @@ protected override bool IsClassDeclarationGeneration(SemanticDocument document, ...@@ -93,7 +94,7 @@ protected override bool IsClassDeclarationGeneration(SemanticDocument document,
SyntaxNode node, SyntaxNode node,
CancellationToken cancellationToken, CancellationToken cancellationToken,
out SyntaxToken token, out SyntaxToken token,
out IList<ArgumentSyntax> arguments, out ImmutableArray<ArgumentSyntax> arguments,
out INamedTypeSymbol typeToGenerateIn) out INamedTypeSymbol typeToGenerateIn)
{ {
var simpleName = (SimpleNameSyntax)node; var simpleName = (SimpleNameSyntax)node;
...@@ -109,14 +110,14 @@ protected override bool IsClassDeclarationGeneration(SemanticDocument document, ...@@ -109,14 +110,14 @@ protected override bool IsClassDeclarationGeneration(SemanticDocument document,
{ {
var symbolInfo = document.SemanticModel.GetSymbolInfo(objectCreationExpression.Type, cancellationToken); var symbolInfo = document.SemanticModel.GetSymbolInfo(objectCreationExpression.Type, cancellationToken);
token = simpleName.Identifier; token = simpleName.Identifier;
arguments = objectCreationExpression.ArgumentList.Arguments.ToList(); arguments = objectCreationExpression.ArgumentList.Arguments.ToImmutableArray();
typeToGenerateIn = symbolInfo.GetAnySymbol() as INamedTypeSymbol; typeToGenerateIn = symbolInfo.GetAnySymbol() as INamedTypeSymbol;
return typeToGenerateIn != null; return typeToGenerateIn != null;
} }
} }
token = default(SyntaxToken); token = default(SyntaxToken);
arguments = null; arguments = default(ImmutableArray<ArgumentSyntax>);
typeToGenerateIn = null; typeToGenerateIn = null;
return false; return false;
} }
...@@ -126,8 +127,8 @@ protected override bool IsClassDeclarationGeneration(SemanticDocument document, ...@@ -126,8 +127,8 @@ protected override bool IsClassDeclarationGeneration(SemanticDocument document,
SyntaxNode node, SyntaxNode node,
CancellationToken cancellationToken, CancellationToken cancellationToken,
out SyntaxToken token, out SyntaxToken token,
out IList<ArgumentSyntax> arguments, out ImmutableArray<ArgumentSyntax> arguments,
out IList<AttributeArgumentSyntax> attributeArguments, out ImmutableArray<AttributeArgumentSyntax> attributeArguments,
out INamedTypeSymbol typeToGenerateIn) out INamedTypeSymbol typeToGenerateIn)
{ {
var simpleName = (SimpleNameSyntax)node; var simpleName = (SimpleNameSyntax)node;
...@@ -145,8 +146,11 @@ protected override bool IsClassDeclarationGeneration(SemanticDocument document, ...@@ -145,8 +146,11 @@ protected override bool IsClassDeclarationGeneration(SemanticDocument document,
if (symbolInfo.CandidateReason == CandidateReason.OverloadResolutionFailure && !symbolInfo.CandidateSymbols.IsEmpty) if (symbolInfo.CandidateReason == CandidateReason.OverloadResolutionFailure && !symbolInfo.CandidateSymbols.IsEmpty)
{ {
token = simpleName.Identifier; token = simpleName.Identifier;
attributeArguments = attribute.ArgumentList.Arguments.ToList(); attributeArguments = attribute.ArgumentList.Arguments.ToImmutableArray();
arguments = attributeArguments.Select(x => SyntaxFactory.Argument(x.NameColon ?? ((x.NameEquals != null) ? SyntaxFactory.NameColon(x.NameEquals.Name) : null), default(SyntaxToken), x.Expression)).ToList(); arguments = attributeArguments.Select(
x => SyntaxFactory.Argument(
x.NameColon ?? (x.NameEquals != null ? SyntaxFactory.NameColon(x.NameEquals.Name) : null),
default(SyntaxToken), x.Expression)).ToImmutableArray();
typeToGenerateIn = symbolInfo.CandidateSymbols.FirstOrDefault().ContainingSymbol as INamedTypeSymbol; typeToGenerateIn = symbolInfo.CandidateSymbols.FirstOrDefault().ContainingSymbol as INamedTypeSymbol;
return typeToGenerateIn != null; return typeToGenerateIn != null;
...@@ -155,23 +159,19 @@ protected override bool IsClassDeclarationGeneration(SemanticDocument document, ...@@ -155,23 +159,19 @@ protected override bool IsClassDeclarationGeneration(SemanticDocument document,
} }
token = default(SyntaxToken); token = default(SyntaxToken);
arguments = null; arguments = default(ImmutableArray<ArgumentSyntax>);
attributeArguments = null; attributeArguments = default(ImmutableArray<AttributeArgumentSyntax>);
typeToGenerateIn = null; typeToGenerateIn = null;
return false; return false;
} }
protected override IList<ParameterName> GenerateParameterNames( protected override ImmutableArray<ParameterName> GenerateParameterNames(
SemanticModel semanticModel, IEnumerable<ArgumentSyntax> arguments, IList<string> reservedNames) SemanticModel semanticModel, IEnumerable<ArgumentSyntax> arguments, IList<string> reservedNames)
{ => semanticModel.GenerateParameterNames(arguments, reservedNames);
return semanticModel.GenerateParameterNames(arguments, reservedNames);
}
protected override IList<ParameterName> GenerateParameterNames( protected override ImmutableArray<ParameterName> GenerateParameterNames(
SemanticModel semanticModel, IEnumerable<AttributeArgumentSyntax> arguments, IList<string> reservedNames) SemanticModel semanticModel, IEnumerable<AttributeArgumentSyntax> arguments, IList<string> reservedNames)
{ => semanticModel.GenerateParameterNames(arguments, reservedNames).ToImmutableArray();
return semanticModel.GenerateParameterNames(arguments, reservedNames);
}
protected override string GenerateNameForArgument( protected override string GenerateNameForArgument(
SemanticModel semanticModel, ArgumentSyntax argument) SemanticModel semanticModel, ArgumentSyntax argument)
......
...@@ -38,7 +38,8 @@ protected override bool ContainingTypesOrSelfHasUnsafeKeyword(INamedTypeSymbol c ...@@ -38,7 +38,8 @@ protected override bool ContainingTypesOrSelfHasUnsafeKeyword(INamedTypeSymbol c
return containingType.ContainingTypesOrSelfHasUnsafeKeyword(); 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); return new CSharpGenerateParameterizedMemberService<CSharpGenerateConversionService>.InvocationExpressionInfo(document, state);
} }
...@@ -196,7 +197,8 @@ protected override bool IsValidSymbol(ISymbol symbol, SemanticModel semanticMode ...@@ -196,7 +197,8 @@ protected override bool IsValidSymbol(ISymbol symbol, SemanticModel semanticMode
return true; return true;
} }
private static IMethodSymbol GenerateMethodSymbol(INamedTypeSymbol typeToGenerateIn, INamedTypeSymbol parameterSymbol) private static IMethodSymbol GenerateMethodSymbol(
INamedTypeSymbol typeToGenerateIn, INamedTypeSymbol parameterSymbol)
{ {
// Remove any generic parameters // Remove any generic parameters
if (typeToGenerateIn.IsGenericType) if (typeToGenerateIn.IsGenericType)
...@@ -205,15 +207,16 @@ private static IMethodSymbol GenerateMethodSymbol(INamedTypeSymbol typeToGenerat ...@@ -205,15 +207,16 @@ private static IMethodSymbol GenerateMethodSymbol(INamedTypeSymbol typeToGenerat
} }
return CodeGenerationSymbolFactory.CreateMethodSymbol( return CodeGenerationSymbolFactory.CreateMethodSymbol(
attributes: SpecializedCollections.EmptyList<AttributeData>(), attributes: SpecializedCollections.EmptyList<AttributeData>(),
accessibility: default(Accessibility), accessibility: default(Accessibility),
modifiers: default(DeclarationModifiers), modifiers: default(DeclarationModifiers),
returnType: typeToGenerateIn, returnType: typeToGenerateIn,
explicitInterfaceSymbol: null, returnsByRef: false,
name: null, explicitInterfaceSymbol: null,
typeParameters: SpecializedCollections.EmptyList<ITypeParameterSymbol>(), name: null,
parameters: new[] { CodeGenerationSymbolFactory.CreateParameterSymbol(parameterSymbol, "v") }, typeParameters: SpecializedCollections.EmptyList<ITypeParameterSymbol>(),
methodKind: MethodKind.Conversion); parameters: new[] { CodeGenerationSymbolFactory.CreateParameterSymbol(parameterSymbol, "v") },
methodKind: MethodKind.Conversion);
} }
protected override string GetImplicitConversionDisplayText(AbstractGenerateParameterizedMemberService<CSharpGenerateConversionService, SimpleNameSyntax, ExpressionSyntax, InvocationExpressionSyntax>.State state) protected override string GetImplicitConversionDisplayText(AbstractGenerateParameterizedMemberService<CSharpGenerateConversionService, SimpleNameSyntax, ExpressionSyntax, InvocationExpressionSyntax>.State state)
......
...@@ -21,19 +21,13 @@ internal partial class CSharpGenerateMethodService : ...@@ -21,19 +21,13 @@ internal partial class CSharpGenerateMethodService :
AbstractGenerateMethodService<CSharpGenerateMethodService, SimpleNameSyntax, ExpressionSyntax, InvocationExpressionSyntax> AbstractGenerateMethodService<CSharpGenerateMethodService, SimpleNameSyntax, ExpressionSyntax, InvocationExpressionSyntax>
{ {
protected override bool IsExplicitInterfaceGeneration(SyntaxNode node) protected override bool IsExplicitInterfaceGeneration(SyntaxNode node)
{ => node is MethodDeclarationSyntax;
return node is MethodDeclarationSyntax;
}
protected override bool IsSimpleNameGeneration(SyntaxNode node) protected override bool IsSimpleNameGeneration(SyntaxNode node)
{ => node is SimpleNameSyntax;
return node is SimpleNameSyntax;
}
protected override bool ContainingTypesOrSelfHasUnsafeKeyword(INamedTypeSymbol containingType) protected override bool ContainingTypesOrSelfHasUnsafeKeyword(INamedTypeSymbol containingType)
{ => containingType.ContainingTypesOrSelfHasUnsafeKeyword();
return containingType.ContainingTypesOrSelfHasUnsafeKeyword();
}
protected override AbstractInvocationInfo CreateInvocationMethodInfo(SemanticDocument document, AbstractGenerateParameterizedMemberService<CSharpGenerateMethodService, SimpleNameSyntax, ExpressionSyntax, InvocationExpressionSyntax>.State state) protected override AbstractInvocationInfo CreateInvocationMethodInfo(SemanticDocument document, AbstractGenerateParameterizedMemberService<CSharpGenerateMethodService, SimpleNameSyntax, ExpressionSyntax, InvocationExpressionSyntax>.State state)
{ {
...@@ -41,14 +35,10 @@ protected override AbstractInvocationInfo CreateInvocationMethodInfo(SemanticDoc ...@@ -41,14 +35,10 @@ protected override AbstractInvocationInfo CreateInvocationMethodInfo(SemanticDoc
} }
protected override bool AreSpecialOptionsActive(SemanticModel semanticModel) protected override bool AreSpecialOptionsActive(SemanticModel semanticModel)
{ => CSharpCommonGenerationServiceMethods.AreSpecialOptionsActive(semanticModel);
return CSharpCommonGenerationServiceMethods.AreSpecialOptionsActive(semanticModel);
}
protected override bool IsValidSymbol(ISymbol symbol, SemanticModel semanticModel) protected override bool IsValidSymbol(ISymbol symbol, SemanticModel semanticModel)
{ => CSharpCommonGenerationServiceMethods.IsValidSymbol(symbol, semanticModel);
return CSharpCommonGenerationServiceMethods.IsValidSymbol(symbol, semanticModel);
}
protected override bool TryInitializeExplicitInterfaceState( protected override bool TryInitializeExplicitInterfaceState(
SemanticDocument document, SemanticDocument document,
...@@ -154,7 +144,7 @@ protected override bool IsValidSymbol(ISymbol symbol, SemanticModel semanticMode ...@@ -154,7 +144,7 @@ protected override bool IsValidSymbol(ISymbol symbol, SemanticModel semanticMode
return false; return false;
} }
protected override ITypeSymbol CanGenerateMethodForSimpleNameOrMemberAccessExpression( protected override ITypeSymbol DetermineReturnTypeForSimpleNameOrMemberAccessExpression(
ITypeInferenceService typeInferenceService, ITypeInferenceService typeInferenceService,
SemanticModel semanticModel, SemanticModel semanticModel,
ExpressionSyntax expression, ExpressionSyntax expression,
......
...@@ -2,6 +2,7 @@ ...@@ -2,6 +2,7 @@
using System; using System;
using System.Collections.Generic; using System.Collections.Generic;
using System.Collections.Immutable;
using System.Linq; using System.Linq;
using System.Threading; using System.Threading;
using Microsoft.CodeAnalysis; using Microsoft.CodeAnalysis;
...@@ -30,24 +31,27 @@ public InvocationExpressionInfo(SemanticDocument document, State state) ...@@ -30,24 +31,27 @@ public InvocationExpressionInfo(SemanticDocument document, State state)
_invocationExpression = state.InvocationExpressionOpt; _invocationExpression = state.InvocationExpressionOpt;
} }
protected override IList<ParameterName> DetermineParameterNames(CancellationToken cancellationToken) protected override ImmutableArray<ParameterName> DetermineParameterNames(CancellationToken cancellationToken)
{ {
return this.Document.SemanticModel.GenerateParameterNames( return this.Document.SemanticModel.GenerateParameterNames(
_invocationExpression.ArgumentList); _invocationExpression.ArgumentList);
} }
protected override bool DetermineReturnsByRef(CancellationToken cancellationToken)
=> _invocationExpression.IsParentKind(SyntaxKind.RefExpression);
protected override ITypeSymbol DetermineReturnTypeWorker(CancellationToken cancellationToken) protected override ITypeSymbol DetermineReturnTypeWorker(CancellationToken cancellationToken)
{ {
// Defer to the type inferrer to figure out what the return type of this new method // Defer to the type inferrer to figure out what the return type of this new method
// should be. // should be.
var typeInference = this.Document.Project.LanguageServices.GetService<ITypeInferenceService>(); var typeInference = this.Document.Document.GetLanguageService<ITypeInferenceService>();
var inferredType = typeInference.InferType( var inferredType = typeInference.InferType(
this.Document.SemanticModel, _invocationExpression, objectAsDefault: true, this.Document.SemanticModel, _invocationExpression, objectAsDefault: true,
nameOpt: this.State.IdentifierToken.ValueText, cancellationToken: cancellationToken); nameOpt: this.State.IdentifierToken.ValueText, cancellationToken: cancellationToken);
return inferredType; return inferredType;
} }
protected override IList<ITypeParameterSymbol> GetCapturedTypeParameters(CancellationToken cancellationToken) protected override ImmutableArray<ITypeParameterSymbol> GetCapturedTypeParameters(CancellationToken cancellationToken)
{ {
var result = new List<ITypeParameterSymbol>(); var result = new List<ITypeParameterSymbol>();
var semanticModel = this.Document.SemanticModel; var semanticModel = this.Document.SemanticModel;
...@@ -57,10 +61,10 @@ protected override IList<ITypeParameterSymbol> GetCapturedTypeParameters(Cancell ...@@ -57,10 +61,10 @@ protected override IList<ITypeParameterSymbol> GetCapturedTypeParameters(Cancell
type.GetReferencedTypeParameters(result); type.GetReferencedTypeParameters(result);
} }
return result; return result.ToImmutableArray();
} }
protected override IList<ITypeParameterSymbol> GenerateTypeParameters(CancellationToken cancellationToken) protected override ImmutableArray<ITypeParameterSymbol> GenerateTypeParameters(CancellationToken cancellationToken)
{ {
// Generate dummy type parameter names for a generic method. If the user is inside a // Generate dummy type parameter names for a generic method. If the user is inside a
// generic method, and calls a generic method with type arguments from the outer // generic method, and calls a generic method with type arguments from the outer
...@@ -78,11 +82,11 @@ protected override IList<ITypeParameterSymbol> GenerateTypeParameters(Cancellati ...@@ -78,11 +82,11 @@ protected override IList<ITypeParameterSymbol> GenerateTypeParameters(Cancellati
s => !State.TypeToGenerateIn.GetAllTypeParameters().Any(t => t.Name == s), s => !State.TypeToGenerateIn.GetAllTypeParameters().Any(t => t.Name == s),
cancellationToken); cancellationToken);
return new List<ITypeParameterSymbol> { typeParameter }; return ImmutableArray.Create(typeParameter);
} }
else else
{ {
var list = new List<ITypeParameterSymbol>(); var list = ArrayBuilder<ITypeParameterSymbol>.GetInstance();
var usedIdentifiers = new HashSet<string> { "T" }; var usedIdentifiers = new HashSet<string> { "T" };
foreach (var type in genericName.TypeArgumentList.Arguments) foreach (var type in genericName.TypeArgumentList.Arguments)
...@@ -97,7 +101,7 @@ protected override IList<ITypeParameterSymbol> GenerateTypeParameters(Cancellati ...@@ -97,7 +101,7 @@ protected override IList<ITypeParameterSymbol> GenerateTypeParameters(Cancellati
list.Add(typeParameter); list.Add(typeParameter);
} }
return list; return list.ToImmutableAndFree();
} }
} }
...@@ -127,18 +131,16 @@ private ITypeParameterSymbol GetMethodTypeParameter(TypeSyntax type, Cancellatio ...@@ -127,18 +131,16 @@ private ITypeParameterSymbol GetMethodTypeParameter(TypeSyntax type, Cancellatio
return null; return null;
} }
protected override IList<RefKind> DetermineParameterModifiers(CancellationToken cancellationToken) protected override ImmutableArray<RefKind> DetermineParameterModifiers(CancellationToken cancellationToken)
{ {
return return
_invocationExpression.ArgumentList.Arguments.Select( _invocationExpression.ArgumentList.Arguments.Select(
a => a.RefOrOutKeyword.Kind() == SyntaxKind.RefKeyword ? RefKind.Ref : a => a.RefOrOutKeyword.Kind() == SyntaxKind.RefKeyword ? RefKind.Ref :
a.RefOrOutKeyword.Kind() == SyntaxKind.OutKeyword ? RefKind.Out : RefKind.None).ToList(); a.RefOrOutKeyword.Kind() == SyntaxKind.OutKeyword ? RefKind.Out : RefKind.None).ToImmutableArray();
} }
protected override IList<ITypeSymbol> DetermineParameterTypes(CancellationToken cancellationToken) protected override ImmutableArray<ITypeSymbol> DetermineParameterTypes(CancellationToken cancellationToken)
{ => _invocationExpression.ArgumentList.Arguments.Select(a => DetermineParameterType(a, cancellationToken)).ToImmutableArray();
return _invocationExpression.ArgumentList.Arguments.Select(a => DetermineParameterType(a, cancellationToken)).ToList();
}
private ITypeSymbol DetermineParameterType( private ITypeSymbol DetermineParameterType(
ArgumentSyntax argument, ArgumentSyntax argument,
...@@ -147,10 +149,8 @@ protected override IList<ITypeSymbol> DetermineParameterTypes(CancellationToken ...@@ -147,10 +149,8 @@ protected override IList<ITypeSymbol> DetermineParameterTypes(CancellationToken
return argument.DetermineParameterType(this.Document.SemanticModel, cancellationToken); return argument.DetermineParameterType(this.Document.SemanticModel, cancellationToken);
} }
protected override IList<bool> DetermineParameterOptionality(CancellationToken cancellationToken) protected override ImmutableArray<bool> DetermineParameterOptionality(CancellationToken cancellationToken)
{ => _invocationExpression.ArgumentList.Arguments.Select(a => false).ToImmutableArray();
return _invocationExpression.ArgumentList.Arguments.Select(a => false).ToList();
}
protected override bool IsIdentifierName() protected override bool IsIdentifierName()
{ {
...@@ -163,9 +163,9 @@ protected override bool IsImplicitReferenceConversion(Compilation compilation, I ...@@ -163,9 +163,9 @@ protected override bool IsImplicitReferenceConversion(Compilation compilation, I
return conversion.IsImplicit && conversion.IsReference; return conversion.IsImplicit && conversion.IsReference;
} }
protected override IList<ITypeSymbol> DetermineTypeArguments(CancellationToken cancellationToken) protected override ImmutableArray<ITypeSymbol> DetermineTypeArguments(CancellationToken cancellationToken)
{ {
var result = new List<ITypeSymbol>(); var result = ArrayBuilder<ITypeSymbol>.GetInstance();
if (State.SimpleNameOpt is GenericNameSyntax) if (State.SimpleNameOpt is GenericNameSyntax)
{ {
...@@ -176,8 +176,8 @@ protected override IList<ITypeSymbol> DetermineTypeArguments(CancellationToken c ...@@ -176,8 +176,8 @@ protected override IList<ITypeSymbol> DetermineTypeArguments(CancellationToken c
} }
} }
return result; return result.ToImmutableAndFree();
} }
} }
} }
} }
\ No newline at end of file
...@@ -893,6 +893,7 @@ internal override async Task<Solution> TryAddUsingsOrImportToDocumentAsync(Solut ...@@ -893,6 +893,7 @@ internal override async Task<Solution> TryAddUsingsOrImportToDocumentAsync(Solut
explicitInterfaceSymbol: null, explicitInterfaceSymbol: null,
name: propertyName.Identifier.ValueText, name: propertyName.Identifier.ValueText,
type: propertyType, type: propertyType,
returnsByRef: false,
parameters: null, parameters: null,
getMethod: s_accessor, getMethod: s_accessor,
setMethod: s_accessor, setMethod: s_accessor,
......
...@@ -61,14 +61,16 @@ protected override async Task<ISymbol> GenerateMemberAsync(ISymbol member, IName ...@@ -61,14 +61,16 @@ protected override async Task<ISymbol> GenerateMemberAsync(ISymbol member, IName
var syntaxFactory = document.GetLanguageService<SyntaxGenerator>(); var syntaxFactory = document.GetLanguageService<SyntaxGenerator>();
var semanticModel = await document.GetSemanticModelAsync(cancellationToken).ConfigureAwait(false); var semanticModel = await document.GetSemanticModelAsync(cancellationToken).ConfigureAwait(false);
var method = (IMethodSymbol)member;
return CodeGenerationSymbolFactory.CreateMethodSymbol(attributes: new List<AttributeData>(), return CodeGenerationSymbolFactory.CreateMethodSymbol(attributes: new List<AttributeData>(),
accessibility: Accessibility.NotApplicable, accessibility: Accessibility.NotApplicable,
modifiers: MemberInsertionCompletionItem.GetModifiers(item), modifiers: MemberInsertionCompletionItem.GetModifiers(item),
returnType: semanticModel.Compilation.GetSpecialType(SpecialType.System_Void), returnType: semanticModel.Compilation.GetSpecialType(SpecialType.System_Void),
returnsByRef: method.ReturnsByRef,
explicitInterfaceSymbol: null, explicitInterfaceSymbol: null,
name: member.Name, name: member.Name,
typeParameters: ((IMethodSymbol)member).TypeParameters, typeParameters: method.TypeParameters,
parameters: member.GetParameters().Select(p => CodeGenerationSymbolFactory.CreateParameterSymbol(p.GetAttributes(), p.RefKind, p.IsParams, p.Type, p.Name)).ToList(), parameters: method.Parameters.Select(p => CodeGenerationSymbolFactory.CreateParameterSymbol(p.GetAttributes(), p.RefKind, p.IsParams, p.Type, p.Name)).ToList(),
statements: syntaxFactory.CreateThrowNotImplementedStatementBlock(semanticModel.Compilation)); statements: syntaxFactory.CreateThrowNotImplementedStatementBlock(semanticModel.Compilation));
} }
......
...@@ -306,6 +306,7 @@ protected async Task<Solution> AddPropertyAsync(Document document, Solution dest ...@@ -306,6 +306,7 @@ protected async Task<Solution> AddPropertyAsync(Document document, Solution dest
accessibility: ComputeAccessibility(accessibility, field.Type), accessibility: ComputeAccessibility(accessibility, field.Type),
modifiers: new DeclarationModifiers(isStatic: field.IsStatic, isReadOnly: field.IsReadOnly, isUnsafe: field.IsUnsafe()), modifiers: new DeclarationModifiers(isStatic: field.IsStatic, isReadOnly: field.IsReadOnly, isUnsafe: field.IsUnsafe()),
type: field.Type, type: field.Type,
returnsByRef: false,
explicitInterfaceSymbol: null, explicitInterfaceSymbol: null,
name: propertyName, name: propertyName,
parameters: SpecializedCollections.EmptyList<IParameterSymbol>(), parameters: SpecializedCollections.EmptyList<IParameterSymbol>(),
......
...@@ -347,6 +347,7 @@ private IList<ISymbol> CreateInterfaceMembers(IEnumerable<ISymbol> includedMembe ...@@ -347,6 +347,7 @@ private IList<ISymbol> CreateInterfaceMembers(IEnumerable<ISymbol> includedMembe
accessibility: Accessibility.Public, accessibility: Accessibility.Public,
modifiers: new DeclarationModifiers(isAbstract: true, isUnsafe: method.IsUnsafe()), modifiers: new DeclarationModifiers(isAbstract: true, isUnsafe: method.IsUnsafe()),
returnType: method.ReturnType, returnType: method.ReturnType,
returnsByRef: method.ReturnsByRef,
explicitInterfaceSymbol: null, explicitInterfaceSymbol: null,
name: method.Name, name: method.Name,
typeParameters: method.TypeParameters, typeParameters: method.TypeParameters,
...@@ -359,6 +360,7 @@ private IList<ISymbol> CreateInterfaceMembers(IEnumerable<ISymbol> includedMembe ...@@ -359,6 +360,7 @@ private IList<ISymbol> CreateInterfaceMembers(IEnumerable<ISymbol> includedMembe
accessibility: Accessibility.Public, accessibility: Accessibility.Public,
modifiers: new DeclarationModifiers(isAbstract: true, isUnsafe: property.IsUnsafe()), modifiers: new DeclarationModifiers(isAbstract: true, isUnsafe: property.IsUnsafe()),
type: property.Type, type: property.Type,
returnsByRef: property.ReturnsByRef,
explicitInterfaceSymbol: null, explicitInterfaceSymbol: null,
name: property.Name, name: property.Name,
parameters: property.Parameters, parameters: property.Parameters,
......
...@@ -2,6 +2,7 @@ ...@@ -2,6 +2,7 @@
using System; using System;
using System.Collections.Generic; using System.Collections.Generic;
using System.Collections.Immutable;
using System.Linq; using System.Linq;
using System.Threading; using System.Threading;
using System.Threading.Tasks; using System.Threading.Tasks;
...@@ -71,7 +72,7 @@ private async Task<Document> GenerateThisOrBaseDelegatingConstructorAsync() ...@@ -71,7 +72,7 @@ private async Task<Document> GenerateThisOrBaseDelegatingConstructorAsync()
{ {
// We don't have to deal with the zero length case, since there's nothing to // We don't have to deal with the zero length case, since there's nothing to
// delegate. It will fall out of the GenerateFieldDelegatingConstructor above. // delegate. It will fall out of the GenerateFieldDelegatingConstructor above.
for (int i = _state.Arguments.Count; i >= 1; i--) for (int i = _state.Arguments.Length; i >= 1; i--)
{ {
var edit = await GenerateThisOrBaseDelegatingConstructorAsync(i).ConfigureAwait(false); var edit = await GenerateThisOrBaseDelegatingConstructorAsync(i).ConfigureAwait(false);
if (edit != null) if (edit != null)
...@@ -156,9 +157,11 @@ private async Task<Document> GenerateDelegatedConstructorAsync() ...@@ -156,9 +157,11 @@ private async Task<Document> GenerateDelegatedConstructorAsync()
} }
var arguments = _state.Arguments.Take(argumentCount).ToList(); var arguments = _state.Arguments.Take(argumentCount).ToList();
var remainingArguments = _state.Arguments.Skip(argumentCount).ToList(); var remainingArguments = _state.Arguments.Skip(argumentCount).ToImmutableArray();
var remainingAttributeArguments = _state.AttributeArguments != null ? _state.AttributeArguments.Skip(argumentCount).ToList() : null; var remainingAttributeArguments = _state.AttributeArguments != null
var remainingParameterTypes = _state.ParameterTypes.Skip(argumentCount).ToList(); ? _state.AttributeArguments.Skip(argumentCount).ToImmutableArray()
: (ImmutableArray<TAttributeArgumentSyntax>?)null;
var remainingParameterTypes = _state.ParameterTypes.Skip(argumentCount).ToImmutableArray();
var instanceConstructors = namedType.InstanceConstructors.Where(IsSymbolAccessible).ToSet(); var instanceConstructors = namedType.InstanceConstructors.Where(IsSymbolAccessible).ToSet();
if (instanceConstructors.IsEmpty()) if (instanceConstructors.IsEmpty())
...@@ -233,10 +236,10 @@ private async Task<Document> GenerateDelegatedConstructorAsync() ...@@ -233,10 +236,10 @@ private async Task<Document> GenerateDelegatedConstructorAsync()
private async Task<Document> GenerateFieldDelegatingConstructorAsync() private async Task<Document> GenerateFieldDelegatingConstructorAsync()
{ {
var arguments = _state.Arguments.ToList(); var arguments = _state.Arguments;
var parameterTypes = _state.ParameterTypes; var parameterTypes = _state.ParameterTypes;
var typeParametersNames = _state.TypeToGenerateIn.GetAllTypeParameters().Select(t => t.Name).ToList(); var typeParametersNames = _state.TypeToGenerateIn.GetAllTypeParameters().Select(t => t.Name).ToImmutableArray();
var parameterNames = GetParameterNames(arguments, typeParametersNames); var parameterNames = GetParameterNames(arguments, typeParametersNames);
GetParameters(arguments, _state.AttributeArguments, parameterTypes, parameterNames, GetParameters(arguments, _state.AttributeArguments, parameterTypes, parameterNames,
out var parameterToExistingFieldMap, out var parameterToNewFieldMap, out var parameters); out var parameterToExistingFieldMap, out var parameterToNewFieldMap, out var parameters);
...@@ -261,8 +264,8 @@ private async Task<Document> GenerateFieldDelegatingConstructorAsync() ...@@ -261,8 +264,8 @@ private async Task<Document> GenerateFieldDelegatingConstructorAsync()
return result; return result;
} }
private IList<ParameterName> GetParameterNames( private ImmutableArray<ParameterName> GetParameterNames(
List<TArgumentSyntax> arguments, List<string> typeParametersNames) ImmutableArray<TArgumentSyntax> arguments, ImmutableArray<string> typeParametersNames)
{ {
return _state.AttributeArguments != null return _state.AttributeArguments != null
? _service.GenerateParameterNames(_document.SemanticModel, _state.AttributeArguments, typeParametersNames) ? _service.GenerateParameterNames(_document.SemanticModel, _state.AttributeArguments, typeParametersNames)
...@@ -270,10 +273,10 @@ private async Task<Document> GenerateFieldDelegatingConstructorAsync() ...@@ -270,10 +273,10 @@ private async Task<Document> GenerateFieldDelegatingConstructorAsync()
} }
private void GetParameters( private void GetParameters(
IList<TArgumentSyntax> arguments, ImmutableArray<TArgumentSyntax> arguments,
IList<TAttributeArgumentSyntax> attributeArguments, ImmutableArray<TAttributeArgumentSyntax>? attributeArguments,
IList<ITypeSymbol> parameterTypes, ImmutableArray<ITypeSymbol> parameterTypes,
IList<ParameterName> parameterNames, ImmutableArray<ParameterName> parameterNames,
out Dictionary<string, ISymbol> parameterToExistingFieldMap, out Dictionary<string, ISymbol> parameterToExistingFieldMap,
out Dictionary<string, string> parameterToNewFieldMap, out Dictionary<string, string> parameterToNewFieldMap,
out List<IParameterSymbol> parameters) out List<IParameterSymbol> parameters)
...@@ -282,13 +285,16 @@ private async Task<Document> GenerateFieldDelegatingConstructorAsync() ...@@ -282,13 +285,16 @@ private async Task<Document> GenerateFieldDelegatingConstructorAsync()
parameterToNewFieldMap = new Dictionary<string, string>(); parameterToNewFieldMap = new Dictionary<string, string>();
parameters = new List<IParameterSymbol>(); parameters = new List<IParameterSymbol>();
for (var i = 0; i < parameterNames.Count; i++) for (var i = 0; i < parameterNames.Length; i++)
{ {
// See if there's a matching field we can use. First test in a case sensitive // See if there's a matching field we can use. First test in a case sensitive
// manner, then case insensitively. // manner, then case insensitively.
if (!TryFindMatchingField(arguments, attributeArguments, parameterNames, parameterTypes, i, parameterToExistingFieldMap, parameterToNewFieldMap, caseSensitive: true)) if (!TryFindMatchingField(
arguments, attributeArguments, parameterNames, parameterTypes, i, parameterToExistingFieldMap,
parameterToNewFieldMap, caseSensitive: true, newParameterNames: out parameterNames))
{ {
if (!TryFindMatchingField(arguments, attributeArguments, parameterNames, parameterTypes, i, parameterToExistingFieldMap, parameterToNewFieldMap, caseSensitive: false)) if (!TryFindMatchingField(arguments, attributeArguments, parameterNames, parameterTypes, i, parameterToExistingFieldMap,
parameterToNewFieldMap, caseSensitive: false, newParameterNames: out parameterNames))
{ {
parameterToNewFieldMap[parameterNames[i].BestNameForParameter] = parameterToNewFieldMap[parameterNames[i].BestNameForParameter] =
parameterNames[i].NameBasedOnArgument; parameterNames[i].NameBasedOnArgument;
...@@ -305,18 +311,20 @@ private async Task<Document> GenerateFieldDelegatingConstructorAsync() ...@@ -305,18 +311,20 @@ private async Task<Document> GenerateFieldDelegatingConstructorAsync()
} }
private bool TryFindMatchingField( private bool TryFindMatchingField(
IList<TArgumentSyntax> arguments, ImmutableArray<TArgumentSyntax> arguments,
IList<TAttributeArgumentSyntax> attributeArguments, ImmutableArray<TAttributeArgumentSyntax>? attributeArguments,
IList<ParameterName> parameterNames, ImmutableArray<ParameterName> parameterNames,
IList<ITypeSymbol> parameterTypes, ImmutableArray<ITypeSymbol> parameterTypes,
int index, int index,
Dictionary<string, ISymbol> parameterToExistingFieldMap, Dictionary<string, ISymbol> parameterToExistingFieldMap,
Dictionary<string, string> parameterToNewFieldMap, Dictionary<string, string> parameterToNewFieldMap,
bool caseSensitive) bool caseSensitive,
out ImmutableArray<ParameterName> newParameterNames)
{ {
var parameterName = parameterNames[index]; var parameterName = parameterNames[index];
var parameterType = parameterTypes[index]; var parameterType = parameterTypes[index];
var isFixed = _service.IsNamedArgument(arguments[index]); var isFixed = _service.IsNamedArgument(arguments[index]);
var newParameterNamesList = parameterNames.ToList();
// For non-out parameters, see if there's already a field there with the same name. // For non-out parameters, see if there's already a field there with the same name.
// If so, and it has a compatible type, then we can just assign to that field. // If so, and it has a compatible type, then we can just assign to that field.
...@@ -346,9 +354,9 @@ private async Task<Document> GenerateFieldDelegatingConstructorAsync() ...@@ -346,9 +354,9 @@ private async Task<Document> GenerateFieldDelegatingConstructorAsync()
// this field. So we need to create a new field. Find a name not in // this field. So we need to create a new field. Find a name not in
// use so we can assign to that. // use so we can assign to that.
var newFieldName = NameGenerator.EnsureUniqueness( var newFieldName = NameGenerator.EnsureUniqueness(
attributeArguments != null ? attributeArguments != null
_service.GenerateNameForArgument(_document.SemanticModel, attributeArguments[index]) : ? _service.GenerateNameForArgument(_document.SemanticModel, attributeArguments.Value[index])
_service.GenerateNameForArgument(_document.SemanticModel, arguments[index]), : _service.GenerateNameForArgument(_document.SemanticModel, arguments[index]),
GetUnavailableMemberNames().Concat(parameterToNewFieldMap.Values)); GetUnavailableMemberNames().Concat(parameterToNewFieldMap.Values));
if (isFixed) if (isFixed)
...@@ -361,16 +369,18 @@ private async Task<Document> GenerateFieldDelegatingConstructorAsync() ...@@ -361,16 +369,18 @@ private async Task<Document> GenerateFieldDelegatingConstructorAsync()
{ {
// Can change the parameter name, so do so. // Can change the parameter name, so do so.
var newParameterName = new ParameterName(newFieldName, isFixed: false); var newParameterName = new ParameterName(newFieldName, isFixed: false);
parameterNames[index] = newParameterName; newParameterNamesList[index] = newParameterName;
parameterToNewFieldMap[newParameterName.BestNameForParameter] = newFieldName; parameterToNewFieldMap[newParameterName.BestNameForParameter] = newFieldName;
} }
} }
newParameterNames = newParameterNamesList.ToImmutableArray();
return true; return true;
} }
} }
} }
newParameterNames = newParameterNamesList.ToImmutableArray();
return false; return false;
} }
......
...@@ -2,6 +2,7 @@ ...@@ -2,6 +2,7 @@
using System; using System;
using System.Collections.Generic; using System.Collections.Generic;
using System.Collections.Immutable;
using System.Linq; using System.Linq;
using System.Threading; using System.Threading;
using System.Threading.Tasks; using System.Threading.Tasks;
...@@ -18,15 +19,15 @@ internal abstract partial class AbstractGenerateConstructorService<TService, TAr ...@@ -18,15 +19,15 @@ internal abstract partial class AbstractGenerateConstructorService<TService, TAr
{ {
protected internal class State protected internal class State
{ {
public IList<TArgumentSyntax> Arguments { get; private set; } public ImmutableArray<TArgumentSyntax> Arguments { get; private set; }
public IList<TAttributeArgumentSyntax> AttributeArguments { get; private set; } public ImmutableArray<TAttributeArgumentSyntax> AttributeArguments { get; private set; }
// The type we're creating a constructor for. Will be a class or struct type. // The type we're creating a constructor for. Will be a class or struct type.
public INamedTypeSymbol TypeToGenerateIn { get; private set; } public INamedTypeSymbol TypeToGenerateIn { get; private set; }
public IList<RefKind> ParameterRefKinds { get; private set; } public IList<RefKind> ParameterRefKinds { get; private set; }
public IList<ITypeSymbol> ParameterTypes { get; private set; } public ImmutableArray<ITypeSymbol> ParameterTypes { get; private set; }
public IMethodSymbol DelegatedConstructorOpt { get; private set; } public IMethodSymbol DelegatedConstructorOpt { get; private set; }
...@@ -90,7 +91,9 @@ private State() ...@@ -90,7 +91,9 @@ private State()
return false; return false;
} }
this.ParameterTypes = this.ParameterTypes ?? GetParameterTypes(service, document, cancellationToken); this.ParameterTypes = this.ParameterTypes.IsDefault
? GetParameterTypes(service, document, cancellationToken)
: this.ParameterTypes;
this.ParameterRefKinds = this.ParameterRefKinds ?? this.Arguments.Select(service.GetRefKind).ToList(); this.ParameterRefKinds = this.ParameterRefKinds ?? this.Arguments.Select(service.GetRefKind).ToList();
return !ClashesWithExistingConstructor(document, cancellationToken); return !ClashesWithExistingConstructor(document, cancellationToken);
...@@ -105,12 +108,12 @@ private bool ClashesWithExistingConstructor(SemanticDocument document, Cancellat ...@@ -105,12 +108,12 @@ private bool ClashesWithExistingConstructor(SemanticDocument document, Cancellat
private bool Matches(IMethodSymbol ctor, ISyntaxFactsService service) private bool Matches(IMethodSymbol ctor, ISyntaxFactsService service)
{ {
if (ctor.Parameters.Length != this.ParameterTypes.Count) if (ctor.Parameters.Length != this.ParameterTypes.Length)
{ {
return false; return false;
} }
for (int i = 0; i < this.ParameterTypes.Count; i++) for (int i = 0; i < this.ParameterTypes.Length; i++)
{ {
var ctorParameter = ctor.Parameters[i]; var ctorParameter = ctor.Parameters[i];
var result = SymbolEquivalenceComparer.Instance.Equals(ctorParameter.Type, this.ParameterTypes[i]) && var result = SymbolEquivalenceComparer.Instance.Equals(ctorParameter.Type, this.ParameterTypes[i]) &&
...@@ -135,15 +138,15 @@ private bool Matches(IMethodSymbol ctor, ISyntaxFactsService service) ...@@ -135,15 +138,15 @@ private bool Matches(IMethodSymbol ctor, ISyntaxFactsService service)
private string GetParameterName(ISyntaxFactsService service, int index) private string GetParameterName(ISyntaxFactsService service, int index)
{ {
if (index >= this.Arguments?.Count) if (this.Arguments.IsDefault || index >= this.Arguments.Length)
{ {
return string.Empty; return string.Empty;
} }
return service.GetNameForArgument(this.Arguments?[index]); return service.GetNameForArgument(this.Arguments[index]);
} }
internal List<ITypeSymbol> GetParameterTypes( internal ImmutableArray<ITypeSymbol> GetParameterTypes(
TService service, TService service,
SemanticDocument document, SemanticDocument document,
CancellationToken cancellationToken) CancellationToken cancellationToken)
...@@ -154,7 +157,7 @@ private string GetParameterName(ISyntaxFactsService service, int index) ...@@ -154,7 +157,7 @@ private string GetParameterName(ISyntaxFactsService service, int index)
? this.AttributeArguments.Select(a => service.GetAttributeArgumentType(semanticModel, a, cancellationToken)) ? this.AttributeArguments.Select(a => service.GetAttributeArgumentType(semanticModel, a, cancellationToken))
: this.Arguments.Select(a => service.GetArgumentType(semanticModel, a, cancellationToken)); : this.Arguments.Select(a => service.GetArgumentType(semanticModel, a, cancellationToken));
return allTypes.Select(t => FixType(t, semanticModel, allTypeParameters)).ToList(); return allTypes.Select(t => FixType(t, semanticModel, allTypeParameters)).ToImmutableArray();
} }
private ITypeSymbol FixType(ITypeSymbol typeSymbol, SemanticModel semanticModel, IEnumerable<ITypeParameterSymbol> allTypeParameters) private ITypeSymbol FixType(ITypeSymbol typeSymbol, SemanticModel semanticModel, IEnumerable<ITypeParameterSymbol> allTypeParameters)
...@@ -204,7 +207,7 @@ private ITypeSymbol FixType(ITypeSymbol typeSymbol, SemanticModel semanticModel, ...@@ -204,7 +207,7 @@ private ITypeSymbol FixType(ITypeSymbol typeSymbol, SemanticModel semanticModel,
{ {
this.Token = token; this.Token = token;
this.DelegatedConstructorOpt = constructor; this.DelegatedConstructorOpt = constructor;
this.ParameterTypes = constructor.Parameters.Select(p => p.Type).ToList(); this.ParameterTypes = constructor.Parameters.Select(p => p.Type).ToImmutableArray();
this.ParameterRefKinds = constructor.Parameters.Select(p => p.RefKind).ToList(); this.ParameterRefKinds = constructor.Parameters.Select(p => p.RefKind).ToList();
} }
cancellationToken.ThrowIfCancellationRequested(); cancellationToken.ThrowIfCancellationRequested();
......
...@@ -26,12 +26,14 @@ protected AbstractGenerateConstructorService() ...@@ -26,12 +26,14 @@ protected AbstractGenerateConstructorService()
protected abstract bool IsClassDeclarationGeneration(SemanticDocument document, SyntaxNode node, CancellationToken cancellationToken); protected abstract bool IsClassDeclarationGeneration(SemanticDocument document, SyntaxNode node, CancellationToken cancellationToken);
protected abstract bool IsConstructorInitializerGeneration(SemanticDocument document, SyntaxNode node, CancellationToken cancellationToken); protected abstract bool IsConstructorInitializerGeneration(SemanticDocument document, SyntaxNode node, CancellationToken cancellationToken);
protected abstract bool TryInitializeSimpleNameGenerationState(SemanticDocument document, SyntaxNode simpleName, CancellationToken cancellationToken, out SyntaxToken token, out IList<TArgumentSyntax> arguments, out INamedTypeSymbol typeToGenerateIn); protected abstract bool TryInitializeSimpleNameGenerationState(SemanticDocument document, SyntaxNode simpleName, CancellationToken cancellationToken, out SyntaxToken token, out ImmutableArray<TArgumentSyntax> arguments, out INamedTypeSymbol typeToGenerateIn);
protected abstract bool TryInitializeClassDeclarationGenerationState(SemanticDocument document, SyntaxNode classDeclaration, CancellationToken cancellationToken, out SyntaxToken token, out IMethodSymbol constructor, out INamedTypeSymbol typeToGenerateIn); protected abstract bool TryInitializeClassDeclarationGenerationState(SemanticDocument document, SyntaxNode classDeclaration, CancellationToken cancellationToken, out SyntaxToken token, out IMethodSymbol constructor, out INamedTypeSymbol typeToGenerateIn);
protected abstract bool TryInitializeConstructorInitializerGeneration(SemanticDocument document, SyntaxNode constructorInitializer, CancellationToken cancellationToken, out SyntaxToken token, out IList<TArgumentSyntax> arguments, out INamedTypeSymbol typeToGenerateIn); protected abstract bool TryInitializeConstructorInitializerGeneration(SemanticDocument document, SyntaxNode constructorInitializer, CancellationToken cancellationToken, out SyntaxToken token, out ImmutableArray<TArgumentSyntax> arguments, out INamedTypeSymbol typeToGenerateIn);
protected abstract bool TryInitializeSimpleAttributeNameGenerationState(SemanticDocument document, SyntaxNode simpleName, CancellationToken cancellationToken, out SyntaxToken token, out IList<TArgumentSyntax> arguments, out IList<TAttributeArgumentSyntax> attributeArguments, out INamedTypeSymbol typeToGenerateIn); protected abstract bool TryInitializeSimpleAttributeNameGenerationState(SemanticDocument document, SyntaxNode simpleName, CancellationToken cancellationToken, out SyntaxToken token, out ImmutableArray<TArgumentSyntax> arguments, out ImmutableArray<TAttributeArgumentSyntax> attributeArguments, out INamedTypeSymbol typeToGenerateIn);
protected abstract IList<ParameterName> GenerateParameterNames(SemanticModel semanticModel, IEnumerable<TArgumentSyntax> arguments, IList<string> reservedNames = null); protected abstract ImmutableArray<ParameterName> GenerateParameterNames(SemanticModel semanticModel, IEnumerable<TArgumentSyntax> arguments, IList<string> reservedNames = null);
protected virtual IList<ParameterName> GenerateParameterNames(SemanticModel semanticModel, IEnumerable<TAttributeArgumentSyntax> arguments, IList<string> reservedNames = null) { return null; } protected virtual ImmutableArray<ParameterName> GenerateParameterNames(SemanticModel semanticModel, IEnumerable<TAttributeArgumentSyntax> arguments, IList<string> reservedNames = null)
=> default(ImmutableArray<ParameterName>);
protected abstract string GenerateNameForArgument(SemanticModel semanticModel, TArgumentSyntax argument); protected abstract string GenerateNameForArgument(SemanticModel semanticModel, TArgumentSyntax argument);
protected virtual string GenerateNameForArgument(SemanticModel semanticModel, TAttributeArgumentSyntax argument) { return null; } protected virtual string GenerateNameForArgument(SemanticModel semanticModel, TAttributeArgumentSyntax argument) { return null; }
protected abstract RefKind GetRefKind(TArgumentSyntax argument); protected abstract RefKind GetRefKind(TArgumentSyntax argument);
......
...@@ -150,7 +150,7 @@ internal new class State : AbstractGenerateParameterizedMemberService<TService, ...@@ -150,7 +150,7 @@ internal new class State : AbstractGenerateParameterizedMemberService<TService,
} }
else else
{ {
var typeInference = document.Project.LanguageServices.GetService<ITypeInferenceService>(); var typeInference = document.Document.GetLanguageService<ITypeInferenceService>();
var delegateType = typeInference.InferDelegateType(semanticModel, this.SimpleNameOrMemberAccessExpression, cancellationToken); var delegateType = typeInference.InferDelegateType(semanticModel, this.SimpleNameOrMemberAccessExpression, cancellationToken);
if (delegateType != null && delegateType.DelegateInvokeMethod != null) if (delegateType != null && delegateType.DelegateInvokeMethod != null)
{ {
...@@ -160,7 +160,7 @@ internal new class State : AbstractGenerateParameterizedMemberService<TService, ...@@ -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 // 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. // 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) if (expressionType == null)
{ {
return false; return false;
...@@ -212,13 +212,15 @@ internal new class State : AbstractGenerateParameterizedMemberService<TService, ...@@ -212,13 +212,15 @@ internal new class State : AbstractGenerateParameterizedMemberService<TService,
return true; return true;
} }
private static IMethodSymbol CreateMethodSymbolWithReturnType(ITypeSymbol expressionType) private static IMethodSymbol CreateMethodSymbolWithReturnType(
ITypeSymbol expressionType)
{ {
return CodeGenerationSymbolFactory.CreateMethodSymbol( return CodeGenerationSymbolFactory.CreateMethodSymbol(
attributes: SpecializedCollections.EmptyList<AttributeData>(), attributes: SpecializedCollections.EmptyList<AttributeData>(),
accessibility: default(Accessibility), accessibility: default(Accessibility),
modifiers: default(DeclarationModifiers), modifiers: default(DeclarationModifiers),
returnType: expressionType, returnType: expressionType,
returnsByRef: false,
explicitInterfaceSymbol: null, explicitInterfaceSymbol: null,
name: null, name: null,
typeParameters: SpecializedCollections.EmptyList<ITypeParameterSymbol>(), typeParameters: SpecializedCollections.EmptyList<ITypeParameterSymbol>(),
......
...@@ -22,7 +22,7 @@ internal abstract partial class AbstractGenerateMethodService<TService, TSimpleN ...@@ -22,7 +22,7 @@ internal abstract partial class AbstractGenerateMethodService<TService, TSimpleN
protected abstract bool IsExplicitInterfaceGeneration(SyntaxNode node); 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 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 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( public async Task<ImmutableArray<CodeAction>> GenerateMethodAsync(
Document document, Document document,
......
// Copyright (c) Microsoft. All Rights Reserved. Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information. // 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.Generic; using System.Collections.Generic;
using System.Collections.Immutable;
using System.Linq; using System.Linq;
using System.Threading; using System.Threading;
using Microsoft.CodeAnalysis; using Microsoft.CodeAnalysis;
...@@ -16,22 +17,22 @@ internal abstract class AbstractInvocationInfo : SignatureInfo ...@@ -16,22 +17,22 @@ internal abstract class AbstractInvocationInfo : SignatureInfo
{ {
protected abstract bool IsIdentifierName(); protected abstract bool IsIdentifierName();
protected abstract IList<ITypeParameterSymbol> GetCapturedTypeParameters(CancellationToken cancellationToken); protected abstract ImmutableArray<ITypeParameterSymbol> GetCapturedTypeParameters(CancellationToken cancellationToken);
protected abstract IList<ITypeParameterSymbol> GenerateTypeParameters(CancellationToken cancellationToken); protected abstract ImmutableArray<ITypeParameterSymbol> GenerateTypeParameters(CancellationToken cancellationToken);
protected AbstractInvocationInfo(SemanticDocument document, State state) protected AbstractInvocationInfo(SemanticDocument document, State state)
: base(document, state) : base(document, state)
{ {
} }
protected override IList<ITypeParameterSymbol> DetermineTypeParametersWorker( protected override ImmutableArray<ITypeParameterSymbol> DetermineTypeParametersWorker(
CancellationToken cancellationToken) CancellationToken cancellationToken)
{ {
var typeParameters = ComputeTypeParameters(cancellationToken); var typeParameters = ComputeTypeParameters(cancellationToken);
return typeParameters.Select(tp => MassageTypeParameter(tp, cancellationToken)).ToList(); return typeParameters.SelectAsArray(tp => MassageTypeParameter(tp, cancellationToken));
} }
private IList<ITypeParameterSymbol> ComputeTypeParameters( private ImmutableArray<ITypeParameterSymbol> ComputeTypeParameters(
CancellationToken cancellationToken) CancellationToken cancellationToken)
{ {
if (IsIdentifierName()) if (IsIdentifierName())
...@@ -40,7 +41,7 @@ protected AbstractInvocationInfo(SemanticDocument document, State state) ...@@ -40,7 +41,7 @@ protected AbstractInvocationInfo(SemanticDocument document, State state)
// a generic method if the expression 'x' captured any method type variables. // a generic method if the expression 'x' captured any method type variables.
var capturedTypeParameters = GetCapturedTypeParameters(cancellationToken); var capturedTypeParameters = GetCapturedTypeParameters(cancellationToken);
var availableTypeParameters = this.State.TypeToGenerateIn.GetAllTypeParameters(); var availableTypeParameters = this.State.TypeToGenerateIn.GetAllTypeParameters();
var result = capturedTypeParameters.Except(availableTypeParameters).ToList(); var result = capturedTypeParameters.Except(availableTypeParameters).ToImmutableArray();
return result; return result;
} }
else else
......
// Copyright (c) Microsoft. All Rights Reserved. Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information. // 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.Generic; using System.Collections.Generic;
using System.Linq; using System.Collections.Immutable;
using System.Threading; using System.Threading;
using Microsoft.CodeAnalysis.Shared.Extensions;
using Microsoft.CodeAnalysis.Utilities; using Microsoft.CodeAnalysis.Utilities;
using Roslyn.Utilities; using Roslyn.Utilities;
...@@ -27,36 +26,26 @@ protected class MethodSignatureInfo : SignatureInfo ...@@ -27,36 +26,26 @@ protected class MethodSignatureInfo : SignatureInfo
protected override ITypeSymbol DetermineReturnTypeWorker(CancellationToken cancellationToken) protected override ITypeSymbol DetermineReturnTypeWorker(CancellationToken cancellationToken)
=> _methodSymbol.ReturnType; => _methodSymbol.ReturnType;
protected override IList<ITypeParameterSymbol> DetermineTypeParametersWorker(CancellationToken cancellationToken) protected override bool DetermineReturnsByRef(CancellationToken cancellationToken)
{ => _methodSymbol.ReturnsByRef;
return _methodSymbol.TypeParameters;
}
protected override IList<RefKind> DetermineParameterModifiers(CancellationToken cancellationToken) protected override ImmutableArray<ITypeParameterSymbol> DetermineTypeParametersWorker(CancellationToken cancellationToken)
{ => _methodSymbol.TypeParameters;
return _methodSymbol.Parameters.Select(p => p.RefKind).ToList();
}
protected override IList<bool> DetermineParameterOptionality(CancellationToken cancellationToken) protected override ImmutableArray<RefKind> DetermineParameterModifiers(CancellationToken cancellationToken)
{ => _methodSymbol.Parameters.SelectAsArray(p => p.RefKind);
return _methodSymbol.Parameters.Select(p => p.IsOptional).ToList();
}
protected override IList<ITypeSymbol> DetermineParameterTypes(CancellationToken cancellationToken) protected override ImmutableArray<bool> DetermineParameterOptionality(CancellationToken cancellationToken)
{ => _methodSymbol.Parameters.SelectAsArray(p => p.IsOptional);
return _methodSymbol.Parameters.Select(p => p.Type).ToList();
}
protected override IList<ParameterName> DetermineParameterNames(CancellationToken cancellationToken) protected override ImmutableArray<ITypeSymbol> DetermineParameterTypes(CancellationToken cancellationToken)
{ => _methodSymbol.Parameters.SelectAsArray(p => p.Type);
return _methodSymbol.Parameters.Select(p => new ParameterName(p.Name, isFixed: true))
.ToList();
}
protected override IList<ITypeSymbol> DetermineTypeArguments(CancellationToken cancellationToken) protected override ImmutableArray<ParameterName> DetermineParameterNames(CancellationToken cancellationToken)
{ => _methodSymbol.Parameters.SelectAsArray(p => new ParameterName(p.Name, isFixed: true));
return SpecializedCollections.EmptyList<ITypeSymbol>();
} protected override ImmutableArray<ITypeSymbol> DetermineTypeArguments(CancellationToken cancellationToken)
=> ImmutableArray<ITypeSymbol>.Empty;
} }
} }
} }
\ No newline at end of file
...@@ -22,7 +22,7 @@ internal abstract class SignatureInfo ...@@ -22,7 +22,7 @@ internal abstract class SignatureInfo
{ {
protected readonly SemanticDocument Document; protected readonly SemanticDocument Document;
protected readonly State State; protected readonly State State;
private IList<ITypeParameterSymbol> _typeParameters; private ImmutableArray<ITypeParameterSymbol> _typeParameters;
private IDictionary<ITypeSymbol, ITypeParameterSymbol> _typeArgumentToTypeParameterMap; private IDictionary<ITypeSymbol, ITypeParameterSymbol> _typeArgumentToTypeParameterMap;
public SignatureInfo( public SignatureInfo(
...@@ -33,12 +33,15 @@ internal abstract class SignatureInfo ...@@ -33,12 +33,15 @@ internal abstract class SignatureInfo
this.State = state; this.State = state;
} }
public IList<ITypeParameterSymbol> DetermineTypeParameters(CancellationToken cancellationToken) public ImmutableArray<ITypeParameterSymbol> DetermineTypeParameters(CancellationToken cancellationToken)
{ {
return _typeParameters ?? (_typeParameters = DetermineTypeParametersWorker(cancellationToken)); return _typeParameters.IsDefault
? (_typeParameters = DetermineTypeParametersWorker(cancellationToken))
: _typeParameters;
} }
protected abstract IList<ITypeParameterSymbol> DetermineTypeParametersWorker(CancellationToken cancellationToken); protected abstract ImmutableArray<ITypeParameterSymbol> DetermineTypeParametersWorker(CancellationToken cancellationToken);
protected abstract bool DetermineReturnsByRef(CancellationToken cancellationToken);
public ITypeSymbol DetermineReturnType(CancellationToken cancellationToken) public ITypeSymbol DetermineReturnType(CancellationToken cancellationToken)
{ {
...@@ -51,12 +54,12 @@ public ITypeSymbol DetermineReturnType(CancellationToken cancellationToken) ...@@ -51,12 +54,12 @@ public ITypeSymbol DetermineReturnType(CancellationToken cancellationToken)
return FixType(type, cancellationToken); return FixType(type, cancellationToken);
} }
protected abstract IList<ITypeSymbol> DetermineTypeArguments(CancellationToken cancellationToken); protected abstract ImmutableArray<ITypeSymbol> DetermineTypeArguments(CancellationToken cancellationToken);
protected abstract ITypeSymbol DetermineReturnTypeWorker(CancellationToken cancellationToken); protected abstract ITypeSymbol DetermineReturnTypeWorker(CancellationToken cancellationToken);
protected abstract IList<RefKind> DetermineParameterModifiers(CancellationToken cancellationToken); protected abstract ImmutableArray<RefKind> DetermineParameterModifiers(CancellationToken cancellationToken);
protected abstract IList<ITypeSymbol> DetermineParameterTypes(CancellationToken cancellationToken); protected abstract ImmutableArray<ITypeSymbol> DetermineParameterTypes(CancellationToken cancellationToken);
protected abstract IList<bool> DetermineParameterOptionality(CancellationToken cancellationToken); protected abstract ImmutableArray<bool> DetermineParameterOptionality(CancellationToken cancellationToken);
protected abstract IList<ParameterName> DetermineParameterNames(CancellationToken cancellationToken); protected abstract ImmutableArray<ParameterName> DetermineParameterNames(CancellationToken cancellationToken);
internal IPropertySymbol GenerateProperty( internal IPropertySymbol GenerateProperty(
SyntaxGenerator factory, SyntaxGenerator factory,
...@@ -76,6 +79,7 @@ public ITypeSymbol DetermineReturnType(CancellationToken cancellationToken) ...@@ -76,6 +79,7 @@ public ITypeSymbol DetermineReturnType(CancellationToken cancellationToken)
accessibility: accessibility, accessibility: accessibility,
modifiers: new DeclarationModifiers(isStatic: State.IsStatic, isAbstract: isAbstract), modifiers: new DeclarationModifiers(isStatic: State.IsStatic, isAbstract: isAbstract),
type: DetermineReturnType(cancellationToken), type: DetermineReturnType(cancellationToken),
returnsByRef: DetermineReturnsByRef(cancellationToken),
explicitInterfaceSymbol: null, explicitInterfaceSymbol: null,
name: this.State.IdentifierToken.ValueText, name: this.State.IdentifierToken.ValueText,
parameters: DetermineParameters(cancellationToken), parameters: DetermineParameters(cancellationToken),
...@@ -90,14 +94,20 @@ public ITypeSymbol DetermineReturnType(CancellationToken cancellationToken) ...@@ -90,14 +94,20 @@ public ITypeSymbol DetermineReturnType(CancellationToken cancellationToken)
{ {
var parameters = DetermineParameters(cancellationToken); var parameters = DetermineParameters(cancellationToken);
var returnType = DetermineReturnType(cancellationToken); var returnType = DetermineReturnType(cancellationToken);
var isUnsafe = (parameters var isUnsafe = false;
.Any(p => p.Type.IsUnsafe()) || returnType.IsUnsafe()) && if (!State.IsContainedInUnsafeType)
!State.IsContainedInUnsafeType; {
isUnsafe = returnType.IsUnsafe() || parameters.Any(p => p.Type.IsUnsafe());
}
var returnsByRef = DetermineReturnsByRef(cancellationToken);
var method = CodeGenerationSymbolFactory.CreateMethodSymbol( var method = CodeGenerationSymbolFactory.CreateMethodSymbol(
attributes: null, attributes: null,
accessibility: DetermineAccessibility(isAbstract), accessibility: DetermineAccessibility(isAbstract),
modifiers: new DeclarationModifiers(isStatic: State.IsStatic, isAbstract: isAbstract, isUnsafe: isUnsafe), modifiers: new DeclarationModifiers(isStatic: State.IsStatic, isAbstract: isAbstract, isUnsafe: isUnsafe),
returnType: returnType, returnType: returnType,
returnsByRef: returnsByRef,
explicitInterfaceSymbol: null, explicitInterfaceSymbol: null,
name: this.State.IdentifierToken.ValueText, name: this.State.IdentifierToken.ValueText,
typeParameters: DetermineTypeParameters(cancellationToken), typeParameters: DetermineTypeParameters(cancellationToken),
...@@ -156,7 +166,7 @@ public ITypeSymbol DetermineReturnType(CancellationToken cancellationToken) ...@@ -156,7 +166,7 @@ public ITypeSymbol DetermineReturnType(CancellationToken cancellationToken)
var result = new Dictionary<ITypeSymbol, ITypeParameterSymbol>(); var result = new Dictionary<ITypeSymbol, ITypeParameterSymbol>();
for(var i = 0; i < typeArguments.Count; i++) for(var i = 0; i < typeArguments.Length; i++)
{ {
if (typeArguments[i] != null) if (typeArguments[i] != null)
{ {
...@@ -179,15 +189,15 @@ public ITypeSymbol DetermineReturnType(CancellationToken cancellationToken) ...@@ -179,15 +189,15 @@ public ITypeSymbol DetermineReturnType(CancellationToken cancellationToken)
: new[] { throwStatement }; : new[] { throwStatement };
} }
private IList<IParameterSymbol> DetermineParameters(CancellationToken cancellationToken) private ImmutableArray<IParameterSymbol> DetermineParameters(CancellationToken cancellationToken)
{ {
var modifiers = DetermineParameterModifiers(cancellationToken); var modifiers = DetermineParameterModifiers(cancellationToken);
var types = DetermineParameterTypes(cancellationToken).Select(t => FixType(t, cancellationToken)).ToList(); var types = DetermineParameterTypes(cancellationToken).Select(t => FixType(t, cancellationToken)).ToList();
var optionality = DetermineParameterOptionality(cancellationToken); var optionality = DetermineParameterOptionality(cancellationToken);
var names = DetermineParameterNames(cancellationToken); var names = DetermineParameterNames(cancellationToken);
var result = new List<IParameterSymbol>(); var result = ArrayBuilder<IParameterSymbol>.GetInstance();
for (var i = 0; i < modifiers.Count; i++) for (var i = 0; i < modifiers.Length; i++)
{ {
result.Add(CodeGenerationSymbolFactory.CreateParameterSymbol( result.Add(CodeGenerationSymbolFactory.CreateParameterSymbol(
attributes: null, attributes: null,
...@@ -198,7 +208,7 @@ private IList<IParameterSymbol> DetermineParameters(CancellationToken cancellati ...@@ -198,7 +208,7 @@ private IList<IParameterSymbol> DetermineParameters(CancellationToken cancellati
name: names[i].BestNameForParameter)); name: names[i].BestNameForParameter));
} }
return result; return result.ToImmutableAndFree();
} }
private Accessibility DetermineAccessibility(bool isAbstract) private Accessibility DetermineAccessibility(bool isAbstract)
......
...@@ -64,7 +64,7 @@ protected ImmutableArray<CodeAction> GetActions(Document document, State state, ...@@ -64,7 +64,7 @@ protected ImmutableArray<CodeAction> GetActions(Document document, State state,
var typeParameters = state.SignatureInfo.DetermineTypeParameters(cancellationToken); var typeParameters = state.SignatureInfo.DetermineTypeParameters(cancellationToken);
var returnType = state.SignatureInfo.DetermineReturnType(cancellationToken); var returnType = state.SignatureInfo.DetermineReturnType(cancellationToken);
if (typeParameters.Count == 0 && returnType.SpecialType != SpecialType.System_Void) if (typeParameters.Length == 0 && returnType.SpecialType != SpecialType.System_Void)
{ {
result.Add(new GenerateParameterizedMemberCodeAction((TService)this, document, state, isAbstract: false, generateProperty: true)); result.Add(new GenerateParameterizedMemberCodeAction((TService)this, document, state, isAbstract: false, generateProperty: true));
......
...@@ -66,6 +66,7 @@ protected override async Task<Document> GetChangedDocumentAsync(CancellationToke ...@@ -66,6 +66,7 @@ protected override async Task<Document> GetChangedDocumentAsync(CancellationToke
accessibility: DetermineMaximalAccessibility(_state), accessibility: DetermineMaximalAccessibility(_state),
modifiers: new DeclarationModifiers(isStatic: _state.IsStatic, isUnsafe: generateUnsafe), modifiers: new DeclarationModifiers(isStatic: _state.IsStatic, isUnsafe: generateUnsafe),
type: _state.TypeMemberType, type: _state.TypeMemberType,
returnsByRef: false,
explicitInterfaceSymbol: null, explicitInterfaceSymbol: null,
name: _state.IdentifierToken.ValueText, name: _state.IdentifierToken.ValueText,
isIndexer: _state.IsIndexer, isIndexer: _state.IsIndexer,
......
...@@ -46,9 +46,10 @@ private INamedTypeSymbol GenerateNamedType(GenerateTypeOptionsResult options) ...@@ -46,9 +46,10 @@ private INamedTypeSymbol GenerateNamedType(GenerateTypeOptionsResult options)
options.Accessibility, options.Accessibility,
DetermineModifiers(), DetermineModifiers(),
DetermineReturnType(options), DetermineReturnType(options),
options.TypeName, returnsByRef: false,
DetermineTypeParameters(options), name: options.TypeName,
DetermineParameters(options)); typeParameters: DetermineTypeParameters(options),
parameters: DetermineParameters(options));
} }
return CodeGenerationSymbolFactory.CreateNamedTypeSymbol( return CodeGenerationSymbolFactory.CreateNamedTypeSymbol(
......
...@@ -120,7 +120,8 @@ Namespace Microsoft.CodeAnalysis.VisualBasic.CodeFixes.GenerateEvent ...@@ -120,7 +120,8 @@ Namespace Microsoft.CodeAnalysis.VisualBasic.CodeFixes.GenerateEvent
Dim delegateType = CodeGenerationSymbolFactory.CreateDelegateTypeSymbol( Dim delegateType = CodeGenerationSymbolFactory.CreateDelegateTypeSymbol(
attributes:=Nothing, accessibility:=Accessibility.Public, modifiers:=Nothing, attributes:=Nothing, accessibility:=Accessibility.Public, modifiers:=Nothing,
returnType:=semanticModel.Compilation.GetSpecialType(SpecialType.System_Void), returnType:=semanticModel.Compilation.GetSpecialType(SpecialType.System_Void),
name:=eventHandlerName, parameters:=delegateSymbol.GetParameters()) returnsByRef:=False, name:=eventHandlerName,
parameters:=delegateSymbol.GetParameters())
Dim generatedEvent = CodeGenerationSymbolFactory.CreateEventSymbol( Dim generatedEvent = CodeGenerationSymbolFactory.CreateEventSymbol(
attributes:=SpecializedCollections.EmptyList(Of AttributeData)(), attributes:=SpecializedCollections.EmptyList(Of AttributeData)(),
...@@ -270,7 +271,7 @@ Namespace Microsoft.CodeAnalysis.VisualBasic.CodeFixes.GenerateEvent ...@@ -270,7 +271,7 @@ Namespace Microsoft.CodeAnalysis.VisualBasic.CodeFixes.GenerateEvent
Dim eventHandlerType = CodeGenerationSymbolFactory.CreateDelegateTypeSymbol( Dim eventHandlerType = CodeGenerationSymbolFactory.CreateDelegateTypeSymbol(
eventType.GetAttributes(), eventType.DeclaredAccessibility, eventType.GetAttributes(), eventType.DeclaredAccessibility,
modifiers:=Nothing, returnType:=returnType, modifiers:=Nothing, returnType:=returnType, returnsByRef:=false,
name:=actualEventName + "EventHandler", name:=actualEventName + "EventHandler",
typeParameters:=eventType.TypeParameters, parameters:=parameters) typeParameters:=eventType.TypeParameters, parameters:=parameters)
...@@ -374,7 +375,8 @@ Namespace Microsoft.CodeAnalysis.VisualBasic.CodeFixes.GenerateEvent ...@@ -374,7 +375,8 @@ Namespace Microsoft.CodeAnalysis.VisualBasic.CodeFixes.GenerateEvent
Dim delegateType = CodeGenerationSymbolFactory.CreateDelegateTypeSymbol( Dim delegateType = CodeGenerationSymbolFactory.CreateDelegateTypeSymbol(
attributes:=Nothing, accessibility:=Accessibility.Public, modifiers:=Nothing, attributes:=Nothing, accessibility:=Accessibility.Public, modifiers:=Nothing,
returnType:=semanticModel.Compilation.GetSpecialType(SpecialType.System_Void), returnType:=semanticModel.Compilation.GetSpecialType(SpecialType.System_Void),
name:=actualEventName + "Handler", parameters:=boundMethod.GetParameters()) returnsByRef:=False, name:=actualEventName + "Handler",
parameters:=boundMethod.GetParameters())
Dim generatedEvent = CodeGenerationSymbolFactory.CreateEventSymbol( Dim generatedEvent = CodeGenerationSymbolFactory.CreateEventSymbol(
attributes:=Nothing, accessibility:=Accessibility.Public, modifiers:=Nothing, attributes:=Nothing, accessibility:=Accessibility.Public, modifiers:=Nothing,
......
...@@ -66,6 +66,7 @@ Namespace Microsoft.CodeAnalysis.VisualBasic.ExtractMethod ...@@ -66,6 +66,7 @@ Namespace Microsoft.CodeAnalysis.VisualBasic.ExtractMethod
accessibility:=Accessibility.Private, accessibility:=Accessibility.Private,
modifiers:=CreateMethodModifiers(), modifiers:=CreateMethodModifiers(),
returnType:=Me.AnalyzerResult.ReturnType, returnType:=Me.AnalyzerResult.ReturnType,
returnsByRef:=False,
explicitInterfaceSymbol:=Nothing, explicitInterfaceSymbol:=Nothing,
name:=_methodName.ToString(), name:=_methodName.ToString(),
typeParameters:=CreateMethodTypeParameters(cancellationToken), typeParameters:=CreateMethodTypeParameters(cancellationToken),
......
' Copyright (c) Microsoft. All Rights Reserved. Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information. ' 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.Composition
Imports System.Threading Imports System.Threading
Imports Microsoft.CodeAnalysis.GenerateMember.GenerateConstructor Imports Microsoft.CodeAnalysis.GenerateMember.GenerateConstructor
...@@ -20,7 +21,7 @@ Namespace Microsoft.CodeAnalysis.VisualBasic.GenerateMember.GenerateConstructor ...@@ -20,7 +21,7 @@ Namespace Microsoft.CodeAnalysis.VisualBasic.GenerateMember.GenerateConstructor
Protected Overrides Function GenerateParameterNames( Protected Overrides Function GenerateParameterNames(
semanticModel As SemanticModel, semanticModel As SemanticModel,
arguments As IEnumerable(Of ArgumentSyntax), arguments As IEnumerable(Of ArgumentSyntax),
Optional reservedNames As IList(Of String) = Nothing) As IList(Of ParameterName) Optional reservedNames As IList(Of String) = Nothing) As ImmutableArray(Of ParameterName)
Return semanticModel.GenerateParameterNames(arguments?.ToList(), reservedNames) Return semanticModel.GenerateParameterNames(arguments?.ToList(), reservedNames)
End Function End Function
...@@ -48,7 +49,7 @@ Namespace Microsoft.CodeAnalysis.VisualBasic.GenerateMember.GenerateConstructor ...@@ -48,7 +49,7 @@ Namespace Microsoft.CodeAnalysis.VisualBasic.GenerateMember.GenerateConstructor
Protected Overrides Function TryInitializeConstructorInitializerGeneration( Protected Overrides Function TryInitializeConstructorInitializerGeneration(
document As SemanticDocument, node As SyntaxNode, cancellationToken As CancellationToken, document As SemanticDocument, node As SyntaxNode, cancellationToken As CancellationToken,
ByRef token As SyntaxToken, ByRef arguments As IList(Of ArgumentSyntax), ByRef typeToGenerateIn As INamedTypeSymbol) As Boolean ByRef token As SyntaxToken, ByRef arguments As ImmutableArray(Of ArgumentSyntax), ByRef typeToGenerateIn As INamedTypeSymbol) As Boolean
Dim simpleName = DirectCast(node, SimpleNameSyntax) Dim simpleName = DirectCast(node, SimpleNameSyntax)
Dim memberAccess = DirectCast(simpleName.Parent, MemberAccessExpressionSyntax) Dim memberAccess = DirectCast(simpleName.Parent, MemberAccessExpressionSyntax)
Dim invocation = DirectCast(memberAccess.Parent, InvocationExpressionSyntax) Dim invocation = DirectCast(memberAccess.Parent, InvocationExpressionSyntax)
...@@ -58,7 +59,7 @@ Namespace Microsoft.CodeAnalysis.VisualBasic.GenerateMember.GenerateConstructor ...@@ -58,7 +59,7 @@ Namespace Microsoft.CodeAnalysis.VisualBasic.GenerateMember.GenerateConstructor
If containingType IsNot Nothing Then If containingType IsNot Nothing Then
token = simpleName.Identifier token = simpleName.Identifier
arguments = invocation.ArgumentList.Arguments.ToList() arguments = invocation.ArgumentList.Arguments.ToImmutableArray()
typeToGenerateIn = If(memberAccess.Expression.IsKind(SyntaxKind.MyBaseExpression), typeToGenerateIn = If(memberAccess.Expression.IsKind(SyntaxKind.MyBaseExpression),
containingType.BaseType, containingType.BaseType,
containingType) containingType)
...@@ -82,7 +83,7 @@ Namespace Microsoft.CodeAnalysis.VisualBasic.GenerateMember.GenerateConstructor ...@@ -82,7 +83,7 @@ Namespace Microsoft.CodeAnalysis.VisualBasic.GenerateMember.GenerateConstructor
node As SyntaxNode, node As SyntaxNode,
cancellationToken As CancellationToken, cancellationToken As CancellationToken,
ByRef token As SyntaxToken, ByRef token As SyntaxToken,
ByRef arguments As IList(Of ArgumentSyntax), ByRef arguments As ImmutableArray(Of ArgumentSyntax),
ByRef typeToGenerateIn As INamedTypeSymbol) As Boolean ByRef typeToGenerateIn As INamedTypeSymbol) As Boolean
Dim simpleName = DirectCast(node, SimpleNameSyntax) Dim simpleName = DirectCast(node, SimpleNameSyntax)
...@@ -97,7 +98,7 @@ Namespace Microsoft.CodeAnalysis.VisualBasic.GenerateMember.GenerateConstructor ...@@ -97,7 +98,7 @@ Namespace Microsoft.CodeAnalysis.VisualBasic.GenerateMember.GenerateConstructor
Dim semanticModel = document.SemanticModel Dim semanticModel = document.SemanticModel
token = simpleName.Identifier token = simpleName.Identifier
arguments = objectCreationExpression.ArgumentList.Arguments.ToList() arguments = objectCreationExpression.ArgumentList.Arguments.ToImmutableArray()
Dim symbolInfo = semanticModel.GetSymbolInfo(objectCreationExpression.Type, cancellationToken) Dim symbolInfo = semanticModel.GetSymbolInfo(objectCreationExpression.Type, cancellationToken)
typeToGenerateIn = TryCast(symbolInfo.GetAnySymbol(), INamedTypeSymbol) typeToGenerateIn = TryCast(symbolInfo.GetAnySymbol(), INamedTypeSymbol)
...@@ -117,8 +118,8 @@ Namespace Microsoft.CodeAnalysis.VisualBasic.GenerateMember.GenerateConstructor ...@@ -117,8 +118,8 @@ Namespace Microsoft.CodeAnalysis.VisualBasic.GenerateMember.GenerateConstructor
node As SyntaxNode, node As SyntaxNode,
cancellationToken As CancellationToken, cancellationToken As CancellationToken,
ByRef token As SyntaxToken, ByRef token As SyntaxToken,
ByRef arguments As IList(Of ArgumentSyntax), ByRef arguments As ImmutableArray(Of ArgumentSyntax),
ByRef attributeArguments As IList(Of AttributeSyntax), ByRef attributeArguments As ImmutableArray(Of AttributeSyntax),
ByRef typeToGenerateIn As INamedTypeSymbol) As Boolean ByRef typeToGenerateIn As INamedTypeSymbol) As Boolean
Dim simpleName = DirectCast(node, SimpleNameSyntax) Dim simpleName = DirectCast(node, SimpleNameSyntax)
...@@ -133,7 +134,7 @@ Namespace Microsoft.CodeAnalysis.VisualBasic.GenerateMember.GenerateConstructor ...@@ -133,7 +134,7 @@ Namespace Microsoft.CodeAnalysis.VisualBasic.GenerateMember.GenerateConstructor
Dim symbolInfo = document.SemanticModel.GetSymbolInfo(attribute, cancellationToken) Dim symbolInfo = document.SemanticModel.GetSymbolInfo(attribute, cancellationToken)
If symbolInfo.CandidateReason = CandidateReason.OverloadResolutionFailure AndAlso Not symbolInfo.CandidateSymbols.IsEmpty Then If symbolInfo.CandidateReason = CandidateReason.OverloadResolutionFailure AndAlso Not symbolInfo.CandidateSymbols.IsEmpty Then
token = simpleName.Identifier token = simpleName.Identifier
arguments = attribute.ArgumentList.Arguments.ToList() arguments = attribute.ArgumentList.Arguments.ToImmutableArray()
attributeArguments = Nothing attributeArguments = Nothing
typeToGenerateIn = TryCast(symbolInfo.CandidateSymbols.FirstOrDefault().ContainingSymbol, INamedTypeSymbol) typeToGenerateIn = TryCast(symbolInfo.CandidateSymbols.FirstOrDefault().ContainingSymbol, INamedTypeSymbol)
......
...@@ -8,7 +8,6 @@ Imports Microsoft.CodeAnalysis.GenerateMember.GenerateParameterizedMember ...@@ -8,7 +8,6 @@ Imports Microsoft.CodeAnalysis.GenerateMember.GenerateParameterizedMember
Imports Microsoft.CodeAnalysis.Host.Mef Imports Microsoft.CodeAnalysis.Host.Mef
Imports Microsoft.CodeAnalysis.VisualBasic.Syntax Imports Microsoft.CodeAnalysis.VisualBasic.Syntax
Namespace Microsoft.CodeAnalysis.VisualBasic.GenerateMember.GenerateMethod Namespace Microsoft.CodeAnalysis.VisualBasic.GenerateMember.GenerateMethod
<ExportLanguageService(GetType(IGenerateConversionService), LanguageNames.VisualBasic), [Shared]> <ExportLanguageService(GetType(IGenerateConversionService), LanguageNames.VisualBasic), [Shared]>
Partial Friend Class VisualBasicGenerateConversionService Partial Friend Class VisualBasicGenerateConversionService
...@@ -138,18 +137,19 @@ Namespace Microsoft.CodeAnalysis.VisualBasic.GenerateMember.GenerateMethod ...@@ -138,18 +137,19 @@ Namespace Microsoft.CodeAnalysis.VisualBasic.GenerateMember.GenerateMethod
typeToGenerateIn = typeToGenerateIn.ConstructUnboundGenericType.ConstructedFrom typeToGenerateIn = typeToGenerateIn.ConstructUnboundGenericType.ConstructedFrom
End If End If
Return CodeGenerationSymbolFactory.CreateMethodSymbol( Return CodeGenerationSymbolFactory.CreateMethodSymbol(
attributes:=SpecializedCollections.EmptyList(Of AttributeData), attributes:=SpecializedCollections.EmptyList(Of AttributeData),
accessibility:=Nothing, accessibility:=Nothing,
modifiers:=Nothing, modifiers:=Nothing,
returnType:=typeToGenerateIn, returnType:=typeToGenerateIn,
explicitInterfaceSymbol:=Nothing, returnsByRef:=False,
name:=Nothing, explicitInterfaceSymbol:=Nothing,
typeParameters:=SpecializedCollections.EmptyList(Of ITypeParameterSymbol), name:=Nothing,
parameters:={CodeGenerationSymbolFactory.CreateParameterSymbol(parameterSymbol, "v")}, typeParameters:=SpecializedCollections.EmptyList(Of ITypeParameterSymbol),
statements:=Nothing, parameters:={CodeGenerationSymbolFactory.CreateParameterSymbol(parameterSymbol, "v")},
handlesExpressions:=Nothing, statements:=Nothing,
returnTypeAttributes:=Nothing, handlesExpressions:=Nothing,
methodKind:=MethodKind.Conversion) returnTypeAttributes:=Nothing,
methodKind:=MethodKind.Conversion)
End Function End Function
Protected Overrides Function GetExplicitConversionDisplayText(state As AbstractGenerateParameterizedMemberService(Of VisualBasicGenerateConversionService, SimpleNameSyntax, ExpressionSyntax, InvocationExpressionSyntax).State) As String 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 ...@@ -160,7 +160,4 @@ Namespace Microsoft.CodeAnalysis.VisualBasic.GenerateMember.GenerateMethod
Return String.Format(VBFeaturesResources.Generate_widening_conversion_in_0, state.TypeToGenerateIn.Name) Return String.Format(VBFeaturesResources.Generate_widening_conversion_in_0, state.TypeToGenerateIn.Name)
End Function End Function
End Class End Class
End Namespace End Namespace
\ No newline at end of file
...@@ -152,7 +152,7 @@ Namespace Microsoft.CodeAnalysis.VisualBasic.GenerateMember.GenerateMethod ...@@ -152,7 +152,7 @@ Namespace Microsoft.CodeAnalysis.VisualBasic.GenerateMember.GenerateMethod
Return New VisualBasicGenerateParameterizedMemberService(Of VisualBasicGenerateMethodService).InvocationExpressionInfo(document, state) Return New VisualBasicGenerateParameterizedMemberService(Of VisualBasicGenerateMethodService).InvocationExpressionInfo(document, state)
End Function 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) Return typeInferenceService.InferType(semanticModel, expression, True, cancellationToken)
End Function End Function
End Class End Class
......
...@@ -8,6 +8,7 @@ Imports Microsoft.CodeAnalysis.VisualBasic.Symbols ...@@ -8,6 +8,7 @@ Imports Microsoft.CodeAnalysis.VisualBasic.Symbols
Imports Microsoft.CodeAnalysis.VisualBasic.Syntax Imports Microsoft.CodeAnalysis.VisualBasic.Syntax
Imports Microsoft.CodeAnalysis.GenerateMember.GenerateParameterizedMember Imports Microsoft.CodeAnalysis.GenerateMember.GenerateParameterizedMember
Imports Microsoft.CodeAnalysis.Utilities Imports Microsoft.CodeAnalysis.Utilities
Imports System.Collections.Immutable
Namespace Microsoft.CodeAnalysis.VisualBasic.GenerateMember.GenerateMethod Namespace Microsoft.CodeAnalysis.VisualBasic.GenerateMember.GenerateMethod
Partial Friend MustInherit Class VisualBasicGenerateParameterizedMemberService(Of TService As AbstractGenerateParameterizedMemberService(Of TService, SimpleNameSyntax, ExpressionSyntax, InvocationExpressionSyntax)) Partial Friend MustInherit Class VisualBasicGenerateParameterizedMemberService(Of TService As AbstractGenerateParameterizedMemberService(Of TService, SimpleNameSyntax, ExpressionSyntax, InvocationExpressionSyntax))
...@@ -24,14 +25,18 @@ Namespace Microsoft.CodeAnalysis.VisualBasic.GenerateMember.GenerateMethod ...@@ -24,14 +25,18 @@ Namespace Microsoft.CodeAnalysis.VisualBasic.GenerateMember.GenerateMethod
Me.InvocationExpression = state.InvocationExpressionOpt Me.InvocationExpression = state.InvocationExpressionOpt
End Sub End Sub
Protected Overrides Function DetermineParameterNames(cancellationToken As CancellationToken) As IList(Of ParameterName) Protected Overrides Function DetermineParameterNames(cancellationToken As CancellationToken) As ImmutableArray(Of ParameterName)
Dim typeParametersNames = Me.DetermineTypeParameters(cancellationToken).Select(Function(t) t.Name).ToList() Dim typeParametersNames = Me.DetermineTypeParameters(cancellationToken).SelectAsArray(Function(t) t.Name)
Return Me.Document.SemanticModel.GenerateParameterNames( Return Me.Document.SemanticModel.GenerateParameterNames(
Me.InvocationExpression.ArgumentList, reservedNames:=typeParametersNames) Me.InvocationExpression.ArgumentList, reservedNames:=typeParametersNames)
End Function End Function
Protected Overrides Function DetermineReturnsByRef(cancellationToken As CancellationToken) As Boolean
Return False
End Function
Protected Overrides Function DetermineReturnTypeWorker(cancellationToken As CancellationToken) As ITypeSymbol 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 Case TypeCharacter.Integer
Return Me.Document.SemanticModel.Compilation.GetSpecialType(SpecialType.System_Int32) Return Me.Document.SemanticModel.Compilation.GetSpecialType(SpecialType.System_Int32)
Case TypeCharacter.Long Case TypeCharacter.Long
...@@ -53,7 +58,7 @@ Namespace Microsoft.CodeAnalysis.VisualBasic.GenerateMember.GenerateMethod ...@@ -53,7 +58,7 @@ Namespace Microsoft.CodeAnalysis.VisualBasic.GenerateMember.GenerateMethod
Return inferredType Return inferredType
End Function End Function
Protected Overrides Function GetCapturedTypeParameters(cancellationToken As CancellationToken) As IList(Of ITypeParameterSymbol) Protected Overrides Function GetCapturedTypeParameters(cancellationToken As CancellationToken) As ImmutableArray(Of ITypeParameterSymbol)
Dim result = New List(Of ITypeParameterSymbol)() Dim result = New List(Of ITypeParameterSymbol)()
If Not Me.InvocationExpression.ArgumentList Is Nothing Then If Not Me.InvocationExpression.ArgumentList Is Nothing Then
For Each argument In Me.InvocationExpression.ArgumentList.Arguments For Each argument In Me.InvocationExpression.ArgumentList.Arguments
...@@ -62,10 +67,10 @@ Namespace Microsoft.CodeAnalysis.VisualBasic.GenerateMember.GenerateMethod ...@@ -62,10 +67,10 @@ Namespace Microsoft.CodeAnalysis.VisualBasic.GenerateMember.GenerateMethod
Next Next
End If End If
Return result Return result.ToImmutableArray()
End Function End Function
Protected Overrides Function GenerateTypeParameters(cancellationToken As CancellationToken) As IList(Of ITypeParameterSymbol) Protected Overrides Function GenerateTypeParameters(cancellationToken As CancellationToken) As ImmutableArray(Of ITypeParameterSymbol)
' Generate dummy type parameter names for a generic method. If the user is inside a ' Generate dummy type parameter names for a generic method. If the user is inside a
' generic method, and calls a generic method with type arguments from the outer ' generic method, and calls a generic method with type arguments from the outer
' method, then use those same names for the generated type parameters. ' method, then use those same names for the generated type parameters.
...@@ -79,12 +84,12 @@ Namespace Microsoft.CodeAnalysis.VisualBasic.GenerateMember.GenerateMethod ...@@ -79,12 +84,12 @@ Namespace Microsoft.CodeAnalysis.VisualBasic.GenerateMember.GenerateMethod
Function(s) Not State.TypeToGenerateIn.GetAllTypeParameters().Any(Function(t) t.Name = s), Function(s) Not State.TypeToGenerateIn.GetAllTypeParameters().Any(Function(t) t.Name = s),
cancellationToken) cancellationToken)
Return New List(Of ITypeParameterSymbol) From {typeParameter} Return ImmutableArray.Create(typeParameter)
End If End If
Dim usedIdentifiers = New HashSet(Of String) From {"T"} Dim usedIdentifiers = New HashSet(Of String) From {"T"}
Dim list = New List(Of ITypeParameterSymbol)() Dim list = ArrayBuilder(Of ITypeParameterSymbol).GetInstance()
For Each typeArgument In genericName.TypeArgumentList.Arguments For Each typeArgument In genericName.TypeArgumentList.Arguments
Dim typeParameter = GetUniqueTypeParameter(typeArgument, Dim typeParameter = GetUniqueTypeParameter(typeArgument,
Function(s) Not usedIdentifiers.Contains(s) AndAlso Not State.TypeToGenerateIn.GetAllTypeParameters().Any(Function(t) t.Name = s), Function(s) Not usedIdentifiers.Contains(s) AndAlso Not State.TypeToGenerateIn.GetAllTypeParameters().Any(Function(t) t.Name = s),
...@@ -95,7 +100,7 @@ Namespace Microsoft.CodeAnalysis.VisualBasic.GenerateMember.GenerateMethod ...@@ -95,7 +100,7 @@ Namespace Microsoft.CodeAnalysis.VisualBasic.GenerateMember.GenerateMethod
list.Add(typeParameter) list.Add(typeParameter)
Next Next
Return list Return list.ToImmutableAndFree()
End Function End Function
Private Function GetUniqueTypeParameter(type As TypeSyntax, Private Function GetUniqueTypeParameter(type As TypeSyntax,
...@@ -120,22 +125,22 @@ Namespace Microsoft.CodeAnalysis.VisualBasic.GenerateMember.GenerateMethod ...@@ -120,22 +125,22 @@ Namespace Microsoft.CodeAnalysis.VisualBasic.GenerateMember.GenerateMethod
Return Nothing Return Nothing
End Function End Function
Protected Overrides Function DetermineParameterModifiers(cancellationToken As CancellationToken) As IList(Of RefKind) Protected Overrides Function DetermineParameterModifiers(cancellationToken As CancellationToken) As ImmutableArray(Of RefKind)
Return If(Me.InvocationExpression.ArgumentList IsNot Nothing AndAlso Me.InvocationExpression.ArgumentList.GetArgumentCount() > 0, Return If(Me.InvocationExpression.ArgumentList IsNot Nothing AndAlso Me.InvocationExpression.ArgumentList.GetArgumentCount() > 0,
Me.InvocationExpression.ArgumentList.Arguments.Select(Function(a) RefKind.None).ToList(), Me.InvocationExpression.ArgumentList.Arguments.Select(Function(a) RefKind.None).ToImmutableArray(),
SpecializedCollections.EmptyList(Of RefKind)) ImmutableArray(Of RefKind).Empty)
End Function End Function
Protected Overrides Function DetermineParameterTypes(cancellationToken As CancellationToken) As IList(Of ITypeSymbol) Protected Overrides Function DetermineParameterTypes(cancellationToken As CancellationToken) As ImmutableArray(Of ITypeSymbol)
Return If(Me.InvocationExpression.ArgumentList IsNot Nothing AndAlso Me.InvocationExpression.ArgumentList.GetArgumentCount() > 0, Return If(Me.InvocationExpression.ArgumentList IsNot Nothing AndAlso Me.InvocationExpression.ArgumentList.GetArgumentCount() > 0,
Me.InvocationExpression.ArgumentList.Arguments.Select(Function(a) DetermineParameterType(a, cancellationToken)).ToList(), Me.InvocationExpression.ArgumentList.Arguments.Select(Function(a) DetermineParameterType(a, cancellationToken)).ToImmutableArray(),
SpecializedCollections.EmptyList(Of ITypeSymbol)) ImmutableArray(Of ITypeSymbol).Empty)
End Function End Function
Protected Overrides Function DetermineParameterOptionality(cancellationToken As CancellationToken) As IList(Of Boolean) Protected Overrides Function DetermineParameterOptionality(cancellationToken As CancellationToken) As ImmutableArray(Of Boolean)
Return If(Me.InvocationExpression.ArgumentList IsNot Nothing AndAlso Me.InvocationExpression.ArgumentList.GetArgumentCount() > 0, Return If(Me.InvocationExpression.ArgumentList IsNot Nothing AndAlso Me.InvocationExpression.ArgumentList.GetArgumentCount() > 0,
Me.InvocationExpression.ArgumentList.Arguments.Select(Function(a) DetermineParameterOptionality(a, cancellationToken)).ToList(), Me.InvocationExpression.ArgumentList.Arguments.Select(Function(a) DetermineParameterOptionality(a, cancellationToken)).ToImmutableArray(),
SpecializedCollections.EmptyList(Of Boolean)) ImmutableArray(Of Boolean).Empty)
End Function End Function
Private Overloads Function DetermineParameterOptionality(argument As ArgumentSyntax, Private Overloads Function DetermineParameterOptionality(argument As ArgumentSyntax,
...@@ -157,8 +162,8 @@ Namespace Microsoft.CodeAnalysis.VisualBasic.GenerateMember.GenerateMethod ...@@ -157,8 +162,8 @@ Namespace Microsoft.CodeAnalysis.VisualBasic.GenerateMember.GenerateMethod
Return conversion.IsWidening AndAlso conversion.IsReference Return conversion.IsWidening AndAlso conversion.IsReference
End Function End Function
Protected Overrides Function DetermineTypeArguments(cancellationToken As CancellationToken) As IList(Of ITypeSymbol) Protected Overrides Function DetermineTypeArguments(cancellationToken As CancellationToken) As ImmutableArray(Of ITypeSymbol)
Dim Result = New List(Of ITypeSymbol)() Dim Result = ArrayBuilder(Of ITypeSymbol).GetInstance()
If TypeOf State.SimpleNameOpt Is GenericNameSyntax Then If TypeOf State.SimpleNameOpt Is GenericNameSyntax Then
For Each typeArgument In DirectCast(State.SimpleNameOpt, GenericNameSyntax).TypeArgumentList.Arguments For Each typeArgument In DirectCast(State.SimpleNameOpt, GenericNameSyntax).TypeArgumentList.Arguments
...@@ -167,7 +172,7 @@ Namespace Microsoft.CodeAnalysis.VisualBasic.GenerateMember.GenerateMethod ...@@ -167,7 +172,7 @@ Namespace Microsoft.CodeAnalysis.VisualBasic.GenerateMember.GenerateMethod
Next Next
End If End If
Return Result Return Result.ToImmutableAndFree()
End Function End Function
End Class End Class
End Class End Class
......
...@@ -697,6 +697,7 @@ Namespace Microsoft.CodeAnalysis.VisualBasic.GenerateType ...@@ -697,6 +697,7 @@ Namespace Microsoft.CodeAnalysis.VisualBasic.GenerateType
explicitInterfaceSymbol:=Nothing, explicitInterfaceSymbol:=Nothing,
name:=propertyName.ToString, name:=propertyName.ToString,
type:=typeSymbol, type:=typeSymbol,
returnsByRef:=False,
parameters:=Nothing, parameters:=Nothing,
getMethod:=Nothing, getMethod:=Nothing,
setMethod:=Nothing, setMethod:=Nothing,
......
...@@ -187,6 +187,7 @@ public static string GetEventHandlerMemberId(Document document, string className ...@@ -187,6 +187,7 @@ public static string GetEventHandlerMemberId(Document document, string className
accessibility: Accessibility.Protected, accessibility: Accessibility.Protected,
modifiers: new DeclarationModifiers(), modifiers: new DeclarationModifiers(),
returnType: targetDocument.Project.GetCompilationAsync(cancellationToken).WaitAndGetResult_Venus(cancellationToken).GetSpecialType(SpecialType.System_Void), returnType: targetDocument.Project.GetCompilationAsync(cancellationToken).WaitAndGetResult_Venus(cancellationToken).GetSpecialType(SpecialType.System_Void),
returnsByRef: false,
explicitInterfaceSymbol: null, explicitInterfaceSymbol: null,
name: eventHandlerName, name: eventHandlerName,
typeParameters: null, typeParameters: null,
......
...@@ -59,6 +59,7 @@ protected SyntaxNode CreateDelegateTypeDeclaration(SyntaxNode containerNode, str ...@@ -59,6 +59,7 @@ protected SyntaxNode CreateDelegateTypeDeclaration(SyntaxNode containerNode, str
accessibility: CodeModelService.GetAccessibility(access, SymbolKind.NamedType, destination), accessibility: CodeModelService.GetAccessibility(access, SymbolKind.NamedType, destination),
modifiers: new DeclarationModifiers(), modifiers: new DeclarationModifiers(),
returnType: returnType, returnType: returnType,
returnsByRef: false,
name: name); name: name);
return CodeGenerationService.CreateNamedTypeDeclaration( return CodeGenerationService.CreateNamedTypeDeclaration(
...@@ -80,6 +81,7 @@ protected SyntaxNode CreateEventDeclaration(SyntaxNode containerNode, string nam ...@@ -80,6 +81,7 @@ protected SyntaxNode CreateEventDeclaration(SyntaxNode containerNode, string nam
accessibility: Accessibility.NotApplicable, accessibility: Accessibility.NotApplicable,
modifiers: new DeclarationModifiers(), modifiers: new DeclarationModifiers(),
returnType: null, returnType: null,
returnsByRef: false,
explicitInterfaceSymbol: null, explicitInterfaceSymbol: null,
name: "add_" + name, name: "add_" + name,
typeParameters: null, typeParameters: null,
...@@ -90,6 +92,7 @@ protected SyntaxNode CreateEventDeclaration(SyntaxNode containerNode, string nam ...@@ -90,6 +92,7 @@ protected SyntaxNode CreateEventDeclaration(SyntaxNode containerNode, string nam
accessibility: Accessibility.NotApplicable, accessibility: Accessibility.NotApplicable,
modifiers: new DeclarationModifiers(), modifiers: new DeclarationModifiers(),
returnType: null, returnType: null,
returnsByRef: false,
explicitInterfaceSymbol: null, explicitInterfaceSymbol: null,
name: "remove_" + name, name: "remove_" + name,
typeParameters: null, typeParameters: null,
...@@ -136,6 +139,7 @@ protected SyntaxNode CreateMethodDeclaration(SyntaxNode containerNode, string na ...@@ -136,6 +139,7 @@ protected SyntaxNode CreateMethodDeclaration(SyntaxNode containerNode, string na
accessibility: CodeModelService.GetAccessibility(access, SymbolKind.Method, destination), accessibility: CodeModelService.GetAccessibility(access, SymbolKind.Method, destination),
modifiers: new DeclarationModifiers(), modifiers: new DeclarationModifiers(),
returnType: returnType, returnType: returnType,
returnsByRef: false,
explicitInterfaceSymbol: null, explicitInterfaceSymbol: null,
name: name, name: name,
typeParameters: null, typeParameters: null,
...@@ -158,6 +162,7 @@ protected SyntaxNode CreatePropertyDeclaration(SyntaxNode containerNode, string ...@@ -158,6 +162,7 @@ protected SyntaxNode CreatePropertyDeclaration(SyntaxNode containerNode, string
accessibility: Accessibility.NotApplicable, accessibility: Accessibility.NotApplicable,
modifiers: new DeclarationModifiers(), modifiers: new DeclarationModifiers(),
returnType: null, returnType: null,
returnsByRef: false,
explicitInterfaceSymbol: null, explicitInterfaceSymbol: null,
name: "get_" + name, name: "get_" + name,
typeParameters: null, typeParameters: null,
...@@ -173,6 +178,7 @@ protected SyntaxNode CreatePropertyDeclaration(SyntaxNode containerNode, string ...@@ -173,6 +178,7 @@ protected SyntaxNode CreatePropertyDeclaration(SyntaxNode containerNode, string
accessibility: Accessibility.NotApplicable, accessibility: Accessibility.NotApplicable,
modifiers: new DeclarationModifiers(), modifiers: new DeclarationModifiers(),
returnType: null, returnType: null,
returnsByRef: false,
explicitInterfaceSymbol: null, explicitInterfaceSymbol: null,
name: "set_" + name, name: "set_" + name,
typeParameters: null, typeParameters: null,
...@@ -184,6 +190,7 @@ protected SyntaxNode CreatePropertyDeclaration(SyntaxNode containerNode, string ...@@ -184,6 +190,7 @@ protected SyntaxNode CreatePropertyDeclaration(SyntaxNode containerNode, string
accessibility: CodeModelService.GetAccessibility(access, SymbolKind.Field, destination), accessibility: CodeModelService.GetAccessibility(access, SymbolKind.Field, destination),
modifiers: new DeclarationModifiers(), modifiers: new DeclarationModifiers(),
type: type, type: type,
returnsByRef: false,
explicitInterfaceSymbol: null, explicitInterfaceSymbol: null,
name: name, name: name,
parameters: null, parameters: null,
......
...@@ -96,7 +96,7 @@ public static bool CanBeGenerated(IPropertySymbol property) ...@@ -96,7 +96,7 @@ public static bool CanBeGenerated(IPropertySymbol property)
var declaration = SyntaxFactory.IndexerDeclaration( var declaration = SyntaxFactory.IndexerDeclaration(
attributeLists: AttributeGenerator.GenerateAttributeLists(property.GetAttributes(), options), attributeLists: AttributeGenerator.GenerateAttributeLists(property.GetAttributes(), options),
modifiers: GenerateModifiers(property, destination, options), modifiers: GenerateModifiers(property, destination, options),
type: property.Type.GenerateTypeSyntax(), type: GeneratePropertyType(property),
explicitInterfaceSpecifier: explicitInterfaceSpecifier, explicitInterfaceSpecifier: explicitInterfaceSpecifier,
parameterList: ParameterGenerator.GenerateBracketedParameterList(property.Parameters, explicitInterfaceSpecifier != null, options), parameterList: ParameterGenerator.GenerateBracketedParameterList(property.Parameters, explicitInterfaceSpecifier != null, options),
accessorList: GenerateAccessorList(property, destination, workspace, options, parseOptions)); accessorList: GenerateAccessorList(property, destination, workspace, options, parseOptions));
...@@ -106,6 +106,13 @@ public static bool CanBeGenerated(IPropertySymbol property) ...@@ -106,6 +106,13 @@ public static bool CanBeGenerated(IPropertySymbol property)
AddAnnotationsTo(property, declaration)); AddAnnotationsTo(property, declaration));
} }
private static TypeSyntax GeneratePropertyType(IPropertySymbol property)
{
return property.ReturnsByRef
? property.Type.GenerateRefTypeSyntax()
: property.Type.GenerateTypeSyntax();
}
private static MemberDeclarationSyntax GeneratePropertyDeclaration( private static MemberDeclarationSyntax GeneratePropertyDeclaration(
IPropertySymbol property, CodeGenerationDestination destination, IPropertySymbol property, CodeGenerationDestination destination,
Workspace workspace, CodeGenerationOptions options, ParseOptions parseOptions) Workspace workspace, CodeGenerationOptions options, ParseOptions parseOptions)
...@@ -123,7 +130,7 @@ public static bool CanBeGenerated(IPropertySymbol property) ...@@ -123,7 +130,7 @@ public static bool CanBeGenerated(IPropertySymbol property)
var propertyDeclaration = SyntaxFactory.PropertyDeclaration( var propertyDeclaration = SyntaxFactory.PropertyDeclaration(
attributeLists: AttributeGenerator.GenerateAttributeLists(property.GetAttributes(), options), attributeLists: AttributeGenerator.GenerateAttributeLists(property.GetAttributes(), options),
modifiers: GenerateModifiers(property, destination, options), modifiers: GenerateModifiers(property, destination, options),
type: property.Type.GenerateTypeSyntax(), type: GeneratePropertyType(property),
explicitInterfaceSpecifier: explicitInterfaceSpecifier, explicitInterfaceSpecifier: explicitInterfaceSpecifier,
identifier: property.Name.ToIdentifierToken(), identifier: property.Name.ToIdentifierToken(),
accessorList: accessorList, accessorList: accessorList,
......
...@@ -254,9 +254,8 @@ private static bool CanBindToken(SyntaxToken token) ...@@ -254,9 +254,8 @@ private static bool CanBindToken(SyntaxToken token)
return type.CreateParameterName(capitalize); return type.CreateParameterName(capitalize);
} }
public static IList<ParameterName> GenerateParameterNames( public static ImmutableArray<ParameterName> GenerateParameterNames(
this SemanticModel semanticModel, this SemanticModel semanticModel, ArgumentListSyntax argumentList)
ArgumentListSyntax argumentList)
{ {
return semanticModel.GenerateParameterNames(argumentList.Arguments); return semanticModel.GenerateParameterNames(argumentList.Arguments);
} }
...@@ -268,7 +267,7 @@ private static bool CanBindToken(SyntaxToken token) ...@@ -268,7 +267,7 @@ private static bool CanBindToken(SyntaxToken token)
return semanticModel.GenerateParameterNames(argumentList.Arguments); return semanticModel.GenerateParameterNames(argumentList.Arguments);
} }
public static IList<ParameterName> GenerateParameterNames( public static ImmutableArray<ParameterName> GenerateParameterNames(
this SemanticModel semanticModel, this SemanticModel semanticModel,
IEnumerable<ArgumentSyntax> arguments, IEnumerable<ArgumentSyntax> arguments,
IList<string> reservedNames = null) IList<string> reservedNames = null)
...@@ -285,11 +284,11 @@ private static bool CanBindToken(SyntaxToken token) ...@@ -285,11 +284,11 @@ private static bool CanBindToken(SyntaxToken token)
return GenerateNames(reservedNames, isFixed, parameterNames); return GenerateNames(reservedNames, isFixed, parameterNames);
} }
private static IList<ParameterName> GenerateNames(IList<string> reservedNames, List<bool> isFixed, List<string> parameterNames) private static ImmutableArray<ParameterName> GenerateNames(IList<string> reservedNames, List<bool> isFixed, List<string> parameterNames)
{ {
return NameGenerator.EnsureUniqueness(parameterNames, isFixed) return NameGenerator.EnsureUniqueness(parameterNames, isFixed)
.Select((name, index) => new ParameterName(name, isFixed[index])) .Select((name, index) => new ParameterName(name, isFixed[index]))
.Skip(reservedNames.Count).ToList(); .Skip(reservedNames.Count).ToImmutableArray();
} }
public static IList<ParameterName> GenerateParameterNames( public static IList<ParameterName> GenerateParameterNames(
......
...@@ -87,7 +87,11 @@ private IEnumerable<TypeInferenceInfo> GetTypesComplex(ExpressionSyntax expressi ...@@ -87,7 +87,11 @@ private IEnumerable<TypeInferenceInfo> GetTypesComplex(ExpressionSyntax expressi
private IEnumerable<TypeInferenceInfo> GetTypesSimple(ExpressionSyntax expression) 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 typeInfo = SemanticModel.GetTypeInfo(expression, CancellationToken);
var symbolInfo = SemanticModel.GetSymbolInfo(expression, CancellationToken); var symbolInfo = SemanticModel.GetSymbolInfo(expression, CancellationToken);
...@@ -154,6 +158,7 @@ private IEnumerable<TypeInferenceInfo> GetTypesSimple(ExpressionSyntax expressio ...@@ -154,6 +158,7 @@ private IEnumerable<TypeInferenceInfo> GetTypesSimple(ExpressionSyntax expressio
case ParenthesizedLambdaExpressionSyntax parenthesizedLambdaExpression: return InferTypeInParenthesizedLambdaExpression(parenthesizedLambdaExpression); case ParenthesizedLambdaExpressionSyntax parenthesizedLambdaExpression: return InferTypeInParenthesizedLambdaExpression(parenthesizedLambdaExpression);
case PostfixUnaryExpressionSyntax postfixUnary: return InferTypeInPostfixUnaryExpression(postfixUnary); case PostfixUnaryExpressionSyntax postfixUnary: return InferTypeInPostfixUnaryExpression(postfixUnary);
case PrefixUnaryExpressionSyntax prefixUnary: return InferTypeInPrefixUnaryExpression(prefixUnary); case PrefixUnaryExpressionSyntax prefixUnary: return InferTypeInPrefixUnaryExpression(prefixUnary);
case RefExpressionSyntax refExpression: return InferTypeInRefExpression(refExpression);
case ReturnStatementSyntax returnStatement: return InferTypeForReturnStatement(returnStatement); case ReturnStatementSyntax returnStatement: return InferTypeForReturnStatement(returnStatement);
case SimpleLambdaExpressionSyntax simpleLambdaExpression: return InferTypeInSimpleLambdaExpression(simpleLambdaExpression); case SimpleLambdaExpressionSyntax simpleLambdaExpression: return InferTypeInSimpleLambdaExpression(simpleLambdaExpression);
case SwitchLabelSyntax switchLabel: return InferTypeInSwitchLabel(switchLabel); case SwitchLabelSyntax switchLabel: return InferTypeInSwitchLabel(switchLabel);
...@@ -1802,6 +1807,9 @@ private static ITypeSymbol GetMemberType(ISymbol memberSymbol) ...@@ -1802,6 +1807,9 @@ private static ITypeSymbol GetMemberType(ISymbol memberSymbol)
return null; return null;
} }
private IEnumerable<TypeInferenceInfo> InferTypeInRefExpression(RefExpressionSyntax refExpression)
=> InferTypes(refExpression);
private IEnumerable<TypeInferenceInfo> InferTypeForReturnStatement(ReturnStatementSyntax returnStatement, SyntaxToken? previousToken = null) private IEnumerable<TypeInferenceInfo> InferTypeForReturnStatement(ReturnStatementSyntax returnStatement, SyntaxToken? previousToken = null)
{ {
InferTypeForReturnStatement(returnStatement, previousToken, InferTypeForReturnStatement(returnStatement, previousToken,
......
...@@ -43,6 +43,7 @@ public static bool IsCodeGenerationSymbol(this ISymbol symbol) ...@@ -43,6 +43,7 @@ public static bool IsCodeGenerationSymbol(this ISymbol symbol)
Accessibility accessibility, Accessibility accessibility,
DeclarationModifiers modifiers, DeclarationModifiers modifiers,
ITypeSymbol type, ITypeSymbol type,
bool returnsByRef,
IPropertySymbol explicitInterfaceSymbol, IPropertySymbol explicitInterfaceSymbol,
string name, string name,
IList<IParameterSymbol> parameters, IList<IParameterSymbol> parameters,
...@@ -57,6 +58,7 @@ public static bool IsCodeGenerationSymbol(this ISymbol symbol) ...@@ -57,6 +58,7 @@ public static bool IsCodeGenerationSymbol(this ISymbol symbol)
accessibility, accessibility,
modifiers, modifiers,
type, type,
returnsByRef,
explicitInterfaceSymbol, explicitInterfaceSymbol,
name, name,
isIndexer, isIndexer,
...@@ -70,7 +72,11 @@ public static bool IsCodeGenerationSymbol(this ISymbol symbol) ...@@ -70,7 +72,11 @@ public static bool IsCodeGenerationSymbol(this ISymbol symbol)
/// <summary> /// <summary>
/// Creates a property symbol that can be used to describe a property declaration. /// Creates a property symbol that can be used to describe a property declaration.
/// </summary> /// </summary>
public static IPropertySymbol CreatePropertySymbol(IList<AttributeData> attributes, Accessibility accessibility, DeclarationModifiers modifiers, ITypeSymbol type, IPropertySymbol explicitInterfaceSymbol, string name, IList<IParameterSymbol> parameters, IMethodSymbol getMethod, IMethodSymbol setMethod, bool isIndexer = false) public static IPropertySymbol CreatePropertySymbol(
IList<AttributeData> attributes, Accessibility accessibility, DeclarationModifiers modifiers,
ITypeSymbol type, bool returnsByRef, IPropertySymbol explicitInterfaceSymbol, string name,
IList<IParameterSymbol> parameters, IMethodSymbol getMethod, IMethodSymbol setMethod,
bool isIndexer = false)
{ {
return CreatePropertySymbol( return CreatePropertySymbol(
containingType: null, containingType: null,
...@@ -78,6 +84,7 @@ public static IPropertySymbol CreatePropertySymbol(IList<AttributeData> attribut ...@@ -78,6 +84,7 @@ public static IPropertySymbol CreatePropertySymbol(IList<AttributeData> attribut
accessibility: accessibility, accessibility: accessibility,
modifiers: modifiers, modifiers: modifiers,
type: type, type: type,
returnsByRef: returnsByRef,
explicitInterfaceSymbol: explicitInterfaceSymbol, explicitInterfaceSymbol: explicitInterfaceSymbol,
name: name, name: name,
parameters: parameters, parameters: parameters,
...@@ -116,7 +123,15 @@ public static IMethodSymbol CreateDestructorSymbol(IList<AttributeData> attribut ...@@ -116,7 +123,15 @@ public static IMethodSymbol CreateDestructorSymbol(IList<AttributeData> attribut
return result; 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); 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); CodeGenerationMethodInfo.Attach(result, modifiers.IsNew, modifiers.IsUnsafe, modifiers.IsPartial, modifiers.IsAsync, statements, handlesExpressions);
...@@ -126,9 +141,14 @@ internal static IMethodSymbol CreateMethodSymbol(INamedTypeSymbol containingType ...@@ -126,9 +141,14 @@ internal static IMethodSymbol CreateMethodSymbol(INamedTypeSymbol containingType
/// <summary> /// <summary>
/// Creates a method symbol that can be used to describe a method declaration. /// Creates a method symbol that can be used to describe a method declaration.
/// </summary> /// </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> /// <summary>
...@@ -223,6 +243,7 @@ public static IArrayTypeSymbol CreateArrayTypeSymbol(ITypeSymbol elementType, in ...@@ -223,6 +243,7 @@ public static IArrayTypeSymbol CreateArrayTypeSymbol(ITypeSymbol elementType, in
accessibility ?? accessor.DeclaredAccessibility, accessibility ?? accessor.DeclaredAccessibility,
accessor.GetSymbolModifiers().WithIsAbstract(statements == null), accessor.GetSymbolModifiers().WithIsAbstract(statements == null),
accessor.ReturnType, accessor.ReturnType,
accessor.ReturnsByRef,
explicitInterfaceSymbol ?? accessor.ExplicitInterfaceImplementations.FirstOrDefault(), explicitInterfaceSymbol ?? accessor.ExplicitInterfaceImplementations.FirstOrDefault(),
accessor.Name, accessor.Name,
accessor.TypeParameters, accessor.TypeParameters,
...@@ -243,9 +264,12 @@ public static IArrayTypeSymbol CreateArrayTypeSymbol(ITypeSymbol elementType, in ...@@ -243,9 +264,12 @@ public static IArrayTypeSymbol CreateArrayTypeSymbol(ITypeSymbol elementType, in
attributes, attributes,
accessibility, accessibility,
new DeclarationModifiers(isAbstract: statements == null), new DeclarationModifiers(isAbstract: statements == null),
null, null, returnType: null,
string.Empty, returnsByRef: false,
null, null, explicitInterfaceSymbol: null,
name: string.Empty,
typeParameters: null,
parameters: null,
statements: statements); statements: statements);
} }
...@@ -283,6 +307,7 @@ public static INamedTypeSymbol CreateNamedTypeSymbol(IList<AttributeData> attrib ...@@ -283,6 +307,7 @@ public static INamedTypeSymbol CreateNamedTypeSymbol(IList<AttributeData> attrib
Accessibility accessibility, Accessibility accessibility,
DeclarationModifiers modifiers, DeclarationModifiers modifiers,
ITypeSymbol returnType, ITypeSymbol returnType,
bool returnsByRef,
string name, string name,
IList<ITypeParameterSymbol> typeParameters = null, IList<ITypeParameterSymbol> typeParameters = null,
IList<IParameterSymbol> parameters = null) IList<IParameterSymbol> parameters = null)
...@@ -292,6 +317,7 @@ public static INamedTypeSymbol CreateNamedTypeSymbol(IList<AttributeData> attrib ...@@ -292,6 +317,7 @@ public static INamedTypeSymbol CreateNamedTypeSymbol(IList<AttributeData> attrib
accessibility: Accessibility.Public, accessibility: Accessibility.Public,
modifiers: new DeclarationModifiers(), modifiers: new DeclarationModifiers(),
returnType: returnType, returnType: returnType,
returnsByRef: returnsByRef,
explicitInterfaceSymbol: null, explicitInterfaceSymbol: null,
name: "Invoke", name: "Invoke",
typeParameters: null, typeParameters: null,
...@@ -337,6 +363,7 @@ public static INamespaceSymbol CreateNamespaceSymbol(string name, IList<ISymbol> ...@@ -337,6 +363,7 @@ public static INamespaceSymbol CreateNamespaceSymbol(string name, IList<ISymbol>
accessibility ?? method.DeclaredAccessibility, accessibility ?? method.DeclaredAccessibility,
modifiers ?? method.GetSymbolModifiers(), modifiers ?? method.GetSymbolModifiers(),
method.ReturnType, method.ReturnType,
method.ReturnsByRef,
explicitInterfaceSymbol, explicitInterfaceSymbol,
name ?? method.Name, name ?? method.Name,
method.TypeParameters, method.TypeParameters,
...@@ -361,6 +388,7 @@ public static INamespaceSymbol CreateNamespaceSymbol(string name, IList<ISymbol> ...@@ -361,6 +388,7 @@ public static INamespaceSymbol CreateNamespaceSymbol(string name, IList<ISymbol>
accessibility ?? property.DeclaredAccessibility, accessibility ?? property.DeclaredAccessibility,
modifiers ?? property.GetSymbolModifiers(), modifiers ?? property.GetSymbolModifiers(),
property.Type, property.Type,
property.ReturnsByRef,
explicitInterfaceSymbol, explicitInterfaceSymbol,
name ?? property.Name, name ?? property.Name,
property.Parameters, property.Parameters,
......
...@@ -10,12 +10,12 @@ namespace Microsoft.CodeAnalysis.CodeGeneration ...@@ -10,12 +10,12 @@ namespace Microsoft.CodeAnalysis.CodeGeneration
{ {
internal partial class CodeGenerationMethodSymbol : CodeGenerationAbstractMethodSymbol internal partial class CodeGenerationMethodSymbol : CodeGenerationAbstractMethodSymbol
{ {
private readonly ITypeSymbol _returnType; public override ITypeSymbol ReturnType { get; }
private readonly bool _returnsByRef; public override ImmutableArray<ITypeParameterSymbol> TypeParameters { get; }
private readonly ImmutableArray<ITypeParameterSymbol> _typeParameters; public override ImmutableArray<IParameterSymbol> Parameters { get; }
private readonly ImmutableArray<IParameterSymbol> _parameters; public override ImmutableArray<IMethodSymbol> ExplicitInterfaceImplementations { get; }
private readonly ImmutableArray<IMethodSymbol> _explicitInterfaceImplementations; public override bool ReturnsByRef { get; }
private readonly MethodKind _methodKind; public override MethodKind MethodKind { get; }
public CodeGenerationMethodSymbol( public CodeGenerationMethodSymbol(
INamedTypeSymbol containingType, INamedTypeSymbol containingType,
...@@ -32,48 +32,17 @@ internal partial class CodeGenerationMethodSymbol : CodeGenerationAbstractMethod ...@@ -32,48 +32,17 @@ internal partial class CodeGenerationMethodSymbol : CodeGenerationAbstractMethod
MethodKind methodKind = MethodKind.Ordinary) MethodKind methodKind = MethodKind.Ordinary)
: base(containingType, attributes, declaredAccessibility, modifiers, name, returnTypeAttributes) : base(containingType, attributes, declaredAccessibility, modifiers, name, returnTypeAttributes)
{ {
_returnType = returnType; this.ReturnType = returnType;
_returnsByRef = returnsByRef; this.ReturnsByRef = returnsByRef;
_typeParameters = typeParameters.AsImmutableOrEmpty(); this.TypeParameters = typeParameters.AsImmutableOrEmpty();
_parameters = parameters.AsImmutableOrEmpty(); this.Parameters = parameters.AsImmutableOrEmpty();
_explicitInterfaceImplementations = explicitInterfaceSymbolOpt == null this.MethodKind = methodKind;
this.ExplicitInterfaceImplementations = explicitInterfaceSymbolOpt == null
? ImmutableArray.Create<IMethodSymbol>() ? ImmutableArray.Create<IMethodSymbol>()
: ImmutableArray.Create(explicitInterfaceSymbolOpt); : ImmutableArray.Create(explicitInterfaceSymbolOpt);
this.OriginalDefinition = this; this.OriginalDefinition = this;
_methodKind = methodKind;
}
public override ITypeSymbol ReturnType
{
get
{
return _returnType;
}
}
public override ImmutableArray<ITypeParameterSymbol> TypeParameters
{
get
{
return _typeParameters;
}
}
public override ImmutableArray<IParameterSymbol> Parameters
{
get
{
return _parameters;
}
}
public override ImmutableArray<IMethodSymbol> ExplicitInterfaceImplementations
{
get
{
return _explicitInterfaceImplementations;
}
} }
protected override CodeGenerationSymbol Clone() protected override CodeGenerationSymbol Clone()
...@@ -94,13 +63,7 @@ protected override CodeGenerationSymbol Clone() ...@@ -94,13 +63,7 @@ protected override CodeGenerationSymbol Clone()
return result; return result;
} }
public override int Arity public override int Arity => this.TypeParameters.Length;
{
get
{
return this.TypeParameters.Length;
}
}
public override bool ReturnsVoid public override bool ReturnsVoid
{ {
...@@ -110,53 +73,14 @@ public override bool ReturnsVoid ...@@ -110,53 +73,14 @@ public override bool ReturnsVoid
} }
} }
public override bool ReturnsByRef
{
get
{
return _returnsByRef;
}
}
public override ImmutableArray<ITypeSymbol> TypeArguments public override ImmutableArray<ITypeSymbol> TypeArguments
{ => this.TypeParameters.As<ITypeSymbol>();
get
{
return this.TypeParameters.As<ITypeSymbol>();
}
}
public override IMethodSymbol ConstructedFrom
{
get
{
return this;
}
}
public override IMethodSymbol OverriddenMethod public override IMethodSymbol ConstructedFrom => this;
{
get
{
return null;
}
}
public override IMethodSymbol ReducedFrom public override IMethodSymbol OverriddenMethod => null;
{
get
{
return null;
}
}
public override MethodKind MethodKind public override IMethodSymbol ReducedFrom => null;
{
get
{
return _methodKind;
}
}
public override ITypeSymbol GetTypeInferredDuringReduction(ITypeParameterSymbol reducedFromTypeParameter) public override ITypeSymbol GetTypeInferredDuringReduction(ITypeParameterSymbol reducedFromTypeParameter)
{ {
...@@ -168,20 +92,8 @@ public override IMethodSymbol ReduceExtensionMethod(ITypeSymbol receiverType) ...@@ -168,20 +92,8 @@ public override IMethodSymbol ReduceExtensionMethod(ITypeSymbol receiverType)
return null; return null;
} }
public override IMethodSymbol PartialImplementationPart public override IMethodSymbol PartialImplementationPart => null;
{
get
{
return null;
}
}
public override IMethodSymbol PartialDefinitionPart public override IMethodSymbol PartialDefinitionPart => null;
{
get
{
return null;
}
}
} }
} }
\ No newline at end of file
...@@ -10,6 +10,7 @@ namespace Microsoft.CodeAnalysis.CodeGeneration ...@@ -10,6 +10,7 @@ namespace Microsoft.CodeAnalysis.CodeGeneration
internal class CodeGenerationPropertySymbol : CodeGenerationSymbol, IPropertySymbol internal class CodeGenerationPropertySymbol : CodeGenerationSymbol, IPropertySymbol
{ {
public ITypeSymbol Type { get; } public ITypeSymbol Type { get; }
public bool ReturnsByRef { get; }
public bool IsIndexer { get; } public bool IsIndexer { get; }
public ImmutableArray<IParameterSymbol> Parameters { get; } public ImmutableArray<IParameterSymbol> Parameters { get; }
...@@ -24,6 +25,7 @@ internal class CodeGenerationPropertySymbol : CodeGenerationSymbol, IPropertySym ...@@ -24,6 +25,7 @@ internal class CodeGenerationPropertySymbol : CodeGenerationSymbol, IPropertySym
Accessibility declaredAccessibility, Accessibility declaredAccessibility,
DeclarationModifiers modifiers, DeclarationModifiers modifiers,
ITypeSymbol type, ITypeSymbol type,
bool returnsByRef,
IPropertySymbol explicitInterfaceSymbolOpt, IPropertySymbol explicitInterfaceSymbolOpt,
string name, string name,
bool isIndexer, bool isIndexer,
...@@ -33,6 +35,7 @@ internal class CodeGenerationPropertySymbol : CodeGenerationSymbol, IPropertySym ...@@ -33,6 +35,7 @@ internal class CodeGenerationPropertySymbol : CodeGenerationSymbol, IPropertySym
: base(containingType, attributes, declaredAccessibility, modifiers, name) : base(containingType, attributes, declaredAccessibility, modifiers, name)
{ {
this.Type = type; this.Type = type;
this.ReturnsByRef = returnsByRef;
this.IsIndexer = isIndexer; this.IsIndexer = isIndexer;
this.Parameters = parametersOpt.AsImmutableOrEmpty(); this.Parameters = parametersOpt.AsImmutableOrEmpty();
this.ExplicitInterfaceImplementations = explicitInterfaceSymbolOpt == null this.ExplicitInterfaceImplementations = explicitInterfaceSymbolOpt == null
...@@ -46,7 +49,7 @@ protected override CodeGenerationSymbol Clone() ...@@ -46,7 +49,7 @@ protected override CodeGenerationSymbol Clone()
{ {
var result = new CodeGenerationPropertySymbol( var result = new CodeGenerationPropertySymbol(
this.ContainingType, this.GetAttributes(), this.DeclaredAccessibility, this.ContainingType, this.GetAttributes(), this.DeclaredAccessibility,
this.Modifiers, this.Type, this.ExplicitInterfaceImplementations.FirstOrDefault(), this.Modifiers, this.Type, this.ReturnsByRef, this.ExplicitInterfaceImplementations.FirstOrDefault(),
this.Name, this.IsIndexer, this.Parameters.IsDefault ? null : (IList<IParameterSymbol>)this.Parameters, this.Name, this.IsIndexer, this.Parameters.IsDefault ? null : (IList<IParameterSymbol>)this.Parameters,
this.GetMethod, this.SetMethod); this.GetMethod, this.SetMethod);
CodeGenerationPropertyInfo.Attach(result, CodeGenerationPropertyInfo.Attach(result,
...@@ -57,23 +60,13 @@ protected override CodeGenerationSymbol Clone() ...@@ -57,23 +60,13 @@ protected override CodeGenerationSymbol Clone()
return result; return result;
} }
public override SymbolKind Kind public override SymbolKind Kind => SymbolKind.Property;
{
get
{
return SymbolKind.Property;
}
}
public override void Accept(SymbolVisitor visitor) public override void Accept(SymbolVisitor visitor)
{ => visitor.VisitProperty(this);
visitor.VisitProperty(this);
}
public override TResult Accept<TResult>(SymbolVisitor<TResult> visitor) public override TResult Accept<TResult>(SymbolVisitor<TResult> visitor)
{ => visitor.VisitProperty(this);
return visitor.VisitProperty(this);
}
public bool IsReadOnly public bool IsReadOnly
{ {
...@@ -91,52 +84,14 @@ public bool IsWriteOnly ...@@ -91,52 +84,14 @@ public bool IsWriteOnly
} }
} }
public bool ReturnsByRef public new IPropertySymbol OriginalDefinition => this;
{
get
{
return this.GetMethod != null && this.GetMethod.ReturnsByRef;
}
}
public new IPropertySymbol OriginalDefinition
{
get
{
return this;
}
}
public IPropertySymbol OverriddenProperty public IPropertySymbol OverriddenProperty => null;
{
get
{
return null;
}
}
public bool IsWithEvents public bool IsWithEvents => false;
{
get
{
return false;
}
}
public ImmutableArray<CustomModifier> RefCustomModifiers public ImmutableArray<CustomModifier> RefCustomModifiers => ImmutableArray<CustomModifier>.Empty;
{
get
{
return ImmutableArray.Create<CustomModifier>();
}
}
public ImmutableArray<CustomModifier> TypeCustomModifiers public ImmutableArray<CustomModifier> TypeCustomModifiers => ImmutableArray<CustomModifier>.Empty;
{
get
{
return ImmutableArray.Create<CustomModifier>();
}
}
} }
} }
\ No newline at end of file
...@@ -31,6 +31,7 @@ internal static partial class ICodeDefinitionFactoryExtensions ...@@ -31,6 +31,7 @@ internal static partial class ICodeDefinitionFactoryExtensions
accessibility: Accessibility.Public, accessibility: Accessibility.Public,
modifiers: new DeclarationModifiers(isOverride: true), modifiers: new DeclarationModifiers(isOverride: true),
returnType: compilation.GetSpecialType(SpecialType.System_Boolean), returnType: compilation.GetSpecialType(SpecialType.System_Boolean),
returnsByRef: false,
explicitInterfaceSymbol: null, explicitInterfaceSymbol: null,
name: EqualsName, name: EqualsName,
typeParameters: null, typeParameters: null,
......
...@@ -25,6 +25,7 @@ internal static partial class ICodeDefinitionFactoryExtensions ...@@ -25,6 +25,7 @@ internal static partial class ICodeDefinitionFactoryExtensions
accessibility: Accessibility.Public, accessibility: Accessibility.Public,
modifiers: new DeclarationModifiers(isOverride: true), modifiers: new DeclarationModifiers(isOverride: true),
returnType: compilation.GetSpecialType(SpecialType.System_Int32), returnType: compilation.GetSpecialType(SpecialType.System_Int32),
returnsByRef: false,
explicitInterfaceSymbol: null, explicitInterfaceSymbol: null,
name: GetHashCodeName, name: GetHashCodeName,
typeParameters: null, typeParameters: null,
......
...@@ -76,6 +76,7 @@ public static IMethodSymbol RenameTypeParameters(this IMethodSymbol method, ILis ...@@ -76,6 +76,7 @@ public static IMethodSymbol RenameTypeParameters(this IMethodSymbol method, ILis
method.DeclaredAccessibility, method.DeclaredAccessibility,
method.GetSymbolModifiers(), method.GetSymbolModifiers(),
method.ReturnType.SubstituteTypes(mapping, typeGenerator), method.ReturnType.SubstituteTypes(mapping, typeGenerator),
method.ReturnsByRef,
method.ExplicitInterfaceImplementations.FirstOrDefault(), method.ExplicitInterfaceImplementations.FirstOrDefault(),
method.Name, method.Name,
updatedTypeParameters, updatedTypeParameters,
...@@ -84,7 +85,8 @@ public static IMethodSymbol RenameTypeParameters(this IMethodSymbol method, ILis ...@@ -84,7 +85,8 @@ public static IMethodSymbol RenameTypeParameters(this IMethodSymbol method, ILis
p.HasExplicitDefaultValue, p.HasExplicitDefaultValue ? p.ExplicitDefaultValue : null)).ToList()); 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; var parameterList = method.Parameters;
if (parameterList.Select(p => p.Name).SequenceEqual(parameterNames)) if (parameterList.Select(p => p.Name).SequenceEqual(parameterNames))
...@@ -100,6 +102,7 @@ public static IMethodSymbol RenameParameters(this IMethodSymbol method, IList<st ...@@ -100,6 +102,7 @@ public static IMethodSymbol RenameParameters(this IMethodSymbol method, IList<st
method.DeclaredAccessibility, method.DeclaredAccessibility,
method.GetSymbolModifiers(), method.GetSymbolModifiers(),
method.ReturnType, method.ReturnType,
method.ReturnsByRef,
method.ExplicitInterfaceImplementations.FirstOrDefault(), method.ExplicitInterfaceImplementations.FirstOrDefault(),
method.Name, method.Name,
method.TypeParameters, method.TypeParameters,
...@@ -199,6 +202,7 @@ public static IMethodSymbol RenameParameters(this IMethodSymbol method, IList<st ...@@ -199,6 +202,7 @@ public static IMethodSymbol RenameParameters(this IMethodSymbol method, IList<st
method.DeclaredAccessibility, method.DeclaredAccessibility,
method.GetSymbolModifiers(), method.GetSymbolModifiers(),
method.ReturnType, method.ReturnType,
method.ReturnsByRef,
method.ExplicitInterfaceImplementations.FirstOrDefault(), method.ExplicitInterfaceImplementations.FirstOrDefault(),
method.Name, method.Name,
method.TypeParameters, method.TypeParameters,
......
...@@ -26,6 +26,7 @@ public static IPropertySymbol RenameParameters(this IPropertySymbol property, IL ...@@ -26,6 +26,7 @@ public static IPropertySymbol RenameParameters(this IPropertySymbol property, IL
property.DeclaredAccessibility, property.DeclaredAccessibility,
property.GetSymbolModifiers(), property.GetSymbolModifiers(),
property.Type, property.Type,
property.ReturnsByRef,
property.ExplicitInterfaceImplementations.FirstOrDefault(), property.ExplicitInterfaceImplementations.FirstOrDefault(),
property.Name, property.Name,
parameters, parameters,
...@@ -58,6 +59,7 @@ public static IPropertySymbol RenameParameters(this IPropertySymbol property, IL ...@@ -58,6 +59,7 @@ public static IPropertySymbol RenameParameters(this IPropertySymbol property, IL
property.DeclaredAccessibility, property.DeclaredAccessibility,
property.GetSymbolModifiers(), property.GetSymbolModifiers(),
property.Type, property.Type,
property.ReturnsByRef,
property.ExplicitInterfaceImplementations.FirstOrDefault(), property.ExplicitInterfaceImplementations.FirstOrDefault(),
property.Name, property.Name,
property.Parameters.Select(p => property.Parameters.Select(p =>
......
...@@ -134,9 +134,9 @@ Namespace Microsoft.CodeAnalysis.VisualBasic.Extensions ...@@ -134,9 +134,9 @@ Namespace Microsoft.CodeAnalysis.VisualBasic.Extensions
<Extension()> <Extension()>
Public Function GenerateParameterNames(semanticModel As SemanticModel, Public Function GenerateParameterNames(semanticModel As SemanticModel,
arguments As ArgumentListSyntax, arguments As ArgumentListSyntax,
Optional reservedNames As IEnumerable(Of String) = Nothing) As IList(Of ParameterName) Optional reservedNames As IEnumerable(Of String) = Nothing) As ImmutableArray(Of ParameterName)
If arguments Is Nothing Then If arguments Is Nothing Then
Return SpecializedCollections.EmptyList(Of ParameterName)() Return ImmutableArray(Of ParameterName).Empty
End If End If
Return GenerateParameterNames(semanticModel, arguments.Arguments.ToList(), reservedNames) Return GenerateParameterNames(semanticModel, arguments.Arguments.ToList(), reservedNames)
...@@ -145,7 +145,7 @@ Namespace Microsoft.CodeAnalysis.VisualBasic.Extensions ...@@ -145,7 +145,7 @@ Namespace Microsoft.CodeAnalysis.VisualBasic.Extensions
<Extension()> <Extension()>
Public Function GenerateParameterNames(semanticModel As SemanticModel, Public Function GenerateParameterNames(semanticModel As SemanticModel,
arguments As IList(Of ArgumentSyntax), arguments As IList(Of ArgumentSyntax),
Optional reservedNames As IEnumerable(Of String) = Nothing) As IList(Of ParameterName) Optional reservedNames As IEnumerable(Of String) = Nothing) As ImmutableArray(Of ParameterName)
reservedNames = If(reservedNames, SpecializedCollections.EmptyEnumerable(Of String)) reservedNames = If(reservedNames, SpecializedCollections.EmptyEnumerable(Of String))
Return semanticModel.GenerateParameterNames( Return semanticModel.GenerateParameterNames(
arguments, arguments,
...@@ -155,9 +155,9 @@ Namespace Microsoft.CodeAnalysis.VisualBasic.Extensions ...@@ -155,9 +155,9 @@ Namespace Microsoft.CodeAnalysis.VisualBasic.Extensions
<Extension()> <Extension()>
Public Function GenerateParameterNames(semanticModel As SemanticModel, Public Function GenerateParameterNames(semanticModel As SemanticModel,
arguments As IList(Of ArgumentSyntax), arguments As IList(Of ArgumentSyntax),
canUse As Func(Of String, Boolean)) As IList(Of ParameterName) canUse As Func(Of String, Boolean)) As ImmutableArray(Of ParameterName)
If arguments.Count = 0 Then If arguments.Count = 0 Then
Return SpecializedCollections.EmptyList(Of ParameterName)() Return ImmutableArray(Of ParameterName).Empty
End If End If
' We can't change the names of named parameters. Any other names we're flexible on. ' We can't change the names of named parameters. Any other names we're flexible on.
...@@ -169,7 +169,7 @@ Namespace Microsoft.CodeAnalysis.VisualBasic.Extensions ...@@ -169,7 +169,7 @@ Namespace Microsoft.CodeAnalysis.VisualBasic.Extensions
Dim parameterNames = arguments.Select(Function(a) semanticModel.GenerateNameForArgument(a)).ToList() Dim parameterNames = arguments.Select(Function(a) semanticModel.GenerateNameForArgument(a)).ToList()
Return NameGenerator.EnsureUniqueness(parameterNames, isFixed, canUse). Return NameGenerator.EnsureUniqueness(parameterNames, isFixed, canUse).
Select(Function(name, index) New ParameterName(name, isFixed(index))). Select(Function(name, index) New ParameterName(name, isFixed(index))).
ToList() ToImmutableArray()
End Function End Function
Private Function SetEquals(array1 As ImmutableArray(Of ISymbol), array2 As ImmutableArray(Of ISymbol)) As Boolean Private Function SetEquals(array1 As ImmutableArray(Of ISymbol), array2 As ImmutableArray(Of ISymbol)) As Boolean
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册