//
//
//
//
// $Revision$
//
using System;
using System.Collections.Generic;
namespace ICSharpCode.NRefactory.Ast
{
public interface INode
{
INode Parent {
get;
set;
}
IList Children {
get;
}
Location StartLocation {
get;
set;
}
Location EndLocation {
get;
set;
}
object UserData {
get;
set;
}
///
/// Visits all children
///
/// The visitor to accept
/// Additional data for the visitor
/// The paremeter
object AcceptChildren(IAstVisitor visitor, object data);
///
/// Accept the visitor
///
/// The visitor to accept
/// Additional data for the visitor
/// The value the visitor returns after the visit
object AcceptVisitor(IAstVisitor visitor, object data);
}
public static class INodeExtensionMethods
{
public static void Remove(this INode node)
{
node.Parent.Children.Remove(node);
}
public static INode Previous(this INode node)
{
if (node.Parent == null) return null;
int myIndex = node.Parent.Children.IndexOf(node);
int index = myIndex - 1;
if (0 <= index && index < node.Parent.Children.Count) {
return node.Parent.Children[index];
} else {
return null;
}
}
public static INode Next(this INode node)
{
if (node.Parent == null) return null;
int myIndex = node.Parent.Children.IndexOf(node);
int index = myIndex + 1;
if (0 <= index && index < node.Parent.Children.Count) {
return node.Parent.Children[index];
} else {
return null;
}
}
public static void ReplaceWith(this INode node, INode newNode)
{
int myIndex = node.Parent.Children.IndexOf(node);
node.Parent.Children[myIndex] = newNode;
}
}
}