Skip to content

Commit

Permalink
Use collection expressions
Browse files Browse the repository at this point in the history
  • Loading branch information
CyrusNajmabadi committed Aug 28, 2024
1 parent 8e04e3a commit 3523f48
Show file tree
Hide file tree
Showing 156 changed files with 1,235 additions and 1,255 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -291,9 +291,9 @@ private static SyntaxNode ReplaceWithBlockScopedNamespace(
}

return document.Root.ReplaceSyntax(
new SyntaxNode[] { namespaceDeclaration },
[namespaceDeclaration],
(_, _) => converted.WithAdditionalAnnotations(annotation),
new SyntaxToken[] { tokenAfterNamespace },
[tokenAfterNamespace],
(_, _) => tokenAfterNamespace.WithLeadingTrivia(triviaAfterSplit),
[],
(_, _) => throw ExceptionUtilities.Unreachable());
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -247,7 +247,7 @@ public override void Method1()
inner.Method1();
}
}
""", new string[] { AnalyzersResources.Implement_abstract_class });
""", [AnalyzersResources.Implement_abstract_class]);
}

[Fact, WorkItem("https://github.com/dotnet/roslyn/issues/41420")]
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -44,9 +44,9 @@ void M(string someValue)
var diagnostics = await GetDiagnosticsWorkerAsync(workspace, parameters);

Assert.Equal(
new[] {
[
("IDE0071", DiagnosticSeverity.Info),
},
],
diagnostics.Select(d => (d.Descriptor.Id, d.Severity)));
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -148,7 +148,7 @@ private bool IsFileAndNamespaceMismatch(
var relativeDirectoryPath = PathUtilities.GetRelativePath(
projectDir,
PathUtilities.GetDirectoryName(namespaceDeclaration.SyntaxTree.FilePath)!);
var folders = relativeDirectoryPath.Split(new[] { Path.DirectorySeparatorChar }, StringSplitOptions.RemoveEmptyEntries);
var folders = relativeDirectoryPath.Split([Path.DirectorySeparatorChar], StringSplitOptions.RemoveEmptyEntries);

var expectedNamespace = PathMetadataUtilities.TryBuildNamespaceFromFolders(folders, GetSyntaxFacts(), rootNamespace);

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -94,7 +94,7 @@ protected async Task<Document> AddParamTagAsync(
nodeBeforeNewParamNode ??= summaryNode;

newDocComment = newDocComment.InsertNodesAfter(nodeBeforeNewParamNode!,
new[] { GetNewNode(parameterName, isFirstNodeInComment: false) });
[GetNewNode(parameterName, isFirstNodeInComment: false)]);

continue;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -96,7 +96,7 @@ private SyntaxNode GetRewrittenCollection(
collection,
generator.GenericName(
nameof(Enumerable.Cast),
new[] { iterationVariableType })));
[iterationVariableType])));
}
else
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -101,7 +101,7 @@ private async Task<Document> AddFinalizerCommentAsync(
.First();

finalizer = finalizer.NormalizeWhitespace();
var finalizerLines = finalizer.ToFullString().Split(new[] { '\r', '\n' }, StringSplitOptions.RemoveEmptyEntries);
var finalizerLines = finalizer.ToFullString().Split(['\r', '\n'], StringSplitOptions.RemoveEmptyEntries);

var generator = document.GetRequiredLanguageService<SyntaxGenerator>();
var finalizerComments = this.Service.CreateCommentTrivia(finalizerLines);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -63,7 +63,7 @@ static void M2(int x, int y, int z) { }
await TestChangeSignatureViaCommandAsync(
LanguageNames.CSharp,
markup: markup,
updatedSignature: new[] { 1, 0 },
updatedSignature: [1, 0],
expectedUpdatedInvocationDocumentCode: expectedCode);
}

