Skip to content

Commit

Permalink
[dotnet] Apply formatting on internal CDP generator (#15049)
Browse files Browse the repository at this point in the history
  • Loading branch information
RenderMichael authored Jan 10, 2025
1 parent d457c4e commit 4aee006
Show file tree
Hide file tree
Showing 26 changed files with 155 additions and 362 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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",
};
Expand Down Expand Up @@ -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; }
}
}
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
namespace OpenQA.Selenium.DevToolsGenerator.CodeGen
namespace OpenQA.Selenium.DevToolsGenerator.CodeGen
{
using Newtonsoft.Json;
using System.Collections.Generic;
Expand Down Expand Up @@ -27,74 +27,42 @@ public CodeGenerationSettings()
/// Collection of templates that will be parsed and output in the target folder.
/// </summary>
[JsonProperty("include")]
public ICollection<CodeGenerationTemplateSettings> Include
{
get;
set;
}
public ICollection<CodeGenerationTemplateSettings> Include { get; set; }

/// <summary>
/// Indicates whether or not domains marked as depreciated will be generated. (Default: true)
/// </summary>
[JsonProperty("includeDeprecatedDomains")]
public bool IncludeDeprecatedDomains
{
get;
set;
}
public bool IncludeDeprecatedDomains { get; set; }

/// <summary>
/// Indicates whether or not domains marked as depreciated will be generated. (Default: true)
/// </summary>
[JsonProperty("includeExperimentalDomains")]
public bool IncludeExperimentalDomains
{
get;
set;
}
public bool IncludeExperimentalDomains { get; set; }

/// <summary>
/// Gets or sets the root namespace of generated classes.
/// </summary>
[JsonProperty("rootNamespace")]
public string RootNamespace
{
get;
set;
}
public string RootNamespace { get; set; }

/// <summary>
/// Gets the version number of the runtime.
/// </summary>
[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; }

/// <summary>
/// The using statements that will be included on each generated file.
/// </summary>
[JsonProperty("usingStatements")]
public ICollection<string> UsingStatements
{
get;
set;
}
public ICollection<string> UsingStatements { get; set; }
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -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; }
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -19,26 +19,17 @@ public abstract class CodeGeneratorBase<T> : ICodeGenerator<T>
/// <summary>
/// Gets the service provider associated with the generator.
/// </summary>
public IServiceProvider ServiceProvider
{
get { return m_serviceProvider; }
}
public IServiceProvider ServiceProvider => m_serviceProvider;

/// <summary>
/// Gets the code generation settings associated with the generator.
/// </summary>
public CodeGenerationSettings Settings
{
get { return m_settings.Value; }
}
public CodeGenerationSettings Settings => m_settings.Value;

/// <summary>
/// Gets a template manager associated with the generator.
/// </summary>
public TemplatesManager TemplatesManager
{
get { return m_templatesManager.Value; }
}
public TemplatesManager TemplatesManager => m_templatesManager.Value;

protected CodeGeneratorBase(IServiceProvider serviceProvider)
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,16 +8,8 @@ namespace OpenQA.Selenium.DevToolsGenerator.CodeGen
/// </summary>
public sealed class CodeGeneratorContext
{
public DomainDefinition Domain
{
get;
set;
}
public DomainDefinition Domain { get; set; }

public Dictionary<string, TypeInfo> KnownTypes
{
get;
set;
}
public Dictionary<string, TypeInfo> KnownTypes { get; set; }
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -19,8 +19,10 @@ public override IDictionary<string, string> GenerateCode(CommandDefinition comma
{
var result = new Dictionary<string, string>(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);

Expand Down
21 changes: 5 additions & 16 deletions third_party/dotnet/devtools/src/generator/CodeGen/CommandInfo.cs
Original file line number Diff line number Diff line change
@@ -1,25 +1,14 @@
namespace OpenQA.Selenium.DevToolsGenerator.CodeGen
namespace OpenQA.Selenium.DevToolsGenerator.CodeGen
{
/// <summary>
/// Represents information about a Chrome Debugger Protocol command.
/// </summary>
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; }
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -45,8 +45,10 @@ public override IDictionary<string, string> 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);

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,8 +19,10 @@ public override IDictionary<string, string> GenerateCode(EventDefinition eventDe
{
var result = new Dictionary<string, string>(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);

Expand Down
14 changes: 3 additions & 11 deletions third_party/dotnet/devtools/src/generator/CodeGen/EventInfo.cs
Original file line number Diff line number Diff line change
@@ -1,20 +1,12 @@
namespace OpenQA.Selenium.DevToolsGenerator.CodeGen
namespace OpenQA.Selenium.DevToolsGenerator.CodeGen
{
/// <summary>
/// Represents information about a Chrome Debugger Protocol event.
/// </summary>
public sealed class EventInfo
{
public string EventName
{
get;
set;
}
public string EventName { get; set; }

public string FullTypeName
{
get;
set;
}
public string FullTypeName { get; set; }
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ public ProtocolGenerator(IServiceProvider serviceProvider)

public override IDictionary<string, string> GenerateCode(ProtocolDefinition protocolDefinition, CodeGeneratorContext context)
{
if (String.IsNullOrWhiteSpace(Settings.TemplatesPath))
if (string.IsNullOrWhiteSpace(Settings.TemplatesPath))
{
Settings.TemplatesPath = Path.GetDirectoryName(Settings.TemplatesPath);
}
Expand Down Expand Up @@ -55,9 +55,9 @@ public override IDictionary<string, string> GenerateCode(ProtocolDefinition prot
//Get eventinfos as an array
ICollection<EventInfo> events = new List<EventInfo>();

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
{
Expand All @@ -71,7 +71,8 @@ public override IDictionary<string, string> 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,
Expand Down Expand Up @@ -140,22 +141,27 @@ private Dictionary<string, TypeInfo> GetTypesInDomain(ICollection<DomainDefiniti
};
break;
case "string":
if (type.Enum != null && type.Enum.Count() > 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");
Expand All @@ -171,8 +177,10 @@ private Dictionary<string, TypeInfo> GetTypesInDomain(ICollection<DomainDefiniti
itemType = "double";
break;
case null:
if (String.IsNullOrWhiteSpace(type.Items.TypeReference))
if (string.IsNullOrWhiteSpace(type.Items.TypeReference))
{
throw new NotImplementedException($"Did not expect a top-level domain array type to have a null type and a null or whitespace type reference.");
}

switch (type.Items.TypeReference)
{
Expand Down
Loading

0 comments on commit 4aee006

Please sign in to comment.