< Summary

Information
Class: NexusLabs.Needlr.Generators.PluginOrderHelper
Assembly: NexusLabs.Needlr.Generators
File(s): /home/runner/work/needlr/needlr/src/NexusLabs.Needlr.Generators/PluginOrderHelper.cs
Line coverage
70%
Covered lines: 7
Uncovered lines: 3
Coverable lines: 10
Total lines: 42
Line coverage: 70%
Branch coverage
66%
Covered branches: 8
Total branches: 12
Branch coverage: 66.6%
Method coverage

Feature is only available for sponsors

Upgrade to PRO version

Metrics

MethodBranch coverage Crap Score Cyclomatic complexity Line coverage
GetPluginOrder(...)66.66%161270%

File(s)

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

#LineLine coverage
 1using Microsoft.CodeAnalysis;
 2
 3namespace NexusLabs.Needlr.Generators;
 4
 5/// <summary>
 6/// Helper for discovering plugin order attributes from Roslyn symbols.
 7/// </summary>
 8internal static class PluginOrderHelper
 9{
 10    private const string PluginOrderAttributeName = "PluginOrderAttribute";
 11    private const string PluginOrderAttributeFullName = "NexusLabs.Needlr.PluginOrderAttribute";
 12
 13    /// <summary>
 14    /// Gets the execution order for a plugin type from the [PluginOrder] attribute.
 15    /// </summary>
 16    /// <param name="typeSymbol">The type symbol to check.</param>
 17    /// <returns>The order value from [PluginOrder], or 0 if not specified.</returns>
 18    public static int GetPluginOrder(INamedTypeSymbol typeSymbol)
 19    {
 287020        foreach (var attribute in typeSymbol.GetAttributes())
 21        {
 5622            var attributeClass = attribute.AttributeClass;
 5623            if (attributeClass == null)
 24                continue;
 25
 5626            var name = attributeClass.Name;
 5627            var fullName = attributeClass.ToDisplayString();
 28
 5629            if (name == PluginOrderAttributeName || fullName == PluginOrderAttributeFullName)
 30            {
 31                // The attribute has a single constructor parameter: int order
 032                if (attribute.ConstructorArguments.Length > 0 &&
 033                    attribute.ConstructorArguments[0].Value is int order)
 34                {
 035                    return order;
 36                }
 37            }
 38        }
 39
 137940        return 0; // Default order
 41    }
 42}