private static EntityPositionInfo getEntityPosition( XPathNavigator current_node) { EntityPositionInfo result = new EntityPositionInfo(); //Search for position. XPathNavigator search_node = current_node; while (search_node != null) { string line = search_node.GetAttribute("line", XML_POS_NS); string column = search_node.GetAttribute("column", XML_POS_NS); if (line != String.Empty && result.line_start == 0) { result.line_start = Convert.ToInt32(line); } if (column != String.Empty && result.col_start == 0) { result.col_start = Convert.ToInt32(column); } if (result.line_start != 0 && result.col_start != 0) { break; } XPathNodeIterator iter = search_node.SelectChildren( XPathNodeType.Element); if (iter.MoveNext()) { search_node = iter.Current; } else { search_node = null; } } if (result.line_start == 0 || result.col_start == 0) { throw new Exception("Line/column of a source code entity " + "could not be found."); } string[] lines = Regex.Split(current_node.Value, "\r\n|\r|\n"); result.line_end = result.line_start + (lines.Length - 1); result.col_end = lines.Length > 1 ? lines[lines.Length - 1].Length : result.col_start + lines[0].Length; return(result); }
private static void collectEntitiesByType(SourceCodeEntitiesFile scef, XPathNavigator navigator, string srcml_name, SourceCodeEntityType type, string name_xpath, Dictionary <string, string> parent_names) { XPathNodeIterator iterator = (XPathNodeIterator)navigator.Evaluate( "//*[local-name() = '" + srcml_name + "']"); while (iterator.MoveNext()) { XPathNavigator element = iterator.Current; EntityPositionInfo position = getEntityPosition(element); string name = ""; XPathNodeIterator search_name = (XPathNodeIterator) element.Evaluate(name_xpath); if (search_name.MoveNext()) { name = search_name.Current.Value; } Stack <string> fully_qualified_name = new Stack <string>(); while (element.MoveToParent()) { if (parent_names.ContainsKey(element.Name)) { search_name = (XPathNodeIterator)element.Evaluate(parent_names[element.Name]); if (search_name.MoveNext()) { fully_qualified_name.Push(search_name.Current.Value); } } } SourceCodeEntity sce = new SourceCodeEntity(); sce.LineStart = position.line_start; sce.LineEnd = position.line_end; sce.ColumnStart = position.col_start; sce.ColumnEnd = position.col_end; sce.Type = type; sce.Name = name; while (fully_qualified_name.Count > 0) { sce.FullyQualifiedName.Add(fully_qualified_name.Pop()); } sce.parent_file = scef; scef.Add(sce); } }