From 4628c2dc0a6c1c8e853ff270b5d193c7b3388b4a Mon Sep 17 00:00:00 2001 From: Brandon Thetford Date: Wed, 1 May 2024 20:33:24 -0700 Subject: [PATCH] Remove unplanned EnumMEmberCombinationsGenerator --- .../CombinationGroupingAttribute.cs | 22 --- ...GenerateEnumMemberCombinationsAttribute.cs | 110 --------------- .../EnumMemberCombinationsGenerator.cs | 130 ------------------ 3 files changed, 262 deletions(-) delete mode 100644 Analyzers/Terminal.Gui.Analyzers.Internal/Attributes/CombinationGroupingAttribute.cs delete mode 100644 Analyzers/Terminal.Gui.Analyzers.Internal/Attributes/GenerateEnumMemberCombinationsAttribute.cs delete mode 100644 Analyzers/Terminal.Gui.Analyzers.Internal/Generators/EnumExtensions/EnumMemberCombinationsGenerator.cs diff --git a/Analyzers/Terminal.Gui.Analyzers.Internal/Attributes/CombinationGroupingAttribute.cs b/Analyzers/Terminal.Gui.Analyzers.Internal/Attributes/CombinationGroupingAttribute.cs deleted file mode 100644 index 22d8eafd3..000000000 --- a/Analyzers/Terminal.Gui.Analyzers.Internal/Attributes/CombinationGroupingAttribute.cs +++ /dev/null @@ -1,22 +0,0 @@ -using System; -using JetBrains.Annotations; - -namespace Terminal.Gui.Analyzers.Internal.Attributes; - -/// -/// Designates an enum member for inclusion in generation of bitwise combinations with other members decorated with -/// this attribute which have the same value.
-///
-/// -/// This attribute is only considered for members of enum types which have the -/// . -/// -[AttributeUsage (AttributeTargets.Field)] -[UsedImplicitly] -internal sealed class CombinationGroupingAttribute : Attribute -{ - /// - /// Name of a group this member participates in, for FastHasFlags. - /// - public string GroupTag { get; set; } -} diff --git a/Analyzers/Terminal.Gui.Analyzers.Internal/Attributes/GenerateEnumMemberCombinationsAttribute.cs b/Analyzers/Terminal.Gui.Analyzers.Internal/Attributes/GenerateEnumMemberCombinationsAttribute.cs deleted file mode 100644 index 77d0c13a2..000000000 --- a/Analyzers/Terminal.Gui.Analyzers.Internal/Attributes/GenerateEnumMemberCombinationsAttribute.cs +++ /dev/null @@ -1,110 +0,0 @@ -// ReSharper disable RedundantUsingDirective - -using System; -using JetBrains.Annotations; -using Terminal.Gui.Analyzers.Internal.Compatibility; - -namespace Terminal.Gui.Analyzers.Internal.Attributes; - -/// -/// Designates an enum member for inclusion in generation of bitwise combinations with other members decorated with -/// this attribute which have the same value.
-///
-/// -/// -/// This attribute is only considered for enum types with the . -/// -/// -[AttributeUsage (AttributeTargets.Enum)] -[UsedImplicitly] -public sealed class GenerateEnumMemberCombinationsAttribute : System.Attribute -{ - private const byte MaximumPopCountLimit = 14; - private uint _mask; - private uint _maskPopCount; - private byte _popCountLimit = 8; - /// - public string GroupTag { get; set; } - - /// - /// The mask for the group defined in - /// - public uint Mask - { - get => _mask; - set - { -#if NET8_0_OR_GREATER - _maskPopCount = uint.PopCount (value); -#else - _maskPopCount = value.GetPopCount (); -#endif - PopCountLimitExceeded = _maskPopCount > PopCountLimit; - MaximumPopCountLimitExceeded = _maskPopCount > MaximumPopCountLimit; - - if (PopCountLimitExceeded || MaximumPopCountLimitExceeded) - { - return; - } - - _mask = value; - } - } - - /// - /// The maximum number of bits allowed to be set to 1 in . - /// - /// - /// - /// Default: 8 (256 possible combinations) - /// - /// - /// Increasing this value is not recommended!
- /// Decreasing this value is pointless unless you want to limit maximum possible generated combinations even - /// further. - ///
- /// - /// If the result of () exceeds 2 ^ - /// , no - /// combinations will be generated for the members which otherwise would have been included by . - /// Values exceeding the actual population count of have no effect. - /// - /// - /// This option is set to a sane default of 8, but also has a hard-coded limit of 14 (16384 combinations), as a - /// protection against generation of extremely large files. - /// - /// - /// CAUTION: The maximum number of possible combinations possible is equal to 1 << - /// (). - /// See for hard-coded limit, - /// - ///
- public byte PopCountLimit - { - get => _popCountLimit; - set - { -#if NET8_0_OR_GREATER - _maskPopCount = uint.PopCount (_mask); -#else - _maskPopCount = _mask.GetPopCount (); -#endif - - PopCountLimitExceeded = _maskPopCount > value; - MaximumPopCountLimitExceeded = _maskPopCount > MaximumPopCountLimit; - - if (PopCountLimitExceeded || MaximumPopCountLimitExceeded) - { - return; - } - - _mask = value; - _popCountLimit = value; - } - } - - [UsedImplicitly] - internal bool MaximumPopCountLimitExceeded { get; private set; } - [UsedImplicitly] - internal bool PopCountLimitExceeded { get; private set; } -} diff --git a/Analyzers/Terminal.Gui.Analyzers.Internal/Generators/EnumExtensions/EnumMemberCombinationsGenerator.cs b/Analyzers/Terminal.Gui.Analyzers.Internal/Generators/EnumExtensions/EnumMemberCombinationsGenerator.cs deleted file mode 100644 index 82753d078..000000000 --- a/Analyzers/Terminal.Gui.Analyzers.Internal/Generators/EnumExtensions/EnumMemberCombinationsGenerator.cs +++ /dev/null @@ -1,130 +0,0 @@ -using System.Text; -using Microsoft.CodeAnalysis; -using Microsoft.CodeAnalysis.Text; -using Terminal.Gui.Analyzers.Internal.Attributes; -using Terminal.Gui.Analyzers.Internal.Constants; - -namespace Terminal.Gui.Analyzers.Internal.Generators.EnumExtensions; - -/// -/// Implementation of for types decorated with . -/// -[Generator] -internal sealed class EnumMemberCombinationsGenerator : IIncrementalGenerator -{ - private const string AttributeCodeText = $$""" - {{Strings.Templates.StandardHeader}} - - namespace {{Strings.AnalyzersAttributesNamespace}}; - - /// - /// Designates an enum member for inclusion in generation of bitwise combinations with other members decorated with - /// this attribute which have the same value.
- ///
- /// - /// - /// This attribute is only considered for enum types with the . - /// - /// - /// Masks with more than 8 bits set will - /// - /// - [AttributeUsageAttribute(AttributeTargets.Enum)] - internal sealed class {{nameof (GenerateEnumMemberCombinationsAttribute)}} : System.Attribute - { - public const byte MaximumPopCountLimit = 14; - private uint _mask; - private uint _maskPopCount; - private byte _popCountLimit = 8; - public required string GroupTag { get; set; } - - public required uint Mask - { - get => _mask; - set - { - _maskPopCount = uint.PopCount(value); - - PopCountLimitExceeded = _maskPopCount > PopCountLimit; - MaximumPopCountLimitExceeded = _maskPopCount > MaximumPopCountLimit; - - if (PopCountLimitExceeded || MaximumPopCountLimitExceeded) - { - return; - } - - _mask = value; - } - } - - /// - /// The maximum number of bits allowed to be set to 1 in . - /// - /// - /// - /// Default: 8 (256 possible combinations) - /// - /// - /// Increasing this value is not recommended!
- /// Decreasing this value is pointless unless you want to limit maximum possible generated combinations even - /// further. - ///
- /// - /// If the result of () exceeds 2 ^ , no - /// combinations will be generated for the members which otherwise would have been included by . - /// Values exceeding the actual population count of have no effect. - /// - /// - /// This option is set to a sane default of 8, but also has a hard-coded limit of 14 (16384 combinations), as a - /// protection against generation of extremely large files. - /// - /// - /// CAUTION: The maximum number of possible combinations possible is equal to 1 << - /// (). - /// See for hard-coded limit, - /// - ///
- public byte PopCountLimit - { - get => _popCountLimit; - set - { - _maskPopCount = uint.PopCount(_mask); - - PopCountLimitExceeded = _maskPopCount > value; - MaximumPopCountLimitExceeded = _maskPopCount > MaximumPopCountLimit; - - if (PopCountLimitExceeded || MaximumPopCountLimitExceeded) - { - return; - } - - _mask = value; - _popCountLimit = value; - } - } - - internal bool MaximumPopCountLimitExceeded { get; private set; } - internal bool PopCountLimitExceeded { get; private set; } - } - - """; - - private const string AttributeFullyQualifiedName = $"{Strings.AnalyzersAttributesNamespace}.{AttributeName}"; - private const string AttributeName = "GenerateEnumMemberCombinationsAttribute"; - - /// - public void Initialize (IncrementalGeneratorInitializationContext context) - { - context.RegisterPostInitializationOutput (GenerateAttributeCode); - - return; - - static void GenerateAttributeCode (IncrementalGeneratorPostInitializationContext initContext) - { -#pragma warning disable IDE0061 // Use expression body for local function - initContext.AddSource ($"{AttributeFullyQualifiedName}.g.cs", SourceText.From (AttributeCodeText, Encoding.UTF8)); -#pragma warning restore IDE0061 // Use expression body for local function - } - } -}