Example #1
0
        /// <summary>
        /// Initializes a new instance of the <see cref="CodeComment" /> class.
        /// </summary>
        public CodeComment(TextPoint point, FormatterOptions options)
        {
            if (point == null)
            {
                throw new ArgumentNullException(nameof(point));
            }

            _document         = point.Parent;
            _commentLineRegex = CodeCommentHelper.GetCommentRegex(_document.GetCodeLanguage());
            _formatterOptions = options;

            Expand(point);
        }
Example #2
0
        public CommentFormatter(ICommentLine line, FormatterOptions formatterOptions, CommentOptions commentOptions)
        {
            _formatterOptions = formatterOptions;
            _commentOptions   = commentOptions;

            _builder             = new StringBuilder();
            _currentPosition     = 0;
            _isFirstWord         = true;
            _isIndented          = false;
            _commentPrefixLength = WordLength(commentOptions.Prefix);

            // Special handling for the root XML line, it should not output it's surrounding xml
            // tags, only it's child lines.
            var xml = line as CommentLineXml;

            if (xml != null)
            {
                // On the content of the root, fix the optional alignment of param tags. This is not
                // important if all tags will be broken onto seperate lines anyway.
                if (!Settings.Default.Formatting_CommentXmlSplitAllTags && Settings.Default.Formatting_CommentXmlAlignParamTags)
                {
                    var paramPhrases = xml.Lines.OfType <CommentLineXml>().Where(p => string.Equals(p.TagName, "param", StringComparison.OrdinalIgnoreCase));
                    if (paramPhrases.Count() > 1)
                    {
                        var longestParam = paramPhrases.Max(p => p.OpenTag.Length);
                        foreach (var phrase in paramPhrases)
                        {
                            phrase.OpenTag = phrase.OpenTag.PadRight(longestParam);
                        }
                    }
                }

                // Process all the lines inside the root XML line.
                foreach (var l in xml.Lines)
                {
                    NewLine();
                    Parse(l);
                }
            }
            else
            {
                // Normal comment line has no child-lines and can be processed normally.
                NewLine();
                Parse(line);
            }
        }
Example #3
0
        public CodeCommentMatch(Match match, FormatterOptions formatterOptions)
        {
            if (!match.Success)
            {
                System.Diagnostics.Debug.Fail("Cannot parse a line that does not match the comment regex.");
                return;
            }

            if (formatterOptions.IgnoreTokens.Any(p => match.Value.StartsWith(p)))
            {
                Words = new List <string> {
                    match.Groups["line"].Value
                };
                IsLiteral = true;
                IsEmpty   = false;
                IsList    = false;
            }
            else
            {
                Indent     = match.Groups["indent"].Success ? match.Groups["indent"].Value.Length : 0;
                ListPrefix = match.Groups["listprefix"].Success ? match.Groups["listprefix"].Value : null;
                Words      = match.Groups["words"].Success ? match.Groups["words"].Captures.OfType <Capture>().Select(c => c.Value).ToList() : null;

                IsLiteral = false;
                IsEmpty   = string.IsNullOrWhiteSpace(match.Value) || Words == null || Words.Count < 1;
                IsList    = !string.IsNullOrWhiteSpace(ListPrefix);
            }

            // In the case of a list prefix but no content (e.g. hyphen line) convert to regular content.
            if (IsEmpty && IsList)
            {
                Words      = new List <string>(new[] { ListPrefix });
                ListPrefix = null;
                IsEmpty    = false;
                IsList     = false;
            }
        }