From bea6083d21e41e36df562a7b8d673ae5134bd9f1 Mon Sep 17 00:00:00 2001 From: Youssef1313 Date: Wed, 14 Dec 2022 21:19:45 +0200 Subject: [PATCH 1/9] Fix generator incrementality --- .../ApplicationConfigurationGenerator.cs | 20 ++++++++++--------- .../Forms/Generators/ProjectFileReader.cs | 8 +------- .../Forms/ApplicationConfig.FontDescriptor.cs | 2 +- .../Forms/ApplicationConfig.FontStyle.cs | 4 ++-- .../Forms/ApplicationConfig.GraphicsUnit.cs | 4 ++-- .../System/Windows/Forms/ApplicationConfig.cs | 18 +++++++++++------ 6 files changed, 29 insertions(+), 27 deletions(-) diff --git a/src/System.Windows.Forms.Analyzers.CSharp/src/System/Windows/Forms/Generators/ApplicationConfigurationGenerator.cs b/src/System.Windows.Forms.Analyzers.CSharp/src/System/Windows/Forms/Generators/ApplicationConfigurationGenerator.cs index 36ef732c5aa..956387294f4 100644 --- a/src/System.Windows.Forms.Analyzers.CSharp/src/System/Windows/Forms/Generators/ApplicationConfigurationGenerator.cs +++ b/src/System.Windows.Forms.Analyzers.CSharp/src/System/Windows/Forms/Generators/ApplicationConfigurationGenerator.cs @@ -2,7 +2,7 @@ // The .NET Foundation licenses this file to you under the MIT license. // See the LICENSE file in the project root for more information. -using System.Collections.Immutable; +using System.Linq; using System.Windows.Forms.Analyzers; using Microsoft.CodeAnalysis; using Microsoft.CodeAnalysis.CSharp.Syntax; @@ -14,12 +14,13 @@ internal class ApplicationConfigurationGenerator : IIncrementalGenerator { private static void Execute( SourceProductionContext context, - ImmutableArray syntaxNodes, + bool hasSupportedSyntaxNode, + string? projectNamespace, OutputKind outputKind, ApplicationConfig? applicationConfig, Diagnostic? applicationConfigDiagnostics) { - if (syntaxNodes.IsEmpty) + if (!hasSupportedSyntaxNode) { return; } @@ -44,7 +45,7 @@ private static void Execute( return; } - string? code = ApplicationConfigurationInitializeBuilder.GenerateInitialize(projectNamespace: GetUserProjectNamespace(syntaxNodes[0]), applicationConfig); + string? code = ApplicationConfigurationInitializeBuilder.GenerateInitialize(projectNamespace, applicationConfig); if (code is not null) { context.AddSource("ApplicationConfiguration.g.cs", code); @@ -65,24 +66,25 @@ private static void Execute( public void Initialize(IncrementalGeneratorInitializationContext context) { + var outputKindProvider = context.CompilationProvider.Select((compilation, _) => compilation.Options.OutputKind); var syntaxProvider = context.SyntaxProvider.CreateSyntaxProvider( predicate: (syntaxNode, _) => IsSupportedSyntaxNode(syntaxNode), - transform: (generatorSyntaxContext, _) => generatorSyntaxContext.Node); + transform: (generatorSyntaxContext, _) => GetUserProjectNamespace(generatorSyntaxContext.Node)); var globalConfig = ProjectFileReader.ReadApplicationConfig(context.AnalyzerConfigOptionsProvider); - var inputs = context.CompilationProvider + var inputs = outputKindProvider .Combine(syntaxProvider.Collect()) .Combine(globalConfig) .Select((data, cancellationToken) - => (Compilation: data.Left.Left, - Nodes: data.Left.Right, + => (OutputKind: data.Left.Left, + ProjectNamespaces: data.Left.Right, ApplicationConfig: data.Right.ApplicationConfig, ApplicationConfigDiagnostics: data.Right.Diagnostic)); context.RegisterSourceOutput( inputs, - (context, source) => Execute(context, source.Nodes, source.Compilation.Options.OutputKind, source.ApplicationConfig, source.ApplicationConfigDiagnostics)); + (context, source) => Execute(context, source.ProjectNamespaces.Length > 0, source.ProjectNamespaces.Length > 0 ? source.ProjectNamespaces[0] : null, source.OutputKind, source.ApplicationConfig, source.ApplicationConfigDiagnostics)); } public static bool IsSupportedSyntaxNode(SyntaxNode syntaxNode) diff --git a/src/System.Windows.Forms.Analyzers.CSharp/src/System/Windows/Forms/Generators/ProjectFileReader.cs b/src/System.Windows.Forms.Analyzers.CSharp/src/System/Windows/Forms/Generators/ProjectFileReader.cs index 8f26d2be324..99ba123daa6 100644 --- a/src/System.Windows.Forms.Analyzers.CSharp/src/System/Windows/Forms/Generators/ProjectFileReader.cs +++ b/src/System.Windows.Forms.Analyzers.CSharp/src/System/Windows/Forms/Generators/ProjectFileReader.cs @@ -28,13 +28,7 @@ internal static partial class ProjectFileReader return ((ApplicationConfig?)null, diagnostic); } - ApplicationConfig projectConfig = new() - { - EnableVisualStyles = enableVisualStyles, - DefaultFont = font, - HighDpiMode = highDpiMode, - UseCompatibleTextRendering = useCompatibleTextRendering - }; + ApplicationConfig projectConfig = new(enableVisualStyles, font?.ToString(), highDpiMode, useCompatibleTextRendering); return (projectConfig, null); }); diff --git a/src/System.Windows.Forms.Analyzers/src/System/Windows/Forms/ApplicationConfig.FontDescriptor.cs b/src/System.Windows.Forms.Analyzers/src/System/Windows/Forms/ApplicationConfig.FontDescriptor.cs index f9041700ea0..c239276b899 100644 --- a/src/System.Windows.Forms.Analyzers/src/System/Windows/Forms/ApplicationConfig.FontDescriptor.cs +++ b/src/System.Windows.Forms.Analyzers/src/System/Windows/Forms/ApplicationConfig.FontDescriptor.cs @@ -7,7 +7,7 @@ namespace System.Windows.Forms.Analyzers { - internal partial class ApplicationConfig + internal partial record ApplicationConfig { public class FontDescriptor { diff --git a/src/System.Windows.Forms.Analyzers/src/System/Windows/Forms/ApplicationConfig.FontStyle.cs b/src/System.Windows.Forms.Analyzers/src/System/Windows/Forms/ApplicationConfig.FontStyle.cs index 97877a077fa..54eac898d13 100644 --- a/src/System.Windows.Forms.Analyzers/src/System/Windows/Forms/ApplicationConfig.FontStyle.cs +++ b/src/System.Windows.Forms.Analyzers/src/System/Windows/Forms/ApplicationConfig.FontStyle.cs @@ -1,10 +1,10 @@ -// Licensed to the .NET Foundation under one or more agreements. +// Licensed to the .NET Foundation under one or more agreements. // The .NET Foundation licenses this file to you under the MIT license. // See the LICENSE file in the project root for more information. namespace System.Windows.Forms.Analyzers { - internal partial class ApplicationConfig + internal partial record ApplicationConfig { // Copied from https://github.com/dotnet/runtime/blob/00ee1c18715723e62484c9bc8a14f517455fc3b3/src/libraries/System.Drawing.Common/src/System/Drawing/FontStyle.cs [Flags] diff --git a/src/System.Windows.Forms.Analyzers/src/System/Windows/Forms/ApplicationConfig.GraphicsUnit.cs b/src/System.Windows.Forms.Analyzers/src/System/Windows/Forms/ApplicationConfig.GraphicsUnit.cs index a436eb2a341..f07d12832b9 100644 --- a/src/System.Windows.Forms.Analyzers/src/System/Windows/Forms/ApplicationConfig.GraphicsUnit.cs +++ b/src/System.Windows.Forms.Analyzers/src/System/Windows/Forms/ApplicationConfig.GraphicsUnit.cs @@ -1,10 +1,10 @@ -// Licensed to the .NET Foundation under one or more agreements. +// Licensed to the .NET Foundation under one or more agreements. // The .NET Foundation licenses this file to you under the MIT license. // See the LICENSE file in the project root for more information. namespace System.Windows.Forms.Analyzers { - internal partial class ApplicationConfig + internal partial record ApplicationConfig { // Copied from https://github.com/dotnet/runtime/blob/00ee1c18715723e62484c9bc8a14f517455fc3b3/src/libraries/System.Drawing.Common/src/System/Drawing/GraphicsUnit.cs public enum GraphicsUnit diff --git a/src/System.Windows.Forms.Analyzers/src/System/Windows/Forms/ApplicationConfig.cs b/src/System.Windows.Forms.Analyzers/src/System/Windows/Forms/ApplicationConfig.cs index c901554407c..56dcd8e6fca 100644 --- a/src/System.Windows.Forms.Analyzers/src/System/Windows/Forms/ApplicationConfig.cs +++ b/src/System.Windows.Forms.Analyzers/src/System/Windows/Forms/ApplicationConfig.cs @@ -2,9 +2,20 @@ // The .NET Foundation licenses this file to you under the MIT license. // See the LICENSE file in the project root for more information. +namespace System.Runtime.CompilerServices +{ + internal static class IsExternalInit + { + } +} + namespace System.Windows.Forms.Analyzers { - internal partial class ApplicationConfig + internal partial record ApplicationConfig( + bool EnableVisualStyles, + string? DefaultFont, + HighDpiMode HighDpiMode, + bool UseCompatibleTextRendering) { public static class PropertyNameCSharp { @@ -27,10 +38,5 @@ public static class PropertyDefaultValue public const HighDpiMode DpiMode = HighDpiMode.SystemAware; public const bool UseCompatibleTextRendering = false; } - - public bool EnableVisualStyles { get; set; } - public FontDescriptor? DefaultFont { get; set; } - public HighDpiMode HighDpiMode { get; set; } - public bool UseCompatibleTextRendering { get; set; } } } From 363bb431b69532a32c66f94f164c0aaa4a5d55b5 Mon Sep 17 00:00:00 2001 From: Youssef Victor Date: Wed, 14 Dec 2022 21:24:34 +0200 Subject: [PATCH 2/9] Cleanup --- .../Forms/Generators/ApplicationConfigurationGenerator.cs | 5 ++--- 1 file changed, 2 insertions(+), 3 deletions(-) diff --git a/src/System.Windows.Forms.Analyzers.CSharp/src/System/Windows/Forms/Generators/ApplicationConfigurationGenerator.cs b/src/System.Windows.Forms.Analyzers.CSharp/src/System/Windows/Forms/Generators/ApplicationConfigurationGenerator.cs index 956387294f4..93b55e37548 100644 --- a/src/System.Windows.Forms.Analyzers.CSharp/src/System/Windows/Forms/Generators/ApplicationConfigurationGenerator.cs +++ b/src/System.Windows.Forms.Analyzers.CSharp/src/System/Windows/Forms/Generators/ApplicationConfigurationGenerator.cs @@ -2,7 +2,6 @@ // The .NET Foundation licenses this file to you under the MIT license. // See the LICENSE file in the project root for more information. -using System.Linq; using System.Windows.Forms.Analyzers; using Microsoft.CodeAnalysis; using Microsoft.CodeAnalysis.CSharp.Syntax; @@ -68,8 +67,8 @@ public void Initialize(IncrementalGeneratorInitializationContext context) { var outputKindProvider = context.CompilationProvider.Select((compilation, _) => compilation.Options.OutputKind); var syntaxProvider = context.SyntaxProvider.CreateSyntaxProvider( - predicate: (syntaxNode, _) => IsSupportedSyntaxNode(syntaxNode), - transform: (generatorSyntaxContext, _) => GetUserProjectNamespace(generatorSyntaxContext.Node)); + predicate: static (syntaxNode, _) => IsSupportedSyntaxNode(syntaxNode), + transform: static (generatorSyntaxContext, _) => GetUserProjectNamespace(generatorSyntaxContext.Node)); var globalConfig = ProjectFileReader.ReadApplicationConfig(context.AnalyzerConfigOptionsProvider); From d7cb27fbf236aaa57934e243166fa32a0e89892a Mon Sep 17 00:00:00 2001 From: Youssef Victor Date: Wed, 14 Dec 2022 21:53:48 +0200 Subject: [PATCH 3/9] Update ApplicationConfigurationInitializeBuilderTests.cs --- ...tionConfigurationInitializeBuilderTests.cs | 111 ++++++++---------- 1 file changed, 52 insertions(+), 59 deletions(-) diff --git a/src/System.Windows.Forms.Analyzers.CSharp/tests/UnitTests/System/Windows/Forms/Generators/ApplicationConfigurationInitializeBuilderTests.cs b/src/System.Windows.Forms.Analyzers.CSharp/tests/UnitTests/System/Windows/Forms/Generators/ApplicationConfigurationInitializeBuilderTests.cs index 07b94220a89..c2284d7b020 100644 --- a/src/System.Windows.Forms.Analyzers.CSharp/tests/UnitTests/System/Windows/Forms/Generators/ApplicationConfigurationInitializeBuilderTests.cs +++ b/src/System.Windows.Forms.Analyzers.CSharp/tests/UnitTests/System/Windows/Forms/Generators/ApplicationConfigurationInitializeBuilderTests.cs @@ -37,13 +37,12 @@ public void ApplicationConfigurationInitializeBuilder_GenerateInitialize_can_han string expected = File.ReadAllText($@"System\Windows\Forms\Generators\MockData\{GetType().Name}.{expectedFileName}.cs"); string output = ApplicationConfigurationInitializeBuilder.GenerateInitialize(ns, - new ApplicationConfig - { - DefaultFont = null, - EnableVisualStyles = PropertyDefaultValue.EnableVisualStyles, - HighDpiMode = PropertyDefaultValue.DpiMode, - UseCompatibleTextRendering = PropertyDefaultValue.UseCompatibleTextRendering - }); + new ApplicationConfig( + EnableVisualStyles: PropertyDefaultValue.EnableVisualStyles, + DefaultFont: null, + HighDpiMode: PropertyDefaultValue.DpiMode, + UseCompatibleTextRendering: PropertyDefaultValue.UseCompatibleTextRendering + )); Assert.Equal(expected, output); } @@ -58,24 +57,22 @@ public static IEnumerable GenerateInitializeData() yield return new object[] { culture, - new ApplicationConfig - { - DefaultFont = null, - EnableVisualStyles = false, - HighDpiMode = PropertyDefaultValue.DpiMode, - UseCompatibleTextRendering = PropertyDefaultValue.UseCompatibleTextRendering - }, + new ApplicationConfig( + EnableVisualStyles: false, + DefaultFont: null, + HighDpiMode: PropertyDefaultValue.DpiMode, + UseCompatibleTextRendering: PropertyDefaultValue.UseCompatibleTextRendering + ), "EnableVisualStyles=false" }; yield return new object[] { culture, - new ApplicationConfig - { - DefaultFont = null, - EnableVisualStyles = true, - HighDpiMode = PropertyDefaultValue.DpiMode, - UseCompatibleTextRendering = PropertyDefaultValue.UseCompatibleTextRendering + new ApplicationConfig( + EnableVisualStyles: true, + DefaultFont: null, + HighDpiMode: PropertyDefaultValue.DpiMode, + UseCompatibleTextRendering: PropertyDefaultValue.UseCompatibleTextRendering }, "EnableVisualStyles=true" }; @@ -84,25 +81,23 @@ public static IEnumerable GenerateInitializeData() yield return new object[] { culture, - new ApplicationConfig - { - DefaultFont = null, - EnableVisualStyles = PropertyDefaultValue.EnableVisualStyles, - HighDpiMode = PropertyDefaultValue.DpiMode, - UseCompatibleTextRendering = false - }, + new ApplicationConfig( + EnableVisualStyles: PropertyDefaultValue.EnableVisualStyles, + DefaultFont: null, + HighDpiMode: PropertyDefaultValue.DpiMode, + UseCompatibleTextRendering: false + ), "UseCompTextRendering=false" }; yield return new object[] { culture, - new ApplicationConfig - { - DefaultFont = null, - EnableVisualStyles = PropertyDefaultValue.EnableVisualStyles, - HighDpiMode = PropertyDefaultValue.DpiMode, - UseCompatibleTextRendering = true - }, + new ApplicationConfig( + EnableVisualStyles: PropertyDefaultValue.EnableVisualStyles, + DefaultFont: null, + HighDpiMode: PropertyDefaultValue.DpiMode, + UseCompatibleTextRendering: true + ), "UseCompTextRendering=true" }; @@ -110,48 +105,46 @@ public static IEnumerable GenerateInitializeData() yield return new object[] { culture, - new ApplicationConfig - { - DefaultFont = null, - EnableVisualStyles = PropertyDefaultValue.EnableVisualStyles, - HighDpiMode = PropertyDefaultValue.DpiMode, - UseCompatibleTextRendering = false - }, + new ApplicationConfig( + EnableVisualStyles: PropertyDefaultValue.EnableVisualStyles, + DefaultFont: null, + HighDpiMode: PropertyDefaultValue.DpiMode, + UseCompatibleTextRendering: false + ), "DefaultFont=null" }; yield return new object[] { culture, - new ApplicationConfig - { - DefaultFont = new FontDescriptor(string.Empty, 12, FontStyle.Bold | FontStyle.Italic, GraphicsUnit.Millimeter), - EnableVisualStyles = PropertyDefaultValue.EnableVisualStyles, - HighDpiMode = PropertyDefaultValue.DpiMode, - UseCompatibleTextRendering = true - }, + new ApplicationConfig( + EnableVisualStyles: PropertyDefaultValue.EnableVisualStyles, + DefaultFont: new FontDescriptor(string.Empty, 12, FontStyle.Bold | FontStyle.Italic, GraphicsUnit.Millimeter).ToString(), + HighDpiMode: PropertyDefaultValue.DpiMode, + UseCompatibleTextRendering: true + ), "DefaultFont=default" }; yield return new object[] { culture, - new ApplicationConfig + new ApplicationConfig( { - DefaultFont = new FontDescriptor("Tahoma", 12, FontStyle.Regular, GraphicsUnit.Point), - EnableVisualStyles = PropertyDefaultValue.EnableVisualStyles, - HighDpiMode = PropertyDefaultValue.DpiMode, - UseCompatibleTextRendering = true - }, + EnableVisualStyles: PropertyDefaultValue.EnableVisualStyles, + DefaultFont: new FontDescriptor("Tahoma", 12, FontStyle.Regular, GraphicsUnit.Point).ToString(), + HighDpiMode: PropertyDefaultValue.DpiMode, + UseCompatibleTextRendering: true + ), "DefaultFont=Tahoma" }; yield return new object[] { culture, - new ApplicationConfig + new ApplicationConfig( { - DefaultFont = new FontDescriptor("Microsoft Sans Serif", 8.25f, FontStyle.Regular, GraphicsUnit.Point), - EnableVisualStyles = PropertyDefaultValue.EnableVisualStyles, - HighDpiMode = PropertyDefaultValue.DpiMode, - UseCompatibleTextRendering = true + EnableVisualStyles: PropertyDefaultValue.EnableVisualStyles, + DefaultFont: new FontDescriptor("Microsoft Sans Serif", 8.25f, FontStyle.Regular, GraphicsUnit.Point).ToString(), + HighDpiMode: PropertyDefaultValue.DpiMode, + UseCompatibleTextRendering: true }, "DefaultFont=SansSerif" }; From a3d5f02e434a4a87cc9071a72c573745cd1b449f Mon Sep 17 00:00:00 2001 From: Youssef Victor Date: Thu, 15 Dec 2022 08:47:49 +0200 Subject: [PATCH 4/9] Fix errors --- .../ApplicationConfigurationInitializeBuilderTests.cs | 5 ++--- 1 file changed, 2 insertions(+), 3 deletions(-) diff --git a/src/System.Windows.Forms.Analyzers.CSharp/tests/UnitTests/System/Windows/Forms/Generators/ApplicationConfigurationInitializeBuilderTests.cs b/src/System.Windows.Forms.Analyzers.CSharp/tests/UnitTests/System/Windows/Forms/Generators/ApplicationConfigurationInitializeBuilderTests.cs index c2284d7b020..4faabba1956 100644 --- a/src/System.Windows.Forms.Analyzers.CSharp/tests/UnitTests/System/Windows/Forms/Generators/ApplicationConfigurationInitializeBuilderTests.cs +++ b/src/System.Windows.Forms.Analyzers.CSharp/tests/UnitTests/System/Windows/Forms/Generators/ApplicationConfigurationInitializeBuilderTests.cs @@ -73,7 +73,7 @@ public static IEnumerable GenerateInitializeData() DefaultFont: null, HighDpiMode: PropertyDefaultValue.DpiMode, UseCompatibleTextRendering: PropertyDefaultValue.UseCompatibleTextRendering - }, + ), "EnableVisualStyles=true" }; @@ -140,12 +140,11 @@ public static IEnumerable GenerateInitializeData() { culture, new ApplicationConfig( - { EnableVisualStyles: PropertyDefaultValue.EnableVisualStyles, DefaultFont: new FontDescriptor("Microsoft Sans Serif", 8.25f, FontStyle.Regular, GraphicsUnit.Point).ToString(), HighDpiMode: PropertyDefaultValue.DpiMode, UseCompatibleTextRendering: true - }, + ), "DefaultFont=SansSerif" }; } From f54d347782f786da5c7d374fb6c1a5c35af6ab0c Mon Sep 17 00:00:00 2001 From: Youssef Victor Date: Thu, 15 Dec 2022 08:50:48 +0200 Subject: [PATCH 5/9] fully qualify --- .../Windows/Forms/ApplicationConfig.FontDescriptor.cs | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/src/System.Windows.Forms.Analyzers/src/System/Windows/Forms/ApplicationConfig.FontDescriptor.cs b/src/System.Windows.Forms.Analyzers/src/System/Windows/Forms/ApplicationConfig.FontDescriptor.cs index c239276b899..97013181df8 100644 --- a/src/System.Windows.Forms.Analyzers/src/System/Windows/Forms/ApplicationConfig.FontDescriptor.cs +++ b/src/System.Windows.Forms.Analyzers/src/System/Windows/Forms/ApplicationConfig.FontDescriptor.cs @@ -30,10 +30,10 @@ public override string ToString() string name = Regex.Replace(Name, @"[^\w\d ]", string.Empty); string fontFamily = string.IsNullOrWhiteSpace(name) - ? "Control.DefaultFont.FontFamily" - : $"new FontFamily(\"{name}\")"; + ? "global::System.Windows.Forms.Control.DefaultFont.FontFamily" + : $"new global::System.Drawing.FontFamily(\"{name}\")"; - return $"new Font({fontFamily}, {Size.ToString(CultureInfo.InvariantCulture)}f, (FontStyle){(int)Style}, (GraphicsUnit){(int)Unit})"; + return $"new global::System.Drawing.Font({fontFamily}, {Size.ToString(CultureInfo.InvariantCulture)}f, (global::System.Drawing.FontStyle){(int)Style}, (global::System.Drawing.GraphicsUnit){(int)Unit})"; } } } From 7bbdbd7043af82d526174ed6e76b5c86aa02fa67 Mon Sep 17 00:00:00 2001 From: Youssef Victor Date: Thu, 15 Dec 2022 10:06:09 +0200 Subject: [PATCH 6/9] Fix build error --- .../Generators/ApplicationConfigurationInitializeBuilderTests.cs | 1 - 1 file changed, 1 deletion(-) diff --git a/src/System.Windows.Forms.Analyzers.CSharp/tests/UnitTests/System/Windows/Forms/Generators/ApplicationConfigurationInitializeBuilderTests.cs b/src/System.Windows.Forms.Analyzers.CSharp/tests/UnitTests/System/Windows/Forms/Generators/ApplicationConfigurationInitializeBuilderTests.cs index 4faabba1956..5ddddc20ae9 100644 --- a/src/System.Windows.Forms.Analyzers.CSharp/tests/UnitTests/System/Windows/Forms/Generators/ApplicationConfigurationInitializeBuilderTests.cs +++ b/src/System.Windows.Forms.Analyzers.CSharp/tests/UnitTests/System/Windows/Forms/Generators/ApplicationConfigurationInitializeBuilderTests.cs @@ -128,7 +128,6 @@ public static IEnumerable GenerateInitializeData() { culture, new ApplicationConfig( - { EnableVisualStyles: PropertyDefaultValue.EnableVisualStyles, DefaultFont: new FontDescriptor("Tahoma", 12, FontStyle.Regular, GraphicsUnit.Point).ToString(), HighDpiMode: PropertyDefaultValue.DpiMode, From d8e39022c64f03697da060681c52bd024f971ad6 Mon Sep 17 00:00:00 2001 From: Youssef1313 Date: Thu, 15 Dec 2022 10:57:55 +0200 Subject: [PATCH 7/9] Fix tests --- ...Initialize_DefaultFont=SansSerif.verified.txt | 4 ++-- ...ateInitialize_DefaultFont=Tahoma.verified.txt | 4 ++-- ...teInitialize_DefaultFont=default.verified.txt | 4 ++-- .../ApplicationConfigTests.FontDescriptor.cs | 16 ++++++++-------- 4 files changed, 14 insertions(+), 14 deletions(-) diff --git a/src/System.Windows.Forms.Analyzers.CSharp/tests/UnitTests/System/Windows/Forms/Generators/ApplicationConfigurationInitializeBuilderTests.GenerateInitialize_DefaultFont=SansSerif.verified.txt b/src/System.Windows.Forms.Analyzers.CSharp/tests/UnitTests/System/Windows/Forms/Generators/ApplicationConfigurationInitializeBuilderTests.GenerateInitialize_DefaultFont=SansSerif.verified.txt index da42d2f7eac..f76e8661f6f 100644 --- a/src/System.Windows.Forms.Analyzers.CSharp/tests/UnitTests/System/Windows/Forms/Generators/ApplicationConfigurationInitializeBuilderTests.GenerateInitialize_DefaultFont=SansSerif.verified.txt +++ b/src/System.Windows.Forms.Analyzers.CSharp/tests/UnitTests/System/Windows/Forms/Generators/ApplicationConfigurationInitializeBuilderTests.GenerateInitialize_DefaultFont=SansSerif.verified.txt @@ -17,7 +17,7 @@ internal static partial class ApplicationConfiguration /// global::System.Windows.Forms.Application.EnableVisualStyles(); /// global::System.Windows.Forms.Application.SetCompatibleTextRenderingDefault(true); /// global::System.Windows.Forms.Application.SetHighDpiMode(HighDpiMode.SystemAware); - /// global::System.Windows.Forms.Application.SetDefaultFont(new Font(new FontFamily("Microsoft Sans Serif"), 8.25f, (FontStyle)0, (GraphicsUnit)3)); + /// global::System.Windows.Forms.Application.SetDefaultFont(new global::System.Drawing.Font(new global::System.Drawing.FontFamily("Microsoft Sans Serif"), 8.25f, (global::System.Drawing.FontStyle)0, (global::System.Drawing.GraphicsUnit)3)); /// /// public static void Initialize() @@ -25,6 +25,6 @@ internal static partial class ApplicationConfiguration global::System.Windows.Forms.Application.EnableVisualStyles(); global::System.Windows.Forms.Application.SetCompatibleTextRenderingDefault(true); global::System.Windows.Forms.Application.SetHighDpiMode(HighDpiMode.SystemAware); - global::System.Windows.Forms.Application.SetDefaultFont(new Font(new FontFamily("Microsoft Sans Serif"), 8.25f, (FontStyle)0, (GraphicsUnit)3)); + global::System.Windows.Forms.Application.SetDefaultFont(new global::System.Drawing.Font(new global::System.Drawing.FontFamily("Microsoft Sans Serif"), 8.25f, (global::System.Drawing.FontStyle)0, (global::System.Drawing.GraphicsUnit)3)); } } diff --git a/src/System.Windows.Forms.Analyzers.CSharp/tests/UnitTests/System/Windows/Forms/Generators/ApplicationConfigurationInitializeBuilderTests.GenerateInitialize_DefaultFont=Tahoma.verified.txt b/src/System.Windows.Forms.Analyzers.CSharp/tests/UnitTests/System/Windows/Forms/Generators/ApplicationConfigurationInitializeBuilderTests.GenerateInitialize_DefaultFont=Tahoma.verified.txt index 281c844b844..97184b57304 100644 --- a/src/System.Windows.Forms.Analyzers.CSharp/tests/UnitTests/System/Windows/Forms/Generators/ApplicationConfigurationInitializeBuilderTests.GenerateInitialize_DefaultFont=Tahoma.verified.txt +++ b/src/System.Windows.Forms.Analyzers.CSharp/tests/UnitTests/System/Windows/Forms/Generators/ApplicationConfigurationInitializeBuilderTests.GenerateInitialize_DefaultFont=Tahoma.verified.txt @@ -17,7 +17,7 @@ internal static partial class ApplicationConfiguration /// global::System.Windows.Forms.Application.EnableVisualStyles(); /// global::System.Windows.Forms.Application.SetCompatibleTextRenderingDefault(true); /// global::System.Windows.Forms.Application.SetHighDpiMode(HighDpiMode.SystemAware); - /// global::System.Windows.Forms.Application.SetDefaultFont(new Font(new FontFamily("Tahoma"), 12f, (FontStyle)0, (GraphicsUnit)3)); + /// global::System.Windows.Forms.Application.SetDefaultFont(new global::System.Drawing.Font(new global::System.Drawing.FontFamily("Tahoma"), 12f, (global::System.Drawing.FontStyle)0, (global::System.Drawing.GraphicsUnit)3)); /// /// public static void Initialize() @@ -25,6 +25,6 @@ internal static partial class ApplicationConfiguration global::System.Windows.Forms.Application.EnableVisualStyles(); global::System.Windows.Forms.Application.SetCompatibleTextRenderingDefault(true); global::System.Windows.Forms.Application.SetHighDpiMode(HighDpiMode.SystemAware); - global::System.Windows.Forms.Application.SetDefaultFont(new Font(new FontFamily("Tahoma"), 12f, (FontStyle)0, (GraphicsUnit)3)); + global::System.Windows.Forms.Application.SetDefaultFont(new global::System.Drawing.Font(new global::System.Drawing.FontFamily("Tahoma"), 12f, (global::System.Drawing.FontStyle)0, (global::System.Drawing.GraphicsUnit)3)); } } diff --git a/src/System.Windows.Forms.Analyzers.CSharp/tests/UnitTests/System/Windows/Forms/Generators/ApplicationConfigurationInitializeBuilderTests.GenerateInitialize_DefaultFont=default.verified.txt b/src/System.Windows.Forms.Analyzers.CSharp/tests/UnitTests/System/Windows/Forms/Generators/ApplicationConfigurationInitializeBuilderTests.GenerateInitialize_DefaultFont=default.verified.txt index 4ba59493dd5..f47084cb332 100644 --- a/src/System.Windows.Forms.Analyzers.CSharp/tests/UnitTests/System/Windows/Forms/Generators/ApplicationConfigurationInitializeBuilderTests.GenerateInitialize_DefaultFont=default.verified.txt +++ b/src/System.Windows.Forms.Analyzers.CSharp/tests/UnitTests/System/Windows/Forms/Generators/ApplicationConfigurationInitializeBuilderTests.GenerateInitialize_DefaultFont=default.verified.txt @@ -17,7 +17,7 @@ internal static partial class ApplicationConfiguration /// global::System.Windows.Forms.Application.EnableVisualStyles(); /// global::System.Windows.Forms.Application.SetCompatibleTextRenderingDefault(true); /// global::System.Windows.Forms.Application.SetHighDpiMode(HighDpiMode.SystemAware); - /// global::System.Windows.Forms.Application.SetDefaultFont(new Font(Control.DefaultFont.FontFamily, 12f, (FontStyle)3, (GraphicsUnit)6)); + /// global::System.Windows.Forms.Application.SetDefaultFont(new global::System.Drawing.Font(global::System.Windows.Forms.Control.DefaultFont.FontFamily, 12f, (global::System.Drawing.FontStyle)3, (global::System.Drawing.GraphicsUnit)6)); /// /// public static void Initialize() @@ -25,6 +25,6 @@ internal static partial class ApplicationConfiguration global::System.Windows.Forms.Application.EnableVisualStyles(); global::System.Windows.Forms.Application.SetCompatibleTextRenderingDefault(true); global::System.Windows.Forms.Application.SetHighDpiMode(HighDpiMode.SystemAware); - global::System.Windows.Forms.Application.SetDefaultFont(new Font(Control.DefaultFont.FontFamily, 12f, (FontStyle)3, (GraphicsUnit)6)); + global::System.Windows.Forms.Application.SetDefaultFont(new global::System.Drawing.Font(global::System.Windows.Forms.Control.DefaultFont.FontFamily, 12f, (global::System.Drawing.FontStyle)3, (global::System.Drawing.GraphicsUnit)6)); } } diff --git a/src/System.Windows.Forms.Analyzers/tests/UnitTests/System/Windows/Forms/Analyzers/ApplicationConfigTests.FontDescriptor.cs b/src/System.Windows.Forms.Analyzers/tests/UnitTests/System/Windows/Forms/Analyzers/ApplicationConfigTests.FontDescriptor.cs index 5a4059c1fc1..4dd85c4633e 100644 --- a/src/System.Windows.Forms.Analyzers/tests/UnitTests/System/Windows/Forms/Analyzers/ApplicationConfigTests.FontDescriptor.cs +++ b/src/System.Windows.Forms.Analyzers/tests/UnitTests/System/Windows/Forms/Analyzers/ApplicationConfigTests.FontDescriptor.cs @@ -32,14 +32,14 @@ public void FontDescriptor_ctor() } [Theory] - [InlineData("", "new Font(Control.DefaultFont.FontFamily, 10f, (FontStyle)3, (GraphicsUnit)3)")] - [InlineData(" ", "new Font(Control.DefaultFont.FontFamily, 10f, (FontStyle)3, (GraphicsUnit)3)")] - [InlineData("\t", "new Font(Control.DefaultFont.FontFamily, 10f, (FontStyle)3, (GraphicsUnit)3)")] - [InlineData("fontName", "new Font(new FontFamily(\"fontName\"), 10f, (FontStyle)3, (GraphicsUnit)3)")] - [InlineData("\"fontName\"", "new Font(new FontFamily(\"fontName\"), 10f, (FontStyle)3, (GraphicsUnit)3)")] - [InlineData("Name with \tspaces", "new Font(new FontFamily(\"Name with spaces\"), 10f, (FontStyle)3, (GraphicsUnit)3)")] - [InlineData("Name with 'quotes'", "new Font(new FontFamily(\"Name with quotes\"), 10f, (FontStyle)3, (GraphicsUnit)3)")] - [InlineData("Name with \r\n lines", "new Font(new FontFamily(\"Name with lines\"), 10f, (FontStyle)3, (GraphicsUnit)3)")] + [InlineData("", "new global::System.Drawing.Font(global::System.Windows.Forms.Control.DefaultFont.FontFamily, 10f, (global::System.Drawing.FontStyle)3, (global::System.Drawing.GraphicsUnit)3)")] + [InlineData(" ", "new global::System.Drawing.Font(global::System.Windows.Forms.Control.DefaultFont.FontFamily, 10f, (global::System.Drawing.FontStyle)3, (global::System.Drawing.GraphicsUnit)3)")] + [InlineData("\t", "new global::System.Drawing.Font(global::System.Windows.Forms.Control.DefaultFont.FontFamily, 10f, (global::System.Drawing.FontStyle)3, (global::System.Drawing.GraphicsUnit)3)")] + [InlineData("fontName", "new global::System.Drawing.Font(new global::System.Drawing.FontFamily(\"fontName\"), 10f, (global::System.Drawing.FontStyle)3, (global::System.Drawing.GraphicsUnit)3)")] + [InlineData("\"fontName\"", "new global::System.Drawing.Font(new global::System.Drawing.FontFamily(\"fontName\"), 10f, (global::System.Drawing.FontStyle)3, (global::System.Drawing.GraphicsUnit)3)")] + [InlineData("Name with \tspaces", "new global::System.Drawing.Font(new global::System.Drawing.FontFamily(\"Name with spaces\"), 10f, (global::System.Drawing.FontStyle)3, (global::System.Drawing.GraphicsUnit)3)")] + [InlineData("Name with 'quotes'", "new global::System.Drawing.Font(new global::System.Drawing.FontFamily(\"Name with quotes\"), 10f, (global::System.Drawing.FontStyle)3, (global::System.Drawing.GraphicsUnit)3)")] + [InlineData("Name with \r\n lines", "new global::System.Drawing.Font(new global::System.Drawing.FontFamily(\"Name with lines\"), 10f, (global::System.Drawing.FontStyle)3, (global::System.Drawing.GraphicsUnit)3)")] public void FontDescriptor_ToString(string fontName, string expected) { FontDescriptor descriptor = new(fontName, 10f, FontStyle.Bold | FontStyle.Italic, GraphicsUnit.Point); From 515ac2e11fac91e26167eae4ff5760abfeb00046 Mon Sep 17 00:00:00 2001 From: Youssef1313 Date: Wed, 4 Jan 2023 10:39:40 +0200 Subject: [PATCH 8/9] Fix tests --- ...igurationGeneratorTests.GenerateInitialize_user_top_level.cs | 2 +- .../Forms/Analyzers/ApplicationConfigTests.FontDescriptor.cs | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/src/System.Windows.Forms.Analyzers.CSharp/tests/UnitTests/System/Windows/Forms/Generators/MockData/ApplicationConfigurationGeneratorTests.GenerateInitialize_user_top_level.cs b/src/System.Windows.Forms.Analyzers.CSharp/tests/UnitTests/System/Windows/Forms/Generators/MockData/ApplicationConfigurationGeneratorTests.GenerateInitialize_user_top_level.cs index 760d80e44b9..393bf749c8f 100644 --- a/src/System.Windows.Forms.Analyzers.CSharp/tests/UnitTests/System/Windows/Forms/Generators/MockData/ApplicationConfigurationGeneratorTests.GenerateInitialize_user_top_level.cs +++ b/src/System.Windows.Forms.Analyzers.CSharp/tests/UnitTests/System/Windows/Forms/Generators/MockData/ApplicationConfigurationGeneratorTests.GenerateInitialize_user_top_level.cs @@ -25,6 +25,6 @@ public static void Initialize() global::System.Windows.Forms.Application.EnableVisualStyles(); global::System.Windows.Forms.Application.SetCompatibleTextRenderingDefault(true); global::System.Windows.Forms.Application.{|CS0117:SetHighDpiMode|}({|CS0103:HighDpiMode|}.DpiUnawareGdiScaled); - global::System.Windows.Forms.Application.{|CS0117:SetDefaultFont|}(new Font(new FontFamily("Microsoft Sans Serif"), 8.25f, (FontStyle)0, (GraphicsUnit)2)); + global::System.Windows.Forms.Application.{|CS0117:SetDefaultFont|}(new global::System.Drawing.Font(new global::System.Drawing.FontFamily("Microsoft Sans Serif"), 8.25f, (global::System.Drawing.FontStyle)0, (global::System.Drawing.GraphicsUnit)2)); } } diff --git a/src/System.Windows.Forms.Analyzers/tests/UnitTests/System/Windows/Forms/Analyzers/ApplicationConfigTests.FontDescriptor.cs b/src/System.Windows.Forms.Analyzers/tests/UnitTests/System/Windows/Forms/Analyzers/ApplicationConfigTests.FontDescriptor.cs index 4dd85c4633e..a3c6d61a233 100644 --- a/src/System.Windows.Forms.Analyzers/tests/UnitTests/System/Windows/Forms/Analyzers/ApplicationConfigTests.FontDescriptor.cs +++ b/src/System.Windows.Forms.Analyzers/tests/UnitTests/System/Windows/Forms/Analyzers/ApplicationConfigTests.FontDescriptor.cs @@ -65,7 +65,7 @@ public void FontDescriptor_ToString_culture_agnostic(string cultureName) FontDescriptor descriptor = new("Microsoft Sans Serif", 8.25f, FontStyle.Bold | FontStyle.Italic, GraphicsUnit.Point); _output.WriteLine(descriptor.ToString()); - Assert.Equal("new Font(new FontFamily(\"Microsoft Sans Serif\"), 8.25f, (FontStyle)3, (GraphicsUnit)3)", descriptor.ToString()); + Assert.Equal("new global::System.Drawing.Font(new global::System.Drawing.FontFamily(\"Microsoft Sans Serif\"), 8.25f, (global::System.Drawing.FontStyle)3, (global::System.Drawing.GraphicsUnit)3)", descriptor.ToString()); } } } From f78c1ba0e0df9a75c8197075a12c858cd82e7ea6 Mon Sep 17 00:00:00 2001 From: Youssef1313 Date: Wed, 4 Jan 2023 13:42:58 +0200 Subject: [PATCH 9/9] fix tests --- ...ratorTests.GenerateInitialize_user_settings_boilerplate.cs | 4 ++-- ...urationGeneratorTests.GenerateInitialize_user_top_level.cs | 2 +- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/src/System.Windows.Forms.Analyzers.CSharp/tests/UnitTests/System/Windows/Forms/Generators/MockData/ApplicationConfigurationGeneratorTests.GenerateInitialize_user_settings_boilerplate.cs b/src/System.Windows.Forms.Analyzers.CSharp/tests/UnitTests/System/Windows/Forms/Generators/MockData/ApplicationConfigurationGeneratorTests.GenerateInitialize_user_settings_boilerplate.cs index 98b21f3e51a..7e3e726507a 100644 --- a/src/System.Windows.Forms.Analyzers.CSharp/tests/UnitTests/System/Windows/Forms/Generators/MockData/ApplicationConfigurationGeneratorTests.GenerateInitialize_user_settings_boilerplate.cs +++ b/src/System.Windows.Forms.Analyzers.CSharp/tests/UnitTests/System/Windows/Forms/Generators/MockData/ApplicationConfigurationGeneratorTests.GenerateInitialize_user_settings_boilerplate.cs @@ -18,7 +18,7 @@ internal static partial class ApplicationConfiguration /// global::System.Windows.Forms.Application.EnableVisualStyles(); /// global::System.Windows.Forms.Application.SetCompatibleTextRenderingDefault(true); /// global::System.Windows.Forms.Application.SetHighDpiMode(HighDpiMode.DpiUnawareGdiScaled); - /// global::System.Windows.Forms.Application.SetDefaultFont(new Font(new FontFamily("Microsoft Sans Serif"), 8.25f, (FontStyle)0, (GraphicsUnit)2)); + /// global::System.Windows.Forms.Application.SetDefaultFont(new global::System.Drawing.Font(new global::System.Drawing.FontFamily("Microsoft Sans Serif"), 8.25f, (global::System.Drawing.FontStyle)0, (global::System.Drawing.GraphicsUnit)2)); /// /// public static void Initialize() @@ -26,7 +26,7 @@ public static void Initialize() global::System.Windows.Forms.Application.EnableVisualStyles(); global::System.Windows.Forms.Application.SetCompatibleTextRenderingDefault(true); global::System.Windows.Forms.Application.{|CS0117:SetHighDpiMode|}({|CS0103:HighDpiMode|}.DpiUnawareGdiScaled); - global::System.Windows.Forms.Application.{|CS0117:SetDefaultFont|}(new Font(new FontFamily("Microsoft Sans Serif"), 8.25f, (FontStyle)0, (GraphicsUnit)2)); + global::System.Windows.Forms.Application.{|CS0117:SetDefaultFont|}(new global::System.Drawing.Font(new global::System.Drawing.FontFamily("Microsoft Sans Serif"), 8.25f, (global::System.Drawing.FontStyle)0, (global::System.Drawing.GraphicsUnit)2)); } } } diff --git a/src/System.Windows.Forms.Analyzers.CSharp/tests/UnitTests/System/Windows/Forms/Generators/MockData/ApplicationConfigurationGeneratorTests.GenerateInitialize_user_top_level.cs b/src/System.Windows.Forms.Analyzers.CSharp/tests/UnitTests/System/Windows/Forms/Generators/MockData/ApplicationConfigurationGeneratorTests.GenerateInitialize_user_top_level.cs index 393bf749c8f..d030c8babd4 100644 --- a/src/System.Windows.Forms.Analyzers.CSharp/tests/UnitTests/System/Windows/Forms/Generators/MockData/ApplicationConfigurationGeneratorTests.GenerateInitialize_user_top_level.cs +++ b/src/System.Windows.Forms.Analyzers.CSharp/tests/UnitTests/System/Windows/Forms/Generators/MockData/ApplicationConfigurationGeneratorTests.GenerateInitialize_user_top_level.cs @@ -17,7 +17,7 @@ internal static partial class ApplicationConfiguration /// global::System.Windows.Forms.Application.EnableVisualStyles(); /// global::System.Windows.Forms.Application.SetCompatibleTextRenderingDefault(true); /// global::System.Windows.Forms.Application.SetHighDpiMode(HighDpiMode.DpiUnawareGdiScaled); - /// global::System.Windows.Forms.Application.SetDefaultFont(new Font(new FontFamily("Microsoft Sans Serif"), 8.25f, (FontStyle)0, (GraphicsUnit)2)); + /// global::System.Windows.Forms.Application.SetDefaultFont(new global::System.Drawing.Font(new global::System.Drawing.FontFamily("Microsoft Sans Serif"), 8.25f, (global::System.Drawing.FontStyle)0, (global::System.Drawing.GraphicsUnit)2)); /// /// public static void Initialize()