-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
changed incrementalgenerator implementation
- Loading branch information
Showing
5 changed files
with
115 additions
and
132 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,17 +1,24 @@ | ||
using System.Collections.Immutable; | ||
using Microsoft.CodeAnalysis; | ||
using Microsoft.CodeAnalysis.CSharp.Syntax; | ||
|
||
namespace nyingi.Kafa.Generators | ||
{ | ||
internal sealed partial class KafaSourceGenerator | ||
{ | ||
private record struct KafaGeneratorContext(string? actualnamespace, string name, TypeContext typeContext); | ||
|
||
private record struct TypeContext(bool isReferenceType, string name, ImmutableArray<PropertyContext> propertyContext); | ||
|
||
private record struct PropertyContext(string type, string name); | ||
|
||
private static readonly SymbolDisplayFormat Format = SymbolDisplayFormat.FullyQualifiedFormat.WithMiscellaneousOptions(SymbolDisplayMiscellaneousOptions.UseSpecialTypes | SymbolDisplayMiscellaneousOptions.ExpandNullable | SymbolDisplayMiscellaneousOptions.IncludeNullableReferenceTypeModifier); | ||
|
||
private record struct KafaEnumContext(ClassDeclarationSyntax ClassDeclarationSyntax, | ||
INamedTypeSymbol NamedTypeSymbol, SemanticModel SemanticModel, SyntaxList<AttributeListSyntax> AttributeList); | ||
|
||
private record struct TypeDefinition(string Name, ImmutableArray<PropertyContext> Properties); | ||
|
||
private record struct TypeDefinitionContext(bool IsGlobalNameSpace, string NameSpace, string Name, | ||
ImmutableArray<TypeDefinition> TypeDefinitions) | ||
{ | ||
public string GetFullName() => IsGlobalNameSpace ? Name : $"{NameSpace}.{Name}"; | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,57 @@ | ||
using System.Text; | ||
using Microsoft.CodeAnalysis; | ||
|
||
namespace nyingi.Kafa.Generators; | ||
|
||
internal sealed partial class KafaSourceGenerator | ||
{ | ||
private static void Emit(SourceProductionContext context, TypeDefinitionContext source) | ||
{ | ||
StringBuilder builder = new StringBuilder(); | ||
string Namespace = | ||
"{(source.Namespace is null ? String.Empty : $\"namespace {source.Namespace};{Environment.NewLine}\")}"; | ||
|
||
// lang=c# | ||
string classDef = $@" | ||
// <auto-generated/> | ||
#nullable enable | ||
{Namespace} | ||
partial class {source.Name} | ||
{{ | ||
}} | ||
"; | ||
|
||
} | ||
|
||
private static string EmitSerializer(TypeDefinitionContext source) | ||
{ | ||
|
||
// lang=c# | ||
string serializer = $@" | ||
public static void Serializer(global::System.Collections.Generic.List<{source.Name}> entities, ref nyingi.Kafa.Writer.KafaWriter writer) | ||
{{ | ||
}} | ||
"; | ||
return ""; | ||
} | ||
|
||
private static string EmitDeserializer(TypeDefinitionContext source) | ||
{ | ||
// lang=c# | ||
string deserializer = $@" | ||
{GeneratedAttribute} | ||
public static global::System.Collections.Generic.List<{source.Name}> Deserialize(nyingi.Kafa.Reader.RowEnumerable rows) | ||
{{ | ||
var results = new global::System.Collections.Generic.List<{source.Name}>(rows.Length); | ||
}} | ||
"; | ||
return ""; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters