Skip to content

Commit 5772e4b

Browse files
committed
Rename property to improve intent
1 parent 3540fc4 commit 5772e4b

File tree

5 files changed

+23
-23
lines changed

5 files changed

+23
-23
lines changed

src/DynamoDBGenerator.SourceGenerator/Generations/AttributeExpressionValue.cs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -63,7 +63,7 @@ MarshallerOptions options
6363

6464
var yields = (typeIdentifier switch
6565
{
66-
{ IsNullable: true } => $"if ({param} is null)".CreateScope(
66+
{ IsSupposedToBeNull: true } => $"if ({param} is null)".CreateScope(
6767
$"yield return new ({self}.Value, {AttributeValueUtilityFactory.Null});", "yield break;"),
6868
{ TypeSymbol.IsReferenceType: true } => $"if ({param} is null)".CreateScope(
6969
$"throw {ExceptionHelper.NullExceptionMethod}(\"{structName}\");"),
@@ -89,7 +89,7 @@ MarshallerOptions options
8989
}
9090

9191
private static string? HandeNullability(TypeIdentifier typeSymbol) =>
92-
typeSymbol.IsNullable ? $" ?? {AttributeValueUtilityFactory.Null}" : null;
92+
typeSymbol.IsSupposedToBeNull ? $" ?? {AttributeValueUtilityFactory.Null}" : null;
9393

9494
private static IEnumerable<string> YieldSelector(
9595
(bool IsUnknown, DynamoDbDataMember DDB, string AttributeReference, string AttributeInterfaceName) x,

src/DynamoDBGenerator.SourceGenerator/Generations/Marshalling/Marshaller.cs

Lines changed: 12 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -25,22 +25,22 @@ private static CodeFactory CreateDictionaryMethod(TypeIdentifier typeIdentifier,
2525

2626
var marshallerInvocation = InvokeMarshallerMethod(x.DataMember.TypeIdentifier, accessPattern, $"\"{x.DataMember.Name}\"", options);
2727

28-
var assignment = x.DataMember.TypeIdentifier.IsNullable
28+
var assignment = x.DataMember.TypeIdentifier.IsSupposedToBeNull
2929
? $"if ({x.DataMember.NameAsCamelCase} is not null)"
3030
.CreateScope($"{DictionaryReference}[\"{x.AttributeName}\"] = {x.DataMember.NameAsCamelCase};")
3131
.Prepend($"var {x.DataMember.NameAsCamelCase} = {marshallerInvocation};")
3232
: new[] { $"{DictionaryReference}[\"{x.AttributeName}\"] = {marshallerInvocation};" };
3333

3434
return (
3535
dictionaryAssignment: assignment,
36-
capacityTernary: x.DataMember.TypeIdentifier.IsNullable ? x.DataMember.TypeIdentifier.TypeSymbol.NotNullTernaryExpression(in accessPattern, "1", "0") : "1",
36+
capacityTernary: x.DataMember.TypeIdentifier.IsSupposedToBeNull ? x.DataMember.TypeIdentifier.TypeSymbol.NotNullTernaryExpression(in accessPattern, "1", "0") : "1",
3737
x.DataMember
3838
);
3939
})
4040
.ToArray();
4141

4242
var enumerable = Enumerable.Empty<string>();
43-
if (typeIdentifier.IsNullable)
43+
if (typeIdentifier.IsSupposedToBeNull)
4444
enumerable = $"if ({ParamReference} is null)".CreateScope("return null;");
4545
else if (typeIdentifier.TypeSymbol.IsReferenceType)
4646
enumerable = $"if ({ParamReference} is null)".CreateScope($"throw {ExceptionHelper.NullExceptionMethod}({DataMember});");
@@ -51,7 +51,7 @@ private static CodeFactory CreateDictionaryMethod(TypeIdentifier typeIdentifier,
5151
.Append($"return {DictionaryReference};"));
5252

5353
var code =
54-
$"public static Dictionary<string, AttributeValue>{(typeIdentifier.IsNullable ? '?' : null)} {GetSerializationMethodName(typeIdentifier.TypeSymbol)}({typeIdentifier.AnnotatedString} {ParamReference}, {options.FullName} {MarshallerOptions.ParamReference}, string? {DataMember} = null)"
54+
$"public static Dictionary<string, AttributeValue>{(typeIdentifier.IsSupposedToBeNull ? '?' : null)} {GetSerializationMethodName(typeIdentifier.TypeSymbol)}({typeIdentifier.AnnotatedString} {ParamReference}, {options.FullName} {MarshallerOptions.ParamReference}, string? {DataMember} = null)"
5555
.CreateScope(body);
5656

5757
return new CodeFactory(code, properties.Select(y => y.DataMember.TypeIdentifier));
@@ -81,7 +81,7 @@ private static CodeFactory CreateMethod(TypeIdentifier typeIdentifier, Func<ITyp
8181
return typeIdentifier.CanBeNull is false
8282
? signature.CreateScope($"return {conversion};").ToConversion()
8383
: signature.CreateScope($"if ({ParamReference} is null)"
84-
.CreateScope(typeIdentifier.IsNullable
84+
.CreateScope(typeIdentifier.IsSupposedToBeNull
8585
? "return null;"
8686
: $"throw {ExceptionHelper.NullExceptionMethod}({DataMember});"
8787
)
@@ -104,28 +104,28 @@ private static CodeFactory CreateMethod(TypeIdentifier typeIdentifier, Func<ITyp
104104
.CreateScope(
105105
$"if ({ParamReference} is null)"
106106
.CreateScope(singleGeneric.ReturnNullOrThrow(DataMember))
107-
.Append($"return {AttributeValueUtilityFactory.FromArray}({ParamReference}, {MarshallerOptions.ParamReference}, {DataMember}, static (a, o, d) => {InvokeMarshallerMethod(singleGeneric.T, "a", "d", options, "o")}{(singleGeneric.T.IsNullable ? $" ?? {AttributeValueUtilityFactory.Null}" : null)});")
107+
.Append($"return {AttributeValueUtilityFactory.FromArray}({ParamReference}, {MarshallerOptions.ParamReference}, {DataMember}, static (a, o, d) => {InvokeMarshallerMethod(singleGeneric.T, "a", "d", options, "o")}{(singleGeneric.T.IsSupposedToBeNull ? $" ?? {AttributeValueUtilityFactory.Null}" : null)});")
108108
).ToConversion(singleGeneric.T),
109109
SingleGeneric.SupportedType.List => signature
110110
.CreateScope(
111111
$"if ({ParamReference} is null)"
112112
.CreateScope(singleGeneric.ReturnNullOrThrow(DataMember))
113-
.Append($"return {AttributeValueUtilityFactory.FromList}({ParamReference}, {MarshallerOptions.ParamReference}, {DataMember}, static (a, o, d) => {InvokeMarshallerMethod(singleGeneric.T, "a", "d", options, "o")}{(singleGeneric.T.IsNullable ? $" ?? {AttributeValueUtilityFactory.Null}" : null)});")
113+
.Append($"return {AttributeValueUtilityFactory.FromList}({ParamReference}, {MarshallerOptions.ParamReference}, {DataMember}, static (a, o, d) => {InvokeMarshallerMethod(singleGeneric.T, "a", "d", options, "o")}{(singleGeneric.T.IsSupposedToBeNull ? $" ?? {AttributeValueUtilityFactory.Null}" : null)});")
114114
).ToConversion(singleGeneric.T),
115115
SingleGeneric.SupportedType.IReadOnlyCollection
116116
or SingleGeneric.SupportedType.IEnumerable
117117
or SingleGeneric.SupportedType.ICollection => signature
118118
.CreateScope(
119119
$"if ({ParamReference} is null)"
120120
.CreateScope(singleGeneric.ReturnNullOrThrow(DataMember))
121-
.Append($"return {AttributeValueUtilityFactory.FromEnumerable}({ParamReference}, {MarshallerOptions.ParamReference}, {DataMember}, static (a, o, d) => {InvokeMarshallerMethod(singleGeneric.T, "a", "d", options, "o")}{(singleGeneric.T.IsNullable ? $" ?? {AttributeValueUtilityFactory.Null}" : null)});")
121+
.Append($"return {AttributeValueUtilityFactory.FromEnumerable}({ParamReference}, {MarshallerOptions.ParamReference}, {DataMember}, static (a, o, d) => {InvokeMarshallerMethod(singleGeneric.T, "a", "d", options, "o")}{(singleGeneric.T.IsSupposedToBeNull ? $" ?? {AttributeValueUtilityFactory.Null}" : null)});")
122122
).ToConversion(singleGeneric.T),
123123
SingleGeneric.SupportedType.Set when singleGeneric.T.TypeSymbol.SpecialType is SpecialType.System_String
124124
=> signature
125125
.CreateScope(
126126
$"if ({ParamReference} is null)"
127127
.CreateScope(singleGeneric.ReturnNullOrThrow(DataMember))
128-
.Append($"return new {Constants.AWSSDK_DynamoDBv2.AttributeValue} {{ SS = new List<{(singleGeneric.T.IsNullable ? "string?" : "string")}>({(singleGeneric.T.IsNullable ? ParamReference : $"{ParamReference}.Select((y,i) => y ?? throw {ExceptionHelper.NullExceptionMethod}($\"{{{DataMember}}}[UNKNOWN]\"))")})}};")
128+
.Append($"return new {Constants.AWSSDK_DynamoDBv2.AttributeValue} {{ SS = new List<{(singleGeneric.T.IsSupposedToBeNull ? "string?" : "string")}>({(singleGeneric.T.IsSupposedToBeNull ? ParamReference : $"{ParamReference}.Select((y,i) => y ?? throw {ExceptionHelper.NullExceptionMethod}($\"{{{DataMember}}}[UNKNOWN]\"))")})}};")
129129
)
130130
.ToConversion(singleGeneric.T),
131131
SingleGeneric.SupportedType.Set when singleGeneric.T.IsNumeric
@@ -147,14 +147,14 @@ SingleGeneric.SupportedType.Set when singleGeneric.T.IsNumeric
147147
.CreateScope(
148148
$"if ({ParamReference} is null)"
149149
.CreateScope(keyValueGeneric.ReturnNullOrThrow(DataMember))
150-
.Append($"return {AttributeValueUtilityFactory.FromDictionary}({ParamReference}, {MarshallerOptions.ParamReference}, {DataMember}, static (a, o, d) => {InvokeMarshallerMethod(keyValueGeneric.TValue, "a", "d", options, "o")}{(keyValueGeneric.TValue.IsNullable ? $" ?? {AttributeValueUtilityFactory.Null}" : null)});")
150+
.Append($"return {AttributeValueUtilityFactory.FromDictionary}({ParamReference}, {MarshallerOptions.ParamReference}, {DataMember}, static (a, o, d) => {InvokeMarshallerMethod(keyValueGeneric.TValue, "a", "d", options, "o")}{(keyValueGeneric.TValue.IsSupposedToBeNull ? $" ?? {AttributeValueUtilityFactory.Null}" : null)});")
151151
)
152152
.ToConversion(keyValueGeneric.TValue),
153153
KeyValueGeneric.SupportedType.LookUp => signature
154154
.CreateScope(
155155
$"if ({ParamReference} is null)"
156156
.CreateScope(keyValueGeneric.ReturnNullOrThrow(DataMember))
157-
.Append($"return {AttributeValueUtilityFactory.FromLookup}({ParamReference}, {MarshallerOptions.ParamReference}, {DataMember}, static (a, o, d) => {InvokeMarshallerMethod(keyValueGeneric.TValue, "a", "d", options, "o")}{(keyValueGeneric.TValue.IsNullable ? $" ?? {AttributeValueUtilityFactory.Null}" : null)});")
157+
.Append($"return {AttributeValueUtilityFactory.FromLookup}({ParamReference}, {MarshallerOptions.ParamReference}, {DataMember}, static (a, o, d) => {InvokeMarshallerMethod(keyValueGeneric.TValue, "a", "d", options, "o")}{(keyValueGeneric.TValue.IsSupposedToBeNull ? $" ?? {AttributeValueUtilityFactory.Null}" : null)});")
158158
)
159159
.ToConversion(keyValueGeneric.TValue),
160160
_ => throw UncoveredConversionException(keyValueGeneric, nameof(CreateMethod))
@@ -168,7 +168,7 @@ SingleGeneric.SupportedType.Set when singleGeneric.T.IsNumeric
168168
private static string CreateSignature(TypeIdentifier typeIdentifier, MarshallerOptions options)
169169
{
170170
var typeSymbol = typeIdentifier.TypeSymbol;
171-
return typeIdentifier.IsNullable
171+
return typeIdentifier.IsSupposedToBeNull
172172
? $"public static {Constants.AWSSDK_DynamoDBv2.AttributeValue}? {GetSerializationMethodName(typeSymbol)}({typeIdentifier.AnnotatedString} {ParamReference}, {options.FullName} {MarshallerOptions.ParamReference}, string? {DataMember} = null)"
173173
: $"public static {Constants.AWSSDK_DynamoDBv2.AttributeValue} {GetSerializationMethodName(typeSymbol)}({typeIdentifier.AnnotatedString} {ParamReference}, {options.FullName} {MarshallerOptions.ParamReference}, string? {DataMember} = null)";
174174
}

src/DynamoDBGenerator.SourceGenerator/Generations/UnMarshaller.cs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -55,7 +55,7 @@ private static CodeFactory CreateCode(TypeIdentifier typeIdentifier, Func<ITypeS
5555

5656
var blockBody =
5757
$"if ({Dict} is null)"
58-
.CreateScope(typeIdentifier.IsNullable ? "return null;" : $"throw {ExceptionHelper.NullExceptionMethod}({DataMember});").Concat(
58+
.CreateScope(typeIdentifier.IsSupposedToBeNull ? "return null;" : $"throw {ExceptionHelper.NullExceptionMethod}({DataMember});").Concat(
5959
Assignments(typeIdentifier, assignments)
6060
.AllAndLast(x => ObjectAssignmentBlock(x.useParentheses, x.assignments, false), x => ObjectAssignmentBlock(x.useParentheses, x.assignments, true))
6161
.SelectMany(x => x)
@@ -75,7 +75,7 @@ private static CodeFactory CreateMethod(TypeIdentifier typeIdentifier, Func<ITyp
7575
if (options.TryReadConversion(typeIdentifier, Value) is {} conversion)
7676
{
7777
var signature = CreateSignature(typeIdentifier, options);
78-
return typeIdentifier.CanBeNull || typeIdentifier.IsNullable is false
78+
return typeIdentifier.CanBeNull || typeIdentifier.IsSupposedToBeNull is false
7979
? signature
8080
.CreateScope(
8181
$"if ({Value} is null)"
@@ -130,7 +130,7 @@ private static CodeFactory CreateMethod(TypeIdentifier typeIdentifier, Func<ITyp
130130
.CreateScope(
131131
$"if ({Value} is null || {Value}.SS is null)"
132132
.CreateScope(singleGeneric.ReturnNullOrThrow(DataMember))
133-
.Append($"return new {(singleGeneric.TypeSymbol.TypeKind is TypeKind.Interface ? $"HashSet<{(singleGeneric.T.IsNullable ? "string?" : "string")}>" : null)}({(singleGeneric.T.IsNullable ? $"{Value}.SS" : $"{Value}.SS.Select((y,i) => y ?? throw {ExceptionHelper.NullExceptionMethod}($\"{{{DataMember}}}[UNKNOWN]\")")}));")
133+
.Append($"return new {(singleGeneric.TypeSymbol.TypeKind is TypeKind.Interface ? $"HashSet<{(singleGeneric.T.IsSupposedToBeNull ? "string?" : "string")}>" : null)}({(singleGeneric.T.IsSupposedToBeNull ? $"{Value}.SS" : $"{Value}.SS.Select((y,i) => y ?? throw {ExceptionHelper.NullExceptionMethod}($\"{{{DataMember}}}[UNKNOWN]\")")}));")
134134
)
135135
.ToConversion(),
136136
SingleGeneric.SupportedType.Set when singleGeneric.T.IsNumeric => signature

src/DynamoDBGenerator.SourceGenerator/Types/TypeIdentifier.cs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@ public abstract record TypeIdentifier
1717

1818
protected TypeIdentifier(ITypeSymbol typeSymbol)
1919
{
20-
IsNullable = typeSymbol switch
20+
IsSupposedToBeNull = typeSymbol switch
2121
{
2222
{ IsReferenceType: true, NullableAnnotation: NullableAnnotation.None or NullableAnnotation.Annotated } => true,
2323
{ IsReferenceType: true, NullableAnnotation: NullableAnnotation.NotAnnotated } => false,
@@ -42,7 +42,7 @@ protected TypeIdentifier(ITypeSymbol typeSymbol)
4242
/// <summary>
4343
/// Represents whether the type is intended to be nullable
4444
/// </summary>
45-
public bool IsNullable { get; }
45+
public bool IsSupposedToBeNull { get; }
4646
public bool IsNumeric { get; }
4747
public string AnnotatedString { get; }
4848
public string UnannotatedString { get; }
@@ -134,7 +134,7 @@ or SpecialType.System_Double
134134

135135
public string ReturnNullOrThrow(string dataMember)
136136
{
137-
return IsNullable
137+
return IsSupposedToBeNull
138138
? "return null;"
139139
: $"throw {Constants.DynamoDBGenerator.ExceptionHelper.NullExceptionMethod}({dataMember});";
140140
}

tests/DynamoDBGenerator.SourceGenerator.Tests/DynamoDBDocumentTests/Deserialize/CustomObjects/ChildClassTests.cs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -57,7 +57,7 @@ public void Deserialize_ChildClass_NotIncluded()
5757
[Fact]
5858
public void Deserialize_ChildClassField_NotIncluded()
5959
{
60-
var result = ParentClassMarshaller.Unmarshall(new Dictionary<string, AttributeValue>
60+
var attributeValues = new Dictionary<string, AttributeValue>
6161
{
6262
{ nameof(ParentClass.Id), new AttributeValue { S = "I am the root" } },
6363
{
@@ -66,8 +66,8 @@ public void Deserialize_ChildClassField_NotIncluded()
6666
M = new Dictionary<string, AttributeValue>()
6767
}
6868
}
69-
});
70-
69+
};
70+
ParentClass result = ParentClassMarshaller.Unmarshall(attributeValues);
7171
result.Id.Should().Be("I am the root");
7272
result.CustomClass.Should().NotBeNull();
7373
result.CustomClass!.PropertyId.Should().BeNull();

0 commit comments

Comments
 (0)