<commit_before>﻿using System.Collections.Generic;
using System.Linq;
using System.Xml.Linq;
using Typewriter.CodeModel.Collections;

namespace Typewriter.CodeModel.Implementation
{
    public class DocCommentImpl : DocComment
    {
        private readonly XElement _root;

        private DocCommentImpl(XElement root, Item parent)
        {
            _root = root;
            Parent = parent;
        }

        public override Item Parent { get; }

        private string _summary;
        public override string Summary => _summary ?? (_summary = FormatValue(_root.Element("summary") == null ? string.Empty : string.Concat(_root.Element("summary").Nodes())));

        private string _returns;
        public override string Returns => _returns ?? (_returns = FormatValue(_root.Element("returns") == null ? string.Empty : string.Concat(_root.Element("returns").Nodes())));

        private ParameterCommentCollection _parameters;
        public override ParameterCommentCollection Parameters => _parameters ?? (_parameters = ParameterCommentImpl.FromXElements(_root.Elements("param"), this));

        public override string ToString()
        {
            return Summary;
        }

        public static string FormatValue(string value)
        {
            if (string.IsNullOrEmpty(value)) return value;

            var lines = value.Split('\r', '\n');
            return string.Join(" ", lines.Select(l => l.Trim())).Trim();
        }

        public static DocComment FromXml(string xml, Item parent)
        {
            if (string.IsNullOrEmpty(xml)) return null;

            var root = XDocument.Parse(xml).Root;
            return root != null ? new DocCommentImpl(root, parent) : null;
        }
    }
    <commit_msg>fixed bug where badly formatted DocComments caused generation to fail<commit_after>﻿using System.Collections.Generic;
using System.Linq;
using System.Xml.Linq;
using Typewriter.CodeModel.Collections;

namespace Typewriter.CodeModel.Implementation
{
    public class DocCommentImpl : DocComment
    {
        private readonly XElement _root;

        private DocCommentImpl(XElement root, Item parent)
        {
            _root = root;
            Parent = parent;
        }

        public override Item Parent { get; }

        private string _summary;
        public override string Summary => _summary ?? (_summary = FormatValue(_root.Element("summary") == null ? string.Empty : string.Concat(_root.Element("summary").Nodes())));

        private string _returns;
        public override string Returns => _returns ?? (_returns = FormatValue(_root.Element("returns") == null ? string.Empty : string.Concat(_root.Element("returns").Nodes())));

        private ParameterCommentCollection _parameters;
        public override ParameterCommentCollection Parameters => _parameters ?? (_parameters = ParameterCommentImpl.FromXElements(_root.Elements("param"), this));

        public override string ToString()
        {
            return Summary;
        }

        public static string FormatValue(string value)
        {
            if (string.IsNullOrEmpty(value)) return value;

            var lines = value.Split('\r', '\n');
            return string.Join(" ", lines.Select(l => l.Trim())).Trim();
        }

        public static DocComment FromXml(string xml, Item parent)
        {
            try
            {
                if (string.IsNullOrEmpty(xml)) return null;

                var root = XDocument.Parse(xml).Root;
                return root != null ? new DocCommentImpl(root, parent) : null;
            }
            catch
            {
                return null;
            }
        }
    }
    
{'fraction_non_alphanumeric': 0.1028088355604036, 'fraction_numerical': 0.0, 'mean_word_length': 2.4152700186219738, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 11, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 6}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '7482899', 'n_tokens_mistral': 900, 'n_tokens_neox': 879, 'n_words': 239}