Skip to content

Commit

Permalink
Refactored.
Browse files Browse the repository at this point in the history
  • Loading branch information
kekyo committed Sep 2, 2024
1 parent 44fcf5d commit 9d04c90
Show file tree
Hide file tree
Showing 9 changed files with 40 additions and 14 deletions.
6 changes: 3 additions & 3 deletions RelaxVersioner.Core/Processor.cs
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@ public sealed class ProcessorContext
public sealed class Processor
{
private readonly Logger logger;
private readonly Dictionary<string, WriterBase> writers;
private readonly Dictionary<string, SourceCodeWriterBase> writers;

Check failure on line 44 in RelaxVersioner.Core/Processor.cs

View workflow job for this annotation

GitHub Actions / build

The type or namespace name 'SourceCodeWriterBase' could not be found (are you missing a using directive or an assembly reference?)

Check failure on line 44 in RelaxVersioner.Core/Processor.cs

View workflow job for this annotation

GitHub Actions / build

The type or namespace name 'SourceCodeWriterBase' could not be found (are you missing a using directive or an assembly reference?)

Check failure on line 44 in RelaxVersioner.Core/Processor.cs

View workflow job for this annotation

GitHub Actions / build

The type or namespace name 'SourceCodeWriterBase' could not be found (are you missing a using directive or an assembly reference?)

public Processor(Logger logger)
{
Expand Down Expand Up @@ -71,7 +71,7 @@ public override string ToString() =>

private static async Task<Result> WriteVersionSourceFileAsync(
Logger logger,
WriterBase writer,
SourceCodeWriterBase sourceCodeWriter,

Check failure on line 74 in RelaxVersioner.Core/Processor.cs

View workflow job for this annotation

GitHub Actions / build

The type or namespace name 'SourceCodeWriterBase' could not be found (are you missing a using directive or an assembly reference?)

Check failure on line 74 in RelaxVersioner.Core/Processor.cs

View workflow job for this annotation

GitHub Actions / build

The type or namespace name 'SourceCodeWriterBase' could not be found (are you missing a using directive or an assembly reference?)

Check failure on line 74 in RelaxVersioner.Core/Processor.cs

View workflow job for this annotation

GitHub Actions / build

The type or namespace name 'SourceCodeWriterBase' could not be found (are you missing a using directive or an assembly reference?)

Check failure on line 74 in RelaxVersioner.Core/Processor.cs

View workflow job for this annotation

GitHub Actions / build

The type or namespace name 'SourceCodeWriterBase' could not be found (are you missing a using directive or an assembly reference?)
ProcessorContext context,
Branch targetBranch,
DateTimeOffset generated,
Expand Down Expand Up @@ -156,7 +156,7 @@ static string FormatSignature(Signature? sig) => sig is { } s ?

if (!string.IsNullOrWhiteSpace(context.OutputPath))
{
writer.Write(context, keyValues, generated, ruleSet, importSet);
sourceCodeWriter.Write(context, keyValues, generated, ruleSet, importSet);
}

return new Result(
Expand Down
6 changes: 3 additions & 3 deletions RelaxVersioner.Core/Utilities.cs
Original file line number Diff line number Diff line change
Expand Up @@ -36,12 +36,12 @@ public static string GetDirectoryPath(string path) =>
var dp => dp,
};

public static Dictionary<string, WriterBase> GetWriters()
public static Dictionary<string, SourceCodeWriterBase> GetWriters()

Check failure on line 39 in RelaxVersioner.Core/Utilities.cs

View workflow job for this annotation

GitHub Actions / build

The type or namespace name 'SourceCodeWriterBase' could not be found (are you missing a using directive or an assembly reference?)

Check failure on line 39 in RelaxVersioner.Core/Utilities.cs

View workflow job for this annotation

GitHub Actions / build

The type or namespace name 'SourceCodeWriterBase' could not be found (are you missing a using directive or an assembly reference?)

Check failure on line 39 in RelaxVersioner.Core/Utilities.cs

View workflow job for this annotation

GitHub Actions / build

The type or namespace name 'SourceCodeWriterBase' could not be found (are you missing a using directive or an assembly reference?)
{
return typeof(Utilities).Assembly.
GetTypes().
Where(type => type.IsSealed && type.IsClass && typeof(WriterBase).IsAssignableFrom(type)).
Select(type => (WriterBase)Activator.CreateInstance(type)).
Where(type => type.IsSealed && type.IsClass && typeof(SourceCodeWriterBase).IsAssignableFrom(type)).
Select(type => (SourceCodeWriterBase)Activator.CreateInstance(type)).
ToDictionary(writer => writer.Language, StringComparer.InvariantCultureIgnoreCase);
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@

namespace RelaxVersioner.Writers;

internal sealed class CPlusPlusCLIWriter : WriterBase
internal sealed class CPlusPlusCliSourceCodeWriter : SourceCodeWriteProviderBase
{
public override string Language => "C++/CLI";

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@

namespace RelaxVersioner.Writers;

internal sealed class CSharpWriter : WriterBase
internal sealed class CSharpSourceCodeWriter : SourceCodeWriteProviderBase
{
public override string Language => "C#";

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@

namespace RelaxVersioner.Writers;

internal sealed class FSharpWriter : WriterBase
internal sealed class FSharpSourceCodeWriter : SourceCodeWriteProviderBase
{
public override string Language => "F#";

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,11 +19,9 @@

namespace RelaxVersioner.Writers;

internal abstract class WriterBase
internal abstract class SourceCodeWriteProviderBase : WriteProviderBase
{
public abstract string Language { get; }

public void Write(
public override void Write(
ProcessorContext context,
Dictionary<string, object?> keyValues,
DateTimeOffset generated,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@

namespace RelaxVersioner.Writers;

internal sealed class VisualBasicWriter : WriterBase
internal sealed class VisualBasicSourceCodeWriter : SourceCodeWriteProviderBase
{
public override string Language => "VB";

Expand Down
27 changes: 27 additions & 0 deletions RelaxVersioner.Core/Writers/WriteProviderBase.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
////////////////////////////////////////////////////////////////////////////////////////
//
// RelaxVersioner - Git tag/branch based, full-automatic version generator.
// Copyright (c) Kouji Matsui (@kozy_kekyo, @[email protected])
//
// Licensed under Apache-v2: https://opensource.org/licenses/Apache-2.0
//
////////////////////////////////////////////////////////////////////////////////////////

#nullable enable

using System;
using System.Collections.Generic;

namespace RelaxVersioner.Writers;

internal abstract class WriteProviderBase
{
public abstract string Language { get; }

public abstract void Write(
ProcessorContext context,
Dictionary<string, object?> keyValues,
DateTimeOffset generated,
IEnumerable<Rule> ruleSet,
IEnumerable<string> importSet);
}
1 change: 1 addition & 0 deletions RelaxVersioner/Program.cs
Original file line number Diff line number Diff line change
Expand Up @@ -63,6 +63,7 @@ public static async Task<int> Main(string[] args)

if (help || (trails.Count < 1))
{
logger.Error($"RelaxVersioner [{relaxVersionerVersion}] [{ThisAssembly.AssemblyInformationalVersion}]");
logger.Error("Usage: rv [options...] <projectDirectory>");
options.WriteOptionDescriptions(Console.Error);
return 1;
Expand Down

0 comments on commit 9d04c90

Please sign in to comment.