Skip to content

Commit 0188a9d

Browse files
Code cleanup
1 parent 5fed627 commit 0188a9d

18 files changed

+136
-200
lines changed

Immutype.Tests/Integration/TestExtensions.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,7 @@ private static CSharpCompilation CreateCompilation() =>
3131
MetadataReference.CreateFromFile(typeof(Uri).Assembly.Location),
3232
MetadataReference.CreateFromFile(typeof(SourceBuilder).Assembly.Location));
3333

34-
public static IReadOnlyList<string> Run(this string setupCode, out string generatedCode, RunOptions? options = default)
34+
public static IReadOnlyList<string> Run(this string setupCode, out string generatedCode, RunOptions? options = null)
3535
{
3636
var curOptions = options ?? new RunOptions();
3737
var parseOptions = CSharpParseOptions.Default.WithLanguageVersion(curOptions.LanguageVersion);

Immutype.UsageScenarios.Tests/ExplicitConstructorChoice.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,7 @@ internal readonly struct Person
2929
public Person(
3030
string name,
3131
int age = 0,
32-
IImmutableList<Person>? friends = default)
32+
IImmutableList<Person>? friends = null)
3333
{
3434
Name = name;
3535
Age = age;

Immutype.UsageScenarios.Tests/GenericTypes.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@ namespace Immutype.UsageScenarios.Tests.GenericTypes
1919
// $header=It is possible to use generic types including any generic constraints.
2020
// {
2121
[Immutype.Target]
22-
internal record Person<TAge>(string Name, TAge Age = default, IEnumerable<Person<TAge>>? Friends = default)
22+
internal record Person<TAge>(string Name, TAge Age = default, IEnumerable<Person<TAge>>? Friends = null)
2323
where TAge : struct;
2424

2525
public class GenericTypes

Immutype.UsageScenarios.Tests/ImmutableCollection.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,7 @@ internal readonly struct Person
2626
public Person(
2727
string name,
2828
int age = 0,
29-
IImmutableList<Person>? friends = default)
29+
IImmutableList<Person>? friends = null)
3030
{
3131
Name = name;
3232
Age = age;

Immutype.UsageScenarios.Tests/NullableCollection.cs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -19,8 +19,8 @@ namespace Immutype.UsageScenarios.Tests.NullableCollection
1919
[Immutype.Target]
2020
internal record Person(
2121
string Name,
22-
int? Age = default,
23-
ICollection<Person>? Friends = default);
22+
int? Age = null,
23+
ICollection<Person>? Friends = null);
2424

