Skip to content

Commit

Permalink
cleanup
Browse files Browse the repository at this point in the history
  • Loading branch information
Aaronontheweb committed Dec 22, 2023
1 parent 0dc8512 commit 6ab228a
Show file tree
Hide file tree
Showing 2 changed files with 28 additions and 28 deletions.
15 changes: 14 additions & 1 deletion src/Akka.Analyzers/Utility/AkkaDiagnosticAnalyzer.cs
Original file line number Diff line number Diff line change
Expand Up @@ -4,9 +4,22 @@
// </copyright>
// -----------------------------------------------------------------------

using System.Collections.Immutable;
using Microsoft.CodeAnalysis;
using Microsoft.CodeAnalysis.Diagnostics;

namespace Akka.Analyzers;

public class AkkaDiagnosticAnalyzer
/// <summary>
/// Base class for all Akka.NET diagnostic analyzers.
/// </summary>
public abstract class AkkaDiagnosticAnalyzer(params DiagnosticDescriptor[] descriptors) : DiagnosticAnalyzer
{
/// <inheritdoc/>
public override ImmutableArray<DiagnosticDescriptor> SupportedDiagnostics { get; } = descriptors.ToImmutableArray();


public abstract void AnalyzeCompilation(
CompilationStartAnalysisContext context,
AkkaContext akkaContext);
}
41 changes: 14 additions & 27 deletions src/Akka.Analyzers/Utility/IAkkaContext.cs
Original file line number Diff line number Diff line change
Expand Up @@ -11,40 +11,27 @@ namespace Akka.Analyzers;
/// <summary>
/// Provides information about the Akka.NET context (i.e. which libraries, which versions) in which the analyzer is running.
/// </summary>
public interface IAkkaContext
public class AkkaContext
{
/// <summary>
/// Initializes a new instance of the <see cref="AkkaContext"/> class.
/// </summary>
/// <param name="compilation">The Roslyn compilation object used to look up types and
/// inspect references</param>
public AkkaContext(Compilation compilation)
{
AkkaCore = AkkaCoreContext.Get(compilation);
}

private AkkaContext(){}

/// <summary>
/// Data about the core Akka.NET library.
/// </summary>
IAkkaCoreContext? AkkaCore { get; }
public IAkkaCoreContext? AkkaCore { get; private set; }

/// <summary>
/// Does the current compilation context even have Akka.NET installed?
/// </summary>
public bool HasAkkaInstalled { get; }
}

public class AkkaContext : IAkkaContext
{
private AkkaContext(){}

public IAkkaCoreContext? AkkaCore { get; private set; }
public bool HasAkkaInstalled => AkkaCore is not null;

public static AkkaContext? Get(
Compilation compilation,
Version? versionOverride = null)
{
// assert that compilation is not null
Guard.AssertIsNotNull(compilation);

var akkaCoreContext = AkkaCoreContext.Get(compilation, versionOverride);
if (akkaCoreContext is null)
return null;

return new AkkaContext
{
AkkaCore = AkkaCoreContext.Get(compilation, versionOverride)
};
}
}

0 comments on commit 6ab228a

Please sign in to comment.