Add new InvalidD2DResourceTextureIndexUseAnalyzer analyzer
このコミットが含まれているのは:
1 親
5204402c49
コミット
f27e98f2fa
3ファイル変更
+52
-38
検索条件に一致するファイルはありません
+52
@@ -0,0 +1,52 @@
|
||||
// Licensed to the .NET Foundation under one or more agreements.
|
||||
// The .NET Foundation licenses this file to you under the MIT license.
|
||||
// See the LICENSE file in the project root for more information.
|
||||
|
||||
using System.Collections.Immutable;
|
||||
using System.Linq;
|
||||
using ComputeSharp.SourceGeneration.Extensions;
|
||||
using ComputeSharp.SourceGeneration.Mappings;
|
||||
using Microsoft.CodeAnalysis;
|
||||
using Microsoft.CodeAnalysis.Diagnostics;
|
||||
using static ComputeSharp.SourceGeneration.Diagnostics.DiagnosticDescriptors;
|
||||
|
||||
namespace ComputeSharp.D2D1.SourceGenerators;
|
||||
|
||||
/// <summary>
|
||||
/// A diagnostic analyzer that generates an error whenever [D2DResourceTextureIndex] is used incorrectly to annotate an invalid field.
|
||||
/// </summary>
|
||||
[DiagnosticAnalyzer(LanguageNames.CSharp)]
|
||||
public sealed class InvalidD2DResourceTextureIndexUseAnalyzer : DiagnosticAnalyzer
|
||||
{
|
||||
/// <inheritdoc/>
|
||||
public override ImmutableArray<DiagnosticDescriptor> SupportedDiagnostics { get; } = ImmutableArray.Create(InvalidD2DResourceTextureIndexAttributeUse);
|
||||
|
||||
/// <inheritdoc/>
|
||||
public override void Initialize(AnalysisContext context)
|
||||
{
|
||||
context.ConfigureGeneratedCodeAnalysis(GeneratedCodeAnalysisFlags.Analyze | GeneratedCodeAnalysisFlags.ReportDiagnostics);
|
||||
context.EnableConcurrentExecution();
|
||||
|
||||
context.RegisterSymbolAction(static context =>
|
||||
{
|
||||
IFieldSymbol fieldSymbol = (IFieldSymbol)context.Symbol;
|
||||
|
||||
if (fieldSymbol.HasAttributeWithFullyQualifiedName("ComputeSharp.D2D1.D2DResourceTextureIndexAttribute"))
|
||||
{
|
||||
string metadataName = fieldSymbol.Type.GetFullMetadataName();
|
||||
|
||||
if (!HlslKnownTypes.IsResourceTextureType(metadataName))
|
||||
{
|
||||
Diagnostic diagnostic = Diagnostic.Create(
|
||||
InvalidD2DResourceTextureIndexAttributeUse,
|
||||
fieldSymbol.Locations.FirstOrDefault(),
|
||||
fieldSymbol.Name,
|
||||
fieldSymbol.ContainingType,
|
||||
fieldSymbol.Type);
|
||||
|
||||
context.ReportDiagnostic(diagnostic);
|
||||
}
|
||||
}
|
||||
}, SymbolKind.Field);
|
||||
}
|
||||
}
|
||||
新しいイシューから参照
ユーザーをブロックする