public void TestGetXElement() { var archive = new SrcMLArchive("SrcMLLocationTest", false, new SrcMLGenerator("SrcML")); var sourcePath = Path.GetFullPath(@"..\..\TestInputs\class_test.h"); archive.AddOrUpdateFile(sourcePath); var unit = archive.GetXElementForSourceFile(sourcePath); Assert.IsNotNull(unit); var classElement = unit.Descendants(SRC.Class).FirstOrDefault(); Assert.IsNotNull(classElement); var parser = new CPlusPlusCodeParser(); var globalScope = parser.ParseFileUnit(unit); var typeDefinition = globalScope.ChildStatements.OfType <TypeDefinition>().FirstOrDefault(); Assert.IsNotNull(typeDefinition); var element = typeDefinition.PrimaryLocation.GetXElement(archive); Assert.IsNotNull(element); Assert.AreEqual(classElement.GetSrcLineNumber(), element.GetSrcLineNumber()); Assert.AreEqual(classElement.GetSrcLinePosition(), element.GetSrcLinePosition()); Assert.AreEqual(classElement.GetXPath(), element.GetXPath()); }
public static XElement GetElement(SrcMLArchive archive, SrcMLLocation location) { string fileName = location.SourceFileName; string query = location.XPath; var unit = archive.GetXElementForSourceFile(fileName); var element = unit.XPathSelectElement(query, SrcMLNamespaces.Manager); return(element); }
public static XElement GetElement(SrcMLArchive archive, SrcMLLocation location) { string fileName = location.SourceFileName; string query = location.XPath; var unit = archive.GetXElementForSourceFile(fileName); var startingLength = fileName.Length + 23; var path = query.Substring(startingLength); var element = unit.XPathSelectElement(path, SrcMLNamespaces.Manager); return element; }
public static XElement GetElement(SrcMLArchive archive, SrcMLLocation location) { string fileName = location.SourceFileName; string query = location.XPath; var unit = archive.GetXElementForSourceFile(fileName); var startingLength = fileName.Length + 23; var path = query.Substring(startingLength); var element = unit.XPathSelectElement(path, SrcMLNamespaces.Manager); return(element); }
/// <summary> /// Gets the XElement referred to by <see cref="XPath"/>. /// </summary> /// <param name="archive">The archive for this location</param> /// <returns>The XElement referred to by <see cref="XPath"/></returns> public XElement GetXElement(SrcMLArchive archive) { if (null == archive) { throw new ArgumentNullException("archive"); } var unit = archive.GetXElementForSourceFile(this.SourceFileName); if (unit != null) { return(unit.XPathSelectElement(this.XPath, SrcMLNamespaces.Manager)); } return(null); }
public void TestGetXElement() { var archive = new SrcMLArchive("SrcMLLocationTest", false, new SrcMLGenerator("SrcML")); var sourcePath = Path.GetFullPath(@"..\..\TestInputs\class_test.h"); archive.AddOrUpdateFile(sourcePath); var unit = archive.GetXElementForSourceFile(sourcePath); Assert.IsNotNull(unit); var classElement = unit.Descendants(SRC.Class).FirstOrDefault(); Assert.IsNotNull(classElement); var parser = new CPlusPlusCodeParser(); var globalScope = parser.ParseFileUnit(unit); var typeDefinition = globalScope.ChildStatements.OfType<TypeDefinition>().FirstOrDefault(); Assert.IsNotNull(typeDefinition); var element = typeDefinition.PrimaryLocation.GetXElement(archive); Assert.IsNotNull(element); Assert.AreEqual(classElement.GetSrcLineNumber(), element.GetSrcLineNumber()); Assert.AreEqual(classElement.GetSrcLinePosition(), element.GetSrcLinePosition()); Assert.AreEqual(classElement.GetXPath(), element.GetXPath()); }
/// <summary> /// Gets the XElement referred to by <see cref="XPath"/>. /// </summary> /// <param name="archive">The archive for this location</param> /// <returns>The XElement referred to by <see cref="XPath"/></returns> public XElement GetXElement(SrcMLArchive archive) { if(null == archive) throw new ArgumentNullException("archive"); var unit = archive.GetXElementForSourceFile(this.SourceFileName); if(unit != null) { return unit.XPathSelectElement(this.XPath, SrcMLNamespaces.Manager); } return null; }
public System.Xml.Linq.XElement GetXElementForSourceFile(string sourceFilePath) { return(_srcMLArchive.GetXElementForSourceFile(sourceFilePath)); }