Skip to content

Commit 77faffb

Browse files
committed
Use collection expressions
1 parent a507859 commit 77faffb

File tree

12 files changed

+30
-29
lines changed

12 files changed

+30
-29
lines changed

src/Abc.Zebus.MessageDsl.Generator.Tests/MessageDslGeneratorTests.cs

Lines changed: 6 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,11 @@
1-
using System.Collections.Immutable;
1+
using System.Linq;
2+
using System.Threading;
23
using Microsoft.CodeAnalysis;
34
using Microsoft.CodeAnalysis.CSharp;
45
using Microsoft.CodeAnalysis.Diagnostics;
56
using Microsoft.CodeAnalysis.Text;
67
using Moq;
78
using NUnit.Framework;
8-
using System.Linq;
9-
using System.Threading;
109

1110
namespace Abc.Zebus.MessageDsl.Generator.Tests;
1211

@@ -22,7 +21,7 @@ public void Should_generate_message_class_for_simple_dsl_file()
2221

2322
// Act
2423
var runResults = CSharpGeneratorDriver.Create(new MessageDslGenerator())
25-
.AddAdditionalTexts(ImmutableArray.Create(additionalTextMock.Object))
24+
.AddAdditionalTexts([additionalTextMock.Object])
2625
.WithUpdatedAnalyzerConfigOptions(optionsProviderMock.Object)
2726
.RunGenerators(CSharpCompilation.Create("Tests"))
2827
.GetRunResult();
@@ -46,7 +45,7 @@ public void Should_generate_message_class_for_multiple_additional_files_with_con
4645

4746
// Act
4847
var runResults = CSharpGeneratorDriver.Create(new MessageDslGenerator())
49-
.AddAdditionalTexts(ImmutableArray.Create(additionalTextMock1.Object, additionalTextMock2.Object))
48+
.AddAdditionalTexts([additionalTextMock1.Object, additionalTextMock2.Object])
5049
.WithUpdatedAnalyzerConfigOptions(CombineOptionProviderMocks(optionsProviderMock1.Object, optionsProviderMock2.Object).Object)
5150
.RunGenerators(CSharpCompilation.Create("Tests"))
5251
.GetRunResult();
@@ -67,7 +66,7 @@ public void Should_not_generate_message_class_for_non_message_additional_files()
6766

6867
// Act
6968
var runResults = CSharpGeneratorDriver.Create(new MessageDslGenerator())
70-
.AddAdditionalTexts(ImmutableArray.Create(additionalTextMock.Object))
69+
.AddAdditionalTexts([additionalTextMock.Object])
7170
.WithUpdatedAnalyzerConfigOptions(optionsProviderMock.Object)
7271
.RunGenerators(CSharpCompilation.Create("Tests"))
7372
.GetRunResult();
@@ -84,7 +83,7 @@ public void Should_generate_message_class_if_ZebusMessageDslNamespace_option_is_
8483

8584
// Act
8685
var runResults = CSharpGeneratorDriver.Create(new MessageDslGenerator())
87-
.AddAdditionalTexts(ImmutableArray.Create(additionalTextMock.Object))
86+
.AddAdditionalTexts([additionalTextMock.Object])
8887
.RunGenerators(CSharpCompilation.Create("Tests"))
8988
.GetRunResult();
9089

src/Abc.Zebus.MessageDsl.Generator/Generator/MessageDslGenerator.cs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,12 @@
1+
#nullable enable
2+
13
using System;
24
using System.Collections.Generic;
35
using System.Text.RegularExpressions;
46
using System.Threading;
57
using Abc.Zebus.MessageDsl.Ast;
68
using Microsoft.CodeAnalysis;
79

8-
#nullable enable
9-
1010
namespace Abc.Zebus.MessageDsl.Generator;
1111

