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