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