< Summary

Information
Class: NexusLabs.Needlr.Generators.FactoryConsumerDiscoveryHelper
Assembly: NexusLabs.Needlr.Generators
File(s): /home/runner/work/needlr/needlr/src/NexusLabs.Needlr.Generators/FactoryConsumerDiscoveryHelper.cs
Line coverage
100%
Covered lines: 13
Uncovered lines: 0
Coverable lines: 13
Total lines: 37
Line coverage: 100%
Branch coverage
75%
Covered branches: 3
Total branches: 4
Branch coverage: 75%
Method coverage

Feature is only available for sponsors

Upgrade to PRO version

Metrics

MethodBranch coverage Crap Score Cyclomatic complexity Line coverage
BindFactoryConsumers(...)75%44100%

File(s)

/home/runner/work/needlr/needlr/src/NexusLabs.Needlr.Generators/FactoryConsumerDiscoveryHelper.cs

#LineLine coverage
 1using Microsoft.CodeAnalysis;
 2using Microsoft.CodeAnalysis.CSharp;
 3
 4using NexusLabs.Needlr.Generators.CodeGen;
 5using NexusLabs.Needlr.Generators.Models;
 6
 7namespace NexusLabs.Needlr.Generators;
 8
 9internal static class FactoryConsumerDiscoveryHelper
 10{
 11    internal static Compilation BindFactoryConsumers(
 12        Compilation compilation,
 13        IReadOnlyList<DiscoveredFactory> factories,
 14        string assemblyName,
 15        BreadcrumbWriter breadcrumbs,
 16        string? projectDirectory)
 17    {
 65318        var interfaceFactories = factories.Where(factory => factory.GenerateInterface).ToArray();
 60819        if (interfaceFactories.Length == 0)
 56520            return compilation;
 21
 22        // AddSource does not update the input compilation. Reuse the real emitter in
 23        // a private compilation so Roslyn binds factory names, aliases and namespaces
 24        // without relaxing discovery's rejection of unrelated error symbols.
 4325        var source = FactoryCodeGenerator.GenerateFactoryInterfacesSource(
 4326            interfaceFactories,
 4327            assemblyName,
 4328            breadcrumbs,
 4329            projectDirectory);
 4330        var parseOptions = compilation.SyntaxTrees.FirstOrDefault()?.Options as CSharpParseOptions;
 4331        var factoryTree = CSharpSyntaxTree.ParseText(
 4332            GeneratedSourceText.Create(source),
 4333            parseOptions);
 34
 4335        return compilation.AddSyntaxTrees(factoryTree);
 36    }
 37}