Skip to content

Commit

Permalink
use collection syntax in illink (#108458)
Browse files Browse the repository at this point in the history
Co-authored-by: Sven Boemer <[email protected]>
Co-authored-by: Andy Gocke <[email protected]>
  • Loading branch information
3 people authored Feb 3, 2025
1 parent fd9c728 commit 2728f2c
Show file tree
Hide file tree
Showing 7 changed files with 11 additions and 10 deletions.
2 changes: 1 addition & 1 deletion src/tools/illink/external/Mono.Options/Options.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -132,14 +132,14 @@ private static async Task<Document> 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;
Expand Down
2 changes: 1 addition & 1 deletion src/tools/illink/src/ILLink.CodeFix/RequiresHelpers.cs
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ internal static SyntaxNode[] GetAttributeArgumentsForRequires (ISymbol targetSym
if (string.IsNullOrEmpty (symbolDisplayName) || hasPublicAccessibility)
return Array.Empty<SyntaxNode> ();

return new[] { syntaxGenerator.AttributeArgument (syntaxGenerator.LiteralExpression ($"Calls {symbolDisplayName}")) };
return [syntaxGenerator.AttributeArgument (syntaxGenerator.LiteralExpression ($"Calls {symbolDisplayName}"))];
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,7 @@ protected override SyntaxNode[] GetAttributeArguments (ISymbol? attributableSymb
syntaxGenerator.LiteralExpression ("<Pending>"));

// [UnconditionalSuppressWarning (category, id, Justification = "<Pending>")]
return new[] { ruleCategory, ruleId, suppressionJustification };
return [ruleCategory, ruleId, suppressionJustification];
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -96,7 +96,7 @@ internal sealed class MemberNotNullAttribute : Attribute
/// <param name="member">
/// The field or property member that is promised to be not-null.
/// </param>
public MemberNotNullAttribute (string member) => Members = new[] { member };
public MemberNotNullAttribute (string member) => Members = [member];

/// <summary>Initializes the attribute with the list of field and property members.</summary>
/// <param name="members">
Expand All @@ -122,7 +122,7 @@ internal sealed class MemberNotNullWhenAttribute : Attribute
public MemberNotNullWhenAttribute (bool returnValue, string member)
{
ReturnValue = returnValue;
Members = new[] { member };
Members = [member];
}

/// <summary>Initializes the attribute with the specified return value condition and list of field and property members.</summary>
Expand Down
2 changes: 1 addition & 1 deletion src/tools/illink/src/linker/Linker/AssemblyResolver.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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)
{
Expand Down
5 changes: 3 additions & 2 deletions src/tools/illink/src/tlens/TLens/LensesCollection.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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",
Expand All @@ -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<LensAnalyzerDetails> All => all;

Expand Down

0 comments on commit 2728f2c

Please sign in to comment.