Skip to content

Commit

Permalink
fix: cap filenames
Browse files Browse the repository at this point in the history
  • Loading branch information
jolexxa committed Jun 4, 2024
1 parent 905a913 commit 5cd607f
Show file tree
Hide file tree
Showing 125 changed files with 4,878 additions and 5 deletions.
24 changes: 23 additions & 1 deletion Chickensoft.Introspection.Generator/src/models/DeclaredType.cs
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ namespace Chickensoft.Introspection.Generator.Models;
using System.Collections.Generic;
using System.Collections.Immutable;
using System.Linq;
using System.Security.Cryptography;
using Chickensoft.Introspection.Generator.Utils;
using Microsoft.CodeAnalysis;

Expand Down Expand Up @@ -41,8 +42,29 @@ public sealed record DeclaredType(
ImmutableArray<DeclaredAttribute> Attributes,
ImmutableArray<string> Mixins
) {
private static readonly MD5 _md5 = MD5.Create();
private const int NAME_PORTION = 25;
private const int HASH_PORTION = 10;

/// <summary>Output filename (only works for non-generic types).</summary>
public string Filename => FullNameOpen.Replace('.', '_');
public string Filename {
get {
var name = FullNameOpen.Replace('.', '_');

if (name.Length <= NAME_PORTION + HASH_PORTION) {
return name;
}

// Name is too long, grab last section of the string
var truncated = name.Substring(name.Length - NAME_PORTION);
var hash = _md5.ComputeHash(System.Text.Encoding.UTF8.GetBytes(name));
var hashString = BitConverter.ToString(hash).Replace("-", "");
var hashLast = hashString.Substring(
hashString.Length - HASH_PORTION
);
return $"{truncated}{hashLast}";
}
}

/// <summary>
/// Fully qualified, open generic name, as determined based on syntax nodes
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,52 @@
#pragma warning disable
#nullable enable
namespace Chickensoft.Introspection.Tests;

using Chickensoft.Introspection;
using Moq;
using Shouldly;
using System;
using System.Collections.Generic;
using System.Data;
using System.Linq;
using Xunit;

partial class TypeGraphVersionTest {
partial class Model2 : Chickensoft.Introspection.IIntrospective {
public Chickensoft.Introspection.MixinBlackboard MixinState { get; } = new();

public Chickensoft.Introspection.IMetatype Metatype => ((Chickensoft.Introspection.IIntrospectiveTypeMetadata)Chickensoft.Introspection.Types.Graph.GetMetadata(typeof(Model2))).Metatype;

public class MetatypeMetadata : Chickensoft.Introspection.IMetatype {
public System.Type Type => typeof(Model2);
public bool HasInitProperties { get; } = false;

public System.Collections.Generic.IReadOnlyList<Chickensoft.Introspection.PropertyMetadata> Properties { get; } = new System.Collections.Generic.List<Chickensoft.Introspection.PropertyMetadata>() {
};

public System.Collections.Generic.IReadOnlyDictionary<System.Type, System.Attribute[]> Attributes { get; } = new System.Collections.Generic.Dictionary<System.Type, System.Attribute[]>() {
[typeof(MetaAttribute)] = new System.Attribute[] {
new MetaAttribute()
},
[typeof(VersionAttribute)] = new System.Attribute[] {
new VersionAttribute(2)
}
};

public System.Collections.Generic.IReadOnlyList<System.Type> Mixins { get; } = new System.Collections.Generic.List<System.Type>() {
};

public System.Collections.Generic.IReadOnlyDictionary<System.Type, System.Action<object>> MixinHandlers { get; } = new System.Collections.Generic.Dictionary<System.Type, System.Action<object>>() {
};


public object Construct(System.Collections.Generic.IReadOnlyDictionary<string, object?>? args = null) {
return new Model2();
}
public override bool Equals(object obj) => true;
public override int GetHashCode() => base.GetHashCode();
}
}
}
#nullable restore
#pragma warning restore
Original file line number Diff line number Diff line change
@@ -0,0 +1,52 @@
#pragma warning disable
#nullable enable
namespace Chickensoft.Introspection.Tests;

using Chickensoft.Introspection;
using Moq;
using Shouldly;
using System;
using System.Collections.Generic;
using System.Data;
using System.Linq;
using Xunit;

partial class TypeGraphTest {
partial class SubtypeC : Chickensoft.Introspection.IIntrospective, Chickensoft.Introspection.IIdentifiable {
public Chickensoft.Introspection.MixinBlackboard MixinState { get; } = new();

public Chickensoft.Introspection.IMetatype Metatype => ((Chickensoft.Introspection.IIntrospectiveTypeMetadata)Chickensoft.Introspection.Types.Graph.GetMetadata(typeof(SubtypeC))).Metatype;

public class MetatypeMetadata : Chickensoft.Introspection.IMetatype {
public System.Type Type => typeof(SubtypeC);
public bool HasInitProperties { get; } = false;

public System.Collections.Generic.IReadOnlyList<Chickensoft.Introspection.PropertyMetadata> Properties { get; } = new System.Collections.Generic.List<Chickensoft.Introspection.PropertyMetadata>() {
};

public System.Collections.Generic.IReadOnlyDictionary<System.Type, System.Attribute[]> Attributes { get; } = new System.Collections.Generic.Dictionary<System.Type, System.Attribute[]>() {
[typeof(IdAttribute)] = new System.Attribute[] {
new IdAttribute("test_model_subtype_c")
},
[typeof(MetaAttribute)] = new System.Attribute[] {
new MetaAttribute()
}
};

public System.Collections.Generic.IReadOnlyList<System.Type> Mixins { get; } = new System.Collections.Generic.List<System.Type>() {
};

public System.Collections.Generic.IReadOnlyDictionary<System.Type, System.Action<object>> MixinHandlers { get; } = new System.Collections.Generic.Dictionary<System.Type, System.Action<object>>() {
};


public object Construct(System.Collections.Generic.IReadOnlyDictionary<string, object?>? args = null) {
return new SubtypeC();
}
public override bool Equals(object obj) => true;
public override int GetHashCode() => base.GetHashCode();
}
}
}
#nullable restore
#pragma warning restore
Original file line number Diff line number Diff line change
@@ -0,0 +1,54 @@
#pragma warning disable
#nullable enable
namespace Chickensoft.Introspection.Tests;

using Chickensoft.Introspection;
using Moq;
using Shouldly;
using System;
using System.Collections.Generic;
using System.Data;
using System.Linq;
using Xunit;

partial class TypeGraphTest {
partial class SubtypeA {
partial class SubtypeB : Chickensoft.Introspection.IIntrospective, Chickensoft.Introspection.IIdentifiable {
public Chickensoft.Introspection.MixinBlackboard MixinState { get; } = new();

public Chickensoft.Introspection.IMetatype Metatype => ((Chickensoft.Introspection.IIntrospectiveTypeMetadata)Chickensoft.Introspection.Types.Graph.GetMetadata(typeof(SubtypeB))).Metatype;

public class MetatypeMetadata : Chickensoft.Introspection.IMetatype {
public System.Type Type => typeof(SubtypeB);
public bool HasInitProperties { get; } = false;

public System.Collections.Generic.IReadOnlyList<Chickensoft.Introspection.PropertyMetadata> Properties { get; } = new System.Collections.Generic.List<Chickensoft.Introspection.PropertyMetadata>() {
};

public System.Collections.Generic.IReadOnlyDictionary<System.Type, System.Attribute[]> Attributes { get; } = new System.Collections.Generic.Dictionary<System.Type, System.Attribute[]>() {
[typeof(IdAttribute)] = new System.Attribute[] {
new IdAttribute("test_model_subtype_b")
},
[typeof(MetaAttribute)] = new System.Attribute[] {
new MetaAttribute()
}
};

public System.Collections.Generic.IReadOnlyList<System.Type> Mixins { get; } = new System.Collections.Generic.List<System.Type>() {
};

public System.Collections.Generic.IReadOnlyDictionary<System.Type, System.Action<object>> MixinHandlers { get; } = new System.Collections.Generic.Dictionary<System.Type, System.Action<object>>() {
};


public object Construct(System.Collections.Generic.IReadOnlyDictionary<string, object?>? args = null) {
return new SubtypeB();
}
public override bool Equals(object obj) => true;
public override int GetHashCode() => base.GetHashCode();
}
}
}
}
#nullable restore
#pragma warning restore
Original file line number Diff line number Diff line change
@@ -0,0 +1,46 @@
#pragma warning disable
#nullable enable
namespace Chickensoft.Introspection.Tests;

using Shouldly;
using System;
using Xunit;

partial class MyTypeWithAMixin : Chickensoft.Introspection.IIntrospective, IMixin1, IMixin2 {
public Chickensoft.Introspection.MixinBlackboard MixinState { get; } = new();

public Chickensoft.Introspection.IMetatype Metatype => ((Chickensoft.Introspection.IIntrospectiveTypeMetadata)Chickensoft.Introspection.Types.Graph.GetMetadata(typeof(MyTypeWithAMixin))).Metatype;

public class MetatypeMetadata : Chickensoft.Introspection.IMetatype {
public System.Type Type => typeof(MyTypeWithAMixin);
public bool HasInitProperties { get; } = false;

public System.Collections.Generic.IReadOnlyList<Chickensoft.Introspection.PropertyMetadata> Properties { get; } = new System.Collections.Generic.List<Chickensoft.Introspection.PropertyMetadata>() {
};

public System.Collections.Generic.IReadOnlyDictionary<System.Type, System.Attribute[]> Attributes { get; } = new System.Collections.Generic.Dictionary<System.Type, System.Attribute[]>() {
[typeof(MetaAttribute)] = new System.Attribute[] {
new MetaAttribute(typeof(IMixin1), typeof(IMixin2))
}
};

public System.Collections.Generic.IReadOnlyList<System.Type> Mixins { get; } = new System.Collections.Generic.List<System.Type>() {
typeof(IMixin1),
typeof(IMixin2)
};

public System.Collections.Generic.IReadOnlyDictionary<System.Type, System.Action<object>> MixinHandlers { get; } = new System.Collections.Generic.Dictionary<System.Type, System.Action<object>>() {
[typeof(IMixin1)] = (obj) => ((IMixin1)obj).Handler(),
[typeof(IMixin2)] = (obj) => ((IMixin2)obj).Handler()
};


public object Construct(System.Collections.Generic.IReadOnlyDictionary<string, object?>? args = null) {
return new MyTypeWithAMixin();
}
public override bool Equals(object obj) => true;
public override int GetHashCode() => base.GetHashCode();
}
}
#nullable restore
#pragma warning restore
Original file line number Diff line number Diff line change
@@ -0,0 +1,68 @@
#pragma warning disable
#nullable enable
namespace Chickensoft.Introspection.Tests;

using Chickensoft.Introspection;
using Moq;
using Shouldly;
using System;
using System.Collections.Generic;
using System.Data;
using System.Linq;
using Xunit;

partial class TypeGraphTest {
partial class Model : Chickensoft.Introspection.IIntrospective, Chickensoft.Introspection.IIdentifiable {
public Chickensoft.Introspection.MixinBlackboard MixinState { get; } = new();

public Chickensoft.Introspection.IMetatype Metatype => ((Chickensoft.Introspection.IIntrospectiveTypeMetadata)Chickensoft.Introspection.Types.Graph.GetMetadata(typeof(Model))).Metatype;

public class MetatypeMetadata : Chickensoft.Introspection.IMetatype {
public System.Type Type => typeof(Model);
public bool HasInitProperties { get; } = false;

public System.Collections.Generic.IReadOnlyList<Chickensoft.Introspection.PropertyMetadata> Properties { get; } = new System.Collections.Generic.List<Chickensoft.Introspection.PropertyMetadata>() {
new Chickensoft.Introspection.PropertyMetadata(
Name: "Name",
IsInit: false,
IsRequired: false,
Getter: (object obj) => ((Model)obj).Name,
Setter: (object obj, object? _) => { },
GenericType: new GenericType(
OpenType: typeof(string),
ClosedType: typeof(string),
Arguments: System.Array.Empty<GenericType>(),
GenericTypeGetter: receiver => receiver.Receive<string>(),
GenericTypeGetter2: default
),
Attributes: new System.Collections.Generic.Dictionary<System.Type, System.Attribute[]>() {
}
)
};

public System.Collections.Generic.IReadOnlyDictionary<System.Type, System.Attribute[]> Attributes { get; } = new System.Collections.Generic.Dictionary<System.Type, System.Attribute[]>() {
[typeof(IdAttribute)] = new System.Attribute[] {
new IdAttribute("test_model")
},
[typeof(MetaAttribute)] = new System.Attribute[] {
new MetaAttribute()
}
};

public System.Collections.Generic.IReadOnlyList<System.Type> Mixins { get; } = new System.Collections.Generic.List<System.Type>() {
};

public System.Collections.Generic.IReadOnlyDictionary<System.Type, System.Action<object>> MixinHandlers { get; } = new System.Collections.Generic.Dictionary<System.Type, System.Action<object>>() {
};


public object Construct(System.Collections.Generic.IReadOnlyDictionary<string, object?>? args = null) {
return new Model();
}
public override bool Equals(object obj) => true;
public override int GetHashCode() => base.GetHashCode();
}
}
}
#nullable restore
#pragma warning restore
Original file line number Diff line number Diff line change
@@ -0,0 +1,52 @@
#pragma warning disable
#nullable enable
namespace Chickensoft.Introspection.Tests;

using Chickensoft.Introspection;
using Moq;
using Shouldly;
using System;
using System.Collections.Generic;
using System.Data;
using System.Linq;
using Xunit;

partial class TypeGraphVersionTest {
partial class Model : Chickensoft.Introspection.IIntrospective, Chickensoft.Introspection.IIdentifiable {
public Chickensoft.Introspection.MixinBlackboard MixinState { get; } = new();

public Chickensoft.Introspection.IMetatype Metatype => ((Chickensoft.Introspection.IIntrospectiveTypeMetadata)Chickensoft.Introspection.Types.Graph.GetMetadata(typeof(Model))).Metatype;

public class MetatypeMetadata : Chickensoft.Introspection.IMetatype {
public System.Type Type => typeof(Model);
public bool HasInitProperties { get; } = false;

public System.Collections.Generic.IReadOnlyList<Chickensoft.Introspection.PropertyMetadata> Properties { get; } = new System.Collections.Generic.List<Chickensoft.Introspection.PropertyMetadata>() {
};

public System.Collections.Generic.IReadOnlyDictionary<System.Type, System.Attribute[]> Attributes { get; } = new System.Collections.Generic.Dictionary<System.Type, System.Attribute[]>() {
[typeof(IdAttribute)] = new System.Attribute[] {
new IdAttribute("version_test_model")
},
[typeof(MetaAttribute)] = new System.Attribute[] {
new MetaAttribute()
}
};

public System.Collections.Generic.IReadOnlyList<System.Type> Mixins { get; } = new System.Collections.Generic.List<System.Type>() {
};

public System.Collections.Generic.IReadOnlyDictionary<System.Type, System.Action<object>> MixinHandlers { get; } = new System.Collections.Generic.Dictionary<System.Type, System.Action<object>>() {
};


public object Construct(System.Collections.Generic.IReadOnlyDictionary<string, object?>? args = null) {
throw new System.NotImplementedException("Model is not instantiable.");
}
public override bool Equals(object obj) => true;
public override int GetHashCode() => base.GetHashCode();
}
}
}
#nullable restore
#pragma warning restore
Loading

0 comments on commit 5cd607f

Please sign in to comment.