Skip to content

Commit

Permalink
Tidy up and update snapshots
Browse files Browse the repository at this point in the history
  • Loading branch information
SteveDunn committed Nov 13, 2024
1 parent 03c96a5 commit acd8d74
Show file tree
Hide file tree
Showing 23 changed files with 481 additions and 486 deletions.
1 change: 1 addition & 0 deletions Vogen.sln.DotSettings
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,7 @@
<s:Boolean x:Key="/Default/CodeStyle/CodeFormatting/CSharpFormat/WRAP_AFTER_INVOCATION_LPAR/@EntryValue">True</s:Boolean>
<s:String x:Key="/Default/CodeStyle/CodeFormatting/CSharpFormat/WRAP_ARGUMENTS_STYLE/@EntryValue">CHOP_IF_LONG</s:String>
<s:String x:Key="/Default/CodeStyle/CSharpVarKeywordUsage/ForOtherTypes/@EntryValue">UseVarWhenEvident</s:String>
<s:String x:Key="/Default/CodeStyle/Naming/CSharpNaming/Abbreviations/=EF/@EntryIndexedValue">EF</s:String>
<s:String x:Key="/Default/CodeStyle/Naming/CSharpNaming/PredefinedNamingRules/=PrivateConstants/@EntryIndexedValue">&lt;Policy Inspect="True" Prefix="_" Suffix="" Style="aaBb" /&gt;</s:String>
<s:String x:Key="/Default/CodeStyle/Naming/CSharpNaming/PredefinedNamingRules/=PrivateStaticReadonly/@EntryIndexedValue">&lt;Policy Inspect="True" Prefix="_" Suffix="" Style="aaBb" /&gt;</s:String>
<s:String x:Key="/Default/CodeStyle/Naming/CSharpNaming/UserRules/=15b5b1f1_002D457c_002D4ca6_002Db278_002D5615aedc07d3/@EntryIndexedValue">&lt;Policy&gt;&lt;Descriptor Staticness="Static" AccessRightKinds="Private" Description="Static readonly fields (private)"&gt;&lt;ElementKinds&gt;&lt;Kind Name="READONLY_FIELD" /&gt;&lt;/ElementKinds&gt;&lt;/Descriptor&gt;&lt;Policy Inspect="True" Prefix="_" Suffix="" Style="aaBb" /&gt;&lt;/Policy&gt;</s:String>
Expand Down
2 changes: 1 addition & 1 deletion samples/WebApplication/WebApplication.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@
</PropertyGroup>

<ItemGroup>
<PackageReference Include="Refit" Version="7.0.0"/>
<PackageReference Include="Refit" Version="8.0.0"/>
<PackageReference Include="System.Text.Json" Version="8.0.5" />
</ItemGroup>

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@
<ItemGroup>
<PackageReference Include="System.Text.Json" Version="8.0.5" />
<PackageReference Include="Newtonsoft.Json" Version="13.0.3" />
<PackageReference Include="Refit" Version="7.0.0" />
<PackageReference Include="Refit" Version="8.0.0" />
<PackageReference Include="ServiceStack.Text" Version="8.2.2" />
</ItemGroup>

Expand Down
6 changes: 2 additions & 4 deletions src/Vogen/ConversionMarkers.cs
Original file line number Diff line number Diff line change
Expand Up @@ -83,7 +83,7 @@ public static bool IsTarget(SyntaxNode node) =>
if (!VoFilter.IsTarget(voSymbol))
{
// return ConversionMarkerAttributeDefinition.Error(markerKind, DiagnosticsCatalogue.VoReferencedInAConversionMarkerMustExplicitlySpecifyPrimitive(markerClassSymbol!, voSymbol));
return MarkerAttributeDefinition.Error(markerKind, DiagnosticsCatalogue.TypesReferencedInAConversionMarkerMustBeaValueObjects(markerClassSymbol!, voSymbol));
return MarkerAttributeDefinition.Error(DiagnosticsCatalogue.TypesReferencedInAConversionMarkerMustBeaValueObjects(markerClassSymbol!, voSymbol));
}

List<AttributeData> voAttributes = VoFilter.TryGetValueObjectAttributes(voSymbol).ToList();
Expand All @@ -102,9 +102,7 @@ public static bool IsTarget(SyntaxNode node) =>

if (underlyingType is null)
{
return MarkerAttributeDefinition.Error(
markerKind,
DiagnosticsCatalogue.VoReferencedInAConversionMarkerMustExplicitlySpecifyPrimitive(markerClassSymbol!, voSymbol, markerAtt.ApplicationSyntaxReference?.GetSyntax().GetLocation()));
return MarkerAttributeDefinition.Error(DiagnosticsCatalogue.VoReferencedInAConversionMarkerMustExplicitlySpecifyPrimitive(markerClassSymbol!, voSymbol, markerAtt.ApplicationSyntaxReference?.GetSyntax().GetLocation()));
}