Expand Down Expand Up @@ -92,7 +92,7 @@ static void M()
await TestChangeSignatureViaCommandAsync(
LanguageNames.CSharp,
markup: markup,
updatedSignature: new[] { 1, 0 },
updatedSignature: [1, 0],
expectedUpdatedInvocationDocumentCode: expectedCode);
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2857,7 +2857,7 @@ interface Bar
}
#endregion TaoRegion",
testHost,
new[] { new CSharpParseOptions(LanguageVersion.CSharp8) },
[new CSharpParseOptions(LanguageVersion.CSharp8)],
Keyword("using"),
Identifier("System"),
Punctuation.Semicolon,
Expand Down Expand Up @@ -5673,9 +5673,9 @@ public async Task TestXmlAttributeNameSpan1()
using var workspace = CreateWorkspace(source, options: null, TestHost.InProcess);
var document = workspace.CurrentSolution.Projects.First().Documents.First();

var classifications = await GetSyntacticClassificationsAsync(document, ImmutableArray.Create(new TextSpan(0, source.Length)));
Assert.Equal(new[]
{
var classifications = await GetSyntacticClassificationsAsync(document, [new TextSpan(0, source.Length)]);
AssertEx.Equal(
[
new ClassifiedSpan(ClassificationTypeNames.XmlDocCommentDelimiter, new TextSpan(0, 3)),
new ClassifiedSpan(ClassificationTypeNames.XmlDocCommentText, new TextSpan(3, 1)),
new ClassifiedSpan(ClassificationTypeNames.XmlDocCommentDelimiter, new TextSpan(4, 1)),
Expand All @@ -5689,7 +5689,7 @@ public async Task TestXmlAttributeNameSpan1()
new ClassifiedSpan(ClassificationTypeNames.XmlDocCommentDelimiter, new TextSpan(24, 2)),
new ClassifiedSpan(ClassificationTypeNames.XmlDocCommentName, new TextSpan(26, 5)),
new ClassifiedSpan(ClassificationTypeNames.XmlDocCommentDelimiter, new TextSpan(31, 1))
}, classifications);
], classifications);
}

[Fact, WorkItem("https://github.com/dotnet/roslyn/issues/48094")]
Expand All @@ -5701,9 +5701,9 @@ public async Task TestXmlAttributeNameSpan2()
using var workspace = CreateWorkspace(source, options: null, TestHost.InProcess);
var document = workspace.CurrentSolution.Projects.First().Documents.First();

var classifications = await GetSyntacticClassificationsAsync(document, ImmutableArray.Create(new TextSpan(0, source.Length)));
Assert.Equal(new[]
{
var classifications = await GetSyntacticClassificationsAsync(document, [new TextSpan(0, source.Length)]);
AssertEx.Equal(
[
new ClassifiedSpan(ClassificationTypeNames.XmlDocCommentDelimiter, new TextSpan(2, 3)),
new ClassifiedSpan(ClassificationTypeNames.XmlDocCommentText, new TextSpan(5, 1)),
new ClassifiedSpan(ClassificationTypeNames.XmlDocCommentDelimiter, new TextSpan(6, 1)),
Expand All @@ -5718,7 +5718,7 @@ public async Task TestXmlAttributeNameSpan2()
new ClassifiedSpan(ClassificationTypeNames.XmlDocCommentDelimiter, new TextSpan(31, 2)),
new ClassifiedSpan(ClassificationTypeNames.XmlDocCommentName, new TextSpan(33, 5)),
new ClassifiedSpan(ClassificationTypeNames.XmlDocCommentDelimiter, new TextSpan(38, 1))
}, classifications);
], classifications);
}

[Theory, WorkItem("https://github.com/dotnet/roslyn/issues/52290")]
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3074,8 +3074,8 @@ void M()

var actualFormatted = actualOrdered.Select(a => new FormattedClassification(allCode.Substring(a.Span.Span.Start, a.Span.Span.Length), a.Tag.ClassificationType.Classification));

AssertEx.Equal(new[]
{
AssertEx.Equal(
[
Keyword("using"),
Namespace("System"),
Operators.Dot,
Expand Down Expand Up @@ -3130,7 +3130,7 @@ void M()
Punctuation.Semicolon,
Punctuation.CloseCurly,
Punctuation.CloseCurly,
}, actualFormatted);
], actualFormatted);
}

[WpfFact]
Expand Down Expand Up @@ -3175,8 +3175,8 @@ void M()

var actualFormatted = actualOrdered.Select(a => new FormattedClassification(allCode.Substring(a.Span.Span.Start, a.Span.Span.Length), a.Tag.ClassificationType.Classification));

