Skip to content

Commit c526ce4

Browse files
authored
Merge pull request #26 from chickensoft-games/fix/ignore-ref-struct
fix: ignore ref structs
2 parents 5e2dad4 + 2932c4c commit c526ce4

4 files changed

Lines changed: 93 additions & 1 deletion

File tree

Original file line numberDiff line numberDiff line change
@@ -0,0 +1,85 @@
1+
#pragma warning disable
2+
#nullable enable
3+
namespace Chickensoft.Introspection.Generator.Tests.TestCases;
4+
5+
partial class ExplicitInterfaceProperty : Chickensoft.Introspection.IIntrospectiveRef {
6+
[System.Diagnostics.CodeAnalysis.ExcludeFromCodeCoverage]
7+
public Chickensoft.Introspection.MixinBlackboard MixinState { get; } = new();
8+
9+
[System.Diagnostics.CodeAnalysis.ExcludeFromCodeCoverage]
10+
public Chickensoft.Introspection.IMetatype Metatype => ((Chickensoft.Introspection.IIntrospectiveTypeMetadata)Chickensoft.Introspection.Types.Graph.GetMetadata(typeof(ExplicitInterfaceProperty))).Metatype;
11+
12+
public class MetatypeMetadata : Chickensoft.Introspection.IMetatype {
13+
[System.Diagnostics.CodeAnalysis.ExcludeFromCodeCoverage]
14+
public System.Type Type => typeof(ExplicitInterfaceProperty);
15+
[System.Diagnostics.CodeAnalysis.ExcludeFromCodeCoverage]
16+
public bool HasInitProperties { get; } = false;
17+
18+
[System.Diagnostics.CodeAnalysis.ExcludeFromCodeCoverage]
19+
public System.Collections.Generic.IReadOnlyList<Chickensoft.Introspection.PropertyMetadata> Properties { get; } = new System.Collections.Generic.List<Chickensoft.Introspection.PropertyMetadata>() {
20+
new Chickensoft.Introspection.PropertyMetadata(
21+
Name: "Name",
22+
IsInit: false,
23+
IsRequired: false,
24+
HasDefaultValue: false,
25+
Getter: static (object obj) => ((IInterfaceOne)obj).Name,
26+
Setter: null,
27+
TypeNode: new Chickensoft.Introspection.TypeNode(
28+
OpenType: typeof(string),
29+
ClosedType: typeof(string),
30+
IsNullable: false,
31+
Arguments: System.Array.Empty<TypeNode>(),
32+
GenericTypeGetter: static receiver => receiver.Receive<string>(),
33+
GenericTypeGetter2: default
34+
),
35+
Attributes: new System.Collections.Generic.Dictionary<System.Type, System.Attribute[]>() {
36+
}
37+
),
38+
new Chickensoft.Introspection.PropertyMetadata(
39+
Name: "Name",
40+
IsInit: false,
41+
IsRequired: false,
42+
HasDefaultValue: false,
43+
Getter: static (object obj) => ((IInterfaceTwo)obj).Name,
44+
Setter: null,
45+
TypeNode: new Chickensoft.Introspection.TypeNode(
46+
OpenType: typeof(string),
47+
ClosedType: typeof(string),
48+
IsNullable: false,
49+
Arguments: System.Array.Empty<TypeNode>(),
50+
GenericTypeGetter: static receiver => receiver.Receive<string>(),
51+
GenericTypeGetter2: default
52+
),
53+
Attributes: new System.Collections.Generic.Dictionary<System.Type, System.Attribute[]>() {
54+
}
55+
)
56+
};
57+
58+
[System.Diagnostics.CodeAnalysis.ExcludeFromCodeCoverage]
59+
public System.Collections.Generic.IReadOnlyDictionary<System.Type, System.Attribute[]> Attributes { get; } = new System.Collections.Generic.Dictionary<System.Type, System.Attribute[]>() {
60+
[typeof(MetaAttribute)] = new System.Attribute[] {
61+
new MetaAttribute()
62+
}
63+
};
64+
65+
[System.Diagnostics.CodeAnalysis.ExcludeFromCodeCoverage]
66+
public System.Collections.Generic.IReadOnlyList<System.Type> Mixins { get; } = new System.Collections.Generic.List<System.Type>() {
67+
};
68+
69+
[System.Diagnostics.CodeAnalysis.ExcludeFromCodeCoverage]
70+
public System.Collections.Generic.IReadOnlyDictionary<System.Type, System.Action<object>> MixinHandlers { get; } = new System.Collections.Generic.Dictionary<System.Type, System.Action<object>>() {
71+
};
72+
73+
74+
[System.Diagnostics.CodeAnalysis.ExcludeFromCodeCoverage]
75+
public object Construct(System.Collections.Generic.IReadOnlyDictionary<string, object?>? args = null) {
76+
return new ExplicitInterfaceProperty();
77+
}
78+
[System.Diagnostics.CodeAnalysis.ExcludeFromCodeCoverage]
79+
public override bool Equals(object obj) => true;
80+
[System.Diagnostics.CodeAnalysis.ExcludeFromCodeCoverage]
81+
public override int GetHashCode() => base.GetHashCode();
82+
}
83+
}
84+
#nullable restore
85+
#pragma warning restore

