Do not warn for valid generated properties

このコミットが含まれているのは:
Sergio Pedri committed 2024-10-18 18:41:10 -07:00
1 親 3969ea2924
コミット 8e3f767632
2ファイル変更
+20 -8

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

+1 -1
ファイルの表示
@@ -27,7 +27,7 @@ public sealed partial class CanvasEffectPropertyGenerator : IIncrementalGenerato
/// <summary>
/// The name of generator to include in the generated code.
/// </summary>
private const string GeneratorName =
internal const string GeneratorName =
#if WINDOWS_UWP
"ComputeSharp.D2D1.Uwp.CanvasEffectPropertyGenerator";
#else
@@ -42,8 +42,9 @@ public sealed class InvalidGeneratedCanvasEffectPropertyDeclarationAnalyzer : Di
context.RegisterCompilationStartAction(static context =>
{
// Get the [GeneratedCanvasEffectProperty] symbols
if (context.Compilation.GetTypeByMetadataName(WellKnownTypeNames.GeneratedCanvasEffectPropertyAttribute) is not { } generatedCanvasEffectPropertyAttributeSymbol)
// Get the [GeneratedCanvasEffectProperty] and [GeneratedCode] symbols
if (context.Compilation.GetTypeByMetadataName(WellKnownTypeNames.GeneratedCanvasEffectPropertyAttribute) is not { } generatedCanvasEffectPropertyAttributeSymbol ||
context.Compilation.GetTypeByMetadataName("System.CodeDom.Compiler.GeneratedCodeAttribute") is not { } generatedCodeAttributeSymbol)
{
return;
}
@@ -71,13 +72,24 @@ public sealed class InvalidGeneratedCanvasEffectPropertyDeclarationAnalyzer : Di
context.Symbol));
}
// Emit an error if the property is not a partial definition with no implementation
// Emit an error if the property is not a partial definition with no implementation...
if (propertySymbol is not { IsPartialDefinition: true, PartialImplementationPart: null })
{
context.ReportDiagnostic(Diagnostic.Create(
InvalidGeneratedCanvasEffectPropertyDeclarationIsNotIncompletePartialDefinition,
generatedCanvasEffectPropertyAttribute.GetLocation(),
context.Symbol));
// ...But only if it wasn't actually generated by the [GeneratedCanvasEffectProperty] generator.
bool isImplementationAllowed =
propertySymbol is { IsPartialDefinition: true, PartialImplementationPart: IPropertySymbol implementationPartSymbol } &&
implementationPartSymbol.TryGetAttributeWithType(generatedCodeAttributeSymbol, out AttributeData? generatedCodeAttributeData) &&
generatedCodeAttributeData.TryGetConstructorArgument(0, out string? toolName) &&
toolName == CanvasEffectPropertyGenerator.GeneratorName;
// Emit the diagnostic only for cases that were not valid generator outputs
if (!isImplementationAllowed)
{
context.ReportDiagnostic(Diagnostic.Create(
InvalidGeneratedCanvasEffectPropertyDeclarationIsNotIncompletePartialDefinition,
generatedCanvasEffectPropertyAttribute.GetLocation(),
context.Symbol));
}
}
// Emit an error if the property returns a value by ref