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

loresoft / FluentCommand / 10974284429

21 Sep 2024 05:08PM UTC coverage: 54.174% (-0.3%) from 54.499%
10974284429

push

github

pwelter34
fix bug in GenerateAttributeGenerator

1672 of 3564 branches covered (46.91%)

Branch coverage included in aggregate %.

0 of 28 new or added lines in 5 files covered. (0.0%)

4221 of 7314 relevant lines covered (57.71%)

227.43 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
    {
14
        var provider = context.SyntaxProvider.ForAttributeWithMetadataName(
×
15
            fullyQualifiedMetadataName: "System.ComponentModel.DataAnnotations.Schema.TableAttribute",
×
16
            predicate: SyntacticPredicate,
×
17
            transform: SemanticTransform
×
18
        )
×
19
        .Where(static context => context is not null);
×
20

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

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

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

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

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

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

NEW
52
        var classes = new List<EntityClass>();
×
NEW
53
        var diagnostics = new List<Diagnostic>();
×
54

NEW
55
        var entityClass = CreateClass(context.TargetNode.GetLocation(), targetSymbol, diagnostics);
×
NEW
56
        classes.Add(entityClass);
×
57

NEW
58
        return new EntityContext(classes, diagnostics);
×
59
    }
60
}
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