From f5bdc0b43941c815c298257c8277508a43f186f0 Mon Sep 17 00:00:00 2001 From: Jason Malinowski Date: Thu, 15 Aug 2019 15:53:17 -0700 Subject: [PATCH] Simplify IMethodSymbolExtensions.RemoveAttributesCore We had a helper for 'create an IMethodSymbol with certain changes', but it didn't have quite enough that we could use it in more places. Also inline it into the single caller. --- .../CodeGenerationSymbolFactory.cs | 5 ++-- .../Extensions/IMethodSymbolExtensions.cs | 29 ++++--------------- 2 files changed, 9 insertions(+), 25 deletions(-) diff --git a/src/Workspaces/Core/Portable/CodeGeneration/CodeGenerationSymbolFactory.cs b/src/Workspaces/Core/Portable/CodeGeneration/CodeGenerationSymbolFactory.cs index 4fbda085ce0..04a38f3a145 100644 --- a/src/Workspaces/Core/Portable/CodeGeneration/CodeGenerationSymbolFactory.cs +++ b/src/Workspaces/Core/Portable/CodeGeneration/CodeGenerationSymbolFactory.cs @@ -428,7 +428,8 @@ public static INamespaceSymbol CreateNamespaceSymbol(string name, IList ImmutableArray? parameters = default, ImmutableArray statements = default, INamedTypeSymbol containingType = null, - ITypeSymbol returnType = null) + ITypeSymbol returnType = null, + Optional> returnTypeAttributes = default) { return CreateMethodSymbol( containingType, @@ -442,7 +443,7 @@ public static INamespaceSymbol CreateNamespaceSymbol(string name, IList method.TypeParameters, parameters ?? method.Parameters, statements, - returnTypeAttributes: method.GetReturnTypeAttributes()); + returnTypeAttributes: returnTypeAttributes.HasValue ? returnTypeAttributes.Value : method.GetReturnTypeAttributes()); } internal static IPropertySymbol CreatePropertySymbol( diff --git a/src/Workspaces/Core/Portable/Shared/Extensions/IMethodSymbolExtensions.cs b/src/Workspaces/Core/Portable/Shared/Extensions/IMethodSymbolExtensions.cs index 23ef43ebb67..06715e8c746 100644 --- a/src/Workspaces/Core/Portable/Shared/Extensions/IMethodSymbolExtensions.cs +++ b/src/Workspaces/Core/Portable/Shared/Extensions/IMethodSymbolExtensions.cs @@ -208,16 +208,6 @@ public static IMethodSymbol RenameTypeParameters(this IMethodSymbol method, ILis bool shouldRemoveAttribute(AttributeData a) => removeAttributeTypes.Any(attr => attr != null && attr.Equals(a.AttributeClass)) || !a.AttributeClass.IsAccessibleWithin(accessibleWithin); - return method.RemoveAttributesCore( - shouldRemoveAttribute, - statements: default, - handlesExpressions: default); - } - - private static IMethodSymbol RemoveAttributesCore( - this IMethodSymbol method, Func shouldRemoveAttribute, - ImmutableArray statements, ImmutableArray handlesExpressions) - { var methodHasAttribute = method.GetAttributes().Any(shouldRemoveAttribute); var someParameterHasAttribute = method.Parameters @@ -231,23 +221,16 @@ public static IMethodSymbol RenameTypeParameters(this IMethodSymbol method, ILis } return CodeGenerationSymbolFactory.CreateMethodSymbol( - method.ContainingType, - method.GetAttributes().WhereAsArray(a => !shouldRemoveAttribute(a)), - method.DeclaredAccessibility, - method.GetSymbolModifiers(), - method.ReturnType, - method.RefKind, - method.ExplicitInterfaceImplementations, - method.Name, - method.TypeParameters, - method.Parameters.SelectAsArray(p => + method, + containingType: method.ContainingType, + explicitInterfaceImplementations: method.ExplicitInterfaceImplementations, + attributes: method.GetAttributes().WhereAsArray(a => !shouldRemoveAttribute(a)), + parameters: method.Parameters.SelectAsArray(p => CodeGenerationSymbolFactory.CreateParameterSymbol( p.GetAttributes().WhereAsArray(a => !shouldRemoveAttribute(a)), p.RefKind, p.IsParams, p.Type, p.Name, p.IsOptional, p.HasExplicitDefaultValue, p.HasExplicitDefaultValue ? p.ExplicitDefaultValue : null)), - statements, - handlesExpressions, - method.GetReturnTypeAttributes().WhereAsArray(a => !shouldRemoveAttribute(a))); + returnTypeAttributes: method.GetReturnTypeAttributes().WhereAsArray(a => !shouldRemoveAttribute(a))); } public static bool? IsMoreSpecificThan(this IMethodSymbol method1, IMethodSymbol method2) -- GitLab