Add initial 'CanvasEffectPropertyGenerator' type

このコミットが含まれているのは:
Sergio Pedri committed 2024-10-17 21:41:03 -07:00
1 親 e330bb5372
コミット 8185999b72
5ファイル変更
+73 -1

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

@@ -0,0 +1,42 @@
using System.Threading;
using ComputeSharp.SourceGeneration.Extensions;
using Microsoft.CodeAnalysis;
using Microsoft.CodeAnalysis.CSharp;
using Microsoft.CodeAnalysis.CSharp.Syntax;
namespace ComputeSharp.D2D1.WinUI.SourceGenerators;
/// <inheritdoc/>
partial class CanvasEffectPropertyGenerator
{
/// <summary>
/// A container for all the logic for <see cref="CanvasEffectPropertyGenerator"/>.
/// </summary>
private static partial class Execute
{
/// <summary>
/// Checks whether an input syntax node is a candidate property declaration for the generator.
/// </summary>
/// <param name="node">The input syntax node to check.</param>
/// <param name="token">The <see cref="CancellationToken"/> used to cancel the operation, if needed.</param>
/// <returns>Whether <paramref name="node"/> is a candidate property declaration.</returns>
public static bool IsCandidatePropertyDeclaration(SyntaxNode node, CancellationToken token)
{
// The node must be a property declaration with two accessors
if (node is not PropertyDeclarationSyntax { AccessorList.Accessors: { Count: 2 } accessors })
{
return false;
}
// The accessors must be a get and a set (with any accessibility)
if (accessors[0].Kind() is not (SyntaxKind.GetAccessorDeclaration or SyntaxKind.SetAccessorDeclaration) ||
accessors[1].Kind() is not (SyntaxKind.GetAccessorDeclaration or SyntaxKind.SetAccessorDeclaration))
{
return false;
}
// The property must be in a type with a base type (as it must derive from CanvasEffect)
return node.Parent?.IsTypeDeclarationWithOrPotentiallyWithBaseTypes<ClassDeclarationSyntax>() == true;
}
}
}
+26
ファイルの表示
@@ -0,0 +1,26 @@
using Microsoft.CodeAnalysis;
namespace ComputeSharp.D2D1.WinUI.SourceGenerators;
/// <summary>
/// A source generator creating implementations of effect properties.
/// </summary>
[Generator(LanguageNames.CSharp)]
public sealed partial class CanvasEffectPropertyGenerator : IIncrementalGenerator
{
/// <summary>
/// The name of generator to include in the generated code.
/// </summary>
private const string GeneratorName = "ComputeSharp.D2D1.WinUI.CanvasEffectPropertyGenerator";
/// <inheritdoc/>
public void Initialize(IncrementalGeneratorInitializationContext context)
{
IncrementalValuesProvider<object?> propertyInfo =
context.SyntaxProvider
.ForAttributeWithMetadataName(
"ComputeSharp.D2D1.WinUI.GeneratedCanvasEffectPropertyAttribute",
Execute.IsCandidatePropertyDeclaration,
static (context, token) => (object?)null);
}
}
@@ -11,4 +11,7 @@
<AdditionalFiles Include="AnalyzerReleases.Shipped.md" />
<AdditionalFiles Include="AnalyzerReleases.Unshipped.md" />
</ItemGroup>
<!-- Shared project with common helpers -->
<Import Project="..\ComputeSharp.SourceGeneration\ComputeSharp.SourceGeneration.projitems" Label="Shared" />
</Project>