-
Notifications
You must be signed in to change notification settings - Fork 6
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
wip: removing reflection from introspective type resolver system
- Loading branch information
1 parent
ef534d6
commit 5a3658c
Showing
24 changed files
with
571 additions
and
104 deletions.
There are no files selected for viewing
10 changes: 10 additions & 0 deletions
10
Chickensoft.Introspection.Generator.Tests/test_cases/Collections.cs
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,10 @@ | ||
namespace Chickensoft.Introspection.Generator.Tests.TestCases; | ||
|
||
using System.Collections.Generic; | ||
using Chickensoft.Serialization; | ||
|
||
[Meta] | ||
public partial class Collections { | ||
[Save("nested_collections")] | ||
public Dictionary<List<string>, List<List<int>>> NestedCollections { get; } = new(); | ||
} |
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
2 changes: 1 addition & 1 deletion
2
Chickensoft.Introspection.Generator/src/models/DeclaredAttribute.cs
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
6 changes: 3 additions & 3 deletions
6
Chickensoft.Introspection.Generator/src/models/DeclaredProperty.cs
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,19 +1,19 @@ | ||
namespace Chickensoft.Introspection.Generator.Types.Models; | ||
namespace Chickensoft.Introspection.Generator.Models; | ||
|
||
using System.Collections.Immutable; | ||
|
||
/// <summary> | ||
/// Represents a property on a metatype. Properties are opt-in and persisted. | ||
/// </summary> | ||
/// <param name="Name">Name of the property.</param> | ||
/// <param name="Type">Type of the property.</param> | ||
/// <param name="HasSetter">True if the property has a setter.</param> | ||
/// <param name="IsNullable">True if the property is nullable.</param> | ||
/// <param name="GenericType">Type of the property.</param> | ||
/// <param name="Attributes">Attributes applied to the property.</param> | ||
public record DeclaredProperty( | ||
string Name, | ||
string Type, | ||
bool HasSetter, | ||
bool IsNullable, | ||
GenericTypeNode GenericType, | ||
ImmutableArray<DeclaredAttribute> Attributes | ||
); |
3 changes: 1 addition & 2 deletions
3
Chickensoft.Introspection.Generator/src/models/DeclaredType.cs
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
2 changes: 1 addition & 1 deletion
2
Chickensoft.Introspection.Generator/src/models/DeclaredTypeKind.cs
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
2 changes: 1 addition & 1 deletion
2
Chickensoft.Introspection.Generator/src/models/GenerationData.cs
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
95 changes: 95 additions & 0 deletions
95
Chickensoft.Introspection.Generator/src/models/GenericTypeNode.cs
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,95 @@ | ||
namespace Chickensoft.Introspection.Generator.Models; | ||
|
||
using System.CodeDom.Compiler; | ||
using System.Collections.Immutable; | ||
using System.Linq; | ||
using Microsoft.CodeAnalysis; | ||
using Microsoft.CodeAnalysis.CSharp; | ||
using Microsoft.CodeAnalysis.CSharp.Syntax; | ||
|
||
public record GenericTypeNode( | ||
string Type, | ||
ImmutableArray<GenericTypeNode> Children | ||
) { | ||
/// <summary> | ||
/// Name of the type, including any open generics portion of the name (if the | ||
/// type is generic) — i.e., the open generic type. | ||
/// </summary> | ||
public string OpenType => | ||
Type + TypeReference.GetOpenGenerics(Children.Length); | ||
|
||
/// <summary> | ||
/// Name of the type, including any generic type arguments — i.e., the closed | ||
/// generic type. | ||
/// </summary> | ||
public string ClosedType => Type + TypeReference.GetGenerics( | ||
Children.Select(child => child.ClosedType).ToImmutableArray() | ||
); | ||
|
||
/// <summary> | ||
/// Recursively constructs a generic type node from a generic name syntax. | ||
/// </summary> | ||
/// <param name="genericName">Generic name syntax.</param> | ||
/// <returns>Generic type node tree.</returns> | ||
public static GenericTypeNode Create(GenericNameSyntax genericName) { | ||
var type = genericName.Identifier.NormalizeWhitespace().ToString(); | ||
|
||
var children = genericName.TypeArgumentList.Arguments | ||
.Select(arg => arg switch { | ||
GenericNameSyntax genericNameSyntax => Create(genericNameSyntax), | ||
_ => new GenericTypeNode( | ||
arg.NormalizeWhitespace().ToString(), | ||
ImmutableArray<GenericTypeNode>.Empty | ||
) | ||
}) | ||
.ToImmutableArray(); | ||
|
||
return new GenericTypeNode(type, children); | ||
} | ||
|
||
public void Write(IndentedTextWriter writer) { | ||
var openType = Type + TypeReference.GetOpenGenerics(Children.Length); | ||
var closedType = Type + TypeReference.GetGenerics( | ||
Children.Select(child => child.ClosedType).ToImmutableArray() | ||
); | ||
|
||
writer.WriteLine("new GenericType("); | ||
writer.Indent++; | ||
writer.WriteLine($"OpenType: typeof({openType}),"); | ||
writer.WriteLine($"ClosedType: typeof({closedType}),"); | ||
|
||
if (Children.Length > 0) { | ||
writer.WriteLine("Arguments: new GenericType[] {"); | ||
writer.Indent++; | ||
foreach (var child in Children) { | ||
var isLast = Children[Children.Length - 1] == child; | ||
child.Write(writer); | ||
if (!isLast) { | ||
writer.WriteLine(","); | ||
} | ||
} | ||
writer.Indent--; | ||
writer.WriteLine("},"); | ||
} | ||
else { | ||
writer.WriteLine("Arguments: System.Array.Empty<GenericType>(),"); | ||
} | ||
|
||
writer.WriteLine( | ||
"GenericTypeGetter: receiver => " + | ||
$"receiver.Receive<{closedType}>()," | ||
); | ||
// TODO: Pass child types | ||
if (Children.Length >= 2) { | ||
writer.WriteLine( | ||
"GenericTypeGetter2: receiver => " + | ||
$"receiver.Receive<{Children[0].ClosedType}, {Children[1].ClosedType}>()" | ||
); | ||
} | ||
else { | ||
writer.WriteLine("GenericTypeGetter2: default"); | ||
} | ||
writer.Indent--; | ||
writer.Write(")"); | ||
} | ||
} |
3 changes: 1 addition & 2 deletions
3
Chickensoft.Introspection.Generator/src/models/TypeLocation.cs
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
3 changes: 1 addition & 2 deletions
3
Chickensoft.Introspection.Generator/src/models/TypeReference.cs
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
2 changes: 1 addition & 1 deletion
2
Chickensoft.Introspection.Generator/src/models/TypeResolutionNode.cs
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
2 changes: 1 addition & 1 deletion
2
Chickensoft.Introspection.Generator/src/models/TypeResolutionTree.cs
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
2 changes: 1 addition & 1 deletion
2
Chickensoft.Introspection.Generator/src/models/UsingDirective.cs
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
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
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,21 @@ | ||
namespace Chickensoft.Introspection; | ||
|
||
using System; | ||
|
||
/// <summary> | ||
/// Generic type representation. | ||
/// </summary> | ||
/// <param name="OpenType">Open generic type.</param> | ||
/// <param name="ClosedType">Closed generic type.</param> | ||
/// <param name="Arguments">Type arguments.</param> | ||
/// <param name="GenericTypeGetter">Action which invokes the generic type | ||
/// receiver with the generic type.</param> | ||
/// <param name="GenericTypeGetter2">Action which invokes the generic type | ||
/// receiver with its two child generic types.</param> | ||
public record GenericType( | ||
Type OpenType, | ||
Type ClosedType, | ||
GenericType[] Arguments, | ||
Action<ITypeReceiver> GenericTypeGetter, | ||
Action<ITypeReceiver2>? GenericTypeGetter2 | ||
); |
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
Oops, something went wrong.