From 58488fd8887636a0fdf21c063762f107a690efa9 Mon Sep 17 00:00:00 2001 From: Joanna May Date: Sun, 9 Jun 2024 16:12:15 -0500 Subject: [PATCH] fix: static properties --- .../TypeRegistry.g.cs | 1 + .../s_StaticPropertyIsSkipped2497B0B66A.g.cs | 51 +++++++++++++++++++ .../test_cases/StaticPropertyIsSkipped.cs | 8 +++ .../src/TypeGenerator.cs | 4 ++ 4 files changed, 64 insertions(+) create mode 100644 Chickensoft.Introspection.Generator.Tests/.generated/Chickensoft.Introspection.Generator/Chickensoft.Introspection.Generator.TypeGenerator/s_StaticPropertyIsSkipped2497B0B66A.g.cs create mode 100644 Chickensoft.Introspection.Generator.Tests/test_cases/StaticPropertyIsSkipped.cs diff --git a/Chickensoft.Introspection.Generator.Tests/.generated/Chickensoft.Introspection.Generator/Chickensoft.Introspection.Generator.TypeGenerator/TypeRegistry.g.cs b/Chickensoft.Introspection.Generator.Tests/.generated/Chickensoft.Introspection.Generator/Chickensoft.Introspection.Generator.TypeGenerator/TypeRegistry.g.cs index e68522d..021f94e 100644 --- a/Chickensoft.Introspection.Generator.Tests/.generated/Chickensoft.Introspection.Generator/Chickensoft.Introspection.Generator.TypeGenerator/TypeRegistry.g.cs +++ b/Chickensoft.Introspection.Generator.Tests/.generated/Chickensoft.Introspection.Generator/Chickensoft.Introspection.Generator.TypeGenerator/TypeRegistry.g.cs @@ -66,6 +66,7 @@ public partial class TypeRegistry : Chickensoft.Introspection.ITypeRegistry { [typeof(Chickensoft.Introspection.Generator.Tests.TestCases.PartialModel)] = new Chickensoft.Introspection.IdentifiableTypeMetadata("PartialModel", (r) => r.Receive(), () => System.Activator.CreateInstance(), new Chickensoft.Introspection.Generator.Tests.TestCases.PartialModel.MetatypeMetadata(), "multiple_partial_definitions", 1), [typeof(Chickensoft.Introspection.Generator.Tests.TestCases.PropertyModel)] = new Chickensoft.Introspection.AbstractIntrospectiveTypeMetadata("PropertyModel", (r) => r.Receive(), new Chickensoft.Introspection.Generator.Tests.TestCases.PropertyModel.MetatypeMetadata()), [typeof(Chickensoft.Introspection.Generator.Tests.TestCases.SomeType)] = new Chickensoft.Introspection.IntrospectiveTypeMetadata("SomeType", (r) => r.Receive(), () => System.Activator.CreateInstance(), new Chickensoft.Introspection.Generator.Tests.TestCases.SomeType.MetatypeMetadata(), 1), + [typeof(Chickensoft.Introspection.Generator.Tests.TestCases.StaticPropertyIsSkipped)] = new Chickensoft.Introspection.IntrospectiveTypeMetadata("StaticPropertyIsSkipped", (r) => r.Receive(), () => System.Activator.CreateInstance(), new Chickensoft.Introspection.Generator.Tests.TestCases.StaticPropertyIsSkipped.MetatypeMetadata(), 1), [typeof(Chickensoft.Introspection.Generator.Tests.TestCases.TraditionalNamespace.A)] = new Chickensoft.Introspection.ConcreteTypeMetadata("A", (r) => r.Receive(), () => System.Activator.CreateInstance()), [typeof(Chickensoft.Introspection.Generator.Tests.TestCases.TraditionalNamespace.A.AA)] = new Chickensoft.Introspection.ConcreteTypeMetadata("AA", (r) => r.Receive(), () => System.Activator.CreateInstance()), [typeof(Chickensoft.Introspection.Generator.Tests.TestCases.TraditionalNamespace.A.AA.AAA)] = new Chickensoft.Introspection.ConcreteTypeMetadata("AAA", (r) => r.Receive(), () => System.Activator.CreateInstance()), diff --git a/Chickensoft.Introspection.Generator.Tests/.generated/Chickensoft.Introspection.Generator/Chickensoft.Introspection.Generator.TypeGenerator/s_StaticPropertyIsSkipped2497B0B66A.g.cs b/Chickensoft.Introspection.Generator.Tests/.generated/Chickensoft.Introspection.Generator/Chickensoft.Introspection.Generator.TypeGenerator/s_StaticPropertyIsSkipped2497B0B66A.g.cs new file mode 100644 index 0000000..2c414a5 --- /dev/null +++ b/Chickensoft.Introspection.Generator.Tests/.generated/Chickensoft.Introspection.Generator/Chickensoft.Introspection.Generator.TypeGenerator/s_StaticPropertyIsSkipped2497B0B66A.g.cs @@ -0,0 +1,51 @@ +#pragma warning disable +#nullable enable +namespace Chickensoft.Introspection.Generator.Tests.TestCases; + +using Chickensoft.Introspection; + +partial class StaticPropertyIsSkipped : Chickensoft.Introspection.IIntrospective { + [System.Diagnostics.CodeAnalysis.ExcludeFromCodeCoverage] + public Chickensoft.Introspection.MixinBlackboard MixinState { get; } = new(); + + [System.Diagnostics.CodeAnalysis.ExcludeFromCodeCoverage] + public Chickensoft.Introspection.IMetatype Metatype => ((Chickensoft.Introspection.IIntrospectiveTypeMetadata)Chickensoft.Introspection.Types.Graph.GetMetadata(typeof(StaticPropertyIsSkipped))).Metatype; + + public class MetatypeMetadata : Chickensoft.Introspection.IMetatype { + [System.Diagnostics.CodeAnalysis.ExcludeFromCodeCoverage] + public System.Type Type => typeof(StaticPropertyIsSkipped); + [System.Diagnostics.CodeAnalysis.ExcludeFromCodeCoverage] + public bool HasInitProperties { get; } = false; + + [System.Diagnostics.CodeAnalysis.ExcludeFromCodeCoverage] + public System.Collections.Generic.IReadOnlyList Properties { get; } = new System.Collections.Generic.List() { + }; + + [System.Diagnostics.CodeAnalysis.ExcludeFromCodeCoverage] + public System.Collections.Generic.IReadOnlyDictionary Attributes { get; } = new System.Collections.Generic.Dictionary() { + [typeof(MetaAttribute)] = new System.Attribute[] { + new MetaAttribute() + } + }; + + [System.Diagnostics.CodeAnalysis.ExcludeFromCodeCoverage] + public System.Collections.Generic.IReadOnlyList Mixins { get; } = new System.Collections.Generic.List() { + }; + + [System.Diagnostics.CodeAnalysis.ExcludeFromCodeCoverage] + public System.Collections.Generic.IReadOnlyDictionary> MixinHandlers { get; } = new System.Collections.Generic.Dictionary>() { + }; + + + [System.Diagnostics.CodeAnalysis.ExcludeFromCodeCoverage] + public object Construct(System.Collections.Generic.IReadOnlyDictionary? args = null) { + return new StaticPropertyIsSkipped(); + } + [System.Diagnostics.CodeAnalysis.ExcludeFromCodeCoverage] + public override bool Equals(object obj) => true; + [System.Diagnostics.CodeAnalysis.ExcludeFromCodeCoverage] + public override int GetHashCode() => base.GetHashCode(); + } +} +#nullable restore +#pragma warning restore diff --git a/Chickensoft.Introspection.Generator.Tests/test_cases/StaticPropertyIsSkipped.cs b/Chickensoft.Introspection.Generator.Tests/test_cases/StaticPropertyIsSkipped.cs new file mode 100644 index 0000000..ea43a24 --- /dev/null +++ b/Chickensoft.Introspection.Generator.Tests/test_cases/StaticPropertyIsSkipped.cs @@ -0,0 +1,8 @@ +namespace Chickensoft.Introspection.Generator.Tests.TestCases; + +using Chickensoft.Introspection; + +[Meta] +public partial class StaticPropertyIsSkipped { + public static string Name => "StaticPropertyIsSkipped"; +} diff --git a/Chickensoft.Introspection.Generator/src/TypeGenerator.cs b/Chickensoft.Introspection.Generator/src/TypeGenerator.cs index 4b11807..706f30c 100644 --- a/Chickensoft.Introspection.Generator/src/TypeGenerator.cs +++ b/Chickensoft.Introspection.Generator/src/TypeGenerator.cs @@ -496,6 +496,10 @@ TypeDeclarationSyntax type ) { var properties = ImmutableArray.CreateBuilder(); foreach (var property in type.Members.OfType()) { + if (property.Modifiers.Any(SyntaxKind.StaticKeyword)) { + continue; + } + var propertyAttributes = GetAttributes(property.AttributeLists); // Never identified a situation in which the accessor list is null.