Skip to content

Commit c3c7ce7

Browse files
Run formatter / improve code quality
1 parent 432a8c9 commit c3c7ce7

58 files changed

Lines changed: 304 additions & 441 deletions

File tree

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

Template.GodotUtils/Extensions/RayCastParentTraversal.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
1-
using System;
21
using Godot;
2+
using System;
33

44
namespace GodotUtils;
55

Template.OptionsGen/OptionsGen/Emission/OptionSpecDeduplicator.cs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@ namespace Template.OptionsGen;
77

88
internal sealed class OptionSpecDeduplicator : IOptionSpecDeduplicator
99
{
10-
private static readonly DiagnosticDescriptor ConflictingKeyTypeDescriptor = new(
10+
private static readonly DiagnosticDescriptor _conflictingKeyTypeDescriptor = new(
1111
id: "OG001",
1212
title: "Conflicting option key type",
1313
messageFormat: "Option save key '{0}' is registered with conflicting types '{1}' and '{2}'.",
@@ -31,7 +31,7 @@ public IReadOnlyList<OptionSettingSpec> Deduplicate(
3131
if (existing.ValueKind != raw.ValueKind)
3232
{
3333
context.ReportDiagnostic(Diagnostic.Create(
34-
ConflictingKeyTypeDescriptor,
34+
_conflictingKeyTypeDescriptor,
3535
Location.None,
3636
raw.SaveKey,
3737
OptionValueKindNaming.GetTypeKeyword(existing.ValueKind),

Template.OptionsGen/OptionsGen/Emission/OptionsSettingsSourceEmitter.cs

Lines changed: 10 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -7,29 +7,22 @@
77

88
namespace Template.OptionsGen;
99

10-
internal sealed class OptionsSettingsSourceEmitter : IOptionsSettingsSourceEmitter
10+
internal sealed class OptionsSettingsSourceEmitter(
11+
IOptionSpecDeduplicator specDeduplicator,
12+
IOptionsSettingsTypeLocator typeLocator,
13+
IOptionsSettingsSourceBuilder sourceBuilder) : IOptionsSettingsSourceEmitter
1114
{
12-
private static readonly DiagnosticDescriptor MissingOptionsSettingsDescriptor = new(
15+
private static readonly DiagnosticDescriptor _missingOptionsSettingsDescriptor = new(
1316
id: "OG002",
1417
title: "OptionsSettings not found",
1518
messageFormat: "Could not find an OptionsSettings type. Strongly typed option properties were not generated.",
1619
category: OptionsGenConstants.GeneratorCategory,
1720
DiagnosticSeverity.Info,
1821
isEnabledByDefault: true);
1922

20-
private readonly IOptionSpecDeduplicator _specDeduplicator;
21-
private readonly IOptionsSettingsTypeLocator _typeLocator;
22-
private readonly IOptionsSettingsSourceBuilder _sourceBuilder;
23-
24-
public OptionsSettingsSourceEmitter(
25-
IOptionSpecDeduplicator specDeduplicator,
26-
IOptionsSettingsTypeLocator typeLocator,
27-
IOptionsSettingsSourceBuilder sourceBuilder)
28-
{
29-
_specDeduplicator = specDeduplicator ?? throw new ArgumentNullException(nameof(specDeduplicator));
30-
_typeLocator = typeLocator ?? throw new ArgumentNullException(nameof(typeLocator));
31-
_sourceBuilder = sourceBuilder ?? throw new ArgumentNullException(nameof(sourceBuilder));
32-
}
23+
private readonly IOptionSpecDeduplicator _specDeduplicator = specDeduplicator ?? throw new ArgumentNullException(nameof(specDeduplicator));
24+
private readonly IOptionsSettingsTypeLocator _typeLocator = typeLocator ?? throw new ArgumentNullException(nameof(typeLocator));
25+
private readonly IOptionsSettingsSourceBuilder _sourceBuilder = sourceBuilder ?? throw new ArgumentNullException(nameof(sourceBuilder));
3326

3427
public IOptionSpecDeduplicator SpecDeduplicator => _specDeduplicator;
3528
public IOptionsSettingsTypeLocator TypeLocator => _typeLocator;
@@ -49,15 +42,15 @@ public void Emit(
4942

5043
if (optionsSettings is null)
5144
{
52-
context.ReportDiagnostic(Diagnostic.Create(MissingOptionsSettingsDescriptor, Location.None));
45+
context.ReportDiagnostic(Diagnostic.Create(_missingOptionsSettingsDescriptor, Location.None));
5346
return;
5447
}
5548

5649
IReadOnlyList<OptionSettingSpec> dedupedSpecs = _specDeduplicator.Deduplicate(context, rawSpecs);
5750
if (dedupedSpecs.Count == 0)
5851
return;
5952

60-
List<OptionSettingSpec> orderedSpecs = new(dedupedSpecs);
53+
List<OptionSettingSpec> orderedSpecs = [.. dedupedSpecs];
6154
orderedSpecs.Sort(static (left, right) => string.Compare(left.SaveKey, right.SaveKey, StringComparison.Ordinal));
6255

6356
string generatedSource = _sourceBuilder.BuildSource(optionsSettings, orderedSpecs);

Template.OptionsGen/OptionsGen/OptionSettingSpec.cs

Lines changed: 4 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -8,16 +8,9 @@ internal enum OptionValueKind
88
Bool,
99
}
1010

11-
internal sealed class OptionSettingSpec
11+
internal sealed class OptionSettingSpec(string saveKey, OptionValueKind valueKind, string defaultLiteral)
1212
{
13-
public OptionSettingSpec(string saveKey, OptionValueKind valueKind, string defaultLiteral)
14-
{
15-
SaveKey = saveKey;
16-
ValueKind = valueKind;
17-
DefaultLiteral = defaultLiteral;
18-
}
19-
20-
public string SaveKey { get; }
21-
public OptionValueKind ValueKind { get; }
22-
public string DefaultLiteral { get; }
13+
public string SaveKey { get; } = saveKey;
14+
public OptionValueKind ValueKind { get; } = valueKind;
15+
public string DefaultLiteral { get; } = defaultLiteral;
2316
}

Template.OptionsGen/OptionsGen/OptionValueKindNaming.cs

Lines changed: 21 additions & 36 deletions
Original file line numberDiff line numberDiff line change
@@ -4,52 +4,37 @@ internal static class OptionValueKindNaming
44
{
55
public static string GetTypeKeyword(OptionValueKind kind)
66
{
7-
switch (kind)
7+
return kind switch
88
{
9-
case OptionValueKind.Int:
10-
return "int";
11-
case OptionValueKind.Float:
12-
return "float";
13-
case OptionValueKind.String:
14-
return "string";
15-
case OptionValueKind.Bool:
16-
return "bool";
17-
default:
18-
return "object";
19-
}
9+
OptionValueKind.Int => "int",
10+
OptionValueKind.Float => "float",
11+
OptionValueKind.String => "string",
12+
OptionValueKind.Bool => "bool",
13+
_ => "object",
14+
};
2015
}
2116

2217
public static string GetGetterName(OptionValueKind kind)
2318
{
24-
switch (kind)
19+
return kind switch
2520
{
26-
case OptionValueKind.Int:
27-
return "GetInt";
28-
case OptionValueKind.Float:
29-
return "GetFloat";
30-
case OptionValueKind.String:
31-
return "GetString";
32-
case OptionValueKind.Bool:
33-
return "GetBool";
34-
default:
35-
return "GetString";
36-
}
21+
OptionValueKind.Int => "GetInt",
22+
OptionValueKind.Float => "GetFloat",
23+
OptionValueKind.String => "GetString",
24+
OptionValueKind.Bool => "GetBool",
25+
_ => "GetString",
26+
};
3727
}
3828

3929
public static string GetSetterName(OptionValueKind kind)
4030
{
41-
switch (kind)
31+
return kind switch
4232
{
43-
case OptionValueKind.Int:
44-
return "SetInt";
45-
case OptionValueKind.Float:
46-
return "SetFloat";
47-
case OptionValueKind.String:
48-
return "SetString";
49-
case OptionValueKind.Bool:
50-
return "SetBool";
51-
default:
52-
return "SetString";
53-
}
33+
OptionValueKind.Int => "SetInt",
34+
OptionValueKind.Float => "SetFloat",
35+
OptionValueKind.String => "SetString",
36+
OptionValueKind.Bool => "SetBool",
37+
_ => "SetString",
38+
};
5439
}
5540
}

Template.OptionsGen/OptionsGen/OptionsGen.csproj

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@
1212
<NoWarn>NU5128</NoWarn>
1313

1414
<!-- Package Settings -->
15-
<Version>1.0.5</Version>
15+
<Version>1.0.6</Version>
1616
<PackageId>Template.OptionsGen</PackageId>
1717
<AssemblyName>Template.OptionsGen</AssemblyName>
1818
<Description>Strongly typed options settings source generator for CSharpGodotTools/Template</Description>

Template.OptionsGen/OptionsGen/Parsing/DefaultLiteralResolver.cs

Lines changed: 9 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -6,14 +6,9 @@
66

77
namespace Template.OptionsGen;
88

9-
internal sealed class DefaultLiteralResolver : IDefaultLiteralResolver
9+
internal sealed class DefaultLiteralResolver(IInvocationArgumentResolver argumentResolver) : IDefaultLiteralResolver
1010
{
11-
private readonly IInvocationArgumentResolver _argumentResolver;
12-
13-
public DefaultLiteralResolver(IInvocationArgumentResolver argumentResolver)
14-
{
15-
_argumentResolver = argumentResolver ?? throw new ArgumentNullException(nameof(argumentResolver));
16-
}
11+
private readonly IInvocationArgumentResolver _argumentResolver = argumentResolver ?? throw new ArgumentNullException(nameof(argumentResolver));
1712

1813
public IInvocationArgumentResolver ArgumentResolver => _argumentResolver;
1914

@@ -76,18 +71,13 @@ private static string ConvertDefaultLiteral(object value, OptionValueKind valueK
7671

7772
private static string GetFallbackDefaultLiteral(OptionValueKind valueKind)
7873
{
79-
switch (valueKind)
74+
return valueKind switch
8075
{
81-
case OptionValueKind.Int:
82-
return "0";
83-
case OptionValueKind.Float:
84-
return "0f";
85-
case OptionValueKind.String:
86-
return "string.Empty";
87-
case OptionValueKind.Bool:
88-
return "false";
89-
default:
90-
return "default";
91-
}
76+
OptionValueKind.Int => "0",
77+
OptionValueKind.Float => "0f",
78+
OptionValueKind.String => "string.Empty",
79+
OptionValueKind.Bool => "false",
80+
_ => "default",
81+
};
9282
}
9383
}

Template.OptionsGen/OptionsGen/Parsing/OptionFactoryMetadata.cs

Lines changed: 4 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -1,17 +1,10 @@
11
namespace Template.OptionsGen;
22

3-
internal sealed class OptionFactoryMetadata
3+
internal sealed class OptionFactoryMetadata(OptionValueKind valueKind, int saveKeyIndex, int defaultValueIndex)
44
{
5-
private readonly OptionValueKind _valueKind;
6-
private readonly int _saveKeyIndex;
7-
private readonly int _defaultValueIndex;
8-
9-
public OptionFactoryMetadata(OptionValueKind valueKind, int saveKeyIndex, int defaultValueIndex)
10-
{
11-
_valueKind = valueKind;
12-
_saveKeyIndex = saveKeyIndex;
13-
_defaultValueIndex = defaultValueIndex;
14-
}
5+
private readonly OptionValueKind _valueKind = valueKind;
6+
private readonly int _saveKeyIndex = saveKeyIndex;
7+
private readonly int _defaultValueIndex = defaultValueIndex;
158

169
public OptionValueKind ValueKind => _valueKind;
1710
public int SaveKeyIndex => _saveKeyIndex;

Template.OptionsGen/OptionsGen/Parsing/OptionSpecExtractor.cs

Lines changed: 7 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -5,21 +5,14 @@
55

66
namespace Template.OptionsGen;
77

8-
internal sealed class OptionSpecExtractor : IOptionSpecExtractor
8+
internal sealed class OptionSpecExtractor(
9+
IOptionFactoryMetadataResolver metadataResolver,
10+
IInvocationArgumentResolver argumentResolver,
11+
IDefaultLiteralResolver defaultLiteralResolver) : IOptionSpecExtractor
912
{
10-
private readonly IOptionFactoryMetadataResolver _metadataResolver;
11-
private readonly IInvocationArgumentResolver _argumentResolver;
12-
private readonly IDefaultLiteralResolver _defaultLiteralResolver;
13-
14-
public OptionSpecExtractor(
15-
IOptionFactoryMetadataResolver metadataResolver,
16-
IInvocationArgumentResolver argumentResolver,
17-
IDefaultLiteralResolver defaultLiteralResolver)
18-
{
19-
_metadataResolver = metadataResolver ?? throw new ArgumentNullException(nameof(metadataResolver));
20-
_argumentResolver = argumentResolver ?? throw new ArgumentNullException(nameof(argumentResolver));
21-
_defaultLiteralResolver = defaultLiteralResolver ?? throw new ArgumentNullException(nameof(defaultLiteralResolver));
22-
}
13+
private readonly IOptionFactoryMetadataResolver _metadataResolver = metadataResolver ?? throw new ArgumentNullException(nameof(metadataResolver));
14+
private readonly IInvocationArgumentResolver _argumentResolver = argumentResolver ?? throw new ArgumentNullException(nameof(argumentResolver));
15+
private readonly IDefaultLiteralResolver _defaultLiteralResolver = defaultLiteralResolver ?? throw new ArgumentNullException(nameof(defaultLiteralResolver));
2316

2417
public IOptionFactoryMetadataResolver MetadataResolver => _metadataResolver;
2518
public IInvocationArgumentResolver ArgumentResolver => _argumentResolver;

Template.PacketGen/PacketGen/Generators/Components/PacketFrameworkNamespaceResolver.cs

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -88,14 +88,13 @@ internal sealed class PacketFrameworkNamespaceResolver
8888
if (classDeclaration.SyntaxTree.GetRoot() is not CompilationUnitSyntax compilationUnit)
8989
return null;
9090

91-
List<string> candidateUsings = compilationUnit.Usings
91+
List<string> candidateUsings = [.. compilationUnit.Usings
9292
.Where(usingDirective =>
9393
usingDirective.Alias is null
9494
&& usingDirective.StaticKeyword.RawKind != (int)Microsoft.CodeAnalysis.CSharp.SyntaxKind.StaticKeyword
9595
&& usingDirective.Name is not null)
9696
.Select(usingDirective => usingDirective.Name!.ToString())
97-
.Where(namespaceName => !namespaceName.StartsWith("System"))
98-
.ToList();
97+
.Where(namespaceName => !namespaceName.StartsWith("System"))];
9998

10099
if (candidateUsings.Count == 1)
101100
return candidateUsings[0];

0 commit comments

Comments
 (0)