1212
[Generator]
@@ -83,7 +83,7 @@ private record SourceGenerationInput(
8383

8484
private class SourceGenerationResult(SourceGenerationInput input)
8585
{
86-
private readonly List<Diagnostic> _diagnostics = new();
86+
private readonly List<Diagnostic> _diagnostics = [];
8787

8888
public AdditionalText InputFile { get; } = input.InputFile;
8989
public IReadOnlyList<Diagnostic> Diagnostics => _diagnostics;

src/Abc.Zebus.MessageDsl.Tests/MessageDsl/ParsedContractsTests.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -770,7 +770,7 @@ public void should_parse_nested_classes()
770770
var contracts = ParseValid("Foo.Bar.Baz();");
771771
var message = contracts.Messages.ExpectedSingle();
772772
message.Name.ShouldEqual("Baz");
773-
message.ContainingClasses.ShouldEqual(new TypeName[] { "Foo", "Bar" });
773+
message.ContainingClasses.ShouldEqual(["Foo", "Bar"]);
774774
}
775775

776776
[Test]

src/Abc.Zebus.MessageDsl.sln

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@ Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "Build", "Build", "{A0123301
1212
Directory.Build.props = Directory.Build.props
1313
Directory.Build.targets = Directory.Build.targets
1414
..\.github\workflows\build.yml = ..\.github\workflows\build.yml
15+
..\.editorconfig = ..\.editorconfig
1516
EndProjectSection
1617
EndProject
1718
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "Abc.Zebus.MessageDsl.Build", "Abc.Zebus.MessageDsl.Build\Abc.Zebus.MessageDsl.Build.csproj", "{D7C3B2A7-F5EA-4BD1-95FF-0736EF745160}"

src/Abc.Zebus.MessageDsl/Ast/AttributeSet.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@ public class AttributeSet : AstNode, IList<AttributeDefinition>
1515
public IEnumerable<AttributeDefinition> GetAttributes(TypeName attributeType)
1616
{
1717
if (Attributes.Count == 0)
18-
return Enumerable.Empty<AttributeDefinition>();
18+
return [];
1919

2020
attributeType = AttributeDefinition.NormalizeAttributeTypeName(attributeType);
2121
return Attributes.Where(attr => Equals(attr.TypeName, attributeType));

src/Abc.Zebus.MessageDsl/Ast/EnumDefinition.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@ public class EnumDefinition : AstNode, IMemberNode
1212
public string Name { get; set; } = string.Empty;
1313
public TypeName UnderlyingType { get; set; } = "int";
1414
public AccessModifier AccessModifier { get; set; }
15-
public AttributeSet Attributes { get; } = new();
15+
public AttributeSet Attributes { get; } = [];
1616
public IList<EnumMemberDefinition> Members { get; } = new List<EnumMemberDefinition>();
1717

1818
internal bool UseInferredValues { get; set; }

src/Abc.Zebus.MessageDsl/Ast/EnumMemberDefinition.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ public class EnumMemberDefinition : AstNode, INamedNode
44
{
55
public string Name { get; set; } = string.Empty;
66
public string? Value { get; set; }
7-
public AttributeSet Attributes { get; } = new();
7+
public AttributeSet Attributes { get; } = [];
88

99
internal string? InferredValueAsString { get; set; }
1010
internal object? InferredValueAsNumber { get; set; }

src/Abc.Zebus.MessageDsl/Ast/MessageDefinition.cs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@ public class MessageDefinition : AstNode, IClassNode
1616

1717
public IList<ParameterDefinition> Parameters { get; } = new List<ParameterDefinition>();
1818
public IList<TypeName> BaseTypes { get; } = new List<TypeName>();
19-
public AttributeSet Attributes { get; } = new();
19+
public AttributeSet Attributes { get; } = [];
2020

2121
public MemberOptions Options
2222
{
@@ -48,7 +48,7 @@ public MessageType Type
4848
}
4949
}
5050

51-
internal List<ReservationRange> ReservedRanges { get; } = new();
51+
internal List<ReservationRange> ReservedRanges { get; } = [];
5252

5353
public override string ToString()
5454
=> Name;

src/Abc.Zebus.MessageDsl/Ast/ParameterDefinition.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ public class ParameterDefinition : AstNode, INamedNode
88
public bool IsMarkedOptional { get; set; }
99
public string? DefaultValue { get; set; }
1010
public bool IsWritableProperty { get; set; }
11-
public AttributeSet Attributes { get; private set; } = new();
11+
public AttributeSet Attributes { get; private set; } = [];
1212

1313
internal bool IsDiscarded { get; set; }
1414

src/Abc.Zebus.MessageDsl/Ast/TypeName.cs

Lines changed: 8 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -36,13 +36,13 @@ public sealed class TypeName : IEquatable<TypeName>
3636

3737
private static readonly Dictionary<string, string> _clrTypeToAlias;
3838

39-
private static readonly HashSet<string> _knownBclTypes = new()
40-
{
39+
private static readonly HashSet<string> _knownBclTypes =
40+
[
4141
"TimeSpan",
4242
"DateTime",
4343
"Guid",
4444
"Decimal"
45-
};
45+
];
4646

4747
private static readonly Dictionary<string, string> _protoTypeNameMap = new()
4848
{
@@ -56,16 +56,15 @@ public sealed class TypeName : IEquatable<TypeName>
5656
{ "String", "string" },
5757
};
5858

59-
private static readonly HashSet<string> _packableProtoBufTypes = new()
60-
{
59+
private static readonly HashSet<string> _packableProtoBufTypes = [
6160
"double", "float", "int32", "int64", "uint32", "uint64", "sint32", "sint64", "fixed32", "fixed64", "sfixed32", "sfixed64", "bool"
62-
};
61+
];
6362

64-
private static readonly HashSet<string> _knownValueTypes = new()
65-
{
63+
private static readonly HashSet<string> _knownValueTypes =
64+
[
6665
"bool", "byte", "sbyte", "char", "decimal", "double", "float", "int", "uint", "long", "ulong", "short", "ushort",
6766
"TimeSpan", "DateTime", "Guid"
68-
};
67+
];
6968

7069
private static readonly HashSet<string> _csharpNonTypeKeywords = CSharpSyntax.EnumerateCSharpKeywords().Except(_aliasTypeMap.Keys).ToHashSet();
7170

0 commit comments

Comments
 (0)