using System.Linq;
using System.Xml.Linq;
using CoverageFramework.Operator.Generator;
using Paraiba.Linq;

namespace CoverageFramework.Embedder
{
	public class ImportEmbedderForJava
	{
		public void Embed(XElement element, IXElementGenerator importGen)
		{
			var elem = element.Descendants()
				.Where(e => e.Value == "package");
			if (elem.IsEmpty())
			{
				element.AddFirst(importGen.Generate());
			}
			else
			{
				var elem2 = elem.First().Parent.Descendants()
					.Where(e => e.Value == ";");
				elem2.First().AddAfterSelf(importGen.Generate());
			}
		}
	}
}
