/* * 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 { /// /// A class in the syntax tree /// internal sealed class Class : SyntaxNode { // Accumulates field/property declarations to be emitted for this class. private readonly List _properties = new List(); // Accumulates constructor declarations for this class. private readonly List _constructors = new List(); // Accumulates get-only properties (with custom getters). private readonly List _getableProperties = new List(); // Accumulates method declarations for this class. private readonly List _methods = new List(); /// /// Base class of the class /// public string BaseClass { get; private set; } /// /// Properties of the class /// public IReadOnlyList Properties => _properties.AsReadOnly(); /// /// Constructors of the class /// public IReadOnlyList Constructors => _constructors.AsReadOnly(); /// /// Properties of the class that have a getter /// public IReadOnlyList GetableProperties => _getableProperties.AsReadOnly(); /// /// Methods of the class /// public IReadOnlyList Methods => _methods.AsReadOnly(); public readonly Dictionary CachedRegexFields = new Dictionary(); /// /// Initializes a class node with no name/comment. /// public Class() { } /// /// Initializes a class node with a name, optional base class and comment. /// /// Class name. /// Optional base class name. /// Optional XML summary comment. public Class(string name, string baseClass = null, string comment = null) : base(name, comment) { BaseClass = baseClass; } /// /// Sets the base class for this class node. /// /// Base class name. /// The same Class instance for fluent chaining. public Class WithBaseClass(string baseClass) { BaseClass = baseClass; return this; } /// /// Adds a property to the class. /// /// Property to add. /// The same Class instance for fluent chaining. public Class AddProperty(Property property) { _properties.Add(property); return this; } /// /// Adds multiple properties to the class. /// /// Properties to add. /// The same Class instance for fluent chaining. public Class AddProperties(params Property[] properties) { this._properties.AddRange(properties); return this; } /// /// Adds a sequence of properties to the class. /// /// Properties to add. /// The same Class instance for fluent chaining. public Class AddProperties(IEnumerable properties) { this._properties.AddRange(properties); return this; } /// /// Adds a constructor to the class. /// /// Constructor to add. /// The same Class instance for fluent chaining. public Class AddConstructor(Constructor constructor) { _constructors.Add(constructor); return this; } /// /// Adds multiple constructors to the class. /// /// Constructors to add. /// The same Class instance for fluent chaining. public Class AddConstructors(params Constructor[] constructors) { this._constructors.AddRange(constructors); return this; } /// /// Adds a sequence of constructors to the class. /// /// Constructors to add. /// The same Class instance for fluent chaining. public Class AddConstructors(IEnumerable constructors) { this._constructors.AddRange(constructors); return this; } /// /// Adds a get-only property to the class. /// /// Getable property to add. /// The same Class instance for fluent chaining. public Class AddGetableProperty(GetableProperty getableProperty) { _getableProperties.Add(getableProperty); return this; } /// /// Adds multiple get-only properties to the class. /// /// Getable properties to add. /// The same Class instance for fluent chaining. public Class AddGetableProperties(params GetableProperty[] getableProperties) { this._getableProperties.AddRange(getableProperties); return this; } /// /// Adds a sequence of get-only properties to the class. /// /// Getable properties to add. /// The same Class instance for fluent chaining. public Class AddGetableProperties(IEnumerable getableProperties) { this._getableProperties.AddRange(getableProperties); return this; } /// /// Adds a method to the class. /// /// Method to add. /// The same Class instance for fluent chaining. public Class AddMethod(Method method) { _methods.Add(method); return this; } /// /// Adds multiple methods to the class. /// /// Methods to add. /// The same Class instance for fluent chaining. public Class AddMethods(params Method[] methods) { this._methods.AddRange(methods); return this; } /// /// Adds a sequence of methods to the class. /// /// Methods to add. /// The same Class instance for fluent chaining. public Class AddMethods(IEnumerable methods) { this._methods.AddRange(methods); return this; } } } #endif