Skip to content

Commit 45d6fc9

Browse files
committed
Use full path
1 parent c3ce6c6 commit 45d6fc9

File tree

6 files changed

+30
-35
lines changed

6 files changed

+30
-35
lines changed

src/DynamoDBGenerator.SourceGenerator/Generations/AttributeExpressionValue.cs

+1-1
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,7 @@ MarshallerOptions options
2727
: $"{x.DDB.DataMember.NameAsPrivateField} = new ({ValueProvider});")
2828
.Append($"{self} = new({ValueProvider});")
2929
.Append($"{MarshallerOptions.FieldReference} = {MarshallerOptions.ParamReference};");
30-
foreach (var fieldAssignment in $"public {structName}(Func<string> {ValueProvider}, {MarshallerOptions.Name} options)".CreateScope(constructorFieldAssignments))
30+
foreach (var fieldAssignment in $"public {structName}(Func<string> {ValueProvider}, {options.FullName} options)".CreateScope(constructorFieldAssignments))
3131
yield return fieldAssignment;
3232

3333
yield return MarshallerOptions.FieldDeclaration;

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

+1-1
Original file line numberDiff line numberDiff line change
@@ -152,7 +152,7 @@ private static CodeFactory StaticAttributeValueDictionaryKeys(ITypeSymbol typeSy
152152
Func<ITypeSymbol, DynamoDbDataMember[]> fn, MarshallerOptions options)
153153
{
154154
var code =
155-
$"public static Dictionary<string, AttributeValue> {MethodName(typeSymbol)}({MarshallerOptions.Name} {MarshallerOptions.ParamReference}, object? {PkReference}, object? {RkReference}, bool {EnforcePkReference}, bool {EnforceRkReference}, string? index = null)"
155+
$"public static Dictionary<string, AttributeValue> {MethodName(typeSymbol)}({options.FullName} {MarshallerOptions.ParamReference}, object? {PkReference}, object? {RkReference}, bool {EnforcePkReference}, bool {EnforceRkReference}, string? index = null)"
156156
.CreateScope(MethodBody(typeSymbol, fn, options));
157157

158158
return new CodeFactory(code);

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

+10-10
Original file line numberDiff line numberDiff line change
@@ -51,7 +51,7 @@ private static CodeFactory CreateDictionaryMethod(ITypeSymbol typeSymbol, Func<I
5151
.Append($"return {DictionaryReference};"));
5252

5353
var code =
54-
$"public static Dictionary<string, AttributeValue>{(isNullable ? '?' : null)} {GetSerializationMethodName(typeSymbol)}({typeSymbol.Representation().annotated} {ParamReference}, {MarshallerOptions.Name} {MarshallerOptions.ParamReference}, string? {DataMember} = null)"
54+
$"public static Dictionary<string, AttributeValue>{(isNullable ? '?' : null)} {GetSerializationMethodName(typeSymbol)}({typeSymbol.Representation().annotated} {ParamReference}, {options.FullName} {MarshallerOptions.ParamReference}, string? {DataMember} = null)"
5555
.CreateScope(body);
5656

5757
return new CodeFactory(code, properties.Select(y => y.Type));
@@ -81,19 +81,19 @@ private static CodeFactory CreateMethod(ITypeSymbol type, Func<ITypeSymbol, Dyna
8181
{
8282
{ IsValueType: true } => type switch
8383
{
84-
{ OriginalDefinition.SpecialType: SpecialType.System_Nullable_T } => CreateSignature(type)
84+
{ OriginalDefinition.SpecialType: SpecialType.System_Nullable_T } => CreateSignature(type, options)
8585
.CreateScope($"return {ParamReference} is not null ? {conversion} : null;")
8686
.ToConversion(),
87-
_ => CreateSignature(type)
87+
_ => CreateSignature(type, options)
8888
.CreateScope($"return {conversion};")
8989
.ToConversion()
9090
},
9191
{ IsReferenceType: true } => type switch
9292
{
93-
{ NullableAnnotation: NullableAnnotation.None or NullableAnnotation.Annotated } => CreateSignature(type)
93+
{ NullableAnnotation: NullableAnnotation.None or NullableAnnotation.Annotated } => CreateSignature(type, options)
9494
.CreateScope($"return {ParamReference} is not null ? {conversion} : null;")
9595
.ToConversion(),
96-
_ => CreateSignature(type)
96+
_ => CreateSignature(type, options)
9797
.CreateScope($"return {ParamReference} is not null ? {conversion} : throw {ExceptionHelper.NullExceptionMethod}({DataMember});")
9898
.ToConversion()
9999
},
@@ -103,7 +103,7 @@ private static CodeFactory CreateMethod(ITypeSymbol type, Func<ITypeSymbol, Dyna
103103

104104
return type.TypeIdentifier() switch
105105
{
106-
SingleGeneric singleGeneric when CreateSignature(singleGeneric.TypeSymbol) is var signature => singleGeneric.Type switch
106+
SingleGeneric singleGeneric when CreateSignature(singleGeneric.TypeSymbol, options) is var signature => singleGeneric.Type switch
107107
{
108108
SingleGeneric.SupportedType.Nullable => signature
109109
.CreateScope($"return {ParamReference} is not null ? {InvokeMarshallerMethod(singleGeneric.T, $"{ParamReference}.Value", DataMember, options)} : null;")
@@ -133,7 +133,7 @@ SingleGeneric.SupportedType.Set when singleGeneric.T.IsNumeric()
133133
},
134134
KeyValueGeneric {TKey.SpecialType: not SpecialType.System_String} keyValueGeneric => throw new ArgumentException("Only strings are supported for for TKey",
135135
UncoveredConversionException(keyValueGeneric, nameof(CreateMethod))),
136-
KeyValueGeneric keyValueGeneric when CreateSignature(keyValueGeneric.TypeSymbol) is var signature => keyValueGeneric.Type switch
136+
KeyValueGeneric keyValueGeneric when CreateSignature(keyValueGeneric.TypeSymbol, options) is var signature => keyValueGeneric.Type switch
137137
{
138138
KeyValueGeneric.SupportedType.Dictionary => signature
139139
.CreateScope($"return {ParamReference} is not null ? {AttributeValueUtilityFactory.FromDictionary}({ParamReference}, {MarshallerOptions.ParamReference}, {DataMember}, static (a, o, d) => {InvokeMarshallerMethod(keyValueGeneric.TValue, "a", "d", options, "o")}{(keyValueGeneric.TValue.IsNullable() ? $" ?? {AttributeValueUtilityFactory.Null}" : null)}) : {Else(keyValueGeneric)};")
@@ -149,11 +149,11 @@ SingleGeneric.SupportedType.Set when singleGeneric.T.IsNumeric()
149149
};
150150

151151
}
152-
private static string CreateSignature(ITypeSymbol typeSymbol)
152+
private static string CreateSignature(ITypeSymbol typeSymbol, MarshallerOptions options)
153153
{
154154
return typeSymbol.IsNullable()
155-
? $"public static AttributeValue? {GetSerializationMethodName(typeSymbol)}({typeSymbol.Representation().annotated} {ParamReference}, {MarshallerOptions.Name} {MarshallerOptions.ParamReference}, string? {DataMember} = null)"
156-
: $"public static AttributeValue {GetSerializationMethodName(typeSymbol)}({typeSymbol.Representation().annotated} {ParamReference}, {MarshallerOptions.Name} {MarshallerOptions.ParamReference}, string? {DataMember} = null)";
155+
? $"public static AttributeValue? {GetSerializationMethodName(typeSymbol)}({typeSymbol.Representation().annotated} {ParamReference}, {options.FullName} {MarshallerOptions.ParamReference}, string? {DataMember} = null)"
156+
: $"public static AttributeValue {GetSerializationMethodName(typeSymbol)}({typeSymbol.Representation().annotated} {ParamReference}, {options.FullName} {MarshallerOptions.ParamReference}, string? {DataMember} = null)";
157157
}
158158

159159
private static string Else(TypeIdentifier typeIdentifier)

src/DynamoDBGenerator.SourceGenerator/Generations/UnMarshaller.cs

+9-11
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,3 @@
1-
using System.Collections;
2-
using System.Collections.Immutable;
31
using DynamoDBGenerator.SourceGenerator.Extensions;
42
using DynamoDBGenerator.SourceGenerator.Types;
53
using Microsoft.CodeAnalysis;
@@ -13,7 +11,7 @@ public static class UnMarshaller
1311
private const string DataMember = "dataMember";
1412
private const string Dict = "dict";
1513
private static readonly Func<ITypeSymbol, string> GetDeserializationMethodName = TypeExtensions.SuffixedTypeSymbolNameFactory("_U", SymbolEqualityComparer.IncludeNullability);
16-
private const string UnMarshallerClass = $"_{Constants.DynamoDBGenerator.Marshaller.UnmarshalMethodName}_";
14+
private const string UnMarshallerClass = $"_{Marshaller.UnmarshalMethodName}_";
1715
private const string Value = "attributeValue";
1816
private static IEnumerable<(bool useParentheses, IEnumerable<string> assignments)> Assignments(ITypeSymbol type, (DynamoDbDataMember DDB, string MethodCall, string Name)[] assignments)
1917
{
@@ -66,7 +64,7 @@ private static CodeFactory CreateCode(ITypeSymbol type, Func<ITypeSymbol, Dynamo
6664
.Prepend(type.IsTupleType ? "return" : $"return new {typeName.annotated.TrimEnd('?')}")
6765
);
6866

69-
var method = $"public static {typeName.annotated} {GetDeserializationMethodName(type)}(Dictionary<string, AttributeValue>? {Dict}, {MarshallerOptions.Name} {MarshallerOptions.ParamReference}, string? {DataMember} = null)".CreateScope(blockBody);
67+
var method = $"public static {typeName.annotated} {GetDeserializationMethodName(type)}(Dictionary<string, AttributeValue>? {Dict}, {options.FullName} {MarshallerOptions.ParamReference}, string? {DataMember} = null)".CreateScope(blockBody);
7068

7169
return new CodeFactory(method, assignments.Select(x => x.DDB.DataMember.Type));
7270

@@ -78,18 +76,18 @@ private static CodeFactory CreateMethod(ITypeSymbol type, Func<ITypeSymbol, Dyna
7876
if (options.TryReadConversion(type, Value) is {} conversion)
7977
{
8078
if (type.IsNullable())
81-
return CreateSignature(type)
79+
return CreateSignature(type, options)
8280
.CreateScope($"return {Value} is not null ? ({conversion}) : null;")
8381
.ToConversion();
8482

85-
return CreateSignature(type)
83+
return CreateSignature(type, options)
8684
.CreateScope($"return {Value} is not null && ({conversion}) is {{ }} x ? x : throw {ExceptionHelper.NullExceptionMethod}({DataMember});")
8785
.ToConversion();
8886
}
8987

9088
return type.TypeIdentifier() switch
9189
{
92-
SingleGeneric singleGeneric when CreateSignature(singleGeneric.TypeSymbol) is var signature => singleGeneric.Type switch
90+
SingleGeneric singleGeneric when CreateSignature(singleGeneric.TypeSymbol, options) is var signature => singleGeneric.Type switch
9391
{
9492
SingleGeneric.SupportedType.Nullable => signature
9593
.CreateScope($"return {Value} is not null and {{ NULL: false }} ? {InvokeUnmarshallMethod(singleGeneric.T, Value, DataMember, options)} : null;")
@@ -116,7 +114,7 @@ SingleGeneric.SupportedType.Set when singleGeneric.T.IsNumeric() => signature
116114
},
117115
KeyValueGeneric {TKey.SpecialType: not SpecialType.System_String} keyValueGeneric => throw new ArgumentException("Only strings are supported for for TKey",
118116
UncoveredConversionException(keyValueGeneric, nameof(CreateMethod))),
119-
KeyValueGeneric keyValueGeneric when CreateSignature(keyValueGeneric.TypeSymbol) is var signature => keyValueGeneric.Type switch
117+
KeyValueGeneric keyValueGeneric when CreateSignature(keyValueGeneric.TypeSymbol, options) is var signature => keyValueGeneric.Type switch
120118
{
121119
KeyValueGeneric.SupportedType.Dictionary => signature
122120
.CreateScope($"return {Value} is {{ M: {{ }} x }} ? {AttributeValueUtilityFactory.ToDictionary}(x, {MarshallerOptions.ParamReference}, {DataMember}, static (a, o, d) => {InvokeUnmarshallMethod(keyValueGeneric.TValue, "a", "d", options, "o")}) : {Else(keyValueGeneric.TypeSymbol)};")
@@ -133,9 +131,9 @@ SingleGeneric.SupportedType.Set when singleGeneric.T.IsNumeric() => signature
133131

134132
}
135133

136-
private static string CreateSignature(ITypeSymbol typeSymbol)
134+
private static string CreateSignature(ITypeSymbol typeSymbol, MarshallerOptions options)
137135
{
138-
return $"public static {typeSymbol.Representation().annotated} {GetDeserializationMethodName(typeSymbol)}(AttributeValue? {Value}, {MarshallerOptions.Name} {MarshallerOptions.ParamReference}, string? {DataMember} = null)";
136+
return $"public static {typeSymbol.Representation().annotated} {GetDeserializationMethodName(typeSymbol)}(AttributeValue? {Value}, {options.FullName} {MarshallerOptions.ParamReference}, string? {DataMember} = null)";
139137
}
140138
private static IEnumerable<string> CreateTypeContents(IEnumerable<DynamoDBMarshallerArguments> arguments,
141139
Func<ITypeSymbol, DynamoDbDataMember[]> getDynamoDbProperties, MarshallerOptions options)
@@ -196,7 +194,7 @@ private static IEnumerable<string> ObjectAssignmentBlock(bool useParentheses, IE
196194

197195
internal static IEnumerable<string> RootSignature(ITypeSymbol typeSymbol, string rootTypeName)
198196
{
199-
return $"public {rootTypeName} {Constants.DynamoDBGenerator.Marshaller.UnmarshalMethodName}(Dictionary<{nameof(String)}, {Constants.AWSSDK_DynamoDBv2.AttributeValue}> entity)".CreateScope(
197+
return $"public {rootTypeName} {Marshaller.UnmarshalMethodName}(Dictionary<{nameof(String)}, {Constants.AWSSDK_DynamoDBv2.AttributeValue}> entity)".CreateScope(
200198
"ArgumentNullException.ThrowIfNull(entity);",
201199
$"return {UnMarshallerClass}.{GetDeserializationMethodName(typeSymbol)}(entity, {MarshallerOptions.FieldReference});");
202200
}

src/DynamoDBGenerator.SourceGenerator/MarshallerFactory.cs

+2-2
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@ private static IEnumerable<string> CreateImplementations(IEnumerable<DynamoDBMar
2222
var entityTypeName = argument.AnnotatedEntityType;
2323
var argumentTypeName = argument.AnnotatedArgumentType;
2424

25-
var constructor = $"public {argument.ImplementationName}({MarshallerOptions.Name} {MarshallerOptions.ParamReference})"
25+
var constructor = $"public {argument.ImplementationName}({options.FullName} {MarshallerOptions.ParamReference})"
2626
.CreateScope($"{MarshallerOptions.FieldReference} = {MarshallerOptions.ParamReference};", $"{Marshaller.KeyMarshaller.PrimaryKeyMarshallerReference} = {Marshaller.KeyMarshaller.AssignmentRoot(argument.EntityTypeSymbol)};");
2727
var interfaceImplementation = constructor
2828
.Concat(Marshaller.RootSignature(argument.EntityTypeSymbol, entityTypeName))
@@ -40,7 +40,7 @@ private static IEnumerable<string> CreateImplementations(IEnumerable<DynamoDBMar
4040
{
4141
{} arg =>
4242
$"public static {Interface}<{entityTypeName}, {argumentTypeName}, {nameTrackerTypeName}, {valueTrackerTypeName}> {argument.AccessName} {{ get; }} = new {argument.ImplementationName}({arg});",
43-
null => $"public static {Interface}<{entityTypeName}, {argumentTypeName}, {nameTrackerTypeName}, {valueTrackerTypeName}> {argument.AccessName}({MarshallerOptions.Name} options) => new {argument.ImplementationName}(options);"
43+
null => $"public static {Interface}<{entityTypeName}, {argumentTypeName}, {nameTrackerTypeName}, {valueTrackerTypeName}> {argument.AccessName}({options.FullName} options) => new {argument.ImplementationName}(options);"
4444
};
4545

4646
foreach (var s in classImplementation)

src/DynamoDBGenerator.SourceGenerator/Types/MarshallerOptions.cs

+7-10
Original file line numberDiff line numberDiff line change
@@ -9,13 +9,13 @@ public readonly struct MarshallerOptions
99
private readonly INamedTypeSymbol _convertersType;
1010
private readonly int _enumStrategy;
1111
// TODO name needs to take namespace etc into account in order to make it accessible from the outside.
12-
public const string Name = "MarshallerOptions";
12+
private const string TypeName = "MarshallerOptions";
1313
public const string FieldReference = "_options";
1414
public const string ParamReference = "options";
1515
private const string ConvertersProperty = "Converters";
16-
public const string FieldDeclaration = $"private readonly {Name} {FieldReference};";
16+
public const string FieldDeclaration = $"private readonly {TypeName} {FieldReference};";
1717
private readonly string _converterFullPath;
18-
private readonly string _optionsFullPath;
18+
public string FullName { get; }
1919

2020

2121
private MarshallerOptions(
@@ -29,17 +29,14 @@ int enumStrategy
2929
_convertersType = convertersType;
3030
_enumStrategy = enumStrategy;
3131
_converterFullPath = _convertersType.ToDisplayString(SymbolDisplayFormat.FullyQualifiedFormat);
32-
_optionsFullPath =
33-
$"{originalType.ToDisplayString(SymbolDisplayFormat.FullyQualifiedFormat)}.{Name}";
32+
FullName = $"{originalType.ToDisplayString(SymbolDisplayFormat.FullyQualifiedFormat)}.{TypeName}";
3433
}
3534

3635
public string? TryInstantiate()
3736
{
3837
if (_convertersType.InstanceConstructors.Length is 0 ||
3938
_convertersType.InstanceConstructors.All(x => x.Parameters.Length is 0))
40-
{
41-
return $"new {_optionsFullPath}(new {_converterFullPath}())";
42-
}
39+
return $"new {FullName}(new {_converterFullPath}())";
4340

4441
return null;
4542
}
@@ -101,11 +98,11 @@ public IEnumerable<string> ClassDeclaration
10198
{
10299
get
103100
{
104-
var body = $"public {Name} ({_converterFullPath} converters)"
101+
var body = $"public {TypeName} ({_converterFullPath} converters)"
105102
.CreateScope($"{ConvertersProperty} = converters;")
106103
.Append($"public {_converterFullPath} {ConvertersProperty} {{ get; }}");
107104

108-
return $"public sealed class {Name}".CreateScope(body);
105+
return $"public sealed class {TypeName}".CreateScope(body);
109106
}
110107
}
111108

0 commit comments

Comments
 (0)