AssertEx.Equal(new[]
{
AssertEx.Equal(
[
Keyword("using"),
Namespace("System"),
Operators.Dot,
Expand Down Expand Up @@ -3231,6 +3231,6 @@ void M()
Punctuation.Semicolon,
Punctuation.CloseCurly,
Punctuation.CloseCurly,
}, actualFormatted);
], actualFormatted);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -4824,12 +4824,11 @@ static void Main(string[] args)
";

await TestExactActionSetOfferedAsync(code,
new[]
{
[
string.Format(FeaturesResources.Generate_0_1_in_new_file, "class", "Goo"),
string.Format(FeaturesResources.Generate_nested_0_1, "class", "Goo", "Program"),
FeaturesResources.Generate_new_type
});
]);

await TestInRegularAndScriptAsync(code,
@"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3012,7 +3012,7 @@ public class B
accessibility: Accessibility.Public,
typeKind: TypeKind.Class,
isNewFile: false,
assertTypeKindAbsent: new[] { TypeKindOptions.Enum });
assertTypeKindAbsent: [TypeKindOptions.Enum]);
}

[Fact]
Expand Down Expand Up @@ -3049,7 +3049,7 @@ public class B
accessibility: Accessibility.Public,
typeKind: TypeKind.Class,
isNewFile: false,
assertTypeKindAbsent: new[] { TypeKindOptions.Enum });
assertTypeKindAbsent: [TypeKindOptions.Enum]);
}

[Fact]
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -72,7 +72,7 @@ class Inner { }
var expectedDocumentName = "Class1.cs";

await TestRenameFileToMatchTypeAsync(code, expectedDocumentName,
destinationDocumentContainers: new[] { "A", "B" });
destinationDocumentContainers: ["A", "B"]);
}

[Fact]
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -441,7 +441,7 @@ class C
{
}
""";
using var workspace = EditorTestWorkspace.Create(LanguageNames.CSharp, new CSharpCompilationOptions(OutputKind.ConsoleApplication), new CSharpParseOptions(), new[] { text }, composition: GetComposition());
using var workspace = EditorTestWorkspace.Create(LanguageNames.CSharp, new CSharpCompilationOptions(OutputKind.ConsoleApplication), new CSharpParseOptions(), [text], composition: GetComposition());
var called = false;

var hostDocument = workspace.DocumentWithCursor;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -1170,7 +1170,7 @@ public class MyClass
""";
var items = await GetCompletionItemsAsync(markup, SourceCodeKind.Regular);
Assert.Equal(
new[] { "myClass", "my", "@class", "MyClass", "My", "Class", "GetMyClass", "GetMy", "GetClass" },
["myClass", "my", "@class", "MyClass", "My", "Class", "GetMyClass", "GetMy", "GetClass"],
items.Select(item => item.DisplayText));
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3055,7 +3055,7 @@ static void Main(string[] args)
override $$
}
}";
using var workspace = EditorTestWorkspace.Create(LanguageNames.CSharp, new CSharpCompilationOptions(OutputKind.ConsoleApplication), new CSharpParseOptions(), new[] { text }, composition: GetComposition());
using var workspace = EditorTestWorkspace.Create(LanguageNames.CSharp, new CSharpCompilationOptions(OutputKind.ConsoleApplication), new CSharpParseOptions(), [text], composition: GetComposition());
var provider = new OverrideCompletionProvider();
var testDocument = workspace.Documents.Single();
var document = workspace.CurrentSolution.GetRequiredDocument(testDocument.Id);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,7 @@ private protected override Task VerifyWorkerAsync(
[Fact]
public async Task IsCommitCharacterTest()
{
var commitCharacters = PathUtilities.IsUnixLikePlatform ? new[] { '"', '/' } : new[] { '"', '\\', '/', ',' };
var commitCharacters = PathUtilities.IsUnixLikePlatform ? new[] { '"', '/' } : ['"', '\\', '/', ','];
await VerifyCommitCharactersAsync("#r \"$$", textTypedSoFar: "", validChars: commitCharacters, sourceCodeKind: SourceCodeKind.Script);
}

Expand Down
Loading

0 comments on commit 3523f48

Please sign in to comment.