Skip to content

Commit

Permalink
remove redundant reporting classes (#46)
Browse files Browse the repository at this point in the history
  • Loading branch information
YarinOmesi authored Aug 5, 2023
1 parent d6d82d3 commit 0c4b52d
Show file tree
Hide file tree
Showing 6 changed files with 10 additions and 86 deletions.

This file was deleted.

This file was deleted.

This file was deleted.

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -6,9 +6,6 @@
using Microsoft.CodeAnalysis;
using Microsoft.CodeAnalysis.CSharp;
using Microsoft.CodeAnalysis.CSharp.Syntax;
using TestsHelper.SourceGenerator.Diagnostics;
using TestsHelper.SourceGenerator.Diagnostics.Exceptions;
using TestsHelper.SourceGenerator.Diagnostics.Reporters;
using TestsHelper.SourceGenerator.MockFilling;
using TestsHelper.SourceGenerator.MockFilling.Models;

Expand Down Expand Up @@ -43,9 +40,6 @@ private static TestClassMockCandidate Transform(GeneratorSyntaxContext context,

private static void Execute(SourceProductionContext context, ImmutableArray<TestClassMockCandidate> classMockCandidates)
{
var reporter = new ActionDiagnosticReporter(context.ReportDiagnostic);
using IDisposable _ = GlobalDiagnosticReporter.SetReporterForScope(reporter);

foreach (TestClassMockCandidate testClassMockCandidate in classMockCandidates)
{
ReportCatcher.RunCode(() =>
Expand All @@ -54,7 +48,7 @@ private static void Execute(SourceProductionContext context, ImmutableArray<Test
{
context.AddSource(result.FileName, result.SourceCode);
}
});
}, context.ReportDiagnostic);
}
}

Expand Down
Original file line number Diff line number Diff line change
@@ -1,26 +1,30 @@
using System;
using System.Collections.Generic;
using System.Linq;
using Microsoft.CodeAnalysis;
using TestsHelper.SourceGenerator.Diagnostics;
using TestsHelper.SourceGenerator.Diagnostics.Exceptions;
using TestsHelper.SourceGenerator.Diagnostics.Reporters;

namespace TestsHelper.SourceGenerator.SourceGeneratorImplementations;

public static class ReportCatcher
{
public static void RunCode(Action action)
public static void RunCode(Action action, Action<Diagnostic> reporter)
{
IDiagnosticReporter reporter = GlobalDiagnosticReporter.Reporter!;
try
{
action();
}
catch (DiagnosticException e)
{
reporter.Report(e.Diagnostic);
reporter(e.Diagnostic);
}
catch (MultipleDiagnosticsException e)
{
reporter.ReportMultiple(e.Diagnostics);
foreach (Diagnostic diagnostic in e.Diagnostics)
{
reporter(diagnostic);
}
}
}
}

0 comments on commit 0c4b52d

Please sign in to comment.