return MarkerAttributeDefinition.Ok(markerKind, voSymbol, underlyingType, markerClassSymbol!);
Expand Down
37 changes: 13 additions & 24 deletions src/Vogen/GenerateCodeForMessagePack.cs
Original file line number Diff line number Diff line change
Expand Up @@ -9,10 +9,7 @@ namespace Vogen;

internal class GenerateCodeForMessagePack
{
public static void GenerateForAMarkerClass(SourceProductionContext context,
Compilation compilation,
MarkerClassDefinition markerClass,
VogenKnownSymbols vogenKnownSymbols)
public static void GenerateForAMarkerClass(SourceProductionContext context, MarkerClassDefinition markerClass)
{
var markerClassSymbol = markerClass.MarkerClassSymbol;

Expand All @@ -21,7 +18,7 @@ public static void GenerateForAMarkerClass(SourceProductionContext context,
return;
}

string pns = markerClassSymbol.FullNamespace() ?? "";
string pns = markerClassSymbol.FullNamespace();

string ns = pns.Length == 0 ? "" : $"namespace {pns};";

Expand Down Expand Up @@ -66,10 +63,10 @@ string GenerateEach()
m => m.Marker?.Kind is ConversionMarkerKind.MessagePack).Select(
x =>
{
if (x is null) return null;
//if (x is null) return null;
if (x.Marker is null) return null;

string? wrapperNameShort = x.Marker.VoSymbol.Name;
string wrapperNameShort = x.Marker.VoSymbol.Name;

return $"new {wrapperNameShort}MessagePackFormatter()";
}).ToArray();
Expand All @@ -82,12 +79,12 @@ string GenerateFormatters()
{
StringBuilder sb = new();

foreach (MarkerAttributeDefinition eachMarker in markerClass.AttributeDefinitions.Where(
foreach (MarkerAttributeDefinition eachAttr in markerClass.AttributeDefinitions.Where(
m => m.Marker?.Kind is ConversionMarkerKind.MessagePack))
{
sb.AppendLine(
$$"""
{{GenerateSource("public", eachMarker.Marker!.VoSymbol, eachMarker.Marker.UnderlyingTypeSymbol, vogenKnownSymbols)}}
{{GenerateSource("public", eachAttr.Marker!.VoSymbol, eachAttr.Marker.UnderlyingTypeSymbol)}}
""");
}

Expand All @@ -97,8 +94,7 @@ string GenerateFormatters()

public static void GenerateForApplicableValueObjects(SourceProductionContext context,
Compilation compilation,
List<VoWorkItem> valueObjects,
VogenKnownSymbols knownSymbols)
List<VoWorkItem> valueObjects)
{
if (!compilation.IsAtLeastCSharpVersion(LanguageVersion.CSharp12))
{
Expand All @@ -110,7 +106,7 @@ public static void GenerateForApplicableValueObjects(SourceProductionContext con
List<MessagePackStandalone> items = matchingVos.Select(MessagePackStandalone.FromWorkItem).ToList();

List<FormatterSourceAndFilename> toWrite = items.Select(
p => GenerateSourceAndFilename(p.WrapperAccessibility, p.WrapperType, p.ContainerNamespace, p.UnderlyingType, knownSymbols)).ToList();
p => GenerateSourceAndFilename(p.WrapperAccessibility, p.WrapperType, p.ContainerNamespace, p.UnderlyingType)).ToList();

foreach (var eachToWrite in toWrite)
{
Expand All @@ -120,16 +116,13 @@ public static void GenerateForApplicableValueObjects(SourceProductionContext con
}
}

public record FormatterSourceAndFilename(string FormatterFullyQualifiedName, string Filename, string SourceCode);
private record FormatterSourceAndFilename(string Filename, string SourceCode);

private static FormatterSourceAndFilename GenerateSourceAndFilename(string accessibility,
INamedTypeSymbol wrapperSymbol,
string theNamespace,
INamedTypeSymbol underlyingSymbol,
VogenKnownSymbols knownSymbols)
INamedTypeSymbol underlyingSymbol)
{
string wrapperName = Util.EscapeIfRequired(wrapperSymbol.Name);

var ns = string.IsNullOrEmpty(theNamespace) ? string.Empty : $"namespace {theNamespace};";

string sb =
Expand All @@ -138,22 +131,18 @@ private static FormatterSourceAndFilename GenerateSourceAndFilename(string acces
{{ns}}
{{GenerateSource(accessibility, wrapperSymbol, underlyingSymbol, knownSymbols)}}
{{GenerateSource(accessibility, wrapperSymbol, underlyingSymbol)}}
""";

var fn = string.IsNullOrEmpty(theNamespace) ? "" : theNamespace + ".";
string serializerFqn = $"{fn}{wrapperName}MessagePackFormatter";

var unsanitized = $"{wrapperSymbol.ToDisplayString()}_messagepack.g.cs";
string filename = Util.SanitizeToALegalFilename(unsanitized);
return new FormatterSourceAndFilename(serializerFqn, filename, sb);
return new FormatterSourceAndFilename(filename, sb);
}


private static string GenerateSource(string accessibility,
INamedTypeSymbol wrapperSymbol,
INamedTypeSymbol underlyingSymbol,
VogenKnownSymbols vogenKnownSymbols)
INamedTypeSymbol underlyingSymbol)
{
var accessor = accessibility;

Expand Down
2 changes: 1 addition & 1 deletion src/Vogen/GenerateCodeForMessagePackMarkers.cs
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ public static void GenerateForMarkerClasses(SourceProductionContext context,
{
foreach (MarkerClassDefinition? eachMarkerClass in conversionMarkerClasses)
{
GenerateCodeForMessagePack.GenerateForAMarkerClass(context, compilation, eachMarkerClass, vogenKnownSymbols);
GenerateCodeForMessagePack.GenerateForAMarkerClass(context, eachMarkerClass);
}
}
}
2 changes: 1 addition & 1 deletion src/Vogen/MarkerAttributeDefinition.cs
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ private MarkerAttributeDefinition(ConversionMarker? marker, IEnumerable<Diagnost

public List<Diagnostic> Diagnostics { get; }

public static MarkerAttributeDefinition Error(ConversionMarkerKind kind, Diagnostic diag) => new(null, [diag]);
public static MarkerAttributeDefinition Error(Diagnostic diag) => new(null, [diag]);

public static MarkerAttributeDefinition Ok(ConversionMarkerKind kind, INamedTypeSymbol voSymbol, INamedTypeSymbol underlyingTypeSymbol, INamedTypeSymbol sourceSymbol) =>
new(marker: new ConversionMarker(kind, voSymbol, underlyingTypeSymbol, sourceSymbol), diagnostics: []);
Expand Down
2 changes: 1 addition & 1 deletion src/Vogen/ValueObjectGenerator.cs
Original file line number Diff line number Diff line change
Expand Up @@ -128,7 +128,7 @@ private static void Execute(

// the user can specify to create the MessagePack generated code as an attribute
// or as marker in another project.
GenerateCodeForMessagePack.GenerateForApplicableValueObjects(spc, compilation, workItems, vogenKnownSymbols);
GenerateCodeForMessagePack.GenerateForApplicableValueObjects(spc, compilation, workItems);
GenerateCodeForMessagePackMarkers.GenerateForMarkerClasses(spc, compilation, markerClasses, vogenKnownSymbols);

GenerateCodeForBsonSerializers.WriteIfNeeded(spc, compilation, workItems);
Expand Down
5 changes: 0 additions & 5 deletions tests/ConsumerTests/BugFix624.cs
Original file line number Diff line number Diff line change
@@ -1,8 +1,3 @@
using System.Text.Json;
using System.Text.Json.Serialization;
using System.Text.Json.Serialization.Metadata;
using SystemTextJsonSerializer = System.Text.Json.JsonSerializer;

namespace ConsumerTests.BugFixTests.BugFix639;

[ValueObject<string>(fromPrimitiveCasting: CastOperator.Implicit)]
Expand Down
1 change: 0 additions & 1 deletion tests/ConsumerTests/BugFixTests/BugFix595.cs
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
using System.Text.Json;
using System.Text.Json.Serialization;
using System.Text.Json.Serialization.Metadata;
using SystemTextJsonSerializer = System.Text.Json.JsonSerializer;

namespace ConsumerTests.BugFixTests.BugFix595;
Expand Down
3 changes: 0 additions & 3 deletions tests/ConsumerTests/BugFixTests/BugFix624.cs
Original file line number Diff line number Diff line change
@@ -1,7 +1,4 @@
using System.Text.Json;
using System.Text.Json.Serialization;
using System.Text.Json.Serialization.Metadata;
using SystemTextJsonSerializer = System.Text.Json.JsonSerializer;

namespace ConsumerTests.BugFixTests.BugFix624;

Expand Down
2 changes: 0 additions & 2 deletions tests/ConsumerTests/CreationTests.cs
Original file line number Diff line number Diff line change
@@ -1,5 +1,3 @@
using System.Diagnostics;
using System.Runtime.InteropServices;
using @double;
using @bool.@byte.@short.@float.@object;
using Vogen.Tests.Types;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
namespace MediumTests.SerializationAndConversionTests;


public partial class ComplexSerializationTests
public partial class ComplexSerializationTests_ServiceStackDotText
{
[Fact]
public void Bson_CanSerializeAndDeserialize()
Expand Down
Loading

0 comments on commit acd8d74

Please sign in to comment.