/* * SPDX-License-Identifier: AGPL-3.0-or-later * Copyright (C) 2025 Sergej Görzen * This file is part of xAPI4Unity. */ #if UNITY_EDITOR using System.Collections.Generic; namespace xAPI4Unity.Editor.Parser.Code.SyntaxTree { /// /// Root of the syntax tree /// internal class Root { // Holds the primary class node within the syntax tree. private Class _cls; // Holds the list of imported namespaces or classes. private readonly List _imports = new List(); /// /// Class in the syntax tree /// public ref readonly Class Class => ref _cls; /// /// Namespace in the syntax tree /// public string Namespace { get; private set; } /// /// Imports in the syntax tree /// public IReadOnlyList Imports => _imports.AsReadOnly(); /// /// Initializes an empty root node with no class or namespace. /// public Root() { } /// /// Initializes a root node with the specified class and optional namespace. /// /// The main class node associated with the root. /// Optional namespace for this root. public Root(Class cls, string @namespace = default) { this._cls = cls; this.Namespace = @namespace; } /// /// Sets the class node for this root. /// /// The class node to assign. /// The same Root instance for fluent chaining. public Root WithClass(Class cls) { this._cls = cls; return this; } /// /// Sets the namespace for this root. /// /// The namespace to assign. /// The same Root instance for fluent chaining. public Root WithNamespace(string @namespace) { this.Namespace = @namespace; return this; } /// /// Adds a single import to the root's list of imports. /// /// The import to add. /// The same Root instance for fluent chaining. public Root AddImport(Import import) { _imports.Add(import); return this; } /// /// Adds multiple imports to the root's list of imports. /// /// The imports to add. /// The same Root instance for fluent chaining. public Root AddImports(params Import[] imports) { this._imports.AddRange(imports); return this; } /// /// Adds a collection of imports to the root's list of imports. /// /// The collection of imports to add. /// The same Root instance for fluent chaining. public Root AddImports(IEnumerable imports) { this._imports.AddRange(imports); return this; } } } #endif