/* * 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 { /// /// Represents a typed node in the syntax tree that extends the base SyntaxNode functionality. /// /// The derived type of the syntax node, enabling fluent API chaining. internal abstract class TypedNode : SyntaxNode where T : SyntaxNode { // Holds the list of arguments used to initialize this node. public readonly List Arguments = new List(); // Holds the list of parameters associated with this node. public readonly List Parameters = new List(); /// /// Type of the property or node /// public string Type { get; private set; } /// /// Initializes an empty TypedNode with no name, type, or comment. /// public TypedNode() {} /// /// Initializes a TypedNode with a specified name, type, and optional comment. /// /// The name of the node. /// The type of the node (e.g., return type, property type). /// Optional comment/description for the node. public TypedNode(string name, string type, string comment = null) : base(name, comment) { Type = type; } /// /// Sets the type for this node. /// /// The type to assign. /// The same TypedNode instance for fluent chaining. public T WithType(string type) { Type = type; return (T)(object)this; } /// /// Adds a single initialization argument to the node. /// /// The argument to add. /// The same TypedNode instance for fluent chaining. public T AddArgument(Argument arg) { Arguments.Add(arg); return (T)(object)this; } /// /// Adds a single parameter to the node. /// /// The parameter to add. /// The same TypedNode instance for fluent chaining. public T AddParameter(Parameter param) { Parameters.Add(param); return (T)(object)this; } /// /// Adds multiple parameters to the node. /// /// The parameters to add. /// The same TypedNode instance for fluent chaining. public T AddParameters(params Parameter[] @params) { Parameters.AddRange(@params); return (T)(object)this; } /// /// Adds a collection of parameters to the node. /// /// The collection of parameters to add. /// The same TypedNode instance for fluent chaining. public T AddParameters(IEnumerable @params) { Parameters.AddRange(@params); return (T)(object)this; } /// /// Adds multiple initialization arguments to the node. /// /// The arguments to add. /// The same TypedNode instance for fluent chaining. public T AddArguments(params Argument[] args) { Arguments.AddRange(args); return (T)(object)this; } /// /// Adds a collection of initialization arguments to the node. /// /// The collection of arguments to add. /// The same TypedNode instance for fluent chaining. public T AddArguments(IEnumerable args) { Arguments.AddRange(args); return (T)(object)this; } } } #endif