2525
public class NullableCollection
2626
{

Immutype.UsageScenarios.Tests/RecordWithConstructor.cs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -21,8 +21,8 @@ internal record Person
2121
{
2222
public Person(
2323
string name,
24-
int? age = default,
25-
ICollection<Person>? friends = default)
24+
int? age = null,
25+
ICollection<Person>? friends = null)
2626
{
2727
Name = name;
2828
Age = age;

Immutype.UsageScenarios.Tests/Set.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@ namespace Immutype.UsageScenarios.Tests.Set
1919
internal record Person(
2020
string Name,
2121
int Age = 0,
22-
ISet<Person>? Friends = default);
22+
ISet<Person>? Friends = null);
2323

2424
public class Set
2525
{

Immutype/Composition.cs

Lines changed: 10 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -7,21 +7,26 @@ namespace Immutype;
77

88
using Core;
99
using Pure.DI;
10+
using static Pure.DI.Lifetime;
11+
using static Pure.DI.Tag;
1012

1113
internal partial class Composition
1214
{
1315
private static void Setup() => DI.Setup()
14-
.Root<(ISourceBuilder SourceBuilder, IComponentsBuilder ComponentsBuilder, ITypeSyntaxFilter SyntaxFilter)>(nameof(Root))
15-
.DefaultLifetime(Lifetime.PerBlock)
16-
.Bind().To((TT[] arr) => ImmutableArray.Create(arr))
16+
.Root<(
17+
ISourceBuilder SourceBuilder,
18+
IComponentsBuilder ComponentsBuilder,
19+
ITypeSyntaxFilter SyntaxFilter)>(nameof(Root))
20+
21+
.DefaultLifetime(PerBlock)
1722
.Bind().To<SourceBuilder>()
1823
.Bind().To<SyntaxNodeFactory>()
1924
.Bind().To<NameService>()
2025
.Bind().To<ExtensionsFactory>()
2126
.Bind().To<MethodsFactory>()
2227
.Bind().To<DataContainerFactory>()
23-
.Bind(Tag.Type).To<MethodWithFactory>()
24-
.Bind(Tag.Type).To<MethodAddRemoveFactory>()
28+
.Bind(Unique).To<MethodWithFactory>()
29+
.Bind(Unique).To<MethodAddRemoveFactory>()
2530
.Bind().To<CommentsGenerator>()
2631
.Bind().To<Information>()
2732
.Bind().To<Comments>()

Immutype/Core/DataContainerFactory.cs

Lines changed: 22 additions & 62 deletions
Original file line numberDiff line numberDiff line change
@@ -6,74 +6,34 @@ internal class DataContainerFactory : IDataContainerFactory
66
{
77
private static readonly Dictionary<string, string> GenericTypeMap = new()
88
{
9-
{
10-
"List", "List"
11-
},
12-
{
13-
"IEnumerable", "List"
14-
},
15-
{
16-
"IReadOnlyCollection", "List"
17-
},
18-
{
19-
"IReadOnlyList", "List"
20-
},
21-
{
22-
"ICollection", "List"
23-
},
24-
{
25-
"IList", "List"
26-
},
27-
{
28-
"HashSet", "HashSet"
29-
},
30-
{
31-
"ISet", "HashSet"
32-
},
33-
{
34-
"Queue", "Queue"
35-
},
36-
{
37-
"Stack", "Stack"
38-
}
9+
{ "List", "List" },
10+
{ "IEnumerable", "List" },
11+
{ "IReadOnlyCollection", "List" },
12+
{ "IReadOnlyList", "List" },
13+
{ "ICollection", "List" },
14+
{ "IList", "List" },
15+
{ "HashSet", "HashSet" },
16+
{ "ISet", "HashSet" },
17+
{ "Queue", "Queue" },
18+
{ "Stack", "Stack" }
3919
};
4020

4121
private static readonly Dictionary<string, string> ReadonlyTypeMap = new()
4222
{
43-
{
44-
"IReadOnlyCollection", "List"
45-
},
46-
{
47-
"IReadOnlyList", "List"
48-
},
49-
{
50-
"IReadOnlySet", "List"
51-
}
23+
{ "IReadOnlyCollection", "List" },
24+
{ "IReadOnlyList", "List" },
25+
{ "IReadOnlySet", "List" }
5226
};
5327

5428
private static readonly Dictionary<string, string> ImmutableTypeMap = new()
5529
{
56-
{
57-
"ImmutableList", "ImmutableList"
58-
},
59-
{
60-
"IImmutableList", "ImmutableList"
61-
},
62-
{
63-
"ImmutableArray", "ImmutableArray"
64-
},
65-
{
66-
"ImmutableQueue", "ImmutableQueue"
67-
},
68-
{
69-
"IImmutableQueue", "ImmutableQueue"
70-
},
71-
{
72-
"ImmutableStack", "ImmutableStack"
73-
},
74-
{
75-
"IImmutableStack", "ImmutableStack"
76-
}
30+
{ "ImmutableList", "ImmutableList" },
31+
{ "IImmutableList", "ImmutableList" },
32+
{ "ImmutableArray", "ImmutableArray" },
33+
{ "ImmutableQueue", "ImmutableQueue" },
34+
{ "IImmutableQueue", "ImmutableQueue" },
35+
{ "ImmutableStack", "ImmutableStack" },
36+
{ "IImmutableStack", "ImmutableStack" }
7737
};
7838

7939
public bool TryCreate(GenericNameSyntax genericNameSyntax, ref ExpressionSyntax? expressionSyntax, ref ParameterSyntax argumentParameter)
@@ -111,7 +71,7 @@ public bool TryCreate(GenericNameSyntax genericNameSyntax, ref ExpressionSyntax?
11171
if (ImmutableTypeMap.TryGetValue(genericNameSyntax.Identifier.Text, out var immutableTypeName))
11272
{
11373
var immutableDataTypeName = SyntaxFactory.IdentifierName(SyntaxFactory.Identifier($"System.Collections.Immutable.{immutableTypeName}"));
114-
if (expressionSyntax != default)
74+
if (expressionSyntax != null)
11575
{
11676
expressionSyntax = SyntaxFactory.InvocationExpression(
11777
SyntaxFactory.MemberAccessExpression(
@@ -142,7 +102,7 @@ private static ExpressionSyntax CreateGenericContainer(ExpressionSyntax? express
142102
.AddTypeArgumentListArguments(elementType);
143103

144104
var result = SyntaxRepo.ObjectCreationExpression(genericDataType);
145-
return expressionSyntax != default
105+
return expressionSyntax != null
146106
? result.AddArgumentListArguments(SyntaxFactory.Argument(expressionSyntax))
147107
: result.AddArgumentListArguments();
148108
}

Immutype/Core/ExtensionsFactory.cs

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -69,11 +69,11 @@ public IEnumerable<Source> Create(GenerationContext<TypeDeclarationSyntax> conte
6969
private static CompilationUnitSyntax CreateRootNode(SyntaxNode targetNode, UsingDirectiveSyntax[] additionalUsings, params MemberDeclarationSyntax[] members)
7070
{
7171
var namespaces = targetNode.Ancestors().OfType<NamespaceType>();
72-
NamespaceType? rootNamespace = default;
72+
NamespaceType? rootNamespace = null;
7373
foreach (var ns in namespaces)
7474
{
7575
var nextNs = ns.WithMembers(new SyntaxList<MemberDeclarationSyntax>([]));
76-
rootNamespace = rootNamespace == default
76+
rootNamespace = rootNamespace == null
7777
? nextNs.AddMembers(members).AddUsings(GetUsings(nextNs.Usings, additionalUsings))
7878
: nextNs.AddMembers(rootNamespace);
7979
}
@@ -82,7 +82,7 @@ private static CompilationUnitSyntax CreateRootNode(SyntaxNode targetNode, Using
8282
var rootCompilationUnit = (baseCompilationUnit ?? SyntaxFactory.CompilationUnit())
8383
.WithMembers(new SyntaxList<MemberDeclarationSyntax>([]));
8484

85-
return rootNamespace != default
85+
return rootNamespace != null
8686
? rootCompilationUnit.AddMembers(rootNamespace)
8787
: rootCompilationUnit.AddUsings(GetUsings(rootCompilationUnit.Usings, additionalUsings)).AddMembers(members);
8888
}
@@ -96,7 +96,7 @@ private static UsingDirectiveSyntax[] GetUsings(IEnumerable<UsingDirectiveSyntax
9696
private static ClassDeclarationSyntax TryAddAttribute(SemanticModel semanticModel, ClassDeclarationSyntax classDeclarationSyntax, string attributeClassName)
9797
{
9898
var excludeFromCodeCoverageType = semanticModel.Compilation.GetTypeByMetadataName(attributeClassName + "Attribute");
99-
if (excludeFromCodeCoverageType != default)
99+
if (excludeFromCodeCoverageType != null)
100100
{
101101
classDeclarationSyntax = classDeclarationSyntax.WithNewLine()
102102
.AddAttributeLists(SyntaxFactory.AttributeList().AddAttributes(SyntaxFactory.Attribute(SyntaxFactory.IdentifierName(attributeClassName))))

0 commit comments

Comments
 (0)