diff --git a/third_party/dotnet/devtools/src/generator/CodeGen/CodeGenerationDefinitionTemplateSettings.cs b/third_party/dotnet/devtools/src/generator/CodeGen/CodeGenerationDefinitionTemplateSettings.cs index 2ff1ea9a9dcfa..3ebbe82789756 100644 --- a/third_party/dotnet/devtools/src/generator/CodeGen/CodeGenerationDefinitionTemplateSettings.cs +++ b/third_party/dotnet/devtools/src/generator/CodeGen/CodeGenerationDefinitionTemplateSettings.cs @@ -1,68 +1,53 @@ +using System.Text.Json.Serialization; + namespace OpenQA.Selenium.DevToolsGenerator.CodeGen { - using System.Text.Json.Serialization; - /// /// Represents settings around Definition templates. /// public class CodeGenerationDefinitionTemplateSettings { - public CodeGenerationDefinitionTemplateSettings() - { - //Set Defaults; - DomainTemplate = new CodeGenerationTemplateSettings - { - TemplatePath = "domain.hbs", - OutputPath = "{{domainName}}\\{{className}}Adapter.cs", - }; - - CommandTemplate = new CodeGenerationTemplateSettings - { - TemplatePath = "command.hbs", - OutputPath = "{{domainName}}\\{{className}}Command.cs", - }; - - EventTemplate = new CodeGenerationTemplateSettings - { - TemplatePath = "event.hbs", - OutputPath = "{{domainName}}\\{{className}}EventArgs.cs", - }; - - TypeObjectTemplate = new CodeGenerationTemplateSettings - { - TemplatePath = "type-object.hbs", - OutputPath = "{{domainName}}\\{{className}}.cs", - }; - - TypeHashTemplate = new CodeGenerationTemplateSettings - { - TemplatePath = "type-hash.hbs", - OutputPath = "{{domainName}}\\{{className}}.cs", - }; - - TypeEnumTemplate = new CodeGenerationTemplateSettings - { - TemplatePath = "type-enum.hbs", - OutputPath = "{{domainName}}{{separator}}{{className}}.cs", - }; - } - [JsonPropertyName("domainTemplate")] - public CodeGenerationTemplateSettings DomainTemplate { get; set; } + public CodeGenerationTemplateSettings DomainTemplate { get; set; } = new CodeGenerationTemplateSettings + { + TemplatePath = "domain.hbs", + OutputPath = "{{domainName}}\\{{className}}Adapter.cs", + }; [JsonPropertyName("commandTemplate")] - public CodeGenerationTemplateSettings CommandTemplate { get; set; } + public CodeGenerationTemplateSettings CommandTemplate { get; set; } = new CodeGenerationTemplateSettings + { + TemplatePath = "command.hbs", + OutputPath = "{{domainName}}\\{{className}}Command.cs", + }; [JsonPropertyName("eventTemplate")] - public CodeGenerationTemplateSettings EventTemplate { get; set; } + public CodeGenerationTemplateSettings EventTemplate { get; set; } = new CodeGenerationTemplateSettings + { + TemplatePath = "event.hbs", + OutputPath = "{{domainName}}\\{{className}}EventArgs.cs", + }; [JsonPropertyName("typeObjectTemplate")] - public CodeGenerationTemplateSettings TypeObjectTemplate { get; set; } + public CodeGenerationTemplateSettings TypeObjectTemplate { get; set; } = new CodeGenerationTemplateSettings + { + TemplatePath = "type-object.hbs", + OutputPath = "{{domainName}}\\{{className}}.cs", + }; + [JsonPropertyName("typeHashTemplate")] - public CodeGenerationTemplateSettings TypeHashTemplate { get; set; } + public CodeGenerationTemplateSettings TypeHashTemplate { get; set; } = new CodeGenerationTemplateSettings + { + TemplatePath = "type-hash.hbs", + OutputPath = "{{domainName}}\\{{className}}.cs", + }; [JsonPropertyName("typeEnumTemplate")] - public CodeGenerationTemplateSettings TypeEnumTemplate { get; set; } + public CodeGenerationTemplateSettings TypeEnumTemplate { get; set; } = new CodeGenerationTemplateSettings + { + TemplatePath = "type-enum.hbs", + OutputPath = "{{domainName}}{{separator}}{{className}}.cs", + }; } } diff --git a/third_party/dotnet/devtools/src/generator/CodeGen/CodeGenerationSettings.cs b/third_party/dotnet/devtools/src/generator/CodeGen/CodeGenerationSettings.cs index fdcd62b441d6a..b9049b2b08ba3 100644 --- a/third_party/dotnet/devtools/src/generator/CodeGen/CodeGenerationSettings.cs +++ b/third_party/dotnet/devtools/src/generator/CodeGen/CodeGenerationSettings.cs @@ -1,51 +1,36 @@ +using System.Text.Json.Serialization; +using System.Collections.Generic; + namespace OpenQA.Selenium.DevToolsGenerator.CodeGen { - using System.Text.Json.Serialization; - using System.Collections.Generic; - /// /// Settings to be passed to a ICodeGenerator /// public sealed class CodeGenerationSettings { - public CodeGenerationSettings() - { - //Set defaults - Include = new List(); - IncludeDeprecatedDomains = true; - IncludeExperimentalDomains = true; - RootNamespace = "BaristaLabs.ChromeDevTools"; - DefinitionTemplates = new CodeGenerationDefinitionTemplateSettings(); - TemplatesPath = "Templates"; - UsingStatements = new List() - { - "System" - }; - } - /// /// Collection of templates that will be parsed and output in the target folder. /// [JsonPropertyName("include")] - public ICollection Include { get; set; } + public ICollection Include { get; set; } = new List(); /// /// Indicates whether or not domains marked as depreciated will be generated. (Default: true) /// [JsonPropertyName("includeDeprecatedDomains")] - public bool IncludeDeprecatedDomains { get; set; } + public bool IncludeDeprecatedDomains { get; set; } = true; /// /// Indicates whether or not domains marked as depreciated will be generated. (Default: true) /// [JsonPropertyName("includeExperimentalDomains")] - public bool IncludeExperimentalDomains { get; set; } + public bool IncludeExperimentalDomains { get; set; } = true; /// /// Gets or sets the root namespace of generated classes. /// [JsonPropertyName("rootNamespace")] - public string RootNamespace { get; set; } + public string RootNamespace { get; set; } = "BaristaLabs.ChromeDevTools"; /// /// Gets the version number of the runtime. @@ -54,15 +39,18 @@ public CodeGenerationSettings() public string RuntimeVersion { get; set; } [JsonPropertyName("definitionTemplates")] - public CodeGenerationDefinitionTemplateSettings DefinitionTemplates { get; set; } + public CodeGenerationDefinitionTemplateSettings DefinitionTemplates { get; set; } = new CodeGenerationDefinitionTemplateSettings(); [JsonPropertyName("templatesPath")] - public string TemplatesPath { get; set; } + public string TemplatesPath { get; set; } = "Templates"; /// /// The using statements that will be included on each generated file. /// [JsonPropertyName("usingStatements")] - public ICollection UsingStatements { get; set; } + public ICollection UsingStatements { get; set; } = new List() + { + "System" + }; } } diff --git a/third_party/dotnet/devtools/src/generator/CodeGen/CodeGenerationTemplateSettings.cs b/third_party/dotnet/devtools/src/generator/CodeGen/CodeGenerationTemplateSettings.cs index a5360955d5764..99a9a2be31123 100644 --- a/third_party/dotnet/devtools/src/generator/CodeGen/CodeGenerationTemplateSettings.cs +++ b/third_party/dotnet/devtools/src/generator/CodeGen/CodeGenerationTemplateSettings.cs @@ -1,7 +1,7 @@ +using System.Text.Json.Serialization; + namespace OpenQA.Selenium.DevToolsGenerator.CodeGen { - using System.Text.Json.Serialization; - /// /// Defines settings around templates /// diff --git a/third_party/dotnet/devtools/src/generator/CodeGen/CodeGeneratorBase.cs b/third_party/dotnet/devtools/src/generator/CodeGen/CodeGeneratorBase.cs index aaf2344d7f5ce..d142a3a622154 100644 --- a/third_party/dotnet/devtools/src/generator/CodeGen/CodeGeneratorBase.cs +++ b/third_party/dotnet/devtools/src/generator/CodeGen/CodeGeneratorBase.cs @@ -1,10 +1,10 @@ +using Microsoft.Extensions.DependencyInjection; +using OpenQA.Selenium.DevToolsGenerator.ProtocolDefinition; +using System; +using System.Collections.Generic; + namespace OpenQA.Selenium.DevToolsGenerator.CodeGen { - using Microsoft.Extensions.DependencyInjection; - using OpenQA.Selenium.DevToolsGenerator.ProtocolDefinition; - using System; - using System.Collections.Generic; - /// /// Represents a base implementation of a code generator. /// @@ -12,14 +12,13 @@ namespace OpenQA.Selenium.DevToolsGenerator.CodeGen public abstract class CodeGeneratorBase : ICodeGenerator where T : IDefinition { - private readonly IServiceProvider m_serviceProvider; private readonly Lazy m_settings; private readonly Lazy m_templatesManager; /// /// Gets the service provider associated with the generator. /// - public IServiceProvider ServiceProvider => m_serviceProvider; + public IServiceProvider ServiceProvider { get; } /// /// Gets the code generation settings associated with the generator. @@ -33,9 +32,9 @@ public abstract class CodeGeneratorBase : ICodeGenerator protected CodeGeneratorBase(IServiceProvider serviceProvider) { - m_serviceProvider = serviceProvider ?? throw new ArgumentNullException(nameof(serviceProvider)); - m_settings = new Lazy(() => m_serviceProvider.GetRequiredService()); - m_templatesManager = new Lazy(() => m_serviceProvider.GetRequiredService()); + ServiceProvider = serviceProvider ?? throw new ArgumentNullException(nameof(serviceProvider)); + m_settings = new Lazy(() => ServiceProvider.GetRequiredService()); + m_templatesManager = new Lazy(() => ServiceProvider.GetRequiredService()); } public abstract IDictionary GenerateCode(T item, CodeGeneratorContext context); diff --git a/third_party/dotnet/devtools/src/generator/CodeGen/CodeGeneratorContext.cs b/third_party/dotnet/devtools/src/generator/CodeGen/CodeGeneratorContext.cs index 6970ee7ad4f7c..07ce4735c19da 100644 --- a/third_party/dotnet/devtools/src/generator/CodeGen/CodeGeneratorContext.cs +++ b/third_party/dotnet/devtools/src/generator/CodeGen/CodeGeneratorContext.cs @@ -1,8 +1,8 @@ +using OpenQA.Selenium.DevToolsGenerator.ProtocolDefinition; +using System.Collections.Generic; + namespace OpenQA.Selenium.DevToolsGenerator.CodeGen { - using OpenQA.Selenium.DevToolsGenerator.ProtocolDefinition; - using System.Collections.Generic; - /// /// Represents the current context of the code generator. /// diff --git a/third_party/dotnet/devtools/src/generator/CodeGen/CommandGenerator.cs b/third_party/dotnet/devtools/src/generator/CodeGen/CommandGenerator.cs index 4874a604d2989..aafeeb47fabed 100644 --- a/third_party/dotnet/devtools/src/generator/CodeGen/CommandGenerator.cs +++ b/third_party/dotnet/devtools/src/generator/CodeGen/CommandGenerator.cs @@ -1,10 +1,10 @@ +using Humanizer; +using OpenQA.Selenium.DevToolsGenerator.ProtocolDefinition; +using System; +using System.Collections.Generic; + namespace OpenQA.Selenium.DevToolsGenerator.CodeGen { - using Humanizer; - using OpenQA.Selenium.DevToolsGenerator.ProtocolDefinition; - using System; - using System.Collections.Generic; - /// /// Generates code for Command Definitions /// diff --git a/third_party/dotnet/devtools/src/generator/CodeGen/DomainGenerator.cs b/third_party/dotnet/devtools/src/generator/CodeGen/DomainGenerator.cs index 3bb3761aec311..84c2c1988f579 100644 --- a/third_party/dotnet/devtools/src/generator/CodeGen/DomainGenerator.cs +++ b/third_party/dotnet/devtools/src/generator/CodeGen/DomainGenerator.cs @@ -1,12 +1,11 @@ +using Humanizer; +using Microsoft.Extensions.DependencyInjection; +using OpenQA.Selenium.DevToolsGenerator.ProtocolDefinition; +using System; +using System.Collections.Generic; + namespace OpenQA.Selenium.DevToolsGenerator.CodeGen { - using Humanizer; - using Microsoft.Extensions.DependencyInjection; - using OpenQA.Selenium.DevToolsGenerator.ProtocolDefinition; - using System; - using System.Collections.Generic; - using System.Linq; - /// /// Generates code for Domain Definitions /// @@ -22,27 +21,30 @@ public override IDictionary GenerateCode(DomainDefinition domain var result = new Dictionary(StringComparer.OrdinalIgnoreCase); var typeGenerator = ServiceProvider.GetRequiredService>(); - foreach (var type in domainDefinition.Types) + foreach (TypeDefinition type in domainDefinition.Types) { - typeGenerator.GenerateCode(type, context) - .ToList() - .ForEach(x => result.Add(x.Key, x.Value)); + foreach (KeyValuePair x in typeGenerator.GenerateCode(type, context)) + { + result.Add(x.Key, x.Value); + } } var eventGenerator = ServiceProvider.GetRequiredService>(); - foreach (var @event in domainDefinition.Events) + foreach (EventDefinition @event in domainDefinition.Events) { - eventGenerator.GenerateCode(@event, context) - .ToList() - .ForEach(x => result.Add(x.Key, x.Value)); + foreach (KeyValuePair x in eventGenerator.GenerateCode(@event, context)) + { + result.Add(x.Key, x.Value); + } } var commandGenerator = ServiceProvider.GetRequiredService>(); - foreach (var command in domainDefinition.Commands) + foreach (CommandDefinition command in domainDefinition.Commands) { - commandGenerator.GenerateCode(command, context) - .ToList() - .ForEach(x => result.Add(x.Key, x.Value)); + foreach (KeyValuePair x in commandGenerator.GenerateCode(command, context)) + { + result.Add(x.Key, x.Value); + } } if (string.IsNullOrWhiteSpace(Settings.DefinitionTemplates.DomainTemplate.TemplatePath)) diff --git a/third_party/dotnet/devtools/src/generator/CodeGen/EventGenerator.cs b/third_party/dotnet/devtools/src/generator/CodeGen/EventGenerator.cs index 00cefd809cd32..d0d63d5547381 100644 --- a/third_party/dotnet/devtools/src/generator/CodeGen/EventGenerator.cs +++ b/third_party/dotnet/devtools/src/generator/CodeGen/EventGenerator.cs @@ -1,10 +1,10 @@ +using Humanizer; +using OpenQA.Selenium.DevToolsGenerator.ProtocolDefinition; +using System; +using System.Collections.Generic; + namespace OpenQA.Selenium.DevToolsGenerator.CodeGen { - using Humanizer; - using OpenQA.Selenium.DevToolsGenerator.ProtocolDefinition; - using System; - using System.Collections.Generic; - /// /// Generates code for Event Definitions /// diff --git a/third_party/dotnet/devtools/src/generator/CodeGen/ICodeGenerator.cs b/third_party/dotnet/devtools/src/generator/CodeGen/ICodeGenerator.cs index 256598a528f6c..004fcb65ad21f 100644 --- a/third_party/dotnet/devtools/src/generator/CodeGen/ICodeGenerator.cs +++ b/third_party/dotnet/devtools/src/generator/CodeGen/ICodeGenerator.cs @@ -1,8 +1,8 @@ +using OpenQA.Selenium.DevToolsGenerator.ProtocolDefinition; +using System.Collections.Generic; + namespace OpenQA.Selenium.DevToolsGenerator.CodeGen { - using OpenQA.Selenium.DevToolsGenerator.ProtocolDefinition; - using System.Collections.Generic; - /// /// Represents a code generator that generates code files for a specific IDefinition type. /// diff --git a/third_party/dotnet/devtools/src/generator/CodeGen/IServiceProviderExtensions.cs b/third_party/dotnet/devtools/src/generator/CodeGen/IServiceProviderExtensions.cs index 1fca894afb84b..5efcced3260d2 100644 --- a/third_party/dotnet/devtools/src/generator/CodeGen/IServiceProviderExtensions.cs +++ b/third_party/dotnet/devtools/src/generator/CodeGen/IServiceProviderExtensions.cs @@ -1,10 +1,9 @@ +using Microsoft.Extensions.DependencyInjection; +using OpenQA.Selenium.DevToolsGenerator.ProtocolDefinition; +using System; + namespace OpenQA.Selenium.DevToolsGenerator.CodeGen { - using Microsoft.Extensions.DependencyInjection; - using OpenQA.Selenium.DevToolsGenerator.ProtocolDefinition; - using System; - using System.Runtime.InteropServices.ComTypes; - /// /// Contains extensions for IServiceProvider. /// @@ -26,7 +25,7 @@ public static IServiceCollection AddCodeGenerationServices(this IServiceCollecti return serviceCollection .AddSingleton(settings) .AddSingleton() - .AddSingleton>((sp) => new ProtocolGenerator(sp)) + .AddSingleton>((sp) => new ProtocolGenerator(sp)) .AddSingleton>((sp) => new DomainGenerator(sp)) .AddSingleton>((sp) => new TypeGenerator(sp)) .AddSingleton>((sp) => new CommandGenerator(sp)) diff --git a/third_party/dotnet/devtools/src/generator/CodeGen/ProtocolGenerator.cs b/third_party/dotnet/devtools/src/generator/CodeGen/ProtocolGenerator.cs index 676c6937578bc..660b44c07b125 100644 --- a/third_party/dotnet/devtools/src/generator/CodeGen/ProtocolGenerator.cs +++ b/third_party/dotnet/devtools/src/generator/CodeGen/ProtocolGenerator.cs @@ -1,24 +1,24 @@ +using Humanizer; +using Microsoft.Extensions.DependencyInjection; +using OpenQA.Selenium.DevToolsGenerator.ProtocolDefinition; +using System; +using System.Collections.Generic; +using System.IO; +using System.Linq; + namespace OpenQA.Selenium.DevToolsGenerator.CodeGen { - using Humanizer; - using Microsoft.Extensions.DependencyInjection; - using OpenQA.Selenium.DevToolsGenerator.ProtocolDefinition; - using System; - using System.Collections.Generic; - using System.IO; - using System.Linq; - /// /// Represents an object that generates a protocol definition. /// - public sealed class ProtocolGenerator : CodeGeneratorBase + public sealed class ProtocolGenerator : CodeGeneratorBase { public ProtocolGenerator(IServiceProvider serviceProvider) : base(serviceProvider) { } - public override IDictionary GenerateCode(ProtocolDefinition protocolDefinition, CodeGeneratorContext context) + public override IDictionary GenerateCode(ProtocolDefinition.ProtocolDefinition protocolDefinition, CodeGeneratorContext context) { if (string.IsNullOrWhiteSpace(Settings.TemplatesPath)) { @@ -79,7 +79,7 @@ public override IDictionary GenerateCode(ProtocolDefinition prot domains = domains, commands = commands, events = events, - types = types.Select(kvp => kvp.Value).ToList() + types = types.Values.ToList() }; var result = new Dictionary(StringComparer.OrdinalIgnoreCase); @@ -93,9 +93,11 @@ public override IDictionary GenerateCode(ProtocolDefinition prot } //Generate code for each domain, type, command, event from their respective templates. - GenerateCode(domains, types) - .ToList() - .ForEach(x => result.Add(x.Key, x.Value)); + + foreach (KeyValuePair x in GenerateCode(domains, types)) + { + result.Add(x.Key, x.Value); + } return result; } @@ -246,7 +248,7 @@ private Dictionary GetTypesInDomain(ICollection GenerateCode(ICollection domains, Dictionary knownTypes) + private Dictionary GenerateCode(ICollection domains, Dictionary knownTypes) { var result = new Dictionary(StringComparer.OrdinalIgnoreCase); @@ -255,9 +257,11 @@ private IDictionary GenerateCode(ICollection d //Generate types/events/commands for all domains. foreach (var domain in domains) { - domainGenerator.GenerateCode(domain, new CodeGeneratorContext { Domain = domain, KnownTypes = knownTypes }) - .ToList() - .ForEach(x => result.Add(x.Key, x.Value)); + var context = new CodeGeneratorContext { Domain = domain, KnownTypes = knownTypes }; + foreach (KeyValuePair x in domainGenerator.GenerateCode(domain, context)) + { + result.Add(x.Key, x.Value); + } } return result; diff --git a/third_party/dotnet/devtools/src/generator/CodeGen/TemplatesManager.cs b/third_party/dotnet/devtools/src/generator/CodeGen/TemplatesManager.cs index 43af85f93dd7f..4921ab04cbb46 100644 --- a/third_party/dotnet/devtools/src/generator/CodeGen/TemplatesManager.cs +++ b/third_party/dotnet/devtools/src/generator/CodeGen/TemplatesManager.cs @@ -1,30 +1,29 @@ +using HandlebarsDotNet; +using System; +using System.Collections.Generic; +using System.IO; +using Humanizer; +using System.Linq; +using System.Text; +using OpenQA.Selenium.DevToolsGenerator.ProtocolDefinition; + namespace OpenQA.Selenium.DevToolsGenerator.CodeGen { - using HandlebarsDotNet; - using System; - using System.Collections.Generic; - using System.IO; - using Humanizer; - using System.Linq; - using System.Text; - using OpenQA.Selenium.DevToolsGenerator.ProtocolDefinition; - /// /// Represents a class that manages templates and their associated generators. /// public sealed class TemplatesManager { - private readonly IDictionary> m_templateGenerators = new Dictionary>(StringComparer.OrdinalIgnoreCase); - private readonly CodeGenerationSettings m_settings; + private readonly Dictionary> m_templateGenerators = new Dictionary>(StringComparer.OrdinalIgnoreCase); /// /// Gets the code generation settings associated with the protocol generator /// - public CodeGenerationSettings Settings => m_settings; + public CodeGenerationSettings Settings { get; } public TemplatesManager(CodeGenerationSettings settings) { - m_settings = settings ?? throw new ArgumentNullException(nameof(settings)); + Settings = settings ?? throw new ArgumentNullException(nameof(settings)); } /// @@ -111,8 +110,7 @@ public Func GetGeneratorForTemplate(CodeGenerationTemplateSettin Handlebars.RegisterHelper("typemap", (writer, context, arguments) => { - var typeDefinition = context as TypeDefinition; - if (typeDefinition == null) + if (context is not TypeDefinition typeDefinition) { throw new HandlebarsException("{{typemap}} helper expects to be in the context of a TypeDefinition."); } @@ -122,8 +120,7 @@ public Func GetGeneratorForTemplate(CodeGenerationTemplateSettin throw new HandlebarsException("{{typemap}} helper expects exactly one argument - the CodeGeneratorContext."); } - var codeGenContext = arguments[0] as CodeGeneratorContext; - if (codeGenContext == null) + if (arguments[0] is not CodeGeneratorContext codeGenContext) { throw new InvalidOperationException("Expected context argument to be non-null."); } diff --git a/third_party/dotnet/devtools/src/generator/CodeGen/TypeGenerator.cs b/third_party/dotnet/devtools/src/generator/CodeGen/TypeGenerator.cs index 9ff9a467ffaa1..429da07e6f282 100644 --- a/third_party/dotnet/devtools/src/generator/CodeGen/TypeGenerator.cs +++ b/third_party/dotnet/devtools/src/generator/CodeGen/TypeGenerator.cs @@ -1,10 +1,10 @@ +using Humanizer; +using OpenQA.Selenium.DevToolsGenerator.ProtocolDefinition; +using System; +using System.Collections.Generic; + namespace OpenQA.Selenium.DevToolsGenerator.CodeGen { - using Humanizer; - using OpenQA.Selenium.DevToolsGenerator.ProtocolDefinition; - using System; - using System.Collections.Generic; - /// /// Generates code for Type Definitions /// diff --git a/third_party/dotnet/devtools/src/generator/CodeGen/Utility.cs b/third_party/dotnet/devtools/src/generator/CodeGen/Utility.cs index cb62f699409cb..b22454ee952ec 100644 --- a/third_party/dotnet/devtools/src/generator/CodeGen/Utility.cs +++ b/third_party/dotnet/devtools/src/generator/CodeGen/Utility.cs @@ -1,11 +1,10 @@ +using OpenQA.Selenium.DevToolsGenerator.ProtocolDefinition; +using System; +using System.Collections.Generic; +using System.Text.RegularExpressions; + namespace OpenQA.Selenium.DevToolsGenerator.CodeGen { - using OpenQA.Selenium.DevToolsGenerator.ProtocolDefinition; - using System; - using System.Collections.Generic; - using System.Text.RegularExpressions; - using System.Runtime.InteropServices; - /// /// Contains various utility methods. /// diff --git a/third_party/dotnet/devtools/src/generator/CommandLineOptions.cs b/third_party/dotnet/devtools/src/generator/CommandLineOptions.cs index e90ff69a3d173..9b2d35f0851ae 100644 --- a/third_party/dotnet/devtools/src/generator/CommandLineOptions.cs +++ b/third_party/dotnet/devtools/src/generator/CommandLineOptions.cs @@ -1,16 +1,9 @@ using CommandLine; -using System; -using System.Collections.Generic; -using System.Text; namespace OpenQA.Selenium.DevToolsGenerator { public class CommandLineOptions { - public CommandLineOptions() - { - } - [Option( 'f', "force-download", @@ -35,7 +28,7 @@ public CommandLineOptions() 'o', "output-path", Default = "./OutputProtocol", - HelpText ="Indicates the folder that will contain the generated class library [Default: ./OutputProtocol]")] + HelpText = "Indicates the folder that will contain the generated class library [Default: ./OutputProtocol]")] public string OutputPath { get; set; } [Option( diff --git a/third_party/dotnet/devtools/src/generator/Converters/BooleanJsonConverter.cs b/third_party/dotnet/devtools/src/generator/Converters/BooleanJsonConverter.cs index 513fd55a0cc4b..948846078346d 100644 --- a/third_party/dotnet/devtools/src/generator/Converters/BooleanJsonConverter.cs +++ b/third_party/dotnet/devtools/src/generator/Converters/BooleanJsonConverter.cs @@ -1,9 +1,9 @@ +using System; +using System.Text.Json; +using System.Text.Json.Serialization; + namespace OpenQA.Selenium.DevToolsGenerator.Converters { - using System; - using System.Text.Json; - using System.Text.Json.Serialization; - /// /// Handles converting JSON string values into a C# boolean data type. /// diff --git a/third_party/dotnet/devtools/src/generator/ProtocolDefinition/CommandDefinition.cs b/third_party/dotnet/devtools/src/generator/ProtocolDefinition/CommandDefinition.cs index 9a9c900b24d01..521623ed7d856 100644 --- a/third_party/dotnet/devtools/src/generator/ProtocolDefinition/CommandDefinition.cs +++ b/third_party/dotnet/devtools/src/generator/ProtocolDefinition/CommandDefinition.cs @@ -1,27 +1,19 @@ +using System.Text.Json.Serialization; +using System.Collections.Generic; +using System.Collections.ObjectModel; + namespace OpenQA.Selenium.DevToolsGenerator.ProtocolDefinition { - using System.Text.Json.Serialization; - using System.Collections.Generic; - using System.Collections.ObjectModel; - public sealed class CommandDefinition : ProtocolDefinitionItem { - public CommandDefinition() - { - Handlers = new HashSet(); - - Parameters = new Collection(); - Returns = new Collection(); - } - [JsonPropertyName("handlers")] - public ICollection Handlers { get; set; } + public ICollection Handlers { get; set; } = new HashSet(); [JsonPropertyName("parameters")] - public ICollection Parameters { get; set; } + public ICollection Parameters { get; set; } = new Collection(); [JsonPropertyName("returns")] - public ICollection Returns { get; set; } + public ICollection Returns { get; set; } = new Collection(); [JsonPropertyName("redirect")] public string Redirect { get; set; } diff --git a/third_party/dotnet/devtools/src/generator/ProtocolDefinition/DomainDefinition.cs b/third_party/dotnet/devtools/src/generator/ProtocolDefinition/DomainDefinition.cs index e66f36b82487a..9cad0d8cf28ac 100644 --- a/third_party/dotnet/devtools/src/generator/ProtocolDefinition/DomainDefinition.cs +++ b/third_party/dotnet/devtools/src/generator/ProtocolDefinition/DomainDefinition.cs @@ -1,33 +1,24 @@ +using System.Text.Json.Serialization; +using System.Collections.Generic; +using System.Collections.ObjectModel; + namespace OpenQA.Selenium.DevToolsGenerator.ProtocolDefinition { - using System.Text.Json.Serialization; - using System.Collections.Generic; - using System.Collections.ObjectModel; - public sealed class DomainDefinition : ProtocolDefinitionItem { - public DomainDefinition() - { - Dependencies = new HashSet(); - - Types = new Collection(); - Events = new Collection(); - Commands = new Collection(); - } - [JsonPropertyName("domain")] public override string Name { get; set; } [JsonPropertyName("types")] - public ICollection Types { get; set; } + public ICollection Types { get; set; } = new Collection(); [JsonPropertyName("commands")] - public ICollection Commands { get; set; } + public ICollection Commands { get; set; } = new Collection(); [JsonPropertyName("events")] - public ICollection Events { get; set; } + public ICollection Events { get; set; } = new Collection(); [JsonPropertyName("dependencies")] - public ICollection Dependencies { get; set; } + public ICollection Dependencies { get; set; } = new HashSet(); } } diff --git a/third_party/dotnet/devtools/src/generator/ProtocolDefinition/EventDefinition.cs b/third_party/dotnet/devtools/src/generator/ProtocolDefinition/EventDefinition.cs index b005742a6a378..8a381c913b4fe 100644 --- a/third_party/dotnet/devtools/src/generator/ProtocolDefinition/EventDefinition.cs +++ b/third_party/dotnet/devtools/src/generator/ProtocolDefinition/EventDefinition.cs @@ -1,17 +1,12 @@ +using System.Text.Json.Serialization; +using System.Collections.Generic; +using System.Collections.ObjectModel; + namespace OpenQA.Selenium.DevToolsGenerator.ProtocolDefinition { - using System.Text.Json.Serialization; - using System.Collections.Generic; - using System.Collections.ObjectModel; - public sealed class EventDefinition : ProtocolDefinitionItem { - public EventDefinition() - { - Parameters = new Collection(); - } - [JsonPropertyName("parameters")] - public ICollection Parameters { get; set; } + public ICollection Parameters { get; set; } = new Collection(); } } diff --git a/third_party/dotnet/devtools/src/generator/ProtocolDefinition/IDefinition.cs b/third_party/dotnet/devtools/src/generator/ProtocolDefinition/IDefinition.cs index 17c3e6605bd3c..25920d8886a14 100644 --- a/third_party/dotnet/devtools/src/generator/ProtocolDefinition/IDefinition.cs +++ b/third_party/dotnet/devtools/src/generator/ProtocolDefinition/IDefinition.cs @@ -1,4 +1,4 @@ -namespace OpenQA.Selenium.DevToolsGenerator.ProtocolDefinition +namespace OpenQA.Selenium.DevToolsGenerator.ProtocolDefinition { /// /// Interface that identifies definition classes. diff --git a/third_party/dotnet/devtools/src/generator/ProtocolDefinition/ProtocolDefinition.cs b/third_party/dotnet/devtools/src/generator/ProtocolDefinition/ProtocolDefinition.cs index cc7757b8d4a58..ea3483e337056 100644 --- a/third_party/dotnet/devtools/src/generator/ProtocolDefinition/ProtocolDefinition.cs +++ b/third_party/dotnet/devtools/src/generator/ProtocolDefinition/ProtocolDefinition.cs @@ -1,16 +1,11 @@ +using System.Text.Json.Serialization; +using System.Collections.Generic; +using System.Collections.ObjectModel; + namespace OpenQA.Selenium.DevToolsGenerator.ProtocolDefinition { - using System.Text.Json.Serialization; - using System.Collections.Generic; - using System.Collections.ObjectModel; - public sealed class ProtocolDefinition : IDefinition { - public ProtocolDefinition() - { - Domains = new Collection(); - } - [JsonPropertyName("browserVersion")] [JsonRequired] public ProtocolVersionDefinition BrowserVersion { get; set; } @@ -21,6 +16,6 @@ public ProtocolDefinition() [JsonPropertyName("domains")] [JsonRequired] - public ICollection Domains { get; set; } + public ICollection Domains { get; set; } = new Collection(); } } diff --git a/third_party/dotnet/devtools/src/generator/ProtocolDefinition/ProtocolDefinitionItem.cs b/third_party/dotnet/devtools/src/generator/ProtocolDefinition/ProtocolDefinitionItem.cs index 7310359e2f62c..fd0bcf9c582ce 100644 --- a/third_party/dotnet/devtools/src/generator/ProtocolDefinition/ProtocolDefinitionItem.cs +++ b/third_party/dotnet/devtools/src/generator/ProtocolDefinition/ProtocolDefinitionItem.cs @@ -1,8 +1,8 @@ +using System.Text.Json.Serialization; +using OpenQA.Selenium.DevToolsGenerator.Converters; + namespace OpenQA.Selenium.DevToolsGenerator.ProtocolDefinition { - using System.Text.Json.Serialization; - using OpenQA.Selenium.DevToolsGenerator.Converters; - public abstract class ProtocolDefinitionItem : IDefinition { diff --git a/third_party/dotnet/devtools/src/generator/ProtocolDefinition/ProtocolVersionDefinition.cs b/third_party/dotnet/devtools/src/generator/ProtocolDefinition/ProtocolVersionDefinition.cs index a69bd450025b0..9ad237c519c92 100644 --- a/third_party/dotnet/devtools/src/generator/ProtocolDefinition/ProtocolVersionDefinition.cs +++ b/third_party/dotnet/devtools/src/generator/ProtocolDefinition/ProtocolVersionDefinition.cs @@ -1,7 +1,5 @@ using System.Text.Json.Serialization; using System; -using System.Collections.Generic; -using System.Text; using System.Text.RegularExpressions; namespace OpenQA.Selenium.DevToolsGenerator.ProtocolDefinition diff --git a/third_party/dotnet/devtools/src/generator/ProtocolDefinition/TypeDefinition.cs b/third_party/dotnet/devtools/src/generator/ProtocolDefinition/TypeDefinition.cs index 90452390914d8..2e030c15465a7 100644 --- a/third_party/dotnet/devtools/src/generator/ProtocolDefinition/TypeDefinition.cs +++ b/third_party/dotnet/devtools/src/generator/ProtocolDefinition/TypeDefinition.cs @@ -1,19 +1,12 @@ +using System.Text.Json.Serialization; +using OpenQA.Selenium.DevToolsGenerator.Converters; +using System.Collections.Generic; +using System.Collections.ObjectModel; + namespace OpenQA.Selenium.DevToolsGenerator.ProtocolDefinition { - using System.Text.Json.Serialization; - using OpenQA.Selenium.DevToolsGenerator.Converters; - using System; - using System.Collections.Generic; - using System.Collections.ObjectModel; - public sealed class TypeDefinition : ProtocolDefinitionItem { - public TypeDefinition() - { - Enum = new HashSet(); - Properties = new Collection(); - } - [JsonPropertyName("id")] public string Id { get; set; } @@ -21,10 +14,10 @@ public TypeDefinition() public string Type { get; set; } [JsonPropertyName("enum")] - public ICollection Enum { get; set; } + public ICollection Enum { get; set; } = new HashSet(); [JsonPropertyName("properties")] - public ICollection Properties { get; set; } + public ICollection Properties { get; set; } = new Collection(); [JsonPropertyName("items")] public TypeDefinition Items { get; set; } diff --git a/third_party/dotnet/devtools/src/generator/ProtocolDefinition/Version.cs b/third_party/dotnet/devtools/src/generator/ProtocolDefinition/Version.cs index 6ccf659057bac..315400661361d 100644 --- a/third_party/dotnet/devtools/src/generator/ProtocolDefinition/Version.cs +++ b/third_party/dotnet/devtools/src/generator/ProtocolDefinition/Version.cs @@ -1,8 +1,8 @@ +using System.Text.Json.Serialization; +using System; + namespace OpenQA.Selenium.DevToolsGenerator.ProtocolDefinition { - using System.Text.Json.Serialization; - using System; - /// /// Indicates the version of the Protocol Definition. /// @@ -26,9 +26,7 @@ public int CompareTo(Version other) public override bool Equals(object obj) { - var other = obj as Version; - - if (other == null) + if (obj is not Version other) { return false; }