| | | 1 | | using Microsoft.CodeAnalysis; |
| | | 2 | | |
| | | 3 | | namespace Hertzole.ScriptableValues.Generator; |
| | | 4 | | |
| | 600 | 5 | | internal readonly record struct HierarchyInfo(string FilenameHint, string TypeName, string? Namespace, ISymbol Symbol, b |
| | | 6 | | { |
| | | 7 | | public bool IsSealed |
| | | 8 | | { |
| | 48 | 9 | | get { return Symbol.IsSealed; } |
| | | 10 | | } |
| | | 11 | | |
| | | 12 | | public bool IsStruct |
| | | 13 | | { |
| | 48 | 14 | | get { return ((ITypeSymbol) Symbol).IsValueType; } |
| | | 15 | | } |
| | | 16 | | |
| | 25 | 17 | | public int ParentCount { get; private init; } |
| | | 18 | | |
| | | 19 | | public static HierarchyInfo FromSymbol(INamedTypeSymbol symbol) |
| | | 20 | | { |
| | 25 | 21 | | string? nspace = null; |
| | | 22 | | |
| | 25 | 23 | | if (!symbol.ContainingNamespace.IsGlobalNamespace) |
| | | 24 | | { |
| | 12 | 25 | | nspace = symbol.ContainingNamespace.ToDisplayString(); |
| | | 26 | | } |
| | | 27 | | |
| | 25 | 28 | | bool shouldInherit = HasParentWithCallbacks(symbol, out int parentCount); |
| | | 29 | | |
| | 25 | 30 | | return new HierarchyInfo(symbol.GetFullyQualifiedMetadataName(), symbol.ToDisplayString(SymbolDisplayFormat.Mini |
| | 25 | 31 | | nspace, symbol, shouldInherit) |
| | 25 | 32 | | { |
| | 25 | 33 | | ParentCount = parentCount |
| | 25 | 34 | | }; |
| | | 35 | | } |
| | | 36 | | |
| | | 37 | | private static bool HasParentWithCallbacks(INamedTypeSymbol symbol, out int parentCount) |
| | | 38 | | { |
| | 25 | 39 | | parentCount = 0; |
| | | 40 | | |
| | 25 | 41 | | if (symbol.BaseType == null) |
| | | 42 | | { |
| | 0 | 43 | | return false; |
| | | 44 | | } |
| | | 45 | | |
| | 25 | 46 | | INamedTypeSymbol? current = symbol.BaseType; |
| | | 47 | | |
| | 62 | 48 | | while (current != null) |
| | | 49 | | { |
| | 37 | 50 | | if (current.HasAttribute(Types.GLOBAL_MARKER_ATTRIBUTE)) |
| | | 51 | | { |
| | 0 | 52 | | parentCount++; |
| | | 53 | | } |
| | | 54 | | |
| | 37 | 55 | | current = current.BaseType; |
| | | 56 | | } |
| | | 57 | | |
| | 25 | 58 | | return parentCount > 0; |
| | | 59 | | } |
| | | 60 | | } |