From 0578ecf9418b3166b8067b699e9f1ee49383c028 Mon Sep 17 00:00:00 2001 From: Brandon Thetford Date: Sun, 28 Apr 2024 10:34:50 -0700 Subject: [PATCH 01/23] Add Directory.build.props for the Analyzers directory tree --- Analyzers/Directory.build.props | 17 +++++++++++++++++ 1 file changed, 17 insertions(+) create mode 100644 Analyzers/Directory.build.props diff --git a/Analyzers/Directory.build.props b/Analyzers/Directory.build.props new file mode 100644 index 000000000..b4767dc87 --- /dev/null +++ b/Analyzers/Directory.build.props @@ -0,0 +1,17 @@ + + + enable + latest-recommended + 7 + UTF-8 + true + true + $(DefineConstants);JETBRAINS_ANNOTATIONS;CONTRACTS_FULL;CODE_ANALYSIS + + + + + + + + \ No newline at end of file From 1ee8d33d14b9d479655f8a6e15947c6f340b6e30 Mon Sep 17 00:00:00 2001 From: Brandon Thetford Date: Sun, 28 Apr 2024 10:48:20 -0700 Subject: [PATCH 02/23] Solution file cleanup Remove unnecessary platform target (explicit x86 is useless here) Remove monodevelop settings. They didn't match anyway and VSCode is a thing and supports .editorconfig. --- Terminal.sln | 60 +++++++++------------------------------------------- 1 file changed, 10 insertions(+), 50 deletions(-) diff --git a/Terminal.sln b/Terminal.sln index 8f06e5fd6..cb0800437 100644 --- a/Terminal.sln +++ b/Terminal.sln @@ -33,49 +33,39 @@ EndProject Global GlobalSection(SolutionConfigurationPlatforms) = preSolution Debug|Any CPU = Debug|Any CPU - Debug|x86 = Debug|x86 Release|Any CPU = Release|Any CPU - Release|x86 = Release|x86 EndGlobalSection GlobalSection(ProjectConfigurationPlatforms) = postSolution {00F366F8-DEE4-482C-B9FD-6DB0200B79E5}.Debug|Any CPU.ActiveCfg = Debug|Any CPU {00F366F8-DEE4-482C-B9FD-6DB0200B79E5}.Debug|Any CPU.Build.0 = Debug|Any CPU - {00F366F8-DEE4-482C-B9FD-6DB0200B79E5}.Debug|x86.ActiveCfg = Debug|Any CPU - {00F366F8-DEE4-482C-B9FD-6DB0200B79E5}.Debug|x86.Build.0 = Debug|Any CPU {00F366F8-DEE4-482C-B9FD-6DB0200B79E5}.Release|Any CPU.ActiveCfg = Release|Any CPU {00F366F8-DEE4-482C-B9FD-6DB0200B79E5}.Release|Any CPU.Build.0 = Release|Any CPU - {00F366F8-DEE4-482C-B9FD-6DB0200B79E5}.Release|x86.ActiveCfg = Release|Any CPU - {00F366F8-DEE4-482C-B9FD-6DB0200B79E5}.Release|x86.Build.0 = Release|Any CPU {88979F89-9A42-448F-AE3E-3060145F6375}.Debug|Any CPU.ActiveCfg = Debug|Any CPU {88979F89-9A42-448F-AE3E-3060145F6375}.Debug|Any CPU.Build.0 = Debug|Any CPU - {88979F89-9A42-448F-AE3E-3060145F6375}.Debug|x86.ActiveCfg = Debug|Any CPU - {88979F89-9A42-448F-AE3E-3060145F6375}.Debug|x86.Build.0 = Debug|Any CPU {88979F89-9A42-448F-AE3E-3060145F6375}.Release|Any CPU.ActiveCfg = Release|Any CPU {88979F89-9A42-448F-AE3E-3060145F6375}.Release|Any CPU.Build.0 = Release|Any CPU - {88979F89-9A42-448F-AE3E-3060145F6375}.Release|x86.ActiveCfg = Release|Any CPU - {88979F89-9A42-448F-AE3E-3060145F6375}.Release|x86.Build.0 = Release|Any CPU {8B901EDE-8974-4820-B100-5226917E2990}.Debug|Any CPU.ActiveCfg = Debug|Any CPU {8B901EDE-8974-4820-B100-5226917E2990}.Debug|Any CPU.Build.0 = Debug|Any CPU - {8B901EDE-8974-4820-B100-5226917E2990}.Debug|x86.ActiveCfg = Debug|Any CPU - {8B901EDE-8974-4820-B100-5226917E2990}.Debug|x86.Build.0 = Debug|Any CPU {8B901EDE-8974-4820-B100-5226917E2990}.Release|Any CPU.ActiveCfg = Release|Any CPU {8B901EDE-8974-4820-B100-5226917E2990}.Release|Any CPU.Build.0 = Release|Any CPU - {8B901EDE-8974-4820-B100-5226917E2990}.Release|x86.ActiveCfg = Release|Any CPU - {8B901EDE-8974-4820-B100-5226917E2990}.Release|x86.Build.0 = Release|Any CPU {44E15B48-0DB2-4560-82BD-D3B7989811C3}.Debug|Any CPU.ActiveCfg = Debug|Any CPU {44E15B48-0DB2-4560-82BD-D3B7989811C3}.Debug|Any CPU.Build.0 = Debug|Any CPU - {44E15B48-0DB2-4560-82BD-D3B7989811C3}.Debug|x86.ActiveCfg = Debug|Any CPU - {44E15B48-0DB2-4560-82BD-D3B7989811C3}.Debug|x86.Build.0 = Debug|Any CPU {44E15B48-0DB2-4560-82BD-D3B7989811C3}.Release|Any CPU.ActiveCfg = Release|Any CPU {44E15B48-0DB2-4560-82BD-D3B7989811C3}.Release|Any CPU.Build.0 = Release|Any CPU - {44E15B48-0DB2-4560-82BD-D3B7989811C3}.Release|x86.ActiveCfg = Release|Any CPU - {44E15B48-0DB2-4560-82BD-D3B7989811C3}.Release|x86.Build.0 = Release|Any CPU {B0A602CD-E176-449D-8663-64238D54F857}.Debug|Any CPU.ActiveCfg = Debug|Any CPU {B0A602CD-E176-449D-8663-64238D54F857}.Debug|Any CPU.Build.0 = Debug|Any CPU - {B0A602CD-E176-449D-8663-64238D54F857}.Debug|x86.ActiveCfg = Debug|Any CPU - {B0A602CD-E176-449D-8663-64238D54F857}.Debug|x86.Build.0 = Debug|Any CPU {B0A602CD-E176-449D-8663-64238D54F857}.Release|Any CPU.ActiveCfg = Release|Any CPU {B0A602CD-E176-449D-8663-64238D54F857}.Release|Any CPU.Build.0 = Release|Any CPU + EndGlobalSection + GlobalSection(SolutionProperties) = preSolution + HideSolutionNode = FALSE + EndGlobalSection + GlobalSection(ExtensibilityGlobals) = postSolution + SolutionGuid = {9F8F8A4D-7B8D-4C2A-AC5E-CD7117F74C03} + EndGlobalSection +EndGlobal +CPU.ActiveCfg = Release|Any CPU + {B0A602CD-E176-449D-8663-64238D54F857}.Release|Any CPU.Build.0 = Release|Any CPU {B0A602CD-E176-449D-8663-64238D54F857}.Release|x86.ActiveCfg = Release|Any CPU {B0A602CD-E176-449D-8663-64238D54F857}.Release|x86.Build.0 = Release|Any CPU EndGlobalSection @@ -85,34 +75,4 @@ Global GlobalSection(ExtensibilityGlobals) = postSolution SolutionGuid = {9F8F8A4D-7B8D-4C2A-AC5E-CD7117F74C03} EndGlobalSection - GlobalSection(MonoDevelopProperties) = preSolution - Policies = $0 - $0.TextStylePolicy = $1 - $1.FileWidth = 80 - $1.scope = text/x-csharp - $1.TabWidth = 8 - $1.IndentWidth = 8 - $0.CSharpFormattingPolicy = $2 - $2.scope = text/x-csharp - $2.IndentSwitchSection = False - $2.NewLinesForBracesInTypes = False - $2.NewLinesForBracesInProperties = False - $2.NewLinesForBracesInAccessors = False - $2.NewLinesForBracesInAnonymousMethods = False - $2.NewLinesForBracesInControlBlocks = False - $2.NewLinesForBracesInAnonymousTypes = False - $2.NewLinesForBracesInObjectCollectionArrayInitializers = False - $2.NewLinesForBracesInLambdaExpressionBody = False - $2.NewLineForElse = False - $2.NewLineForCatch = False - $2.NewLineForFinally = False - $2.NewLineForMembersInObjectInit = False - $2.NewLineForMembersInAnonymousTypes = False - $2.NewLineForClausesInQuery = False - $2.SpacingAfterMethodDeclarationName = True - $2.SpaceAfterMethodCallName = True - $2.SpaceBeforeOpenSquareBracket = True - $0.DotNetNamingPolicy = $3 - $0.StandardHeader = $4 - EndGlobalSection EndGlobal From 69362a76a5cbc042172ab49015c8b6f9908fa068 Mon Sep 17 00:00:00 2001 From: Brandon Thetford Date: Sun, 28 Apr 2024 10:48:46 -0700 Subject: [PATCH 03/23] Ensure this doesn't come through as a build asset. --- Terminal.Gui/Terminal.Gui.csproj | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/Terminal.Gui/Terminal.Gui.csproj b/Terminal.Gui/Terminal.Gui.csproj index 3c909c250..ecfa82cd3 100644 --- a/Terminal.Gui/Terminal.Gui.csproj +++ b/Terminal.Gui/Terminal.Gui.csproj @@ -1,4 +1,4 @@ - + @@ -45,7 +45,7 @@ - + From c23c32c7d09609f2fe362b620e577b710893663c Mon Sep 17 00:00:00 2001 From: Brandon Thetford Date: Sun, 28 Apr 2024 10:53:29 -0700 Subject: [PATCH 04/23] A couple more common elements to add to this --- Analyzers/Directory.build.props | 2 ++ 1 file changed, 2 insertions(+) diff --git a/Analyzers/Directory.build.props b/Analyzers/Directory.build.props index b4767dc87..d2e12980a 100644 --- a/Analyzers/Directory.build.props +++ b/Analyzers/Directory.build.props @@ -7,6 +7,8 @@ true true $(DefineConstants);JETBRAINS_ANNOTATIONS;CONTRACTS_FULL;CODE_ANALYSIS + True + True From 82a9afaabe9fa04fafd9f0250b6a0cf36fdbf890 Mon Sep 17 00:00:00 2001 From: Brandon Thetford Date: Sun, 28 Apr 2024 10:55:20 -0700 Subject: [PATCH 05/23] Remove elements that are no longer needed because of Directory.build.props --- ...rminal.Gui.Analyzers.Internal.Debugging.csproj | 1 - .../Terminal.Gui.Analyzers.Internal.Tests.csproj | 3 --- .../Terminal.Gui.Analyzers.Internal.csproj | 15 --------------- 3 files changed, 19 deletions(-) diff --git a/Analyzers/Terminal.Gui.Analyzers.Internal.Debugging/Terminal.Gui.Analyzers.Internal.Debugging.csproj b/Analyzers/Terminal.Gui.Analyzers.Internal.Debugging/Terminal.Gui.Analyzers.Internal.Debugging.csproj index 03b5cf379..3cad5995b 100644 --- a/Analyzers/Terminal.Gui.Analyzers.Internal.Debugging/Terminal.Gui.Analyzers.Internal.Debugging.csproj +++ b/Analyzers/Terminal.Gui.Analyzers.Internal.Debugging/Terminal.Gui.Analyzers.Internal.Debugging.csproj @@ -4,7 +4,6 @@ Exe net8.0 enable - enable diff --git a/Analyzers/Terminal.Gui.Analyzers.Internal.Tests/Terminal.Gui.Analyzers.Internal.Tests.csproj b/Analyzers/Terminal.Gui.Analyzers.Internal.Tests/Terminal.Gui.Analyzers.Internal.Tests.csproj index 4020bd357..57846424a 100644 --- a/Analyzers/Terminal.Gui.Analyzers.Internal.Tests/Terminal.Gui.Analyzers.Internal.Tests.csproj +++ b/Analyzers/Terminal.Gui.Analyzers.Internal.Tests/Terminal.Gui.Analyzers.Internal.Tests.csproj @@ -4,15 +4,12 @@ net8.0 enable 12 - enable false true true - True portable $(DefineConstants);JETBRAINS_ANNOTATIONS;CONTRACTS_FULL;CODE_ANALYSIS enable - True true diff --git a/Analyzers/Terminal.Gui.Analyzers.Internal/Terminal.Gui.Analyzers.Internal.csproj b/Analyzers/Terminal.Gui.Analyzers.Internal/Terminal.Gui.Analyzers.Internal.csproj index 1b7ecaf9b..d1bde776f 100644 --- a/Analyzers/Terminal.Gui.Analyzers.Internal/Terminal.Gui.Analyzers.Internal.csproj +++ b/Analyzers/Terminal.Gui.Analyzers.Internal/Terminal.Gui.Analyzers.Internal.csproj @@ -11,21 +11,14 @@ Library 12 - enable Terminal.Gui.Analyzers.Internal disable true true True - latest-recommended - 7 - UTF-8 true - true true - true true - $(DefineConstants);JETBRAINS_ANNOTATIONS;CONTRACTS_FULL;CODE_ANALYSIS True true true @@ -87,12 +80,4 @@ - - - - - - - - From b8d51bce346a9f484e1cafb3858212140b59f627 Mon Sep 17 00:00:00 2001 From: Brandon Thetford Date: Sun, 28 Apr 2024 10:57:09 -0700 Subject: [PATCH 06/23] Add solution folder for Analyzers And let VS finish cleaning some old config out too... --- Terminal.sln | 11 +++++++---- 1 file changed, 7 insertions(+), 4 deletions(-) diff --git a/Terminal.sln b/Terminal.sln index cb0800437..1c7a48c76 100644 --- a/Terminal.sln +++ b/Terminal.sln @@ -30,6 +30,8 @@ Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "Solution Items", "Solution testenvironments.json = testenvironments.json EndProjectSection EndProject +Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "Analyzers", "Analyzers", "{CCADA0BC-61CF-4B4B-96BA-A3B0C0A7F54D}" +EndProject Global GlobalSection(SolutionConfigurationPlatforms) = preSolution Debug|Any CPU = Debug|Any CPU @@ -64,10 +66,7 @@ Global SolutionGuid = {9F8F8A4D-7B8D-4C2A-AC5E-CD7117F74C03} EndGlobalSection EndGlobal -CPU.ActiveCfg = Release|Any CPU - {B0A602CD-E176-449D-8663-64238D54F857}.Release|Any CPU.Build.0 = Release|Any CPU - {B0A602CD-E176-449D-8663-64238D54F857}.Release|x86.ActiveCfg = Release|Any CPU - {B0A602CD-E176-449D-8663-64238D54F857}.Release|x86.Build.0 = Release|Any CPU +uild.0 = Release|Any CPU EndGlobalSection GlobalSection(SolutionProperties) = preSolution HideSolutionNode = FALSE @@ -76,3 +75,7 @@ CPU.ActiveCfg = Release|Any CPU SolutionGuid = {9F8F8A4D-7B8D-4C2A-AC5E-CD7117F74C03} EndGlobalSection EndGlobal +nsibilityGlobals) = postSolution + SolutionGuid = {9F8F8A4D-7B8D-4C2A-AC5E-CD7117F74C03} + EndGlobalSection +EndGlobal From 762ae31f0544fcdb468818cdea3599da0c7da0c4 Mon Sep 17 00:00:00 2001 From: Brandon Thetford Date: Sun, 28 Apr 2024 11:02:27 -0700 Subject: [PATCH 07/23] Cleanup for this project file Don't need the conditional includes since it has to be netstandard2.0 Consolidate sections after removing that. Correct and clarify the comment up top for current state of the csproj --- .../Terminal.Gui.Analyzers.Internal.csproj | 47 +++++++------------ 1 file changed, 18 insertions(+), 29 deletions(-) diff --git a/Analyzers/Terminal.Gui.Analyzers.Internal/Terminal.Gui.Analyzers.Internal.csproj b/Analyzers/Terminal.Gui.Analyzers.Internal/Terminal.Gui.Analyzers.Internal.csproj index d1bde776f..f63bacf78 100644 --- a/Analyzers/Terminal.Gui.Analyzers.Internal/Terminal.Gui.Analyzers.Internal.csproj +++ b/Analyzers/Terminal.Gui.Analyzers.Internal/Terminal.Gui.Analyzers.Internal.csproj @@ -1,9 +1,9 @@  netstandard2.0 @@ -32,36 +32,22 @@ - - - - - $(NoWarn);nullable;CA1067 - - - - - - - - - - - - - - - - - - - - + + + $(NoWarn);nullable;CA1067 + + + + + + + + - + - + @@ -79,5 +65,8 @@ + + + From 60242a252a7535f9f4dbf2dde854ff624884f024 Mon Sep 17 00:00:00 2001 From: Brandon Thetford Date: Sun, 28 Apr 2024 11:03:03 -0700 Subject: [PATCH 08/23] Add analyzer project to solution (but not referenced by Terminal.Gui yet) --- Terminal.sln | 22 +++++++++------------- 1 file changed, 9 insertions(+), 13 deletions(-) diff --git a/Terminal.sln b/Terminal.sln index 1c7a48c76..89ad7003e 100644 --- a/Terminal.sln +++ b/Terminal.sln @@ -32,7 +32,12 @@ Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "Solution Items", "Solution EndProject Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "Analyzers", "Analyzers", "{CCADA0BC-61CF-4B4B-96BA-A3B0C0A7F54D}" EndProject +Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "Terminal.Gui.Analyzers.Internal", "Analyzers\Terminal.Gui.Analyzers.Internal\Terminal.Gui.Analyzers.Internal.csproj", "{5DE91722-8765-4E2B-97E4-2A18010B5CED}" +EndProject Global + GlobalSection(NestedProjects) = preSolution + {5DE91722-8765-4E2B-97E4-2A18010B5CED} = {CCADA0BC-61CF-4B4B-96BA-A3B0C0A7F54D} + EndGlobalSection GlobalSection(SolutionConfigurationPlatforms) = preSolution Debug|Any CPU = Debug|Any CPU Release|Any CPU = Release|Any CPU @@ -42,6 +47,10 @@ Global {00F366F8-DEE4-482C-B9FD-6DB0200B79E5}.Debug|Any CPU.Build.0 = Debug|Any CPU {00F366F8-DEE4-482C-B9FD-6DB0200B79E5}.Release|Any CPU.ActiveCfg = Release|Any CPU {00F366F8-DEE4-482C-B9FD-6DB0200B79E5}.Release|Any CPU.Build.0 = Release|Any CPU + {5DE91722-8765-4E2B-97E4-2A18010B5CED}.Debug|Any CPU.ActiveCfg = Debug|Any CPU + {5DE91722-8765-4E2B-97E4-2A18010B5CED}.Debug|Any CPU.Build.0 = Debug|Any CPU + {5DE91722-8765-4E2B-97E4-2A18010B5CED}.Release|Any CPU.ActiveCfg = Release|Any CPU + {5DE91722-8765-4E2B-97E4-2A18010B5CED}.Release|Any CPU.Build.0 = Release|Any CPU {88979F89-9A42-448F-AE3E-3060145F6375}.Debug|Any CPU.ActiveCfg = Debug|Any CPU {88979F89-9A42-448F-AE3E-3060145F6375}.Debug|Any CPU.Build.0 = Debug|Any CPU {88979F89-9A42-448F-AE3E-3060145F6375}.Release|Any CPU.ActiveCfg = Release|Any CPU @@ -66,16 +75,3 @@ Global SolutionGuid = {9F8F8A4D-7B8D-4C2A-AC5E-CD7117F74C03} EndGlobalSection EndGlobal -uild.0 = Release|Any CPU - EndGlobalSection - GlobalSection(SolutionProperties) = preSolution - HideSolutionNode = FALSE - EndGlobalSection - GlobalSection(ExtensibilityGlobals) = postSolution - SolutionGuid = {9F8F8A4D-7B8D-4C2A-AC5E-CD7117F74C03} - EndGlobalSection -EndGlobal -nsibilityGlobals) = postSolution - SolutionGuid = {9F8F8A4D-7B8D-4C2A-AC5E-CD7117F74C03} - EndGlobalSection -EndGlobal From c9297372b3a5e7004ec0cbfa0e0fc3c834dde402 Mon Sep 17 00:00:00 2001 From: Brandon Thetford Date: Sun, 28 Apr 2024 11:04:28 -0700 Subject: [PATCH 09/23] Add analyzer test project to solution --- Terminal.sln | 7 +++++++ 1 file changed, 7 insertions(+) diff --git a/Terminal.sln b/Terminal.sln index 89ad7003e..c4e9b016b 100644 --- a/Terminal.sln +++ b/Terminal.sln @@ -34,9 +34,12 @@ Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "Analyzers", "Analyzers", "{ EndProject Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "Terminal.Gui.Analyzers.Internal", "Analyzers\Terminal.Gui.Analyzers.Internal\Terminal.Gui.Analyzers.Internal.csproj", "{5DE91722-8765-4E2B-97E4-2A18010B5CED}" EndProject +Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "Terminal.Gui.Analyzers.Internal.Tests", "Analyzers\Terminal.Gui.Analyzers.Internal.Tests\Terminal.Gui.Analyzers.Internal.Tests.csproj", "{715DB4BA-F989-4DF6-B46F-5ED26A32B2DD}" +EndProject Global GlobalSection(NestedProjects) = preSolution {5DE91722-8765-4E2B-97E4-2A18010B5CED} = {CCADA0BC-61CF-4B4B-96BA-A3B0C0A7F54D} + {715DB4BA-F989-4DF6-B46F-5ED26A32B2DD} = {CCADA0BC-61CF-4B4B-96BA-A3B0C0A7F54D} EndGlobalSection GlobalSection(SolutionConfigurationPlatforms) = preSolution Debug|Any CPU = Debug|Any CPU @@ -51,6 +54,10 @@ Global {5DE91722-8765-4E2B-97E4-2A18010B5CED}.Debug|Any CPU.Build.0 = Debug|Any CPU {5DE91722-8765-4E2B-97E4-2A18010B5CED}.Release|Any CPU.ActiveCfg = Release|Any CPU {5DE91722-8765-4E2B-97E4-2A18010B5CED}.Release|Any CPU.Build.0 = Release|Any CPU + {715DB4BA-F989-4DF6-B46F-5ED26A32B2DD}.Debug|Any CPU.ActiveCfg = Debug|Any CPU + {715DB4BA-F989-4DF6-B46F-5ED26A32B2DD}.Debug|Any CPU.Build.0 = Debug|Any CPU + {715DB4BA-F989-4DF6-B46F-5ED26A32B2DD}.Release|Any CPU.ActiveCfg = Release|Any CPU + {715DB4BA-F989-4DF6-B46F-5ED26A32B2DD}.Release|Any CPU.Build.0 = Release|Any CPU {88979F89-9A42-448F-AE3E-3060145F6375}.Debug|Any CPU.ActiveCfg = Debug|Any CPU {88979F89-9A42-448F-AE3E-3060145F6375}.Debug|Any CPU.Build.0 = Debug|Any CPU {88979F89-9A42-448F-AE3E-3060145F6375}.Release|Any CPU.ActiveCfg = Release|Any CPU From 8d5e35fbbe67e5f1289b821667366826370ee8eb Mon Sep 17 00:00:00 2001 From: Brandon Thetford Date: Sun, 28 Apr 2024 11:45:59 -0700 Subject: [PATCH 10/23] Add references for annotations --- Analyzers/Directory.build.props | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/Analyzers/Directory.build.props b/Analyzers/Directory.build.props index d2e12980a..f399c85e0 100644 --- a/Analyzers/Directory.build.props +++ b/Analyzers/Directory.build.props @@ -10,6 +10,10 @@ True True + + + + From c5c7f4f4637847576fef9560cdf590a5377b1526 Mon Sep 17 00:00:00 2001 From: Brandon Thetford Date: Sun, 28 Apr 2024 11:47:03 -0700 Subject: [PATCH 11/23] Some improvements to the powershell modules Make open-solution more reliable. Add some variables that will get used various other places --- Scripts/Terminal.Gui.PowerShell.Core.psm1 | 21 +++++++++++++++++---- 1 file changed, 17 insertions(+), 4 deletions(-) diff --git a/Scripts/Terminal.Gui.PowerShell.Core.psm1 b/Scripts/Terminal.Gui.PowerShell.Core.psm1 index 1c1574e74..b3e1c6900 100644 --- a/Scripts/Terminal.Gui.PowerShell.Core.psm1 +++ b/Scripts/Terminal.Gui.PowerShell.Core.psm1 @@ -14,17 +14,18 @@ Function Open-Solution { [CmdletBinding()] param( [Parameter(Mandatory=$false, HelpMessage="The path to the solution file to open.")] - [Uri]$SolutionFilePath = (Resolve-Path "../Terminal.sln") + [ValidatePattern(".*Terminal\.sln" )] + [string]$Path = $SolutionFilePath ) if(!$IsWindows) { [string]$warningMessage = "The Open-Solution cmdlet is only supported on Windows.`n` - Attempt to open file $SolutionFilePath with the system default handler?" + Attempt to open file $Path with the system default handler?" Write-Warning $warningMessage -WarningAction Inquire } - Invoke-Item $SolutionFilePath + Invoke-Item $Path return } @@ -62,6 +63,13 @@ Function Set-PowerShellEnvironment { [CmdletBinding()] param() + # Set up some common globals + New-Variable -Name ScriptsDirectory -Value $PSScriptRoot -Option ReadOnly -Scope Global -Visibility Public + New-Variable -Name RepositoryRootDirectory -Value (Join-Path -Resolve $ScriptsDirectory "..") -Option ReadOnly -Scope Global -Visibility Public + New-Variable -Name SolutionFilePath -Value (Join-Path -Resolve $RepositoryRootDirectory "Terminal.sln") -Option ReadOnly -Scope Global -Visibility Public + New-Variable -Name TerminalGuiProjectDirectory -Value (Join-Path -Resolve $RepositoryRootDirectory "Terminal.Gui") -Option ReadOnly -Scope Global -Visibility Public + New-Variable -Name TerminalGuiProjectFilePath -Value (Join-Path -Resolve $TerminalGuiProjectDirectory "Terminal.Gui.csproj") -Option ReadOnly -Scope Global -Visibility Public + # Set a custom prompt to indicate we're in our modified environment. # Save the normal one first, though. # And save it as ReadOnly and without the -Force parameter, so this will be skipped if run more than once in the same session without a reset. @@ -132,6 +140,11 @@ Function Reset-PowerShellEnvironment { } Remove-Variable -Name PathVarSeparator -Scope Global -Force -ErrorAction SilentlyContinue + Remove-Variable -Name RepositoryRootDirectory -Scope Global -Force -ErrorAction SilentlyContinue + Remove-Variable -Name SolutionFilePath -Scope Global -Force -ErrorAction SilentlyContinue + Remove-Variable -Name TerminalGuiProjectDirectory -Scope Global -Force -ErrorAction SilentlyContinue + Remove-Variable -Name TerminalGuiProjectFilePath -Scope Global -Force -ErrorAction SilentlyContinue + Remove-Variable -Name ScriptsDirectory -Scope Global -Force -ErrorAction SilentlyContinue } # This ensures the environment is reset when unloading the module. @@ -140,4 +153,4 @@ $MyInvocation.MyCommand.ScriptBlock.Module.OnRemove = { Reset-PowerShellEnvironment } -Set-PowerShellEnvironment \ No newline at end of file +Set-PowerShellEnvironment From 096394a85b364a716f0000ac0dfc6e100cbc81ad Mon Sep 17 00:00:00 2001 From: Brandon Thetford Date: Sun, 28 Apr 2024 11:49:00 -0700 Subject: [PATCH 12/23] These need to be includes at this level --- Analyzers/Directory.build.props | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/Analyzers/Directory.build.props b/Analyzers/Directory.build.props index f399c85e0..1257675c1 100644 --- a/Analyzers/Directory.build.props +++ b/Analyzers/Directory.build.props @@ -11,8 +11,8 @@ True - - + + From 16fbee716b47e6255b8bc1d55dd3004dcdbf0c89 Mon Sep 17 00:00:00 2001 From: Brandon Thetford Date: Sun, 28 Apr 2024 11:50:13 -0700 Subject: [PATCH 13/23] Include Roslyn debugging project in solution --- Terminal.sln | 7 +++++++ 1 file changed, 7 insertions(+) diff --git a/Terminal.sln b/Terminal.sln index c4e9b016b..98de83b41 100644 --- a/Terminal.sln +++ b/Terminal.sln @@ -36,10 +36,13 @@ Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "Terminal.Gui.Analyzers.Inte EndProject Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "Terminal.Gui.Analyzers.Internal.Tests", "Analyzers\Terminal.Gui.Analyzers.Internal.Tests\Terminal.Gui.Analyzers.Internal.Tests.csproj", "{715DB4BA-F989-4DF6-B46F-5ED26A32B2DD}" EndProject +Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "Terminal.Gui.Analyzers.Internal.Debugging", "Analyzers\Terminal.Gui.Analyzers.Internal.Debugging\Terminal.Gui.Analyzers.Internal.Debugging.csproj", "{C2AD09BD-D579-45A7-ACA3-E4EF3BC027D2}" +EndProject Global GlobalSection(NestedProjects) = preSolution {5DE91722-8765-4E2B-97E4-2A18010B5CED} = {CCADA0BC-61CF-4B4B-96BA-A3B0C0A7F54D} {715DB4BA-F989-4DF6-B46F-5ED26A32B2DD} = {CCADA0BC-61CF-4B4B-96BA-A3B0C0A7F54D} + {C2AD09BD-D579-45A7-ACA3-E4EF3BC027D2} = {CCADA0BC-61CF-4B4B-96BA-A3B0C0A7F54D} EndGlobalSection GlobalSection(SolutionConfigurationPlatforms) = preSolution Debug|Any CPU = Debug|Any CPU @@ -74,6 +77,10 @@ Global {B0A602CD-E176-449D-8663-64238D54F857}.Debug|Any CPU.Build.0 = Debug|Any CPU {B0A602CD-E176-449D-8663-64238D54F857}.Release|Any CPU.ActiveCfg = Release|Any CPU {B0A602CD-E176-449D-8663-64238D54F857}.Release|Any CPU.Build.0 = Release|Any CPU + {C2AD09BD-D579-45A7-ACA3-E4EF3BC027D2}.Debug|Any CPU.ActiveCfg = Debug|Any CPU + {C2AD09BD-D579-45A7-ACA3-E4EF3BC027D2}.Debug|Any CPU.Build.0 = Debug|Any CPU + {C2AD09BD-D579-45A7-ACA3-E4EF3BC027D2}.Release|Any CPU.ActiveCfg = Release|Any CPU + {C2AD09BD-D579-45A7-ACA3-E4EF3BC027D2}.Release|Any CPU.Build.0 = Release|Any CPU EndGlobalSection GlobalSection(SolutionProperties) = preSolution HideSolutionNode = FALSE From 2ed8f973527ad4609b0c9da2ec0656a78bc96653 Mon Sep 17 00:00:00 2001 From: Brandon Thetford Date: Sun, 28 Apr 2024 11:54:04 -0700 Subject: [PATCH 14/23] Add project reference for the analyzer project in Terminal.Gui --- Terminal.Gui/Terminal.Gui.csproj | 12 ++++++++++-- 1 file changed, 10 insertions(+), 2 deletions(-) diff --git a/Terminal.Gui/Terminal.Gui.csproj b/Terminal.Gui/Terminal.Gui.csproj index ecfa82cd3..f0840c041 100644 --- a/Terminal.Gui/Terminal.Gui.csproj +++ b/Terminal.Gui/Terminal.Gui.csproj @@ -18,7 +18,7 @@ true True portable - $(DefineConstants);JETBRAINS_ANNOTATIONS;CONTRACTS_FULL + $(DefineConstants);JETBRAINS_ANNOTATIONS;CONTRACTS_FULL;CODE_ANALYSIS enable True true @@ -46,18 +46,26 @@ + + + + + all + Analyzer + false + - + From 3cf6b2470749fbf0655620dc66a6019779b09153 Mon Sep 17 00:00:00 2001 From: Brandon Thetford Date: Sun, 28 Apr 2024 11:54:21 -0700 Subject: [PATCH 15/23] Clean up some extraneous whitespace --- .../Terminal.Gui.Analyzers.Internal.csproj | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/Analyzers/Terminal.Gui.Analyzers.Internal/Terminal.Gui.Analyzers.Internal.csproj b/Analyzers/Terminal.Gui.Analyzers.Internal/Terminal.Gui.Analyzers.Internal.csproj index f63bacf78..52fd533b2 100644 --- a/Analyzers/Terminal.Gui.Analyzers.Internal/Terminal.Gui.Analyzers.Internal.csproj +++ b/Analyzers/Terminal.Gui.Analyzers.Internal/Terminal.Gui.Analyzers.Internal.csproj @@ -45,9 +45,9 @@ - + - + From 1e347be27ba3135888b96a39a128880a383467f6 Mon Sep 17 00:00:00 2001 From: Brandon Thetford Date: Sun, 28 Apr 2024 12:17:30 -0700 Subject: [PATCH 16/23] Grr. Have to fully qualify these because we have an Attribute type that collides --- .../EnumExtensionMethodsIncrementalGenerator.cs | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/Analyzers/Terminal.Gui.Analyzers.Internal/Generators/EnumExtensions/EnumExtensionMethodsIncrementalGenerator.cs b/Analyzers/Terminal.Gui.Analyzers.Internal/Generators/EnumExtensions/EnumExtensionMethodsIncrementalGenerator.cs index 66bfd3e81..136ca70ad 100644 --- a/Analyzers/Terminal.Gui.Analyzers.Internal/Generators/EnumExtensions/EnumExtensionMethodsIncrementalGenerator.cs +++ b/Analyzers/Terminal.Gui.Analyzers.Internal/Generators/EnumExtensions/EnumExtensionMethodsIncrementalGenerator.cs @@ -260,8 +260,8 @@ public sealed class EnumExtensionMethodsIncrementalGenerator : IIncrementalGener /// Used to enable source generation of a common set of extension methods for enum types. /// {{Strings.Templates.AttributesForGeneratedTypes}} - [System.AttributeUsageAttribute (System.AttributeTargets.Enum)] - public sealed class {{GeneratorAttributeName}} : Attribute + [{{Strings.DotnetNames.Types.AttributeUsageAttribute}} ({{Strings.DotnetNames.Types.AttributeTargets}}.Enum)] + public sealed class {{GeneratorAttributeName}} : {{Strings.DotnetNames.Types.Attribute}} { /// /// The name of the generated static class. From bb5a538f1d9a4f6e372a9db5d3aa295d6077532b Mon Sep 17 00:00:00 2001 From: Brandon Thetford Date: Sun, 28 Apr 2024 12:18:10 -0700 Subject: [PATCH 17/23] Show it in action --- Terminal.Gui/View/Adornment/Adornment.cs | 2 +- Terminal.Gui/View/ViewDiagnostics.cs | 3 +++ 2 files changed, 4 insertions(+), 1 deletion(-) diff --git a/Terminal.Gui/View/Adornment/Adornment.cs b/Terminal.Gui/View/Adornment/Adornment.cs index 585929e99..0829e961d 100644 --- a/Terminal.Gui/View/Adornment/Adornment.cs +++ b/Terminal.Gui/View/Adornment/Adornment.cs @@ -244,7 +244,7 @@ public class Adornment : View protected internal override bool OnMouseLeave (MouseEvent mouseEvent) { // Invert Normal - if (Diagnostics.HasFlag (ViewDiagnosticFlags.MouseEnter) && ColorScheme != null) + if (Diagnostics.FastHasFlags (ViewDiagnosticFlags.MouseEnter) && ColorScheme != null) { var cs = new ColorScheme (ColorScheme) { diff --git a/Terminal.Gui/View/ViewDiagnostics.cs b/Terminal.Gui/View/ViewDiagnostics.cs index dbaba3b53..20899cfd0 100644 --- a/Terminal.Gui/View/ViewDiagnostics.cs +++ b/Terminal.Gui/View/ViewDiagnostics.cs @@ -1,8 +1,11 @@  +using Terminal.Gui.Analyzers.Internal.Attributes; + namespace Terminal.Gui; /// Enables diagnostic functions for . [Flags] +[GenerateEnumExtensionMethods(FastHasFlags = true)] public enum ViewDiagnosticFlags : uint { /// All diagnostics off From 6c9fef58c3c5de29e4693e2ad076240eb1bdcd53 Mon Sep 17 00:00:00 2001 From: Brandon Thetford Date: Sun, 28 Apr 2024 12:18:34 -0700 Subject: [PATCH 18/23] Better path handling for Open-Solution and Build-Analyzers --- .../Terminal.Gui.PowerShell.Analyzers.psm1 | 29 +++++++------------ Scripts/Terminal.Gui.PowerShell.Core.psm1 | 6 ++++ 2 files changed, 16 insertions(+), 19 deletions(-) diff --git a/Scripts/Terminal.Gui.PowerShell.Analyzers.psm1 b/Scripts/Terminal.Gui.PowerShell.Analyzers.psm1 index 78a87a448..8e3a8dc58 100644 --- a/Scripts/Terminal.Gui.PowerShell.Analyzers.psm1 +++ b/Scripts/Terminal.Gui.PowerShell.Analyzers.psm1 @@ -55,43 +55,34 @@ Function Build-Analyzers { return } - New-Variable -Name solutionRoot -Visibility Public -Value (Resolve-Path ..) - Push-Location $solutionRoot - New-Variable -Name solutionFile -Visibility Public -Value (Resolve-Path ./Terminal.sln) - $mainProjectRoot = Resolve-Path ./Terminal.Gui - $mainProjectFile = Join-Path $mainProjectRoot Terminal.Gui.csproj - $analyzersRoot = Resolve-Path ./Analyzers - $internalAnalyzersProjectRoot = Join-Path $analyzersRoot Terminal.Gui.Analyzers.Internal - $internalAnalyzersProjectFile = Join-Path $internalAnalyzersProjectRoot Terminal.Gui.Analyzers.Internal.csproj + Push-Location $InternalAnalyzersProjectDirectory if(!$NoClean) { if(!$Quiet) { Write-Host Deleting bin and obj folders for Terminal.Gui } - if(Test-Path $mainProjectRoot/bin) { - Remove-Item -Recurse -Force $mainProjectRoot/bin - Remove-Item -Recurse -Force $mainProjectRoot/obj - } + Remove-Item -Recurse -Force $TerminalGuiProjectDirectory/bin -ErrorAction SilentlyContinue + Remove-Item -Recurse -Force $TerminalGuiProjectDirectory/obj -ErrorAction SilentlyContinue if(!$Quiet) { Write-Host Deleting bin and obj folders for Terminal.Gui.InternalAnalyzers } - if(Test-Path $internalAnalyzersProjectRoot/bin) { - Remove-Item -Recurse -Force $internalAnalyzersProjectRoot/bin - Remove-Item -Recurse -Force $internalAnalyzersProjectRoot/obj - } + Remove-Item -Recurse -Force $InternalAnalyzersProjectDirectory/bin -ErrorAction SilentlyContinue + Remove-Item -Recurse -Force $InternalAnalyzersProjectDirectory/obj -ErrorAction SilentlyContinue } if(!$Quiet) { Write-Host Building analyzers in Debug configuration } - dotnet build $internalAnalyzersProjectFile --no-incremental --nologo --force --configuration Debug + dotnet build $InternalAnalyzersProjectFilePath --no-incremental --nologo --force --configuration Debug if(!$Quiet) { Write-Host Building analyzers in Release configuration } - dotnet build $internalAnalyzersProjectFile --no-incremental --nologo --force --configuration Release + dotnet build $InternalAnalyzersProjectFilePath --no-incremental --nologo --force --configuration Release + Pop-Location + if(!$AutoLaunch) { Write-Host -ForegroundColor Green Finished. Restart Visual Studio for changes to take effect. } else { @@ -102,4 +93,4 @@ Function Build-Analyzers { } return -} \ No newline at end of file +} diff --git a/Scripts/Terminal.Gui.PowerShell.Core.psm1 b/Scripts/Terminal.Gui.PowerShell.Core.psm1 index b3e1c6900..6ef11baed 100644 --- a/Scripts/Terminal.Gui.PowerShell.Core.psm1 +++ b/Scripts/Terminal.Gui.PowerShell.Core.psm1 @@ -69,6 +69,9 @@ Function Set-PowerShellEnvironment { New-Variable -Name SolutionFilePath -Value (Join-Path -Resolve $RepositoryRootDirectory "Terminal.sln") -Option ReadOnly -Scope Global -Visibility Public New-Variable -Name TerminalGuiProjectDirectory -Value (Join-Path -Resolve $RepositoryRootDirectory "Terminal.Gui") -Option ReadOnly -Scope Global -Visibility Public New-Variable -Name TerminalGuiProjectFilePath -Value (Join-Path -Resolve $TerminalGuiProjectDirectory "Terminal.Gui.csproj") -Option ReadOnly -Scope Global -Visibility Public + New-Variable -Name AnalyzersDirectory -Value (Join-Path -Resolve $RepositoryRootDirectory "Analyzers") -Option ReadOnly -Scope Global -Visibility Public + New-Variable -Name InternalAnalyzersProjectDirectory -Value (Join-Path -Resolve $AnalyzersDirectory "Terminal.Gui.Analyzers.Internal") -Option ReadOnly -Scope Global -Visibility Public + New-Variable -Name InternalAnalyzersProjectFilePath -Value (Join-Path -Resolve $InternalAnalyzersProjectDirectory "Terminal.Gui.Analyzers.Internal.csproj") -Option ReadOnly -Scope Global -Visibility Public # Set a custom prompt to indicate we're in our modified environment. # Save the normal one first, though. @@ -145,6 +148,9 @@ Function Reset-PowerShellEnvironment { Remove-Variable -Name TerminalGuiProjectDirectory -Scope Global -Force -ErrorAction SilentlyContinue Remove-Variable -Name TerminalGuiProjectFilePath -Scope Global -Force -ErrorAction SilentlyContinue Remove-Variable -Name ScriptsDirectory -Scope Global -Force -ErrorAction SilentlyContinue + Remove-Variable -Name AnalyzersDirectory -Scope Global -Force -ErrorAction SilentlyContinue + Remove-Variable -Name InternalAnalyzersProjectDirectory -Scope Global -Force -ErrorAction SilentlyContinue + Remove-Variable -Name InternalAnalyzersProjectFilePath -Scope Global -Force -ErrorAction SilentlyContinue } # This ensures the environment is reset when unloading the module. From 4628c2dc0a6c1c8e853ff270b5d193c7b3388b4a Mon Sep 17 00:00:00 2001 From: Brandon Thetford Date: Wed, 1 May 2024 20:33:24 -0700 Subject: [PATCH 19/23] 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 - } - } -} From eb7dd9bcb6892a600d91ba1d32c6b89be61594d1 Mon Sep 17 00:00:00 2001 From: Brandon Thetford Date: Wed, 1 May 2024 20:33:40 -0700 Subject: [PATCH 20/23] Clean up some unused code --- .../EnumExtensionMethodsGenerationInfo.cs | 24 ++++--------------- 1 file changed, 5 insertions(+), 19 deletions(-) diff --git a/Analyzers/Terminal.Gui.Analyzers.Internal/Generators/EnumExtensions/EnumExtensionMethodsGenerationInfo.cs b/Analyzers/Terminal.Gui.Analyzers.Internal/Generators/EnumExtensions/EnumExtensionMethodsGenerationInfo.cs index 970c51c35..e78b93626 100644 --- a/Analyzers/Terminal.Gui.Analyzers.Internal/Generators/EnumExtensions/EnumExtensionMethodsGenerationInfo.cs +++ b/Analyzers/Terminal.Gui.Analyzers.Internal/Generators/EnumExtensions/EnumExtensionMethodsGenerationInfo.cs @@ -24,12 +24,10 @@ namespace Terminal.Gui.Analyzers.Internal.Generators.EnumExtensions; internal sealed record EnumExtensionMethodsGenerationInfo : IGeneratedTypeMetadata, IEqualityOperators { - private const int ExplicitFastHasFlagsMask = 0b1000; - private const int ExplicitFastIsDefinedMask = 0b1_0000; - private const int ExplicitIncludeInterfaceMask = 0b10_0000; - private const int ExplicitNameMask = 0b10; - private const int ExplicitNamespaceMask = 0b1; - private const int ExplicitPartialMask = 0b100; + private const int ExplicitFastHasFlagsMask = 0b_0100; + private const int ExplicitFastIsDefinedMask = 0b_1000; + private const int ExplicitNameMask = 0b_0010; + private const int ExplicitNamespaceMask = 0b_0001; private const string GeneratorAttributeFullyQualifiedName = $"{GeneratorAttributeNamespace}.{GeneratorAttributeName}"; private const string GeneratorAttributeName = nameof (GenerateEnumExtensionMethodsAttribute); private const string GeneratorAttributeNamespace = Constants.Strings.AnalyzersAttributesNamespace; @@ -159,7 +157,7 @@ internal sealed record EnumExtensionMethodsGenerationInfo : IGeneratedTypeMetada public bool IsStatic => true; /// - public bool IncludeInterface { get; private set; } + public bool IncludeInterface => false; public string GeneratedTypeFullName => $"{GeneratedTypeNamespace}.{GeneratedTypeName}"; @@ -328,18 +326,6 @@ internal sealed record EnumExtensionMethodsGenerationInfo : IGeneratedTypeMetada set => _discoveredProperties [ExplicitFastIsDefinedMask] = value; } - private bool HasExplicitIncludeInterface - { - [UsedImplicitly]get => _discoveredProperties [ExplicitIncludeInterfaceMask]; - set => _discoveredProperties [ExplicitIncludeInterfaceMask] = value; - } - - private bool HasExplicitPartial - { - [UsedImplicitly]get => _discoveredProperties [ExplicitPartialMask]; - set => _discoveredProperties [ExplicitPartialMask] = value; - } - private bool HasExplicitTypeName { get => _discoveredProperties [ExplicitNameMask]; From 2af91484ef2be22a9f810d349aa8272f4d71e30a Mon Sep 17 00:00:00 2001 From: Brandon Thetford Date: Wed, 1 May 2024 20:41:16 -0700 Subject: [PATCH 21/23] Reference Meziantou.Polyfill and remove local definitions it provides --- .../CompilerFeatureRequiredAttribute.cs | 33 --- .../Compatibility/IsExternalInit.cs | 18 -- .../Compatibility/NullableAttributes.cs | 208 ------------------ .../Compatibility/RequiredMemberAttribute.cs | 12 - .../SetsRequiredMembersAttribute.cs | 12 - .../Compatibility/SkipLocalsInitAttribute.cs | 14 -- .../Terminal.Gui.Analyzers.Internal.csproj | 19 +- 7 files changed, 5 insertions(+), 311 deletions(-) delete mode 100644 Analyzers/Terminal.Gui.Analyzers.Internal/Compatibility/CompilerFeatureRequiredAttribute.cs delete mode 100644 Analyzers/Terminal.Gui.Analyzers.Internal/Compatibility/IsExternalInit.cs delete mode 100644 Analyzers/Terminal.Gui.Analyzers.Internal/Compatibility/NullableAttributes.cs delete mode 100644 Analyzers/Terminal.Gui.Analyzers.Internal/Compatibility/RequiredMemberAttribute.cs delete mode 100644 Analyzers/Terminal.Gui.Analyzers.Internal/Compatibility/SetsRequiredMembersAttribute.cs delete mode 100644 Analyzers/Terminal.Gui.Analyzers.Internal/Compatibility/SkipLocalsInitAttribute.cs diff --git a/Analyzers/Terminal.Gui.Analyzers.Internal/Compatibility/CompilerFeatureRequiredAttribute.cs b/Analyzers/Terminal.Gui.Analyzers.Internal/Compatibility/CompilerFeatureRequiredAttribute.cs deleted file mode 100644 index cefddff94..000000000 --- a/Analyzers/Terminal.Gui.Analyzers.Internal/Compatibility/CompilerFeatureRequiredAttribute.cs +++ /dev/null @@ -1,33 +0,0 @@ -// Licensed to the .NET Foundation under one or more agreements. -// The .NET Foundation licenses this file to you under the MIT license. - -// ReSharper disable once CheckNamespace -namespace System.Runtime.CompilerServices; - -/// -/// Indicates that compiler support for a particular feature is required for the location where this attribute is -/// applied. -/// -[AttributeUsage (AttributeTargets.All, AllowMultiple = true, Inherited = false)] -internal sealed class CompilerFeatureRequiredAttribute(string featureName) : Attribute -{ - /// - /// The used for the ref structs C# feature. - /// - public const string RefStructs = nameof (RefStructs); - - /// - /// The used for the required members C# feature. - /// - public const string RequiredMembers = nameof (RequiredMembers); - - /// - /// The name of the compiler feature. - /// - public string FeatureName { get; } = featureName; - /// - /// If true, the compiler can choose to allow access to the location where this attribute is applied if it does not - /// understand . - /// - public bool IsOptional { get; init; } -} \ No newline at end of file diff --git a/Analyzers/Terminal.Gui.Analyzers.Internal/Compatibility/IsExternalInit.cs b/Analyzers/Terminal.Gui.Analyzers.Internal/Compatibility/IsExternalInit.cs deleted file mode 100644 index 4976ee705..000000000 --- a/Analyzers/Terminal.Gui.Analyzers.Internal/Compatibility/IsExternalInit.cs +++ /dev/null @@ -1,18 +0,0 @@ -using System.ComponentModel; -using System.Diagnostics; -using System.Diagnostics.CodeAnalysis; - -// ReSharper disable CheckNamespace -namespace System.Runtime.CompilerServices; - -/// -/// Reserved to be used by the compiler for tracking metadata. -/// This class should not be used by developers in source code. -/// -/// -/// Copied from .net source code, for support of init property accessors in netstandard2.0. -/// -[ExcludeFromCodeCoverage] -[DebuggerNonUserCode] -[EditorBrowsable (EditorBrowsableState.Never)] -public static class IsExternalInit; diff --git a/Analyzers/Terminal.Gui.Analyzers.Internal/Compatibility/NullableAttributes.cs b/Analyzers/Terminal.Gui.Analyzers.Internal/Compatibility/NullableAttributes.cs deleted file mode 100644 index 11ef7e4cf..000000000 --- a/Analyzers/Terminal.Gui.Analyzers.Internal/Compatibility/NullableAttributes.cs +++ /dev/null @@ -1,208 +0,0 @@ -// Licensed to the .NET Foundation under one or more agreements. -// The .NET Foundation licenses this file to you under the MIT license. -// -// This file is further modified from the original, for this project, -// to comply with project style. -// No changes are made which affect compatibility with the same types from -// APIs later than netstandard2.0, nor will this file be included in compilations -// targeted at later APIs. -// -// Originally rom https://github.com/dotnet/runtime/blob/ef72b95937703e485fdbbb75f3251fedfd1a0ef9/src/libraries/System.Private.CoreLib/src/System/Diagnostics/CodeAnalysis/NullableAttributes.cs - -// ReSharper disable CheckNamespace - -// ReSharper disable UnusedAutoPropertyAccessor.Global -// ReSharper disable UnusedType.Global - -namespace System.Diagnostics.CodeAnalysis; - -/// Specifies that null is allowed as an input even if the corresponding type disallows it. -/// Excluded from output assembly via file specified in ApiCompatExcludeAttributesFile element in the project file. -[AttributeUsage (AttributeTargets.Field | AttributeTargets.Parameter | AttributeTargets.Property)] -[ExcludeFromCodeCoverage] -[DebuggerNonUserCode] -internal sealed class AllowNullAttribute : Attribute; - -/// Specifies that null is disallowed as an input even if the corresponding type allows it. -/// Excluded from output assembly via file specified in ApiCompatExcludeAttributesFile element in the project file. -[AttributeUsage (AttributeTargets.Field | AttributeTargets.Parameter | AttributeTargets.Property)] -[ExcludeFromCodeCoverage] -[DebuggerNonUserCode] -internal sealed class DisallowNullAttribute : Attribute; - -/// Specifies that an output may be null even if the corresponding type disallows it. -/// Excluded from output assembly via file specified in ApiCompatExcludeAttributesFile element in the project file. -[AttributeUsage (AttributeTargets.Field | AttributeTargets.Parameter | AttributeTargets.Property | AttributeTargets.ReturnValue)] -[ExcludeFromCodeCoverage] -[DebuggerNonUserCode] -internal sealed class MaybeNullAttribute : Attribute; - -/// -/// Specifies that an output will not be null even if the corresponding type allows it. Specifies that an input -/// argument was not null when the call returns. -/// -/// Excluded from output assembly via file specified in ApiCompatExcludeAttributesFile element in the project file. -[AttributeUsage (AttributeTargets.Field | AttributeTargets.Parameter | AttributeTargets.Property | AttributeTargets.ReturnValue)] -[ExcludeFromCodeCoverage] -[DebuggerNonUserCode] -internal sealed class NotNullAttribute : Attribute; - -/// -/// Specifies that when a method returns , the parameter may be null even if the corresponding -/// type disallows it. -/// -/// Excluded from output assembly via file specified in ApiCompatExcludeAttributesFile element in the project file. -[AttributeUsage (AttributeTargets.Parameter)] -[ExcludeFromCodeCoverage] -[DebuggerNonUserCode] -internal sealed class MaybeNullWhenAttribute : Attribute -{ - /// Initializes the attribute with the specified return value condition. - /// - /// The return value condition. If the method returns this value, the associated parameter may be null. - /// -#pragma warning disable IDE0290 // Use primary constructor - public MaybeNullWhenAttribute (bool returnValue) { ReturnValue = returnValue; } -#pragma warning restore IDE0290 // Use primary constructor - - /// Gets the return value condition. - public bool ReturnValue { get; } -} - -/// -/// Specifies that when a method returns , the parameter will not be null even if the -/// corresponding type allows it. -/// -/// Excluded from output assembly via file specified in ApiCompatExcludeAttributesFile element in the project file. -[AttributeUsage (AttributeTargets.Parameter)] -[ExcludeFromCodeCoverage] -[DebuggerNonUserCode] -internal sealed class NotNullWhenAttribute : Attribute -{ - /// Initializes the attribute with the specified return value condition. - /// - /// The return value condition. If the method returns this value, the associated parameter will not be null. - /// -#pragma warning disable IDE0290 // Use primary constructor - public NotNullWhenAttribute (bool returnValue) { ReturnValue = returnValue; } -#pragma warning restore IDE0290 // Use primary constructor - - /// Gets the return value condition. - public bool ReturnValue { get; } -} - -/// Specifies that the output will be non-null if the named parameter is non-null. -/// Excluded from output assembly via file specified in ApiCompatExcludeAttributesFile element in the project file. -[AttributeUsage (AttributeTargets.Parameter | AttributeTargets.Property | AttributeTargets.ReturnValue, AllowMultiple = true)] -[ExcludeFromCodeCoverage] -[DebuggerNonUserCode] -internal sealed class NotNullIfNotNullAttribute : Attribute -{ - /// Initializes the attribute with the associated parameter name. - /// - /// The associated parameter name. The output will be non-null if the argument to the parameter specified is non-null. - /// -#pragma warning disable IDE0290 // Use primary constructor - public NotNullIfNotNullAttribute (string parameterName) { ParameterName = parameterName; } -#pragma warning restore IDE0290 // Use primary constructor - - /// Gets the associated parameter name. - public string ParameterName { get; } -} - -/// Applied to a method that will never return under any circumstance. -/// Excluded from output assembly via file specified in ApiCompatExcludeAttributesFile element in the project file. -[AttributeUsage (AttributeTargets.Method, Inherited = false)] -[ExcludeFromCodeCoverage] -[DebuggerNonUserCode] -internal sealed class DoesNotReturnAttribute : Attribute; - -/// Specifies that the method will not return if the associated Boolean parameter is passed the specified value. -/// Excluded from output assembly via file specified in ApiCompatExcludeAttributesFile element in the project file. -[AttributeUsage (AttributeTargets.Parameter)] -[ExcludeFromCodeCoverage] -[DebuggerNonUserCode] -internal sealed class DoesNotReturnIfAttribute : Attribute -{ - /// Initializes the attribute with the specified parameter value. - /// - /// The condition parameter value. Code after the method will be considered unreachable by diagnostics if the argument - /// to - /// the associated parameter matches this value. - /// -#pragma warning disable IDE0290 // Use primary constructor - public DoesNotReturnIfAttribute (bool parameterValue) { ParameterValue = parameterValue; } -#pragma warning restore IDE0290 // Use primary constructor - - /// Gets the condition parameter value. - public bool ParameterValue { get; } -} - -/// -/// Specifies that the method or property will ensure that the listed field and property members have not-null -/// values. -/// -/// Excluded from output assembly via file specified in ApiCompatExcludeAttributesFile element in the project file. -[AttributeUsage (AttributeTargets.Method | AttributeTargets.Property, Inherited = false, AllowMultiple = true)] -[ExcludeFromCodeCoverage] -[DebuggerNonUserCode] -internal sealed class MemberNotNullAttribute : Attribute -{ - /// Initializes the attribute with a field or property member. - /// - /// The field or property member that is promised to be not-null. - /// - public MemberNotNullAttribute (string member) { Members = [member]; } - - /// Initializes the attribute with the list of field and property members. - /// - /// The list of field and property members that are promised to be not-null. - /// - public MemberNotNullAttribute (params string [] members) { Members = members; } - - /// Gets field or property member names. - public string [] Members { get; } -} - -/// -/// Specifies that the method or property will ensure that the listed field and property members have not-null values -/// when returning with the specified return value condition. -/// -/// Excluded from output assembly via file specified in ApiCompatExcludeAttributesFile element in the project file. -[AttributeUsage (AttributeTargets.Method | AttributeTargets.Property, Inherited = false, AllowMultiple = true)] -[ExcludeFromCodeCoverage] -[DebuggerNonUserCode] -internal sealed class MemberNotNullWhenAttribute : Attribute -{ - /// Initializes the attribute with the specified return value condition and a field or property member. - /// - /// The return value condition. If the method returns this value, the associated parameter will not be null. - /// - /// - /// The field or property member that is promised to be not-null. - /// - public MemberNotNullWhenAttribute (bool returnValue, string member) - { - ReturnValue = returnValue; - Members = [member]; - } - - /// Initializes the attribute with the specified return value condition and list of field and property members. - /// - /// The return value condition. If the method returns this value, the associated parameter will not be null. - /// - /// - /// The list of field and property members that are promised to be not-null. - /// - public MemberNotNullWhenAttribute (bool returnValue, params string [] members) - { - ReturnValue = returnValue; - Members = members; - } - - /// Gets field or property member names. - public string [] Members { get; } - - /// Gets the return value condition. - public bool ReturnValue { get; } -} diff --git a/Analyzers/Terminal.Gui.Analyzers.Internal/Compatibility/RequiredMemberAttribute.cs b/Analyzers/Terminal.Gui.Analyzers.Internal/Compatibility/RequiredMemberAttribute.cs deleted file mode 100644 index 2fb8d3841..000000000 --- a/Analyzers/Terminal.Gui.Analyzers.Internal/Compatibility/RequiredMemberAttribute.cs +++ /dev/null @@ -1,12 +0,0 @@ -// ReSharper disable CheckNamespace -// ReSharper disable ConditionalAnnotation - -using JetBrains.Annotations; - -namespace System.Runtime.CompilerServices; - -/// Polyfill to enable netstandard2.0 assembly to use the required keyword. -/// Excluded from output assembly via file specified in ApiCompatExcludeAttributesFile element in the project file. -[AttributeUsage (AttributeTargets.Property)] -[UsedImplicitly] -public sealed class RequiredMemberAttribute : Attribute; diff --git a/Analyzers/Terminal.Gui.Analyzers.Internal/Compatibility/SetsRequiredMembersAttribute.cs b/Analyzers/Terminal.Gui.Analyzers.Internal/Compatibility/SetsRequiredMembersAttribute.cs deleted file mode 100644 index ae09ae2cf..000000000 --- a/Analyzers/Terminal.Gui.Analyzers.Internal/Compatibility/SetsRequiredMembersAttribute.cs +++ /dev/null @@ -1,12 +0,0 @@ -// Licensed to the .NET Foundation under one or more agreements. -// The .NET Foundation licenses this file to you under the MIT license. - -// ReSharper disable once CheckNamespace -namespace System.Diagnostics.CodeAnalysis; - -/// -/// Specifies that this constructor sets all required members for the current type, and callers -/// do not need to set any required members themselves. -/// -[AttributeUsage (AttributeTargets.Constructor)] -public sealed class SetsRequiredMembersAttribute : Attribute; \ No newline at end of file diff --git a/Analyzers/Terminal.Gui.Analyzers.Internal/Compatibility/SkipLocalsInitAttribute.cs b/Analyzers/Terminal.Gui.Analyzers.Internal/Compatibility/SkipLocalsInitAttribute.cs deleted file mode 100644 index 1eb617362..000000000 --- a/Analyzers/Terminal.Gui.Analyzers.Internal/Compatibility/SkipLocalsInitAttribute.cs +++ /dev/null @@ -1,14 +0,0 @@ -namespace System.Runtime.CompilerServices; - -[AttributeUsage ( - AttributeTargets.Class - | AttributeTargets.Constructor - | AttributeTargets.Event - | AttributeTargets.Interface - | AttributeTargets.Method - | AttributeTargets.Module - | AttributeTargets.Property - | AttributeTargets.Struct, - Inherited = false)] - -internal sealed class SkipLocalsInitAttribute : Attribute; \ No newline at end of file diff --git a/Analyzers/Terminal.Gui.Analyzers.Internal/Terminal.Gui.Analyzers.Internal.csproj b/Analyzers/Terminal.Gui.Analyzers.Internal/Terminal.Gui.Analyzers.Internal.csproj index 52fd533b2..3dcd5bc48 100644 --- a/Analyzers/Terminal.Gui.Analyzers.Internal/Terminal.Gui.Analyzers.Internal.csproj +++ b/Analyzers/Terminal.Gui.Analyzers.Internal/Terminal.Gui.Analyzers.Internal.csproj @@ -36,15 +36,9 @@ $(NoWarn);nullable;CA1067 - - - - - - - + + - @@ -53,17 +47,14 @@ + - - - - - - + + From 20ed2251b8bd4d5316d2d6117afda6771b90ea14 Mon Sep 17 00:00:00 2001 From: Brandon Thetford Date: Wed, 1 May 2024 20:41:30 -0700 Subject: [PATCH 22/23] This is here intentionally. Suppress. --- .../Attributes/AssemblyExtendedEnumTypeAttribute.cs | 1 + 1 file changed, 1 insertion(+) diff --git a/Analyzers/Terminal.Gui.Analyzers.Internal/Attributes/AssemblyExtendedEnumTypeAttribute.cs b/Analyzers/Terminal.Gui.Analyzers.Internal/Attributes/AssemblyExtendedEnumTypeAttribute.cs index 6115fdc46..da340e075 100644 --- a/Analyzers/Terminal.Gui.Analyzers.Internal/Attributes/AssemblyExtendedEnumTypeAttribute.cs +++ b/Analyzers/Terminal.Gui.Analyzers.Internal/Attributes/AssemblyExtendedEnumTypeAttribute.cs @@ -1,4 +1,5 @@ // ReSharper disable ClassNeverInstantiated.Global +// ReSharper disable once RedundantNullableDirective #nullable enable namespace Terminal.Gui.Analyzers.Internal.Attributes; From a444bda6d4addaf9c44798f7c82b775fefb099c5 Mon Sep 17 00:00:00 2001 From: Brandon Thetford Date: Wed, 1 May 2024 21:17:24 -0700 Subject: [PATCH 23/23] Took a few suggestions from R# and silenced a warning for intentional naming --- .../Constants/Strings.cs | 24 ++++++++++--------- .../Generators/EnumExtensions/CodeWriter.cs | 4 ++-- .../EnumExtensionMethodsGenerationInfo.cs | 14 +++++------ ...numExtensionMethodsIncrementalGenerator.cs | 4 ++-- 4 files changed, 24 insertions(+), 22 deletions(-) diff --git a/Analyzers/Terminal.Gui.Analyzers.Internal/Constants/Strings.cs b/Analyzers/Terminal.Gui.Analyzers.Internal/Constants/Strings.cs index e03d5fcc3..3ffb234a6 100644 --- a/Analyzers/Terminal.Gui.Analyzers.Internal/Constants/Strings.cs +++ b/Analyzers/Terminal.Gui.Analyzers.Internal/Constants/Strings.cs @@ -46,7 +46,7 @@ internal static class Strings /// internal const string ExcludeFromCodeCoverage = $"{Namespaces.System_Diagnostics_CodeAnalysis}.{nameof (ExcludeFromCodeCoverageAttribute)}"; - internal const string Flags = $"{Namespaces.SystemNS}.{nameof (FlagsAttribute)}"; + internal const string Flags = $"{Namespaces.SystemNs}.{nameof (FlagsAttribute)}"; internal const string GeneratedCode = $"{Namespaces.System_CodeDom_Compiler}.{nameof (GeneratedCodeAttribute)}"; @@ -83,22 +83,24 @@ internal static class Strings /// Names of dotnet namespaces. internal static class Namespaces { - internal const string SystemNS = nameof (System); - internal const string System_CodeDom = $"{SystemNS}.{nameof (System.CodeDom)}"; + internal const string SystemNs = nameof (System); + // ReSharper disable InconsistentNaming + internal const string System_CodeDom = $"{SystemNs}.{nameof (System.CodeDom)}"; internal const string System_CodeDom_Compiler = $"{System_CodeDom}.{nameof (System.CodeDom.Compiler)}"; - internal const string System_ComponentModel = $"{SystemNS}.{nameof (System.ComponentModel)}"; - internal const string System_Diagnostics = $"{SystemNS}.{nameof (System.Diagnostics)}"; + internal const string System_ComponentModel = $"{SystemNs}.{nameof (System.ComponentModel)}"; + internal const string System_Diagnostics = $"{SystemNs}.{nameof (System.Diagnostics)}"; internal const string System_Diagnostics_CodeAnalysis = $"{System_Diagnostics}.{nameof (System.Diagnostics.CodeAnalysis)}"; - internal const string System_Numerics = $"{SystemNS}.{nameof (System.Numerics)}"; - internal const string System_Runtime = $"{SystemNS}.{nameof (System.Runtime)}"; + internal const string System_Numerics = $"{SystemNs}.{nameof (System.Numerics)}"; + internal const string System_Runtime = $"{SystemNs}.{nameof (System.Runtime)}"; internal const string System_Runtime_CompilerServices = $"{System_Runtime}.{nameof (System.Runtime.CompilerServices)}"; + // ReSharper restore InconsistentNaming } internal static class Types { - internal const string Attribute = $"{Namespaces.SystemNS}.{nameof (System.Attribute)}"; - internal const string AttributeTargets = $"{Namespaces.SystemNS}.{nameof (System.AttributeTargets)}"; - internal const string AttributeUsageAttribute = $"{Namespaces.SystemNS}.{nameof (System.AttributeUsageAttribute)}"; + internal const string Attribute = $"{Namespaces.SystemNs}.{nameof (System.Attribute)}"; + internal const string AttributeTargets = $"{Namespaces.SystemNs}.{nameof (System.AttributeTargets)}"; + internal const string AttributeUsageAttribute = $"{Namespaces.SystemNs}.{nameof (System.AttributeUsageAttribute)}"; internal const string MethodImplOptions = $"{Namespaces.System_Runtime_CompilerServices}.{nameof (System.Runtime.CompilerServices.MethodImplOptions)}"; @@ -131,7 +133,7 @@ internal static class Strings /// Using directives for common namespaces in generated code. internal const string DotnetNamespaceUsingDirectives = $""" - using {DotnetNames.Namespaces.SystemNS}; + using {DotnetNames.Namespaces.SystemNs}; using {DotnetNames.Namespaces.System_CodeDom}; using {DotnetNames.Namespaces.System_CodeDom_Compiler}; using {DotnetNames.Namespaces.System_ComponentModel}; diff --git a/Analyzers/Terminal.Gui.Analyzers.Internal/Generators/EnumExtensions/CodeWriter.cs b/Analyzers/Terminal.Gui.Analyzers.Internal/Generators/EnumExtensions/CodeWriter.cs index 230d6293b..f35e20d88 100644 --- a/Analyzers/Terminal.Gui.Analyzers.Internal/Generators/EnumExtensions/CodeWriter.cs +++ b/Analyzers/Terminal.Gui.Analyzers.Internal/Generators/EnumExtensions/CodeWriter.cs @@ -147,14 +147,14 @@ internal sealed class CodeWriter (in EnumExtensionMethodsGenerationInfo metadata switch (Metadata.EnumBackingTypeCode) { case TypeCode.Int32: - foreach (int definedValue in Metadata.IntMembers) + foreach (int definedValue in Metadata._intMembers) { w.WriteLine ($"{definedValue:D} => true,"); } break; case TypeCode.UInt32: - foreach (uint definedValue in Metadata.UIntMembers) + foreach (uint definedValue in Metadata._uIntMembers) { w.WriteLine ($"{definedValue:D} => true,"); } diff --git a/Analyzers/Terminal.Gui.Analyzers.Internal/Generators/EnumExtensions/EnumExtensionMethodsGenerationInfo.cs b/Analyzers/Terminal.Gui.Analyzers.Internal/Generators/EnumExtensions/EnumExtensionMethodsGenerationInfo.cs index e78b93626..cab633cbf 100644 --- a/Analyzers/Terminal.Gui.Analyzers.Internal/Generators/EnumExtensions/EnumExtensionMethodsGenerationInfo.cs +++ b/Analyzers/Terminal.Gui.Analyzers.Internal/Generators/EnumExtensions/EnumExtensionMethodsGenerationInfo.cs @@ -30,7 +30,7 @@ internal sealed record EnumExtensionMethodsGenerationInfo : IGeneratedTypeMetada private const int ExplicitNamespaceMask = 0b_0001; private const string GeneratorAttributeFullyQualifiedName = $"{GeneratorAttributeNamespace}.{GeneratorAttributeName}"; private const string GeneratorAttributeName = nameof (GenerateEnumExtensionMethodsAttribute); - private const string GeneratorAttributeNamespace = Constants.Strings.AnalyzersAttributesNamespace; + private const string GeneratorAttributeNamespace = Strings.AnalyzersAttributesNamespace; /// /// Type containing the information necessary to generate code according to the declared attribute values, @@ -88,7 +88,7 @@ internal sealed record EnumExtensionMethodsGenerationInfo : IGeneratedTypeMetada } [AccessedThroughProperty (nameof (EnumBackingTypeCode))] - private TypeCode _enumBackingTypeCode; + private readonly TypeCode _enumBackingTypeCode; [AccessedThroughProperty (nameof (GeneratedTypeName))] private string? _generatedTypeName; @@ -187,7 +187,7 @@ internal sealed record EnumExtensionMethodsGenerationInfo : IGeneratedTypeMetada public TypeCode EnumBackingTypeCode { get => _enumBackingTypeCode; - set + init { if (value is not TypeCode.Int32 and not TypeCode.UInt32) { @@ -206,8 +206,8 @@ internal sealed record EnumExtensionMethodsGenerationInfo : IGeneratedTypeMetada /// Whether a switch-based IsDefined replacement will be generated (Default: true) public bool GenerateFastIsDefined { [UsedImplicitly]get; set; } = true; - internal ImmutableHashSet? IntMembers; - internal ImmutableHashSet? UIntMembers; + internal ImmutableHashSet? _intMembers; + internal ImmutableHashSet? _uIntMembers; /// /// Fully-qualified name of the extension class @@ -307,11 +307,11 @@ internal sealed record EnumExtensionMethodsGenerationInfo : IGeneratedTypeMetada { ImmutableArray enumMembers = enumSymbol.GetMembers (); IEnumerable fieldSymbols = enumMembers.OfType (); - IntMembers = fieldSymbols.Select (static m => m.HasConstantValue ? (int)m.ConstantValue : 0).ToImmutableHashSet (); + _intMembers = fieldSymbols.Select (static m => m.HasConstantValue ? (int)m.ConstantValue : 0).ToImmutableHashSet (); } private void PopulateUIntMembersHashSet (INamedTypeSymbol enumSymbol) { - UIntMembers = enumSymbol.GetMembers ().OfType ().Select (static m => (uint)m.ConstantValue).ToImmutableHashSet (); + _uIntMembers = enumSymbol.GetMembers ().OfType ().Select (static m => (uint)m.ConstantValue).ToImmutableHashSet (); } private bool HasExplicitFastHasFlags diff --git a/Analyzers/Terminal.Gui.Analyzers.Internal/Generators/EnumExtensions/EnumExtensionMethodsIncrementalGenerator.cs b/Analyzers/Terminal.Gui.Analyzers.Internal/Generators/EnumExtensions/EnumExtensionMethodsIncrementalGenerator.cs index 136ca70ad..7629fd8c2 100644 --- a/Analyzers/Terminal.Gui.Analyzers.Internal/Generators/EnumExtensions/EnumExtensionMethodsIncrementalGenerator.cs +++ b/Analyzers/Terminal.Gui.Analyzers.Internal/Generators/EnumExtensions/EnumExtensionMethodsIncrementalGenerator.cs @@ -22,7 +22,7 @@ public sealed class EnumExtensionMethodsIncrementalGenerator : IIncrementalGener private const string GeneratorAttributeName = nameof (GenerateEnumExtensionMethodsAttribute); /// Fully-qualified symbol name format without the "global::" prefix. - private static readonly SymbolDisplayFormat FullyQualifiedSymbolDisplayFormatWithoutGlobal = + private static readonly SymbolDisplayFormat _fullyQualifiedSymbolDisplayFormatWithoutGlobal = SymbolDisplayFormat.FullyQualifiedFormat.WithGlobalNamespaceStyle (SymbolDisplayGlobalNamespaceStyle.Omitted); /// @@ -160,7 +160,7 @@ public sealed class EnumExtensionMethodsIncrementalGenerator : IIncrementalGener string enumName = namedSymbol.Name; - string enumNamespace = enumNamespaceSymbol.ToDisplayString (FullyQualifiedSymbolDisplayFormatWithoutGlobal); + string enumNamespace = enumNamespaceSymbol.ToDisplayString (_fullyQualifiedSymbolDisplayFormatWithoutGlobal); TypeCode enumTypeCode = namedSymbol.EnumUnderlyingType.Name switch {