Skip to content

Commit

Permalink
[.NET] Adopt c# 12 primary constructors (#272)
Browse files Browse the repository at this point in the history
  • Loading branch information
Romfos authored Aug 27, 2024
1 parent 92b86b3 commit 607a142
Show file tree
Hide file tree
Showing 27 changed files with 178 additions and 370 deletions.
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ This document is formatted according to the principles of [Keep A CHANGELOG](htt
- [Ruby] Upgraded messages support to permit up to v26
- [.NET] Drop unsupported frameworks. Now supported target frameworks are .NET 8, .NET Framework 4.6.2, .NET Standard 2.0
- [.NET] Adopt File Scoped Namespaces c# feature
- [.NET] Adopt c# 12 primary constructors

## [29.0.0] - 2024-08-12
### Added
Expand Down
31 changes: 9 additions & 22 deletions dotnet/Gherkin.Specs/EventStubs/GherkinEventsProvider.cs
Original file line number Diff line number Diff line change
@@ -1,30 +1,17 @@
using System;
using System.Collections.Generic;
using System.IO;
using Gherkin.CucumberMessages;
using Gherkin.CucumberMessages.Pickles;
using Gherkin.CucumberMessages.Types;
using System;
using System.Collections.Generic;
using System.IO;

namespace Gherkin.Specs.EventStubs;

public class GherkinEventsProvider
public class GherkinEventsProvider(bool printSource, bool printAst, bool printPickles, IIdGenerator idGenerator)
{
private readonly Parser _parser = new Parser();
private readonly PickleCompiler _pickleCompiler;
private readonly AstMessagesConverter _astMessagesConverter;

readonly bool _printAst;
readonly bool _printPickles;
readonly bool _printSource;

public GherkinEventsProvider(bool printSource, bool printAst, bool printPickles, IIdGenerator idGenerator)
{
_printSource = printSource;
_astMessagesConverter = new AstMessagesConverter(idGenerator);
_pickleCompiler = new PickleCompiler(idGenerator);
_printAst = printAst;
_printPickles = printPickles;
}
private readonly PickleCompiler _pickleCompiler = new PickleCompiler(idGenerator);
private readonly AstMessagesConverter _astMessagesConverter = new AstMessagesConverter(idGenerator);

public IEnumerable<Envelope> GetEvents(Source source)
{
Expand All @@ -34,22 +21,22 @@ public IEnumerable<Envelope> GetEvents(Source source)
{
var gherkinDocument = _parser.Parse(new StringReader(source.Data));

if (_printSource)
if (printSource)
{
events.Add(new Envelope
{
Source = source
});
}
if (_printAst)
if (printAst)
{
events.Add(new Envelope
{
GherkinDocument =
_astMessagesConverter.ConvertGherkinDocumentToEventArgs(gherkinDocument, source.Uri)
});
}
if (_printPickles)
if (printPickles)
{
var pickles = _pickleCompiler.Compile(_astMessagesConverter.ConvertGherkinDocumentToEventArgs(gherkinDocument, source.Uri));
foreach (Pickle pickle in pickles)
Expand Down
9 changes: 2 additions & 7 deletions dotnet/Gherkin/Ast/Background.cs
Original file line number Diff line number Diff line change
@@ -1,9 +1,4 @@
namespace Gherkin.Ast;

public class Background : StepsContainer
{
public Background(Location location, string keyword, string name, string description, Step[] steps)
: base(location, keyword, name, description, steps)
{
}
}
public class Background(Location location, string keyword, string name, string description, Step[] steps)
: StepsContainer(location, keyword, name, description, steps);
13 changes: 3 additions & 10 deletions dotnet/Gherkin/Ast/Comment.cs
Original file line number Diff line number Diff line change
@@ -1,14 +1,7 @@
namespace Gherkin.Ast;

public class Comment : IHasLocation
public class Comment(Location location, string text) : IHasLocation
{
public Location Location { get; private set; }
public string Text { get; private set; }


public Comment(Location location, string text)
{
Text = text;
Location = location;
}
public Location Location { get; } = location;
public string Text { get; } = text;
}
18 changes: 5 additions & 13 deletions dotnet/Gherkin/Ast/DocString.cs
Original file line number Diff line number Diff line change
@@ -1,17 +1,9 @@
namespace Gherkin.Ast;

public class DocString : StepArgument, IHasLocation
public class DocString(Location location, string contentType, string content, string delimiter = null) : StepArgument, IHasLocation
{
public Location Location { get; private set; }
public string ContentType { get; private set; }
public string Content { get; private set; }
public string Delimiter { get; private set; }

public DocString(Location location, string contentType, string content, string delimiter = null)
{
Location = location;
ContentType = contentType;
Content = content;
Delimiter = delimiter;
}
public Location Location { get; } = location;
public string ContentType { get; } = contentType;
public string Content { get; } = content;
public string Delimiter { get; } = delimiter;
}
28 changes: 9 additions & 19 deletions dotnet/Gherkin/Ast/Examples.cs
Original file line number Diff line number Diff line change
Expand Up @@ -3,26 +3,16 @@

namespace Gherkin.Ast;

public class Examples : IHasLocation, IHasDescription, IHasRows, IHasTags
public class Examples(Tag[] tags, Location location, string keyword, string name, string description, TableRow header, TableRow[] body)
: IHasLocation, IHasDescription, IHasRows, IHasTags
{
public IEnumerable<Tag> Tags { get; private set; }
public Location Location { get; private set; }
public string Keyword { get; private set; }
public string Name { get; private set; }
public string Description { get; private set; }
public TableRow TableHeader { get; private set; }
public IEnumerable<TableRow> TableBody { get; private set; }

public Examples(Tag[] tags, Location location, string keyword, string name, string description, TableRow header, TableRow[] body)
{
Tags = tags;
Location = location;
Keyword = keyword;
Name = name;
Description = description;
TableHeader = header;
TableBody = body;
}
public IEnumerable<Tag> Tags { get; } = tags;
public Location Location { get; } = location;
public string Keyword { get; } = keyword;
public string Name { get; } = name;
public string Description { get; } = description;
public TableRow TableHeader { get; } = header;
public IEnumerable<TableRow> TableBody { get; } = body;

IEnumerable<TableRow> IHasRows.Rows
{
Expand Down
28 changes: 9 additions & 19 deletions dotnet/Gherkin/Ast/Feature.cs
Original file line number Diff line number Diff line change
Expand Up @@ -2,24 +2,14 @@

namespace Gherkin.Ast;

public class Feature : IHasLocation, IHasDescription, IHasTags, IHasChildren
public class Feature(Tag[] tags, Location location, string language, string keyword, string name, string description, IHasLocation[] children)
: IHasLocation, IHasDescription, IHasTags, IHasChildren
{
public IEnumerable<Tag> Tags { get; private set; }
public Location Location { get; private set; }
public string Language { get; private set; }
public string Keyword { get; private set; }
public string Name { get; private set; }
public string Description { get; private set; }
public IEnumerable<IHasLocation> Children { get; private set; }

public Feature(Tag[] tags, Location location, string language, string keyword, string name, string description, IHasLocation[] children)
{
Tags = tags;
Location = location;
Language = language;
Keyword = keyword;
Name = name;
Description = description;
Children = children;
}
public IEnumerable<Tag> Tags { get; } = tags;
public Location Location { get; } = location;
public string Language { get; } = language;
public string Keyword { get; } = keyword;
public string Name { get; } = name;
public string Description { get; } = description;
public IEnumerable<IHasLocation> Children { get; } = children;
}
12 changes: 3 additions & 9 deletions dotnet/Gherkin/Ast/GherkinDocument.cs
Original file line number Diff line number Diff line change
Expand Up @@ -2,14 +2,8 @@

namespace Gherkin.Ast;

public class GherkinDocument
public class GherkinDocument(Feature feature, Comment[] comments)
{
public Feature Feature { get; private set; }
public IEnumerable<Comment> Comments { get; private set; }

public GherkinDocument(Feature feature, Comment[] comments)
{
Feature = feature;
Comments = comments;
}
public Feature Feature { get; } = feature;
public IEnumerable<Comment> Comments { get; } = comments;
}
14 changes: 3 additions & 11 deletions dotnet/Gherkin/Ast/Location.cs
Original file line number Diff line number Diff line change
@@ -1,15 +1,7 @@
using System;

namespace Gherkin.Ast;

public class Location
public class Location(int line = 0, int column = 0)
{
public int Line { get; private set; }
public int Column { get; private set; }

public Location(int line = 0, int column = 0)
{
Line = line;
Column = column;
}
public int Line { get; } = line;
public int Column { get; } = column;
}
25 changes: 8 additions & 17 deletions dotnet/Gherkin/Ast/Rule.cs
Original file line number Diff line number Diff line change
Expand Up @@ -2,22 +2,13 @@

namespace Gherkin.Ast;

public class Rule : IHasLocation, IHasDescription, IHasChildren, IHasTags
public class Rule(Tag[] tags, Location location, string keyword, string name, string description, IHasLocation[] children)
: IHasLocation, IHasDescription, IHasChildren, IHasTags
{
public Location Location { get; private set; }
public string Keyword { get; private set; }
public string Name { get; private set; }
public string Description { get; private set; }
public IEnumerable<Tag> Tags { get; private set; }
public IEnumerable<IHasLocation> Children { get; private set; }

public Rule(Tag[] tags, Location location, string keyword, string name, string description, IHasLocation[] children)
{
Location = location;
Keyword = keyword;
Name = name;
Description = description;
Children = children;
Tags = tags;
}
public Location Location { get; } = location;
public string Keyword { get; } = keyword;
public string Name { get; } = name;
public string Description { get; } = description;
public IEnumerable<Tag> Tags { get; } = tags;
public IEnumerable<IHasLocation> Children { get; } = children;
}
14 changes: 4 additions & 10 deletions dotnet/Gherkin/Ast/Scenario.cs
Original file line number Diff line number Diff line change
Expand Up @@ -2,15 +2,9 @@

namespace Gherkin.Ast;

public class Scenario : StepsContainer, IHasTags
public class Scenario(Tag[] tags, Location location, string keyword, string name, string description, Step[] steps, Examples[] examples)
: StepsContainer(location, keyword, name, description, steps), IHasTags
{
public IEnumerable<Tag> Tags { get; private set; }
public IEnumerable<Examples> Examples { get; private set; }

public Scenario(Tag[] tags, Location location, string keyword, string name, string description, Step[] steps, Examples[] examples)
: base(location, keyword, name, description, steps)
{
Tags = tags;
Examples = examples;
}
public IEnumerable<Tag> Tags { get; } = tags;
public IEnumerable<Examples> Examples { get; } = examples;
}
21 changes: 6 additions & 15 deletions dotnet/Gherkin/Ast/Step.cs
Original file line number Diff line number Diff line change
@@ -1,20 +1,11 @@
namespace Gherkin.Ast;

public class Step : IHasLocation
public class Step(Location location, string keyword, StepKeywordType keywordType, string text, StepArgument argument) : IHasLocation
{
public Location Location { get; private set; }
public string Keyword { get; private set; }
public StepKeywordType KeywordType { get; }
public Location Location { get; } = location;
public string Keyword { get; } = keyword;
public StepKeywordType KeywordType { get; } = keywordType;

public string Text { get; private set; }
public StepArgument Argument { get; private set; }

public Step(Location location, string keyword, StepKeywordType keywordType, string text, StepArgument argument)
{
Location = location;
Keyword = keyword;
KeywordType = keywordType;
Text = text;
Argument = argument;
}
public string Text { get; } = text;
public StepArgument Argument { get; } = argument;
}
22 changes: 7 additions & 15 deletions dotnet/Gherkin/Ast/StepsContainer.cs
Original file line number Diff line number Diff line change
Expand Up @@ -2,20 +2,12 @@

namespace Gherkin.Ast;

public abstract class StepsContainer : IHasLocation, IHasDescription, IHasSteps
public abstract class StepsContainer(Location location, string keyword, string name, string description, Step[] steps)
: IHasLocation, IHasDescription, IHasSteps
{
public Location Location { get; private set; }
public string Keyword { get; private set; }
public string Name { get; private set; }
public string Description { get; private set; }
public IEnumerable<Step> Steps { get; private set; }

protected StepsContainer(Location location, string keyword, string name, string description, Step[] steps)
{
Location = location;
Keyword = keyword;
Name = name;
Description = description;
Steps = steps;
}
public Location Location { get; } = location;
public string Keyword { get; } = keyword;
public string Name { get; } = name;
public string Description { get; } = description;
public IEnumerable<Step> Steps { get; } = steps;
}
12 changes: 3 additions & 9 deletions dotnet/Gherkin/Ast/TableCell.cs
Original file line number Diff line number Diff line change
@@ -1,13 +1,7 @@
namespace Gherkin.Ast;

public class TableCell : IHasLocation
public class TableCell(Location location, string value) : IHasLocation
{
public Location Location { get; private set; }
public string Value { get; private set; }

public TableCell(Location location, string value)
{
Location = location;
Value = value;
}
public Location Location { get; } = location;
public string Value { get; } = value;
}
12 changes: 3 additions & 9 deletions dotnet/Gherkin/Ast/TableRow.cs
Original file line number Diff line number Diff line change
Expand Up @@ -2,14 +2,8 @@

namespace Gherkin.Ast;

public class TableRow : IHasLocation
public class TableRow(Location location, TableCell[] cells) : IHasLocation
{
public Location Location { get; private set; }
public IEnumerable<TableCell> Cells { get; private set; }

public TableRow(Location location, TableCell[] cells)
{
Location = location;
Cells = cells;
}
public Location Location { get; } = location;
public IEnumerable<TableCell> Cells { get; } = cells;
}
12 changes: 3 additions & 9 deletions dotnet/Gherkin/Ast/Tag.cs
Original file line number Diff line number Diff line change
@@ -1,13 +1,7 @@
namespace Gherkin.Ast;

public class Tag : IHasLocation
public class Tag(Location location, string name) : IHasLocation
{
public Location Location { get; private set; }
public string Name { get; private set; }

public Tag(Location location, string name)
{
Name = name;
Location = location;
}
public Location Location { get; } = location;
public string Name { get; } = name;
}
Loading

0 comments on commit 607a142

Please sign in to comment.