< Summary

Information
Class: NexusLabs.Needlr.Generators.RecordConstructorOverloadGenerator
Assembly: NexusLabs.Needlr.Generators
File(s): /home/runner/work/needlr/needlr/src/NexusLabs.Needlr.Generators/RecordConstructorOverloadGenerator.cs
Line coverage
100%
Covered lines: 50
Uncovered lines: 0
Coverable lines: 50
Total lines: 76
Line coverage: 100%
Branch coverage
50%
Covered branches: 1
Total branches: 2
Branch coverage: 50%
Method coverage

Feature is only available for sponsors

Upgrade to PRO version

Metrics

MethodBranch coverage Crap Score Cyclomatic complexity Line coverage
Initialize(...)50%22100%

File(s)

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

#LineLine coverage
 1using System.Text;
 2
 3using Microsoft.CodeAnalysis;
 4using Microsoft.CodeAnalysis.Text;
 5
 6using NexusLabs.Needlr.Generators.CodeGen;
 7using NexusLabs.Needlr.Generators.Models;
 8
 9namespace NexusLabs.Needlr.Generators;
 10
 11/// <summary>
 12/// Incremental source generator that emits one additional public forwarding
 13/// constructor for each eligible positional record.
 14/// </summary>
 15[Generator(LanguageNames.CSharp)]
 16public sealed class RecordConstructorOverloadGenerator : IIncrementalGenerator
 17{
 18    public void Initialize(IncrementalGeneratorInitializationContext context)
 19    {
 3820        var candidateModels = context.SyntaxProvider.CreateSyntaxProvider(
 3821                predicate: static (node, _) =>
 298022                    RecordConstructorOverloadDiscoveryHelper
 298023                        .IsCandidateRecordDeclaration(node),
 3824                transform: static (generatorContext, _) =>
 7425                    RecordConstructorOverloadDiscoveryHelper
 7426                        .TryCreateCanonicalModel(generatorContext))
 3827            .WithTrackingName(
 3828                RecordConstructorOverloadTrackingNames.Candidates);
 29
 3830        var models = candidateModels
 6231            .Where(static model => model is not null)
 5232            .Select(static (model, _) => model!.Value)
 3833            .WithTrackingName(RecordConstructorOverloadTrackingNames.Models);
 34
 3835        var assemblyName = context.CompilationProvider
 3836            .Select(static (compilation, _) =>
 5037                compilation.AssemblyName ?? "Generated")
 3838            .WithTrackingName(
 3839                RecordConstructorOverloadTrackingNames.AssemblyName);
 40
 3841        var breadcrumbLevel = context.AnalyzerConfigOptionsProvider
 3842            .Select(static (options, _) =>
 3843                TypeRegistryGenerator.GetBreadcrumbLevel(options))
 3844            .WithTrackingName(
 3845                RecordConstructorOverloadTrackingNames.BreadcrumbLevel);
 46
 3847        var emitContext = assemblyName
 3848            .Combine(breadcrumbLevel)
 3849            .Select(static (pair, _) =>
 3850                new RecordConstructorOverloadEmitContext(
 3851                    pair.Left,
 3852                    pair.Right))
 3853            .WithTrackingName(
 3854                RecordConstructorOverloadTrackingNames.EmitContext);
 55
 3856        var output = models
 3857            .Combine(emitContext)
 3858            .WithTrackingName(
 3859                RecordConstructorOverloadTrackingNames.Output);
 60
 3861        context.RegisterSourceOutput(output, static (sourceContext, source) =>
 3862        {
 5263            var (model, modelContext) = source;
 5264            var breadcrumbs =
 5265                new BreadcrumbWriter(modelContext.BreadcrumbLevel);
 5266            var generatedSource =
 5267                RecordConstructorOverloadCodeGenerator.GenerateSource(
 5268                    model,
 5269                    modelContext.AssemblyName,
 5270                    breadcrumbs);
 5271            sourceContext.AddSource(
 5272                RecordConstructorOverloadCodeGenerator.BuildHintName(model),
 5273                GeneratedSourceText.Create(generatedSource));
 9074        });
 3875    }
 76}