Use primary constructors in base analyzer types

このコミットが含まれているのは:
Sergio Pedri committed 2023-11-23 23:11:52 +01:00
1 親 a0faddcf7a
コミット fc5f06f5bf
3ファイル変更
+20 -77

検索条件に一致するファイルはありません

@@ -8,26 +8,11 @@ namespace ComputeSharp.SourceGeneration.Diagnostics;
/// <summary>
/// A diagnostic analyzer that generates an error if the <c>AllowUnsafeBlocks</c> compilation option is not set.
/// </summary>
public abstract class MissingAllowUnsafeBlocksCompilationOptionAnalyzerBase : DiagnosticAnalyzer
/// <param name="diagnosticDescriptor">The <see cref="DiagnosticDescriptor"/> instance to use.</param>
public abstract class MissingAllowUnsafeBlocksCompilationOptionAnalyzerBase(DiagnosticDescriptor diagnosticDescriptor) : DiagnosticAnalyzer
{
/// <summary>
/// The <see cref="DiagnosticDescriptor"/> instance to use.
/// </summary>
private readonly DiagnosticDescriptor diagnosticDescriptor;
/// <summary>
/// Creates a new <see cref="MissingAllowUnsafeBlocksCompilationOptionAnalyzerBase"/> instance with the specified arguments.
/// </summary>
/// <param name="diagnosticDescriptor">The <see cref="DiagnosticDescriptor"/> instance to use.</param>
private protected MissingAllowUnsafeBlocksCompilationOptionAnalyzerBase(DiagnosticDescriptor diagnosticDescriptor)
{
this.diagnosticDescriptor = diagnosticDescriptor;
SupportedDiagnostics = ImmutableArray.Create(diagnosticDescriptor);
}
/// <inheritdoc/>
public sealed override ImmutableArray<DiagnosticDescriptor> SupportedDiagnostics { get; }
public sealed override ImmutableArray<DiagnosticDescriptor> SupportedDiagnostics { get; } = ImmutableArray.Create(diagnosticDescriptor);
/// <inheritdoc/>
public sealed override void Initialize(AnalysisContext context)
@@ -40,7 +25,7 @@ public abstract class MissingAllowUnsafeBlocksCompilationOptionAnalyzerBase : Di
// Check whether unsafe blocks are available, and emit an error if they are not
if (!context.Compilation.IsAllowUnsafeBlocksEnabled())
{
context.ReportDiagnostic(Diagnostic.Create(this.diagnosticDescriptor, location: null));
context.ReportDiagnostic(Diagnostic.Create(diagnosticDescriptor, location: null));
}
});
}
@@ -8,35 +8,14 @@ namespace ComputeSharp.SourceGeneration.Diagnostics;
/// <summary>
/// A diagnostic analyzer that generates an error if a field in a target shader type is of a type that is not accessible from its containing assembly.
/// </summary>
public abstract class NotAccessibleFieldTypeInGeneratedShaderDescriptorAttributeTargetAnalyzerBase : DiagnosticAnalyzer
/// <param name="diagnosticDescriptor">The <see cref="DiagnosticDescriptor"/> instance to use.</param>
/// <param name="generatedShaderDescriptorFullyQualifiedTypeName">The fully qualified type name of the target attribute.</param>
public abstract class NotAccessibleFieldTypeInGeneratedShaderDescriptorAttributeTargetAnalyzerBase(
DiagnosticDescriptor diagnosticDescriptor,
string generatedShaderDescriptorFullyQualifiedTypeName) : DiagnosticAnalyzer
{
/// <summary>
/// The <see cref="DiagnosticDescriptor"/> instance to use.
/// </summary>
private readonly DiagnosticDescriptor diagnosticDescriptor;
/// <summary>
/// The fully qualified type name of the target attribute.
/// </summary>
private readonly string generatedShaderDescriptorFullyQualifiedTypeName;
/// <summary>
/// Creates a new <see cref="NotAccessibleFieldTypeInGeneratedShaderDescriptorAttributeTargetAnalyzerBase"/> instance with the specified arguments.
/// </summary>
/// <param name="diagnosticDescriptor">The <see cref="DiagnosticDescriptor"/> instance to use.</param>
/// <param name="generatedShaderDescriptorFullyQualifiedTypeName">The fully qualified type name of the target attribute.</param>
private protected NotAccessibleFieldTypeInGeneratedShaderDescriptorAttributeTargetAnalyzerBase(
DiagnosticDescriptor diagnosticDescriptor,
string generatedShaderDescriptorFullyQualifiedTypeName)
{
this.diagnosticDescriptor = diagnosticDescriptor;
this.generatedShaderDescriptorFullyQualifiedTypeName = generatedShaderDescriptorFullyQualifiedTypeName;
SupportedDiagnostics = ImmutableArray.Create(diagnosticDescriptor);
}
/// <inheritdoc/>
public sealed override ImmutableArray<DiagnosticDescriptor> SupportedDiagnostics { get; }
public sealed override ImmutableArray<DiagnosticDescriptor> SupportedDiagnostics { get; } = ImmutableArray.Create(diagnosticDescriptor);
/// <inheritdoc/>
public sealed override void Initialize(AnalysisContext context)
@@ -47,7 +26,7 @@ public abstract class NotAccessibleFieldTypeInGeneratedShaderDescriptorAttribute
context.RegisterCompilationStartAction(context =>
{
// Get the symbol for the target attribute type
if (context.Compilation.GetTypeByMetadataName(this.generatedShaderDescriptorFullyQualifiedTypeName) is not { } generatedShaderDescriptorAttributeSymbol)
if (context.Compilation.GetTypeByMetadataName(generatedShaderDescriptorFullyQualifiedTypeName) is not { } generatedShaderDescriptorAttributeSymbol)
{
return;
}
@@ -78,7 +57,7 @@ public abstract class NotAccessibleFieldTypeInGeneratedShaderDescriptorAttribute
if (!fieldTypeSymbol.IsAccessibleFromCompilationAssembly(context.Compilation))
{
context.ReportDiagnostic(Diagnostic.Create(
this.diagnosticDescriptor,
diagnosticDescriptor,
attribute.GetLocation(),
typeSymbol,
memberSymbol.Name,
@@ -8,35 +8,14 @@ namespace ComputeSharp.SourceGeneration.Diagnostics;
/// <summary>
/// A diagnostic analyzer that generates an error if a target shader type is not accessible from its containing assembly.
/// </summary>
public abstract class NotAccessibleGeneratedShaderDescriptorAttributeTargetAnalyzerBase : DiagnosticAnalyzer
/// <param name="diagnosticDescriptor">The <see cref="DiagnosticDescriptor"/> instance to use.</param>
/// <param name="generatedShaderDescriptorFullyQualifiedTypeName">The fully qualified type name of the target attribute.</param>
public abstract class NotAccessibleGeneratedShaderDescriptorAttributeTargetAnalyzerBase(
DiagnosticDescriptor diagnosticDescriptor,
string generatedShaderDescriptorFullyQualifiedTypeName) : DiagnosticAnalyzer
{
/// <summary>
/// The <see cref="DiagnosticDescriptor"/> instance to use.
/// </summary>
private readonly DiagnosticDescriptor diagnosticDescriptor;
/// <summary>
/// The fully qualified type name of the target attribute.
/// </summary>
private readonly string generatedShaderDescriptorFullyQualifiedTypeName;
/// <summary>
/// Creates a new <see cref="NotAccessibleGeneratedShaderDescriptorAttributeTargetAnalyzerBase"/> instance with the specified arguments.
/// </summary>
/// <param name="diagnosticDescriptor">The <see cref="DiagnosticDescriptor"/> instance to use.</param>
/// <param name="generatedShaderDescriptorFullyQualifiedTypeName">The fully qualified type name of the target attribute.</param>
private protected NotAccessibleGeneratedShaderDescriptorAttributeTargetAnalyzerBase(
DiagnosticDescriptor diagnosticDescriptor,
string generatedShaderDescriptorFullyQualifiedTypeName)
{
this.diagnosticDescriptor = diagnosticDescriptor;
this.generatedShaderDescriptorFullyQualifiedTypeName = generatedShaderDescriptorFullyQualifiedTypeName;
SupportedDiagnostics = ImmutableArray.Create(diagnosticDescriptor);
}
/// <inheritdoc/>
public sealed override ImmutableArray<DiagnosticDescriptor> SupportedDiagnostics { get; }
public sealed override ImmutableArray<DiagnosticDescriptor> SupportedDiagnostics { get; } = ImmutableArray.Create(diagnosticDescriptor);
/// <inheritdoc/>
public sealed override void Initialize(AnalysisContext context)
@@ -47,7 +26,7 @@ public abstract class NotAccessibleGeneratedShaderDescriptorAttributeTargetAnaly
context.RegisterCompilationStartAction(context =>
{
// Get the symbol for the target attribute type
if (context.Compilation.GetTypeByMetadataName(this.generatedShaderDescriptorFullyQualifiedTypeName) is not { } generatedShaderDescriptorAttributeSymbol)
if (context.Compilation.GetTypeByMetadataName(generatedShaderDescriptorFullyQualifiedTypeName) is not { } generatedShaderDescriptorAttributeSymbol)
{
return;
}
@@ -65,7 +44,7 @@ public abstract class NotAccessibleGeneratedShaderDescriptorAttributeTargetAnaly
!typeSymbol.IsAccessibleFromContainingAssembly(context.Compilation))
{
context.ReportDiagnostic(Diagnostic.Create(
this.diagnosticDescriptor,
diagnosticDescriptor,
attribute.GetLocation(),
typeSymbol));
}