• Home
  • Features
  • Pricing
  • Docs
  • Announcements
  • Sign In

loresoft / FluentCommand / 10891700765

16 Sep 2024 08:36PM UTC coverage: 54.514%. First build
10891700765

push

github

pwelter34
add GenerateReaderAttribute

1672 of 3548 branches covered (47.13%)

Branch coverage included in aggregate %.

37 of 131 new or added lines in 9 files covered. (28.24%)

4221 of 7262 relevant lines covered (58.12%)

229.05 hits per line

Source File
Press 'n' to go to next uncovered line, 'b' for previous

0.0
/src/FluentCommand.Generators/TableAttributeGenerator.cs
1
using FluentCommand.Generators.Models;
2

3
using Microsoft.CodeAnalysis;
4
using Microsoft.CodeAnalysis.CSharp;
5
using Microsoft.CodeAnalysis.CSharp.Syntax;
6

7
namespace FluentCommand.Generators;
8

9
[Generator(LanguageNames.CSharp)]
10
public class TableAttributeGenerator : DataReaderFactoryGenerator, IIncrementalGenerator
11
{
12
    public void Initialize(IncrementalGeneratorInitializationContext context)
13
    {
NEW
14
        var provider = context.SyntaxProvider.ForAttributeWithMetadataName(
×
NEW
15
            fullyQualifiedMetadataName: "System.ComponentModel.DataAnnotations.Schema.TableAttribute",
×
NEW
16
            predicate: SyntacticPredicate,
×
NEW
17
            transform: SemanticTransform
×
NEW
18
        )
×
NEW
19
        .Where(static context => context is not null);
×
20

21
        // Emit the diagnostics, if needed
NEW
22
        var diagnostics = provider
×
NEW
23
            .Select(static (item, _) => item.Diagnostics)
×
NEW
24
            .Where(static item => item.Count > 0);
×
25

NEW
26
        context.RegisterSourceOutput(diagnostics, ReportDiagnostic);
×
27

NEW
28
        var entityClasses = provider
×
NEW
29
            .Select(static (item, _) => item.EntityClass)
×
NEW
30
            .Where(static item => item is not null);
×
31

NEW
32
        context.RegisterSourceOutput(entityClasses, WriteSource);
×
NEW
33
    }
×
34

35
    private static bool SyntacticPredicate(SyntaxNode syntaxNode, CancellationToken cancellationToken)
36
    {
NEW
37
        return (syntaxNode is ClassDeclarationSyntax
×
NEW
38
        { AttributeLists.Count: > 0 } classDeclaration
×
NEW
39
               && !classDeclaration.Modifiers.Any(SyntaxKind.AbstractKeyword)
×
NEW
40
               && !classDeclaration.Modifiers.Any(SyntaxKind.StaticKeyword))
×
NEW
41
            || (syntaxNode is RecordDeclarationSyntax
×
NEW
42
            { AttributeLists.Count: > 0 } recordDeclaration
×
NEW
43
               && !recordDeclaration.Modifiers.Any(SyntaxKind.AbstractKeyword)
×
NEW
44
               && !recordDeclaration.Modifiers.Any(SyntaxKind.StaticKeyword));
×
45
    }
46

47
    private static EntityContext SemanticTransform(GeneratorAttributeSyntaxContext context, CancellationToken cancellationToken)
48
    {
NEW
49
        if (context.TargetSymbol is not INamedTypeSymbol targetSymbol)
×
NEW
50
            return null;
×
51

NEW
52
        return CreateContext(context.TargetNode.GetLocation(), targetSymbol);
×
53
    }
54
}
STATUS · Troubleshooting · Open an Issue · Sales · Support · CAREERS · ENTERPRISE · START FREE · SCHEDULE DEMO
ANNOUNCEMENTS · TWITTER · TOS & SLA · Supported CI Services · What's a CI service? · Automated Testing

© 2026 Coveralls, Inc