using System.Collections.Generic;
using MarketAlly.IronJava.Core.AST.Visitors;
namespace MarketAlly.IronJava.Core.AST
{
///
/// Base class for all Java AST nodes.
///
public abstract class JavaNode
{
///
/// The location of this node in the source code.
///
public SourceRange Location { get; }
///
/// Parent node in the AST.
///
public JavaNode? Parent { get; internal set; }
///
/// Child nodes in the AST.
///
public IReadOnlyList Children => _children;
private readonly List _children = new();
protected JavaNode(SourceRange location)
{
Location = location;
}
///
/// Accept a visitor to traverse this node.
///
public abstract T Accept(IJavaVisitor visitor);
///
/// Accept a visitor to traverse this node without returning a value.
///
public abstract void Accept(IJavaVisitor visitor);
///
/// Add a child node.
///
protected internal void AddChild(JavaNode child)
{
_children.Add(child);
child.Parent = this;
}
///
/// Add multiple child nodes.
///
protected internal void AddChildren(IEnumerable children)
{
foreach (var child in children)
{
AddChild(child);
}
}
}
}