Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

use collection syntax in illink #108458

Open
wants to merge 4 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
Loading