private static FieldElement ParseField(List <ProgramElement> programElements, string fileName, XElement field) { try { string name; int definitionLineNumber; int definitionColumnNumber; SrcMLParsingUtils.ParseNameAndLineNumber(field, out name, out definitionLineNumber, out definitionColumnNumber); ClassElement classElement = RetrieveClassElement(field, programElements); Guid classId = classElement != null ? classElement.Id : Guid.Empty; string className = classElement != null ? classElement.Name : String.Empty; //parse access level and type var typeElement = field.Element(SRC.Type); AccessLevel accessLevel = RetrieveAccessLevel(typeElement); IEnumerable <XElement> types = typeElement.Elements(SRC.Name); string fieldType = String.Empty; foreach (XElement type in types) { fieldType += type.Value + " "; } fieldType = fieldType.TrimEnd(); string initialValue = String.Empty; XElement initialValueElement = field.Element(SRC.Init); if (initialValueElement != null) { initialValue = initialValueElement.Element(SRC.Expression).Value; } string fullFilePath = System.IO.Path.GetFullPath(fileName); string snippet = RetrieveSource(field); return(new FieldElement(name, definitionLineNumber, definitionColumnNumber, fullFilePath, snippet, accessLevel, fieldType, classId, className, String.Empty, initialValue)); } catch (Exception error) { Type t = System.Reflection.MethodBase.GetCurrentMethod().DeclaringType; LogEvents.ParserGenericException(t, error); return(null); } }
public static void ParseComments(List <ProgramElement> programElements, XElement elements, string fileName) { IEnumerable <XElement> comments = from el in elements.Descendants(SRC.Comment) select el; List <List <XElement> > commentGroups = new List <List <XElement> >(); List <XElement> lastGroup = null; foreach (var aComment in comments) { if (lastGroup != null) { int line = Int32.Parse(lastGroup.Last().Attribute(POS.Line).Value); int linenext = Int32.Parse(aComment.Attribute(POS.Line).Value); if (line + 1 == linenext) { lastGroup.Add(aComment); } else { var xElements = new List <XElement>(); xElements.Add(aComment); commentGroups.Add(xElements); lastGroup = xElements; } } else { var xElements = new List <XElement>(); xElements.Add(aComment); commentGroups.Add(xElements); lastGroup = xElements; } } foreach (var oneGroup in commentGroups) { try { var comment = oneGroup.First(); var commentText = GetCommentText(oneGroup); int commentLine = Int32.Parse(comment.Attribute(POS.Line).Value); int definitionColumnNumber = Int32.Parse(comment.Attribute(POS.Column).Value); if (String.IsNullOrWhiteSpace(commentText)) { continue; } //comment name doesn't contain non-word characters and is compact-er than its body var commentName = ""; commentName = GetCommentSummary(GetCommentText(oneGroup, true)); if (string.IsNullOrWhiteSpace(commentName)) { continue; } //comments above method or class var lastComment = oneGroup.Last() as XElement; ProgramElement programElement = null; if (lastComment != null && lastComment.Attribute(POS.Line) != null) { var definitionLineNumber = Int32.Parse(lastComment.Attribute(POS.Line).Value); programElement = programElements.Find(element => element.DefinitionLineNumber == definitionLineNumber + 1); } if (programElement != null) { programElements.Add(new CommentElement(commentName, commentLine, definitionColumnNumber, programElement.FullFilePath, RetrieveSource(commentText), commentText)); continue; } //comments inside a method or class MethodElement methodEl = RetrieveMethodElement(comment, programElements); if (methodEl != null) { programElements.Add(new CommentElement(commentName, commentLine, definitionColumnNumber, methodEl.FullFilePath, RetrieveSource(commentText), commentText)); continue; } ClassElement classEl = RetrieveClassElement(comment, programElements); if (classEl != null) { programElements.Add(new CommentElement(commentName, commentLine, definitionColumnNumber, classEl.FullFilePath, RetrieveSource(commentText), commentText)); continue; } //comments is not associated with another element, so it's a plain CommentElement programElements.Add(new CommentElement(commentName, commentLine, definitionColumnNumber, fileName, RetrieveSource(commentText), commentText)); } catch (Exception error) { Type t = System.Reflection.MethodBase.GetCurrentMethod().DeclaringType; LogEvents.ParserGenericException(t, error); } } }