• 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/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
    {
12
        var provider = context.SyntaxProvider.ForAttributeWithMetadataName(
×
13
            fullyQualifiedMetadataName: "FluentCommand.Attributes.GenerateReaderAttribute",
×
14
            predicate: SyntacticPredicate,
×
15
            transform: SemanticTransform
×
16
        )
×
17
        .Where(static context => context is not null);
×
18

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

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

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

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

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

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

NEW
43
        var classes = new List<EntityClass>();
×
NEW
44
        var diagnostics = new List<Diagnostic>();
×
45

NEW
46
        foreach (var attribute in context.Attributes)
×
47
        {
NEW
48
            if (attribute == null)
×
NEW
49
                return null;
×
50

NEW
51
            if (attribute.ConstructorArguments.Length != 1)
×
NEW
52
                return null;
×
53

NEW
54
            var comparerArgument = attribute.ConstructorArguments[0];
×
NEW
55
            if (comparerArgument.Value is not INamedTypeSymbol targetSymbol)
×
NEW
56
                return null;
×
57

NEW
58
            var entityClass = CreateClass(context.TargetNode.GetLocation(), targetSymbol, diagnostics);
×
NEW
59
            if (entityClass != null)
×
NEW
60
                classes.Add(entityClass);
×
61
        }
62

NEW
63
        return new EntityContext(classes, diagnostics);
×
64
    }
65
}
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