From 4db1904dd2e299faa1b9a9b7977d68097fe06c3a Mon Sep 17 00:00:00 2001 From: kasperk81 <83082615+kasperk81@users.noreply.github.com> Date: Tue, 1 Oct 2024 21:33:42 +0000 Subject: [PATCH] use collection syntax in illink --- src/tools/illink/external/Mono.Options/Options.cs | 2 +- .../DynamicallyAccessedMembersCodeFixProvider.cs | 4 ++-- src/tools/illink/src/ILLink.CodeFix/RequiresHelpers.cs | 2 +- .../UnconditionalSuppressMessageCodeFixProvider.cs | 2 +- .../illink/src/ILLink.RoslynAnalyzer/NullableAttributes.cs | 4 ++-- src/tools/illink/src/linker/Linker/AssemblyResolver.cs | 2 +- src/tools/illink/src/tlens/TLens/LensesCollection.cs | 5 +++-- 7 files changed, 11 insertions(+), 10 deletions(-) diff --git a/src/tools/illink/external/Mono.Options/Options.cs b/src/tools/illink/external/Mono.Options/Options.cs index d8b3d78a45509..b89840c83b6c2 100644 --- a/src/tools/illink/external/Mono.Options/Options.cs +++ b/src/tools/illink/external/Mono.Options/Options.cs @@ -440,7 +440,7 @@ protected Option (string prototype, string description, int maxValueCount, bool this.names = (this is OptionSet.Category) // append GetHashCode() so that "duplicate" categories have distinct // names, e.g. adding multiple "" categories should be valid. - ? new[]{prototype + this.GetHashCode ()} + ? [prototype + this.GetHashCode ()] : prototype.Split ('|'); if (this is OptionSet.Category || this is CommandOption) diff --git a/src/tools/illink/src/ILLink.CodeFix/DynamicallyAccessedMembersCodeFixProvider.cs b/src/tools/illink/src/ILLink.CodeFix/DynamicallyAccessedMembersCodeFixProvider.cs index 28d82bafae887..2c4763bd99f03 100644 --- a/src/tools/illink/src/ILLink.CodeFix/DynamicallyAccessedMembersCodeFixProvider.cs +++ b/src/tools/illink/src/ILLink.CodeFix/DynamicallyAccessedMembersCodeFixProvider.cs @@ -132,14 +132,14 @@ private static async Task AddAttributeAsync ( var editor = await DocumentEditor.CreateAsync (document, cancellationToken).ConfigureAwait (false); var generator = editor.Generator; - var attributeArguments = new[] { generator.AttributeArgument (generator.MemberAccessExpression (generator.DottedName ("System.Diagnostics.CodeAnalysis.DynamicallyAccessedMemberTypes"), stringArguments)) }; + SyntaxNode[] attributeArguments = [generator.AttributeArgument (generator.MemberAccessExpression (generator.DottedName ("System.Diagnostics.CodeAnalysis.DynamicallyAccessedMemberTypes"), stringArguments))]; var attribute = generator.Attribute ( generator.TypeExpression (attributeSymbol), attributeArguments) .WithAdditionalAnnotations (Simplifier.Annotation, Simplifier.AddImportsAnnotation); if (addAsReturnAttribute) { // don't use AddReturnAttribute because it's the same as AddAttribute https://github.com/dotnet/roslyn/pull/63084 - editor.ReplaceNode (targetNode, (d, g) => g.AddReturnAttributes (d, new[] { attribute })); + editor.ReplaceNode (targetNode, (d, g) => g.AddReturnAttributes (d, [attribute])); } else if (addGenericParameterAttribute) { // AddReturnAttributes currently doesn't support adding attributes to type arguments https://github.com/dotnet/roslyn/pull/63292 var newNode = (TypeParameterSyntax) targetNode; diff --git a/src/tools/illink/src/ILLink.CodeFix/RequiresHelpers.cs b/src/tools/illink/src/ILLink.CodeFix/RequiresHelpers.cs index b38f11ca4a8e5..b150275e49c4f 100644 --- a/src/tools/illink/src/ILLink.CodeFix/RequiresHelpers.cs +++ b/src/tools/illink/src/ILLink.CodeFix/RequiresHelpers.cs @@ -16,7 +16,7 @@ internal static SyntaxNode[] GetAttributeArgumentsForRequires (ISymbol targetSym if (string.IsNullOrEmpty (symbolDisplayName) || hasPublicAccessibility) return Array.Empty (); - return new[] { syntaxGenerator.AttributeArgument (syntaxGenerator.LiteralExpression ($"Calls {symbolDisplayName}")) }; + return [syntaxGenerator.AttributeArgument (syntaxGenerator.LiteralExpression ($"Calls {symbolDisplayName}"))]; } } } diff --git a/src/tools/illink/src/ILLink.CodeFix/UnconditionalSuppressMessageCodeFixProvider.cs b/src/tools/illink/src/ILLink.CodeFix/UnconditionalSuppressMessageCodeFixProvider.cs index 2fd1b81a604c4..1dc66ae89aad8 100644 --- a/src/tools/illink/src/ILLink.CodeFix/UnconditionalSuppressMessageCodeFixProvider.cs +++ b/src/tools/illink/src/ILLink.CodeFix/UnconditionalSuppressMessageCodeFixProvider.cs @@ -56,7 +56,7 @@ protected override SyntaxNode[] GetAttributeArguments (ISymbol? attributableSymb syntaxGenerator.LiteralExpression ("")); // [UnconditionalSuppressWarning (category, id, Justification = "")] - return new[] { ruleCategory, ruleId, suppressionJustification }; + return [ruleCategory, ruleId, suppressionJustification]; } } } diff --git a/src/tools/illink/src/ILLink.RoslynAnalyzer/NullableAttributes.cs b/src/tools/illink/src/ILLink.RoslynAnalyzer/NullableAttributes.cs index 7cf10912ea38b..c07621e244d50 100644 --- a/src/tools/illink/src/ILLink.RoslynAnalyzer/NullableAttributes.cs +++ b/src/tools/illink/src/ILLink.RoslynAnalyzer/NullableAttributes.cs @@ -96,7 +96,7 @@ internal sealed class MemberNotNullAttribute : Attribute /// /// The field or property member that is promised to be not-null. /// - public MemberNotNullAttribute (string member) => Members = new[] { member }; + public MemberNotNullAttribute (string member) => Members = [member]; /// Initializes the attribute with the list of field and property members. /// @@ -122,7 +122,7 @@ internal sealed class MemberNotNullWhenAttribute : Attribute public MemberNotNullWhenAttribute (bool returnValue, string member) { ReturnValue = returnValue; - Members = new[] { member }; + Members = [member]; } /// Initializes the attribute with the specified return value condition and list of field and property members. diff --git a/src/tools/illink/src/linker/Linker/AssemblyResolver.cs b/src/tools/illink/src/linker/Linker/AssemblyResolver.cs index 98a593aabdb31..964f8c8a4dca6 100644 --- a/src/tools/illink/src/linker/Linker/AssemblyResolver.cs +++ b/src/tools/illink/src/linker/Linker/AssemblyResolver.cs @@ -187,7 +187,7 @@ AssemblyDefinition IAssemblyResolver.Resolve (AssemblyNameReference name, Reader throw new NotSupportedException (); } - static readonly string[] Extensions = new[] { ".dll", ".exe", ".winmd" }; + static readonly string[] Extensions = [".dll", ".exe", ".winmd"]; AssemblyDefinition? SearchDirectory (AssemblyNameReference name) { diff --git a/src/tools/illink/src/tlens/TLens/LensesCollection.cs b/src/tools/illink/src/tlens/TLens/LensesCollection.cs index 94bded7081613..632cc454f82f8 100644 --- a/src/tools/illink/src/tlens/TLens/LensesCollection.cs +++ b/src/tools/illink/src/tlens/TLens/LensesCollection.cs @@ -37,7 +37,8 @@ public Analyzer CreateAnalyzer () // Most used/unused attributes // Constants passed as arguments // - static readonly LensAnalyzerDetails[] all = new[] { + static readonly LensAnalyzerDetails[] all = + [ new LensAnalyzerDetails ("duplicated-code", "Methods which are possible duplicates", typeof (DuplicatedCodeAnalyzer)), new LensAnalyzerDetails ("fields-init", @@ -64,7 +65,7 @@ public Analyzer CreateAnalyzer () "Types with limited number of constructions", typeof (TypeInstatiationAnalyzer)) { DefaultSet = true }, new LensAnalyzerDetails ("unused-param", "Methods with unused parameters", typeof (UnusedParametersAnalyzer)), - }; + ]; public static IEnumerable All => all;