Skip to content

Commit

Permalink
Improve naming
Browse files Browse the repository at this point in the history
  • Loading branch information
Mafii committed Oct 1, 2024
1 parent ce68064 commit 0f7730c
Show file tree
Hide file tree
Showing 3 changed files with 7 additions and 7 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ internal sealed record DiscriminatedUnion(
TypeDeclarationSyntax Type,
IReadOnlyList<TypeDeclarationSyntax> ParentTypes,
string? Namespace,
string MethodVisibility,
string GeneratedMethodOrClassVisibility,
string MatchResultTypeName,
IReadOnlyList<DiscriminatedUnionVariant> Variants,
bool GeneratePartitionExtension);
Expand Down
10 changes: 5 additions & 5 deletions Funcky.DiscriminatedUnion.SourceGeneration/Emitter.cs
Original file line number Diff line number Diff line change
Expand Up @@ -39,9 +39,9 @@ private static void WriteUnionType(DiscriminatedUnion discriminatedUnion, Indent
writer.WriteLineInterpolated(FormatPartialTypeDeclaration(discriminatedUnion.Type));
writer.OpenScope();

WriteGeneratedMethod(writer, $"{discriminatedUnion.MethodVisibility} abstract {FormatMatchMethodDeclaration(discriminatedUnion.MatchResultTypeName, discriminatedUnion.Variants)};");
WriteGeneratedMethod(writer, $"{discriminatedUnion.GeneratedMethodOrClassVisibility} abstract {FormatMatchMethodDeclaration(discriminatedUnion.MatchResultTypeName, discriminatedUnion.Variants)};");
writer.WriteLine();
WriteGeneratedMethod(writer, $"{discriminatedUnion.MethodVisibility} abstract {FormatSwitchMethodDeclaration(discriminatedUnion.Variants)};");
WriteGeneratedMethod(writer, $"{discriminatedUnion.GeneratedMethodOrClassVisibility} abstract {FormatSwitchMethodDeclaration(discriminatedUnion.Variants)};");

foreach (var variant in discriminatedUnion.Variants)
{
Expand All @@ -54,7 +54,7 @@ private static void WritePartitionExtensions(DiscriminatedUnion discriminatedUni
using var scope = writer.AutoCloseScopes();

writer.WriteLine(GeneratedCodeAttributeSource);
writer.WriteLineInterpolated($"{discriminatedUnion.MethodVisibility} static partial class {discriminatedUnion.Type.Identifier}EnumerableExtensions");
writer.WriteLineInterpolated($"{discriminatedUnion.GeneratedMethodOrClassVisibility} static partial class {discriminatedUnion.Type.Identifier}EnumerableExtensions");
writer.OpenScope();

WriteTupleReturningPartitionExtension(discriminatedUnion, writer);
Expand Down Expand Up @@ -143,9 +143,9 @@ private static void WriteVariant(IndentedTextWriter writer, DiscriminatedUnion d
writer.WriteLineInterpolated(FormatPartialTypeDeclaration(variant.Type));
writer.OpenScope();

WriteGeneratedMethod(writer, $"{discriminatedUnion.MethodVisibility} override {FormatMatchMethodDeclaration(discriminatedUnion.MatchResultTypeName, discriminatedUnion.Variants)} => {FormatIdentifier(variant.ParameterName)}(this);");
WriteGeneratedMethod(writer, $"{discriminatedUnion.GeneratedMethodOrClassVisibility} override {FormatMatchMethodDeclaration(discriminatedUnion.MatchResultTypeName, discriminatedUnion.Variants)} => {FormatIdentifier(variant.ParameterName)}(this);");
writer.WriteLine();
WriteGeneratedMethod(writer, $"{discriminatedUnion.MethodVisibility} override {FormatSwitchMethodDeclaration(discriminatedUnion.Variants)} => {FormatIdentifier(variant.ParameterName)}(this);");
WriteGeneratedMethod(writer, $"{discriminatedUnion.GeneratedMethodOrClassVisibility} override {FormatSwitchMethodDeclaration(discriminatedUnion.Variants)} => {FormatIdentifier(variant.ParameterName)}(this);");
}
}

Expand Down
2 changes: 1 addition & 1 deletion Funcky.DiscriminatedUnion.SourceGeneration/Parser.cs
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ public static bool IsSyntaxTargetForGeneration(SyntaxNode node)
ParentTypes: typeDeclaration.Ancestors().OfType<TypeDeclarationSyntax>().ToList(),
Namespace: FormatNamespace(typeSymbol),
MatchResultTypeName: matchResultType ?? "TResult",
MethodVisibility: nonExhaustive ? "internal" : "public",
GeneratedMethodOrClassVisibility: nonExhaustive ? "internal" : "public",
GeneratePartitionExtension: generatePartitionExtension,
Variants: GetVariantTypeDeclarations(typeDeclaration, isVariant)
.Select(GetDiscriminatedUnionVariant(typeDeclaration, semanticModel, GenerateJsonDerivedTypeAttribute(typeSymbol)))
Expand Down

0 comments on commit 0f7730c

Please sign in to comment.