Chickensoft.Introspection.Generator.Tests/.generated/Chickensoft.Introspection.Generator/Chickensoft.Introspection.Generator.TypeGenerator/TypeRegistry.g.cs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -44,6 +44,7 @@ public partial class TypeRegistry : Chickensoft.Introspection.ITypeRegistry {
4444
[typeof(Chickensoft.Introspection.Generator.Tests.TestCases.ConcreteChildTwo)] = new Chickensoft.Introspection.IdentifiableTypeMetadata("ConcreteChildTwo", static (r) => r.Receive<Chickensoft.Introspection.Generator.Tests.TestCases.ConcreteChildTwo>(), static () => System.Activator.CreateInstance<Chickensoft.Introspection.Generator.Tests.TestCases.ConcreteChildTwo>(), new Chickensoft.Introspection.Generator.Tests.TestCases.ConcreteChildTwo.MetatypeMetadata(), "concrete_child_two", 1),
4545
[typeof(Chickensoft.Introspection.Generator.Tests.TestCases.DerivedModel)] = new Chickensoft.Introspection.IntrospectiveTypeMetadata("DerivedModel", static (r) => r.Receive<Chickensoft.Introspection.Generator.Tests.TestCases.DerivedModel>(), static () => System.Activator.CreateInstance<Chickensoft.Introspection.Generator.Tests.TestCases.DerivedModel>(), new Chickensoft.Introspection.Generator.Tests.TestCases.DerivedModel.MetatypeMetadata(), 1),
4646
[typeof(Chickensoft.Introspection.Generator.Tests.TestCases.ExampleStruct)] = new Chickensoft.Introspection.ConcreteTypeMetadata("ExampleStruct", static (r) => r.Receive<Chickensoft.Introspection.Generator.Tests.TestCases.ExampleStruct>(), static () => System.Activator.CreateInstance<Chickensoft.Introspection.Generator.Tests.TestCases.ExampleStruct>()),
47+
[typeof(Chickensoft.Introspection.Generator.Tests.TestCases.ExplicitInterfaceProperty)] = new Chickensoft.Introspection.IntrospectiveTypeMetadata("ExplicitInterfaceProperty", static (r) => r.Receive<Chickensoft.Introspection.Generator.Tests.TestCases.ExplicitInterfaceProperty>(), static () => System.Activator.CreateInstance<Chickensoft.Introspection.Generator.Tests.TestCases.ExplicitInterfaceProperty>(), new Chickensoft.Introspection.Generator.Tests.TestCases.ExplicitInterfaceProperty.MetatypeMetadata(), 1),
4748
[typeof(Chickensoft.Introspection.Generator.Tests.TestCases.GenericStruct<>)] = new Chickensoft.Introspection.TypeMetadata("GenericStruct<T>"),
4849
[typeof(Chickensoft.Introspection.Generator.Tests.TestCases.InitArgsModel)] = new Chickensoft.Introspection.IdentifiableTypeMetadata("InitArgsModel", static (r) => r.Receive<Chickensoft.Introspection.Generator.Tests.TestCases.InitArgsModel>(), static () => System.Activator.CreateInstance<Chickensoft.Introspection.Generator.Tests.TestCases.InitArgsModel>(), new Chickensoft.Introspection.Generator.Tests.TestCases.InitArgsModel.MetatypeMetadata(), "init_args_model", 1),
4950
[typeof(Chickensoft.Introspection.Generator.Tests.TestCases.JunkAttribute)] = new Chickensoft.Introspection.ConcreteTypeMetadata("JunkAttribute", static (r) => r.Receive<Chickensoft.Introspection.Generator.Tests.TestCases.JunkAttribute>(), static () => System.Activator.CreateInstance<Chickensoft.Introspection.Generator.Tests.TestCases.JunkAttribute>()),
Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
namespace Chickensoft.Introspection.Generator.Tests.TestCases;
2+
3+
public readonly ref struct RefStruct { }

Chickensoft.Introspection.Generator/src/TypeGenerator.cs

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -358,7 +358,7 @@ public static DeclaredType ResolveDeclaredTypeInfo(
358358
// of the same type that we discover, as well as visibility information about
359359
// any containing types.
360360
public static bool IsTypeCandidate(SyntaxNode node, CancellationToken _) =>
361-
node is TypeDeclarationSyntax;
361+
node is TypeDeclarationSyntax { } type && !IsRef(type);
362362

363363
public static bool IsGlobalUsing(SyntaxNode node, CancellationToken _) =>
364364
node is UsingDirectiveSyntax @using &&
@@ -421,6 +421,9 @@ public static bool IsTopLevelAccessible(TypeDeclarationSyntax typeDecl) =>
421421
public static bool IsPartial(TypeDeclarationSyntax typeDecl) =>
422422
typeDecl.Modifiers.Any(SyntaxKind.PartialKeyword);
423423

424+
public static bool IsRef(TypeDeclarationSyntax typeDecl) =>
425+
typeDecl.Modifiers.Any(SyntaxKind.RefKeyword);
426+
424427
public static string? GetBaseType(TypeDeclarationSyntax typeDecl) =>
425428
typeDecl.BaseList?.Types.First().Type.NormalizeWhitespace().ToString();
426429

0 commit comments

Comments
 (0)