• 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/GenerateAttributeGenerator.cs
1
using FluentCommand.Generators.Models;
2

3
using Microsoft.CodeAnalysis;
4

5
namespace FluentCommand.Generators;
6

7
[Generator(LanguageNames.CSharp)]
8
public class GenerateAttributeGenerator : DataReaderFactoryGenerator, IIncrementalGenerator
9
{
10
    public void Initialize(IncrementalGeneratorInitializationContext context)
11
    {
NEW
12
        var provider = context.SyntaxProvider.ForAttributeWithMetadataName(
×
NEW
13
            fullyQualifiedMetadataName: "FluentCommand.Attributes.GenerateReaderAttribute",
×
NEW
14
            predicate: SyntacticPredicate,
×
NEW
15
            transform: SemanticTransform
×
NEW
16
        )
×
NEW
17
        .Where(static context => context is not null);
×
18

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

NEW
24
        context.RegisterSourceOutput(diagnostics, ReportDiagnostic);
×
25

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

NEW
30
        context.RegisterSourceOutput(entityClasses, WriteSource);
×
NEW
31
    }
×
32

33
    private static bool SyntacticPredicate(SyntaxNode syntaxNode, CancellationToken cancellationToken)
34
    {
NEW
35
        return true;
×
36
    }
37

38
    private static EntityContext SemanticTransform(GeneratorAttributeSyntaxContext context, CancellationToken cancellationToken)
39
    {
NEW
40
        if (context.Attributes.Length == 0)
×
NEW
41
            return null;
×
42

NEW
43
        var attribute = context.Attributes[0];
×
NEW
44
        if (attribute == null)
×
NEW
45
            return null;
×
46

NEW
47
        if (attribute.ConstructorArguments.Length != 1)
×
NEW
48
            return null;
×
49

NEW
50
        var comparerArgument = attribute.ConstructorArguments[0];
×
NEW
51
        if (comparerArgument.Value is not INamedTypeSymbol targetSymbol)
×
NEW
52
            return null;
×
53

NEW
54
        return CreateContext(context.TargetNode.GetLocation(), targetSymbol);
×
55
    }
56
}
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