using System.Collections.Generic;
using System.Linq;
using System.Xml.Linq;
using Paraiba.Linq;

namespace CoverageFramework.Operator.Selector.C
{
	public class SwitchSelectorForC : IXElementRangeSelector
	{
		private static readonly string[] _switchNames = new[] {
			"selection_statement",
		};

		#region IXElementRangeSelector メンバ

		public IEnumerable<IEnumerable<XElement>> Select(XElement root)
		{
			return root
				// 全てのswitch文要素を列挙
				.Descendants()
				.Where(e_ => _switchNames.Contains(e_.Name.LocalName))
				.Where(e_ => {
					// if文の除去
					var e2_ = e_.Elements().FirstOrDefault();
					return e2_ != null && !e2_.HasElements && e2_.Value == "switch";
				})
				.Select(e_ => e_.ToEnumerable());
		}

		#endregion
	}
}