/* * 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 body in the syntax tree /// internal sealed class MethodBody { // Accumulates the ordered list of statements that compose this method body. private readonly List _statements = new List(); /// /// Statements in the method /// public IReadOnlyList Statements => _statements.AsReadOnly(); /// /// Initializes an empty method body. /// public MethodBody() { } /// /// Appends a single statement to this method body. /// /// The statement to add. /// The same MethodBody instance for fluent chaining. public MethodBody AddStatement(Statement statement) { _statements.Add(statement); return this; } /// /// Appends multiple statements to this method body. /// /// The statements to add. /// The same MethodBody instance for fluent chaining. public MethodBody AddStatements(params Statement[] statements) { _statements.AddRange(statements); return this; } /// /// Appends a sequence of statements to this method body. /// /// The statements to add. /// The same MethodBody instance for fluent chaining. public MethodBody AddStatements(IEnumerable statements) { _statements.AddRange(statements); return this; } } } #endif