diff --git a/third_party/dotnet/devtools/src/generator/CodeGen/CodeGenerationDefinitionTemplateSettings.cs b/third_party/dotnet/devtools/src/generator/CodeGen/CodeGenerationDefinitionTemplateSettings.cs index 150554d8c0d3f..c1758190172f8 100644 --- a/third_party/dotnet/devtools/src/generator/CodeGen/CodeGenerationDefinitionTemplateSettings.cs +++ b/third_party/dotnet/devtools/src/generator/CodeGen/CodeGenerationDefinitionTemplateSettings.cs @@ -16,7 +16,8 @@ public CodeGenerationDefinitionTemplateSettings() OutputPath = "{{domainName}}\\{{className}}Adapter.cs", }; - CommandTemplate = new CodeGenerationTemplateSettings { + CommandTemplate = new CodeGenerationTemplateSettings + { TemplatePath = "command.hbs", OutputPath = "{{domainName}}\\{{className}}Command.cs", }; @@ -47,46 +48,21 @@ public CodeGenerationDefinitionTemplateSettings() } [JsonProperty("domainTemplate")] - public CodeGenerationTemplateSettings DomainTemplate - { - get; - set; - } + public CodeGenerationTemplateSettings DomainTemplate { get; set; } [JsonProperty("commandTemplate")] - public CodeGenerationTemplateSettings CommandTemplate - { - get; - set; - } + public CodeGenerationTemplateSettings CommandTemplate { get; set; } [JsonProperty("eventTemplate")] - public CodeGenerationTemplateSettings EventTemplate - { - get; - set; - } + public CodeGenerationTemplateSettings EventTemplate { get; set; } [JsonProperty("typeObjectTemplate")] - public CodeGenerationTemplateSettings TypeObjectTemplate - { - get; - set; - } + public CodeGenerationTemplateSettings TypeObjectTemplate { get; set; } [JsonProperty("typeHashTemplate")] - public CodeGenerationTemplateSettings TypeHashTemplate - { - get; - set; - } + public CodeGenerationTemplateSettings TypeHashTemplate { get; set; } [JsonProperty("typeEnumTemplate")] - public CodeGenerationTemplateSettings TypeEnumTemplate - { - get; - set; - } - + public CodeGenerationTemplateSettings TypeEnumTemplate { get; set; } } } diff --git a/third_party/dotnet/devtools/src/generator/CodeGen/CodeGenerationSettings.cs b/third_party/dotnet/devtools/src/generator/CodeGen/CodeGenerationSettings.cs index c8ccff1655312..ebbf2c753107d 100644 --- a/third_party/dotnet/devtools/src/generator/CodeGen/CodeGenerationSettings.cs +++ b/third_party/dotnet/devtools/src/generator/CodeGen/CodeGenerationSettings.cs @@ -1,4 +1,4 @@ -namespace OpenQA.Selenium.DevToolsGenerator.CodeGen +namespace OpenQA.Selenium.DevToolsGenerator.CodeGen { using Newtonsoft.Json; using System.Collections.Generic; @@ -27,74 +27,42 @@ public CodeGenerationSettings() /// Collection of templates that will be parsed and output in the target folder. /// [JsonProperty("include")] - public ICollection Include - { - get; - set; - } + public ICollection Include { get; set; } /// /// Indicates whether or not domains marked as depreciated will be generated. (Default: true) /// [JsonProperty("includeDeprecatedDomains")] - public bool IncludeDeprecatedDomains - { - get; - set; - } + public bool IncludeDeprecatedDomains { get; set; } /// /// Indicates whether or not domains marked as depreciated will be generated. (Default: true) /// [JsonProperty("includeExperimentalDomains")] - public bool IncludeExperimentalDomains - { - get; - set; - } + public bool IncludeExperimentalDomains { get; set; } /// /// Gets or sets the root namespace of generated classes. /// [JsonProperty("rootNamespace")] - public string RootNamespace - { - get; - set; - } + public string RootNamespace { get; set; } /// /// Gets the version number of the runtime. /// [JsonProperty("runtimeVersion")] - public string RuntimeVersion - { - get; - set; - } + public string RuntimeVersion { get; set; } [JsonProperty("definitionTemplates")] - public CodeGenerationDefinitionTemplateSettings DefinitionTemplates - { - get; - set; - } + public CodeGenerationDefinitionTemplateSettings DefinitionTemplates { get; set; } [JsonProperty("templatesPath")] - public string TemplatesPath - { - get; - set; - } + public string TemplatesPath { get; set; } /// /// The using statements that will be included on each generated file. /// [JsonProperty("usingStatements")] - public ICollection UsingStatements - { - get; - set; - } + public ICollection UsingStatements { get; set; } } } diff --git a/third_party/dotnet/devtools/src/generator/CodeGen/CodeGenerationTemplateSettings.cs b/third_party/dotnet/devtools/src/generator/CodeGen/CodeGenerationTemplateSettings.cs index 2c020351d2dd0..4f2dbe266a585 100644 --- a/third_party/dotnet/devtools/src/generator/CodeGen/CodeGenerationTemplateSettings.cs +++ b/third_party/dotnet/devtools/src/generator/CodeGen/CodeGenerationTemplateSettings.cs @@ -8,17 +8,9 @@ namespace OpenQA.Selenium.DevToolsGenerator.CodeGen public class CodeGenerationTemplateSettings { [JsonProperty("templatePath")] - public string TemplatePath - { - get; - set; - } + public string TemplatePath { get; set; } [JsonProperty("outputPath")] - public string OutputPath - { - get; - set; - } + public string OutputPath { get; set; } } } diff --git a/third_party/dotnet/devtools/src/generator/CodeGen/CodeGeneratorBase.cs b/third_party/dotnet/devtools/src/generator/CodeGen/CodeGeneratorBase.cs index c69d3020b0ac0..aaf2344d7f5ce 100644 --- a/third_party/dotnet/devtools/src/generator/CodeGen/CodeGeneratorBase.cs +++ b/third_party/dotnet/devtools/src/generator/CodeGen/CodeGeneratorBase.cs @@ -19,26 +19,17 @@ public abstract class CodeGeneratorBase : ICodeGenerator /// /// Gets the service provider associated with the generator. /// - public IServiceProvider ServiceProvider - { - get { return m_serviceProvider; } - } + public IServiceProvider ServiceProvider => m_serviceProvider; /// /// Gets the code generation settings associated with the generator. /// - public CodeGenerationSettings Settings - { - get { return m_settings.Value; } - } + public CodeGenerationSettings Settings => m_settings.Value; /// /// Gets a template manager associated with the generator. /// - public TemplatesManager TemplatesManager - { - get { return m_templatesManager.Value; } - } + public TemplatesManager TemplatesManager => m_templatesManager.Value; protected CodeGeneratorBase(IServiceProvider serviceProvider) { diff --git a/third_party/dotnet/devtools/src/generator/CodeGen/CodeGeneratorContext.cs b/third_party/dotnet/devtools/src/generator/CodeGen/CodeGeneratorContext.cs index 7a7d713d4de08..6970ee7ad4f7c 100644 --- a/third_party/dotnet/devtools/src/generator/CodeGen/CodeGeneratorContext.cs +++ b/third_party/dotnet/devtools/src/generator/CodeGen/CodeGeneratorContext.cs @@ -8,16 +8,8 @@ namespace OpenQA.Selenium.DevToolsGenerator.CodeGen /// public sealed class CodeGeneratorContext { - public DomainDefinition Domain - { - get; - set; - } + public DomainDefinition Domain { get; set; } - public Dictionary KnownTypes - { - get; - set; - } + public Dictionary KnownTypes { get; set; } } } diff --git a/third_party/dotnet/devtools/src/generator/CodeGen/CommandGenerator.cs b/third_party/dotnet/devtools/src/generator/CodeGen/CommandGenerator.cs index 8e7334d5e091f..4874a604d2989 100644 --- a/third_party/dotnet/devtools/src/generator/CodeGen/CommandGenerator.cs +++ b/third_party/dotnet/devtools/src/generator/CodeGen/CommandGenerator.cs @@ -19,8 +19,10 @@ public override IDictionary GenerateCode(CommandDefinition comma { var result = new Dictionary(StringComparer.OrdinalIgnoreCase); - if (String.IsNullOrWhiteSpace(Settings.DefinitionTemplates.CommandTemplate.TemplatePath)) + if (string.IsNullOrWhiteSpace(Settings.DefinitionTemplates.CommandTemplate.TemplatePath)) + { return result; + } var commandGenerator = TemplatesManager.GetGeneratorForTemplate(Settings.DefinitionTemplates.CommandTemplate); diff --git a/third_party/dotnet/devtools/src/generator/CodeGen/CommandInfo.cs b/third_party/dotnet/devtools/src/generator/CodeGen/CommandInfo.cs index aaaaa90d30f7b..f70dfd4601861 100644 --- a/third_party/dotnet/devtools/src/generator/CodeGen/CommandInfo.cs +++ b/third_party/dotnet/devtools/src/generator/CodeGen/CommandInfo.cs @@ -1,25 +1,14 @@ -namespace OpenQA.Selenium.DevToolsGenerator.CodeGen +namespace OpenQA.Selenium.DevToolsGenerator.CodeGen { /// /// Represents information about a Chrome Debugger Protocol command. /// public sealed class CommandInfo { - public string CommandName - { - get; - set; - } + public string CommandName { get; set; } - public string FullTypeName - { - get; - set; - } - public string FullResponseTypeName - { - get; - set; - } + public string FullTypeName { get; set; } + + public string FullResponseTypeName { get; set; } } } diff --git a/third_party/dotnet/devtools/src/generator/CodeGen/DomainGenerator.cs b/third_party/dotnet/devtools/src/generator/CodeGen/DomainGenerator.cs index 5d22752532ece..3bb3761aec311 100644 --- a/third_party/dotnet/devtools/src/generator/CodeGen/DomainGenerator.cs +++ b/third_party/dotnet/devtools/src/generator/CodeGen/DomainGenerator.cs @@ -45,8 +45,10 @@ public override IDictionary GenerateCode(DomainDefinition domain .ForEach(x => result.Add(x.Key, x.Value)); } - if (String.IsNullOrWhiteSpace(Settings.DefinitionTemplates.DomainTemplate.TemplatePath)) + if (string.IsNullOrWhiteSpace(Settings.DefinitionTemplates.DomainTemplate.TemplatePath)) + { return result; + } var domainGenerator = TemplatesManager.GetGeneratorForTemplate(Settings.DefinitionTemplates.DomainTemplate); diff --git a/third_party/dotnet/devtools/src/generator/CodeGen/EventGenerator.cs b/third_party/dotnet/devtools/src/generator/CodeGen/EventGenerator.cs index 3958ccf135d43..00cefd809cd32 100644 --- a/third_party/dotnet/devtools/src/generator/CodeGen/EventGenerator.cs +++ b/third_party/dotnet/devtools/src/generator/CodeGen/EventGenerator.cs @@ -19,8 +19,10 @@ public override IDictionary GenerateCode(EventDefinition eventDe { var result = new Dictionary(StringComparer.OrdinalIgnoreCase); - if (String.IsNullOrWhiteSpace(Settings.DefinitionTemplates.EventTemplate.TemplatePath)) + if (string.IsNullOrWhiteSpace(Settings.DefinitionTemplates.EventTemplate.TemplatePath)) + { return result; + } var eventGenerator = TemplatesManager.GetGeneratorForTemplate(Settings.DefinitionTemplates.EventTemplate); diff --git a/third_party/dotnet/devtools/src/generator/CodeGen/EventInfo.cs b/third_party/dotnet/devtools/src/generator/CodeGen/EventInfo.cs index bdd95381d69dd..0e78b688ac880 100644 --- a/third_party/dotnet/devtools/src/generator/CodeGen/EventInfo.cs +++ b/third_party/dotnet/devtools/src/generator/CodeGen/EventInfo.cs @@ -1,20 +1,12 @@ -namespace OpenQA.Selenium.DevToolsGenerator.CodeGen +namespace OpenQA.Selenium.DevToolsGenerator.CodeGen { /// /// Represents information about a Chrome Debugger Protocol event. /// public sealed class EventInfo { - public string EventName - { - get; - set; - } + public string EventName { get; set; } - public string FullTypeName - { - get; - set; - } + public string FullTypeName { get; set; } } } diff --git a/third_party/dotnet/devtools/src/generator/CodeGen/IServiceProviderExtensions.cs b/third_party/dotnet/devtools/src/generator/CodeGen/IServiceProviderExtensions.cs index 37d824be071bb..1fca894afb84b 100644 --- a/third_party/dotnet/devtools/src/generator/CodeGen/IServiceProviderExtensions.cs +++ b/third_party/dotnet/devtools/src/generator/CodeGen/IServiceProviderExtensions.cs @@ -19,7 +19,9 @@ public static class IServiceProviderExtensions public static IServiceCollection AddCodeGenerationServices(this IServiceCollection serviceCollection, CodeGenerationSettings settings) { if (settings == null) + { throw new ArgumentNullException(nameof(settings)); + } return serviceCollection .AddSingleton(settings) diff --git a/third_party/dotnet/devtools/src/generator/CodeGen/ProtocolGenerator.cs b/third_party/dotnet/devtools/src/generator/CodeGen/ProtocolGenerator.cs index c58abbd468b55..676c6937578bc 100644 --- a/third_party/dotnet/devtools/src/generator/CodeGen/ProtocolGenerator.cs +++ b/third_party/dotnet/devtools/src/generator/CodeGen/ProtocolGenerator.cs @@ -20,7 +20,7 @@ public ProtocolGenerator(IServiceProvider serviceProvider) public override IDictionary GenerateCode(ProtocolDefinition protocolDefinition, CodeGeneratorContext context) { - if (String.IsNullOrWhiteSpace(Settings.TemplatesPath)) + if (string.IsNullOrWhiteSpace(Settings.TemplatesPath)) { Settings.TemplatesPath = Path.GetDirectoryName(Settings.TemplatesPath); } @@ -55,9 +55,9 @@ public override IDictionary GenerateCode(ProtocolDefinition prot //Get eventinfos as an array ICollection events = new List(); - foreach(var domain in domains) + foreach (var domain in domains) { - foreach(var @event in domain.Events) + foreach (var @event in domain.Events) { events.Add(new EventInfo { @@ -71,7 +71,8 @@ public override IDictionary GenerateCode(ProtocolDefinition prot var types = GetTypesInDomain(domains); //Create an object that contains information that include templates can use. - var includeData = new { + var includeData = new + { chromeVersion = protocolDefinition.BrowserVersion, runtimeVersion = Settings.RuntimeVersion, rootNamespace = Settings.RootNamespace, @@ -140,22 +141,27 @@ private Dictionary GetTypesInDomain(ICollection 0) + if (type.Enum != null && type.Enum.Count > 0) + { typeInfo = new TypeInfo { ByRef = true, IsPrimitive = false, TypeName = type.Id.Dehumanize(), }; + } else + { typeInfo = new TypeInfo { IsPrimitive = true, TypeName = "string" }; + } + break; case "array": - if ((type.Items == null || String.IsNullOrWhiteSpace(type.Items.Type)) && + if ((type.Items == null || string.IsNullOrWhiteSpace(type.Items.Type)) && type.Items.TypeReference != "StringIndex" && type.Items.TypeReference != "FilterEntry") { throw new NotImplementedException("Did not expect a top-level domain array type to specify a TypeReference"); @@ -171,8 +177,10 @@ private Dictionary GetTypesInDomain(ICollection /// Gets the code generation settings associated with the protocol generator /// - public CodeGenerationSettings Settings - { - get { return m_settings; } - } + public CodeGenerationSettings Settings => m_settings; public TemplatesManager(CodeGenerationSettings settings) { @@ -39,14 +36,20 @@ public Func GetGeneratorForTemplate(CodeGenerationTemplateSettin { var templatePath = templateSettings.TemplatePath; if (m_templateGenerators.ContainsKey(templatePath)) + { return m_templateGenerators[templatePath]; + } var targetTemplate = templatePath; if (!Path.IsPathRooted(targetTemplate)) + { targetTemplate = Path.Combine(Settings.TemplatesPath, targetTemplate); + } if (!File.Exists(targetTemplate)) + { throw new FileNotFoundException($"Unable to locate a template at {targetTemplate} - please ensure that a template file exists at this location."); + } var templateContents = File.ReadAllText(targetTemplate); @@ -81,7 +84,7 @@ public Func GetGeneratorForTemplate(CodeGenerationTemplateSettin var str = arguments[0] == null ? "" : arguments[0].ToString(); - if (String.IsNullOrWhiteSpace(str)) + if (string.IsNullOrWhiteSpace(str)) { switch (context) { @@ -100,7 +103,7 @@ public Func GetGeneratorForTemplate(CodeGenerationTemplateSettin { int.TryParse(frontPaddingObj.ToString(), out frontPadding); } - + str = Utility.ReplaceLineEndings(str, Environment.NewLine + new StringBuilder(4 * frontPadding).Insert(0, " ", frontPadding) + "/// "); writer.WriteSafeString(str); @@ -121,7 +124,9 @@ public Func GetGeneratorForTemplate(CodeGenerationTemplateSettin var codeGenContext = arguments[0] as CodeGeneratorContext; if (codeGenContext == null) + { throw new InvalidOperationException("Expected context argument to be non-null."); + } var mappedType = Utility.GetTypeMappingForType(typeDefinition, codeGenContext.Domain, codeGenContext.KnownTypes); writer.WriteSafeString(mappedType); diff --git a/third_party/dotnet/devtools/src/generator/CodeGen/TypeGenerator.cs b/third_party/dotnet/devtools/src/generator/CodeGen/TypeGenerator.cs index d57a4ec7b925a..9ff9a467ffaa1 100644 --- a/third_party/dotnet/devtools/src/generator/CodeGen/TypeGenerator.cs +++ b/third_party/dotnet/devtools/src/generator/CodeGen/TypeGenerator.cs @@ -20,14 +20,20 @@ public override IDictionary GenerateCode(TypeDefinition typeDefi var result = new Dictionary(StringComparer.OrdinalIgnoreCase); if (context.KnownTypes == null) + { throw new InvalidOperationException("Expected knowntypes to be specified in context"); + } if (context.Domain == null) + { throw new InvalidOperationException("Expected domain to be specified in context"); + } var typeInfo = context.KnownTypes[$"{context.Domain.Name}.{typeDefinition.Id}"]; if (typeInfo.IsPrimitive) + { return result; + } //Base the code generation template on the specified type definition type. CodeGenerationTemplateSettings templateSettings; @@ -50,8 +56,10 @@ public override IDictionary GenerateCode(TypeDefinition typeDefi templateSettings = Settings.DefinitionTemplates.TypeHashTemplate; } - if (String.IsNullOrWhiteSpace(templateSettings.TemplatePath)) + if (string.IsNullOrWhiteSpace(templateSettings.TemplatePath)) + { return result; + } var typeGenerator = TemplatesManager.GetGeneratorForTemplate(templateSettings); diff --git a/third_party/dotnet/devtools/src/generator/CodeGen/TypeInfo.cs b/third_party/dotnet/devtools/src/generator/CodeGen/TypeInfo.cs index 9407d6e607ef6..5b87e94c369bc 100644 --- a/third_party/dotnet/devtools/src/generator/CodeGen/TypeInfo.cs +++ b/third_party/dotnet/devtools/src/generator/CodeGen/TypeInfo.cs @@ -1,38 +1,18 @@ -namespace OpenQA.Selenium.DevToolsGenerator.CodeGen +namespace OpenQA.Selenium.DevToolsGenerator.CodeGen { /// /// Represents information about a Chrome Debugger Protocol type. /// public sealed class TypeInfo { - public bool ByRef - { - get; - set; - } + public bool ByRef { get; set; } - public string Namespace - { - get; - set; - } + public string Namespace { get; set; } - public bool IsPrimitive - { - get; - set; - } + public bool IsPrimitive { get; set; } - public string TypeName - { - get; - set; - } + public string TypeName { get; set; } - public string SourcePath - { - get; - set; - } + public string SourcePath { get; set; } } } diff --git a/third_party/dotnet/devtools/src/generator/CodeGen/Utility.cs b/third_party/dotnet/devtools/src/generator/CodeGen/Utility.cs index 52eade64d5519..cb62f699409cb 100644 --- a/third_party/dotnet/devtools/src/generator/CodeGen/Utility.cs +++ b/third_party/dotnet/devtools/src/generator/CodeGen/Utility.cs @@ -42,8 +42,10 @@ public static string GetTypeMappingForType(TypeDefinition typeDefinition, Domain { var type = typeDefinition.Type; - if (String.IsNullOrWhiteSpace(type)) + if (string.IsNullOrWhiteSpace(type)) + { type = typeDefinition.TypeReference; + } string mappedType = null; if (type.Contains(".") && knownTypes.ContainsKey(type)) @@ -54,16 +56,22 @@ public static string GetTypeMappingForType(TypeDefinition typeDefinition, Domain var primitiveType = typeInfo.TypeName; if (typeDefinition.Optional && typeInfo.ByRef) + { primitiveType += "?"; + } if (isArray) + { primitiveType += "[]"; + } return primitiveType; } mappedType = $"{typeInfo.Namespace}.{typeInfo.TypeName}"; if (typeDefinition.Optional && typeInfo.ByRef) + { mappedType += "?"; + } } if (mappedType == null) @@ -76,7 +84,9 @@ public static string GetTypeMappingForType(TypeDefinition typeDefinition, Domain mappedType = typeInfo.TypeName; if (typeInfo.ByRef && typeDefinition.Optional) + { mappedType += "?"; + } } } @@ -113,20 +123,21 @@ public static string GetTypeMappingForType(TypeDefinition typeDefinition, Domain } if (isArray) + { mappedType += "[]"; + } return mappedType; } public static string ReplaceLineEndings(string value, string replacement = null) { - if (String.IsNullOrEmpty(value)) + if (string.IsNullOrEmpty(value)) { return value; } - if (replacement == null) - replacement = string.Empty; + replacement ??= string.Empty; return Regex.Replace(value, @"\r\n?|\n|\u2028|\u2029", replacement, RegexOptions.Compiled); } diff --git a/third_party/dotnet/devtools/src/generator/Converters/BooleanJsonConverter.cs b/third_party/dotnet/devtools/src/generator/Converters/BooleanJsonConverter.cs index 424438eecdcc8..99c2d4292a7fb 100644 --- a/third_party/dotnet/devtools/src/generator/Converters/BooleanJsonConverter.cs +++ b/third_party/dotnet/devtools/src/generator/Converters/BooleanJsonConverter.cs @@ -1,4 +1,4 @@ -namespace OpenQA.Selenium.DevToolsGenerator.Converters +namespace OpenQA.Selenium.DevToolsGenerator.Converters { using Newtonsoft.Json; using System; @@ -54,7 +54,7 @@ public override object ReadJson(JsonReader reader, Type objectType, object exist /// /// Specifies that this converter will not participate in writing results. /// - public override bool CanWrite { get { return false; } } + public override bool CanWrite => false; /// /// Writes the JSON representation of the object. @@ -62,6 +62,7 @@ public override object ReadJson(JsonReader reader, Type objectType, object exist /// The to write to.The value.The calling serializer. public override void WriteJson(JsonWriter writer, object value, JsonSerializer serializer) { + throw new NotSupportedException(); } } } diff --git a/third_party/dotnet/devtools/src/generator/Program.cs b/third_party/dotnet/devtools/src/generator/Program.cs index 20ddf910bc7f2..a2aded339afb1 100644 --- a/third_party/dotnet/devtools/src/generator/Program.cs +++ b/third_party/dotnet/devtools/src/generator/Program.cs @@ -88,7 +88,7 @@ static int Main(string[] args) { var targetFileHash = sha1.ComputeHash(File.ReadAllBytes(targetFilePath)); var codeFileHash = sha1.ComputeHash(Encoding.UTF8.GetBytes(codeFile.Value)); - if (String.Compare(Convert.ToBase64String(targetFileHash), Convert.ToBase64String(codeFileHash)) != 0) + if (string.Compare(Convert.ToBase64String(targetFileHash), Convert.ToBase64String(codeFileHash)) != 0) { File.WriteAllText(targetFilePath, codeFile.Value); } diff --git a/third_party/dotnet/devtools/src/generator/ProtocolDefinition/CommandDefinition.cs b/third_party/dotnet/devtools/src/generator/ProtocolDefinition/CommandDefinition.cs index 4198d006976e7..9d7dec364c5ad 100644 --- a/third_party/dotnet/devtools/src/generator/ProtocolDefinition/CommandDefinition.cs +++ b/third_party/dotnet/devtools/src/generator/ProtocolDefinition/CommandDefinition.cs @@ -1,4 +1,4 @@ -namespace OpenQA.Selenium.DevToolsGenerator.ProtocolDefinition +namespace OpenQA.Selenium.DevToolsGenerator.ProtocolDefinition { using Newtonsoft.Json; using System.Collections.Generic; @@ -15,32 +15,16 @@ public CommandDefinition() } [JsonProperty(PropertyName = "handlers")] - public ICollection Handlers - { - get; - set; - } + public ICollection Handlers { get; set; } [JsonProperty(PropertyName = "parameters")] - public ICollection Parameters - { - get; - set; - } + public ICollection Parameters { get; set; } [JsonProperty(PropertyName = "returns")] - public ICollection Returns - { - get; - set; - } + public ICollection Returns { get; set; } [JsonProperty(PropertyName = "redirect")] - public string Redirect - { - get; - set; - } + public string Redirect { get; set; } [JsonIgnore] public bool NoParameters => Parameters == null || Parameters.Count == 0; diff --git a/third_party/dotnet/devtools/src/generator/ProtocolDefinition/DomainDefinition.cs b/third_party/dotnet/devtools/src/generator/ProtocolDefinition/DomainDefinition.cs index d4cd5b7eefb81..7c461f3277676 100644 --- a/third_party/dotnet/devtools/src/generator/ProtocolDefinition/DomainDefinition.cs +++ b/third_party/dotnet/devtools/src/generator/ProtocolDefinition/DomainDefinition.cs @@ -1,4 +1,4 @@ -namespace OpenQA.Selenium.DevToolsGenerator.ProtocolDefinition +namespace OpenQA.Selenium.DevToolsGenerator.ProtocolDefinition { using Newtonsoft.Json; using System.Collections.Generic; @@ -16,38 +16,18 @@ public DomainDefinition() } [JsonProperty(PropertyName = "domain")] - public override string Name - { - get; - set; - } + public override string Name { get; set; } [JsonProperty(PropertyName = "types")] - public ICollection Types - { - get; - set; - } + public ICollection Types { get; set; } [JsonProperty(PropertyName = "commands")] - public ICollection Commands - { - get; - set; - } + public ICollection Commands { get; set; } [JsonProperty(PropertyName = "events")] - public ICollection Events - { - get; - set; - } + public ICollection Events { get; set; } [JsonProperty(PropertyName = "dependencies")] - public ICollection Dependencies - { - get; - set; - } + public ICollection Dependencies { get; set; } } } diff --git a/third_party/dotnet/devtools/src/generator/ProtocolDefinition/EventDefinition.cs b/third_party/dotnet/devtools/src/generator/ProtocolDefinition/EventDefinition.cs index 161b356dd7908..ba0d19a661b34 100644 --- a/third_party/dotnet/devtools/src/generator/ProtocolDefinition/EventDefinition.cs +++ b/third_party/dotnet/devtools/src/generator/ProtocolDefinition/EventDefinition.cs @@ -1,4 +1,4 @@ -namespace OpenQA.Selenium.DevToolsGenerator.ProtocolDefinition +namespace OpenQA.Selenium.DevToolsGenerator.ProtocolDefinition { using Newtonsoft.Json; using System.Collections.Generic; @@ -12,10 +12,6 @@ public EventDefinition() } [JsonProperty(PropertyName = "parameters")] - public ICollection Parameters - { - get; - set; - } + public ICollection Parameters { get; set; } } } diff --git a/third_party/dotnet/devtools/src/generator/ProtocolDefinition/ProtocolDefinition.cs b/third_party/dotnet/devtools/src/generator/ProtocolDefinition/ProtocolDefinition.cs index c00520f7d8878..487b18e45ae27 100644 --- a/third_party/dotnet/devtools/src/generator/ProtocolDefinition/ProtocolDefinition.cs +++ b/third_party/dotnet/devtools/src/generator/ProtocolDefinition/ProtocolDefinition.cs @@ -12,24 +12,12 @@ public ProtocolDefinition() } [JsonProperty(PropertyName = "browserVersion", Required = Required.Always)] - public ProtocolVersionDefinition BrowserVersion - { - get; - set; - } + public ProtocolVersionDefinition BrowserVersion { get; set; } [JsonProperty(PropertyName = "version", Required = Required.Always)] - public Version Version - { - get; - set; - } + public Version Version { get; set; } [JsonProperty(PropertyName = "domains", Required = Required.Always)] - public ICollection Domains - { - get; - set; - } + public ICollection Domains { get; set; } } } diff --git a/third_party/dotnet/devtools/src/generator/ProtocolDefinition/ProtocolDefinitionItem.cs b/third_party/dotnet/devtools/src/generator/ProtocolDefinition/ProtocolDefinitionItem.cs index cd415d9b225a5..75bdf196f993f 100644 --- a/third_party/dotnet/devtools/src/generator/ProtocolDefinition/ProtocolDefinitionItem.cs +++ b/third_party/dotnet/devtools/src/generator/ProtocolDefinition/ProtocolDefinitionItem.cs @@ -7,32 +7,20 @@ public abstract class ProtocolDefinitionItem : IDefinition { [JsonProperty(PropertyName = "deprecated")] - public bool Deprecated - { - get; - set; - } + public bool Deprecated { get; set; } public string Description { - get => InitialDescription != null ? InitialDescription.Replace("<", "<").Replace(">", ">") : null; + get => InitialDescription?.Replace("<", "<").Replace(">", ">"); set => InitialDescription = value; } [JsonProperty(PropertyName = "experimental")] [JsonConverter(typeof(BooleanJsonConverter))] - public bool Experimental - { - get; - set; - } + public bool Experimental { get; set; } [JsonProperty(PropertyName = "name")] - public virtual string Name - { - get; - set; - } + public virtual string Name { get; set; } public override string ToString() { @@ -40,10 +28,6 @@ public override string ToString() } [JsonProperty(PropertyName = "description")] - protected string InitialDescription - { - get; - set; - } + protected string InitialDescription { get; set; } } } diff --git a/third_party/dotnet/devtools/src/generator/ProtocolDefinition/ProtocolVersionDefinition.cs b/third_party/dotnet/devtools/src/generator/ProtocolDefinition/ProtocolVersionDefinition.cs index 2e3e706ca3284..172f9bd5f47c7 100644 --- a/third_party/dotnet/devtools/src/generator/ProtocolDefinition/ProtocolVersionDefinition.cs +++ b/third_party/dotnet/devtools/src/generator/ProtocolDefinition/ProtocolVersionDefinition.cs @@ -12,44 +12,22 @@ namespace OpenQA.Selenium.DevToolsGenerator.ProtocolDefinition public class ProtocolVersionDefinition { [JsonProperty(PropertyName = "Browser")] - public string Browser - { - get; - set; - } + public string Browser { get; set; } [JsonIgnore] - public string BrowserVersion - { - get { return Regex.Match(Browser, ".*/(.*)").Groups[1].Value; } - } + public string BrowserVersion => Regex.Match(Browser, ".*/(.*)").Groups[1].Value; [JsonIgnore] - public string BrowserMajorVersion - { - get { return Regex.Match(Browser, ".*/(\\d+)\\..*").Groups[1].Value; } - } + public string BrowserMajorVersion => Regex.Match(Browser, ".*/(\\d+)\\..*").Groups[1].Value; [JsonProperty(PropertyName = "Protocol-Version")] - public string ProtocolVersion - { - get; - set; - } + public string ProtocolVersion { get; set; } [JsonProperty(PropertyName = "User-Agent")] - public string UserAgent - { - get; - set; - } + public string UserAgent { get; set; } [JsonProperty(PropertyName = "V8-Version")] - public string V8Version - { - get; - set; - } + public string V8Version { get; set; } [JsonIgnore] public string V8VersionNumber @@ -60,18 +38,16 @@ public string V8VersionNumber var v8VersionRegex = new Regex(@"^(\d+)\.(\d+)\.(\d+)(\.\d+.*)?"); var v8VersionMatch = v8VersionRegex.Match(V8Version); if (v8VersionMatch.Success == false || v8VersionMatch.Groups.Count < 4) + { throw new InvalidOperationException($"Unable to determine v8 version number from v8 version string ({V8Version})"); + } return $"{v8VersionMatch.Groups[1].Value}.{v8VersionMatch.Groups[2].Value}.{v8VersionMatch.Groups[3].Value}"; } } [JsonProperty(PropertyName = "WebKit-Version")] - public string WebKitVersion - { - get; - set; - } + public string WebKitVersion { get; set; } [JsonIgnore] public string WebKitVersionHash @@ -82,7 +58,9 @@ public string WebKitVersionHash var webkitVersionRegex = new Regex(@"\s\(@(\b[0-9a-f]{5,40}\b)"); var webkitVersionMatch = webkitVersionRegex.Match(WebKitVersion); if (webkitVersionMatch.Success == false || webkitVersionMatch.Groups.Count != 2) + { throw new InvalidOperationException($"Unable to determine webkit version hash from webkit version string ({WebKitVersion})"); + } return webkitVersionMatch.Groups[1].Value; } diff --git a/third_party/dotnet/devtools/src/generator/ProtocolDefinition/TypeDefinition.cs b/third_party/dotnet/devtools/src/generator/ProtocolDefinition/TypeDefinition.cs index 5bb39aded4496..0c1948b0c356c 100644 --- a/third_party/dotnet/devtools/src/generator/ProtocolDefinition/TypeDefinition.cs +++ b/third_party/dotnet/devtools/src/generator/ProtocolDefinition/TypeDefinition.cs @@ -15,76 +15,44 @@ public TypeDefinition() } [JsonProperty(PropertyName = "id")] - public string Id - { - get; - set; - } + public string Id { get; set; } [JsonProperty(PropertyName = "type")] - public string Type - { - get; - set; - } + public string Type { get; set; } [JsonProperty(PropertyName = "enum")] - public ICollection Enum - { - get; - set; - } + public ICollection Enum { get; set; } [JsonProperty(PropertyName = "properties")] - public ICollection Properties - { - get; - set; - } + public ICollection Properties { get; set; } [JsonProperty(PropertyName = "items")] - public TypeDefinition Items - { - get; - set; - } + public TypeDefinition Items { get; set; } [JsonProperty(PropertyName = "minItems")] - public int MinItems - { - get; - set; - } + public int MinItems { get; set; } [JsonProperty(PropertyName = "maxItems")] - public int MaxItems - { - get; - set; - } + public int MaxItems { get; set; } [JsonProperty(PropertyName = "$ref")] - public string TypeReference - { - get; - set; - } + public string TypeReference { get; set; } [JsonProperty(PropertyName = "optional")] [JsonConverter(typeof(BooleanJsonConverter))] - public bool Optional - { - get; - set; - } + public bool Optional { get; set; } public override string ToString() { - if (!String.IsNullOrWhiteSpace(Id)) + if (!string.IsNullOrWhiteSpace(Id)) + { return Id; + } - if (!String.IsNullOrWhiteSpace(Name)) + if (!string.IsNullOrWhiteSpace(Name)) + { return Name; + } return $"Ref: {TypeReference}"; } diff --git a/third_party/dotnet/devtools/src/generator/ProtocolDefinition/Version.cs b/third_party/dotnet/devtools/src/generator/ProtocolDefinition/Version.cs index 82f92dc636426..efbde86ee9ee2 100644 --- a/third_party/dotnet/devtools/src/generator/ProtocolDefinition/Version.cs +++ b/third_party/dotnet/devtools/src/generator/ProtocolDefinition/Version.cs @@ -1,4 +1,4 @@ -namespace OpenQA.Selenium.DevToolsGenerator.ProtocolDefinition +namespace OpenQA.Selenium.DevToolsGenerator.ProtocolDefinition { using Newtonsoft.Json; using System; @@ -9,23 +9,17 @@ public sealed class Version : IComparable { [JsonProperty(PropertyName = "major")] - public string Major - { - get; - set; - } + public string Major { get; set; } [JsonProperty(PropertyName = "minor")] - public string Minor - { - get; - set; - } + public string Minor { get; set; } public int CompareTo(Version other) { if (other == null) + { return -1; + } return ToString().CompareTo(other.ToString()); }