< Summary

Information
Class: Hertzole.ScriptableValues.Generator.HierarchyInfo
Assembly: Hertzole.ScriptableValues.Generator
File(s): Generator/Hertzole.ScriptableValues.Generator/Data/HierarchyInfo.cs
Tag: 52_28197466029
Line coverage
90%
Covered lines: 20
Uncovered lines: 2
Coverable lines: 22
Total lines: 60
Line coverage: 90.9%
Branch coverage
75%
Covered branches: 6
Total branches: 8
Branch coverage: 75%
Method coverage

Feature is only available for sponsors

Upgrade to PRO version

Metrics

MethodBranch coverage Cyclomatic complexity NPath complexity Sequence coverage
FromSymbol(...)100%22100%
HasParentWithCallbacks(...)66.66%6677.77%

File(s)

Generator/Hertzole.ScriptableValues.Generator/Data/HierarchyInfo.cs

#LineLine coverage
 1using Microsoft.CodeAnalysis;
 2
 3namespace Hertzole.ScriptableValues.Generator;
 4
 6005internal readonly record struct HierarchyInfo(string FilenameHint, string TypeName, string? Namespace, ISymbol Symbol, b
 6{
 7    public bool IsSealed
 8    {
 489        get { return Symbol.IsSealed; }
 10    }
 11
 12    public bool IsStruct
 13    {
 4814        get { return ((ITypeSymbol) Symbol).IsValueType; }
 15    }
 16
 2517    public int ParentCount { get; private init; }
 18
 19    public static HierarchyInfo FromSymbol(INamedTypeSymbol symbol)
 20    {
 2521        string? nspace = null;
 22
 2523        if (!symbol.ContainingNamespace.IsGlobalNamespace)
 24        {
 1225            nspace = symbol.ContainingNamespace.ToDisplayString();
 26        }
 27
 2528        bool shouldInherit = HasParentWithCallbacks(symbol, out int parentCount);
 29
 2530        return new HierarchyInfo(symbol.GetFullyQualifiedMetadataName(), symbol.ToDisplayString(SymbolDisplayFormat.Mini
 2531            nspace, symbol, shouldInherit)
 2532        {
 2533            ParentCount = parentCount
 2534        };
 35    }
 36
 37    private static bool HasParentWithCallbacks(INamedTypeSymbol symbol, out int parentCount)
 38    {
 2539        parentCount = 0;
 40
 2541        if (symbol.BaseType == null)
 42        {
 043            return false;
 44        }
 45
 2546        INamedTypeSymbol? current = symbol.BaseType;
 47
 6248        while (current != null)
 49        {
 3750            if (current.HasAttribute(Types.GLOBAL_MARKER_ATTRIBUTE))
 51            {
 052                parentCount++;
 53            }
 54
 3755            current = current.BaseType;
 56        }
 57
 2558        return parentCount > 0;
 59    }
 60}