/* * 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 method in the syntax tree /// internal sealed class Method : TypedNode { // Holds the serialized body for this method (its statements). private MethodBody _body; // Arguments to be forwarded to a base method invocation, when applicable. private readonly List _baseArguments = new List(); /// /// Body of the method /// public ref readonly MethodBody Body => ref _body; /// /// Arguments for the method's base method /// public IReadOnlyList BaseArguments => _baseArguments.AsReadOnly(); /// /// Initializes an empty method node. /// public Method() { } /// /// Initializes a method node with name, return type, optional body, and XML summary comment. /// /// Method name. /// Return type (nullable). /// Optional method body. /// Optional XML summary comment. public Method(string name, string type = null, MethodBody body = null, string comment = null) : base(name, type, comment) { _body = body; } /// /// Sets the method body. /// /// The MethodBody to assign. /// The same Method instance for fluent chaining. public Method WithBody(MethodBody b) { _body = b; return this; } /// /// Adds a single base-method argument. /// /// Argument to forward to the base method. /// The same Method instance for fluent chaining. public Method AddBaseArgument(Argument arg) { _baseArguments.Add(arg); return this; } /// /// Adds multiple base-method arguments. /// /// Arguments to forward to the base method. /// The same Method instance for fluent chaining. public Method AddBaseArguments(params Argument[] args) { _baseArguments.AddRange(args); return this; } /// /// Adds a sequence of base-method arguments. /// /// Arguments to forward to the base method. /// The same Method instance for fluent chaining. public Method AddBaseArguments(IEnumerable args) { _baseArguments.AddRange(args); return this; } } } #endif