Exemplo n.º 1
0
        /// <summary>
        /// Loads the settings.
        /// </summary>
        public override void LoadSettings()
        {
            _options = new CodeCommentOptions(Settings.Default, 4);

            RaisePropertyChangedForAllOptionsProperties();
            UpdatePreviewText();
        }
Exemplo n.º 2
0
        /// <summary>
        /// Creates the XML open tag string for an XElement.
        /// </summary>
        /// <param name="element">The element.</param>
        /// <param name="options">The comment options used to contruct the tag.</param>
        /// <returns>The XML open tag. In case of an element without value, the tag is self-closing.</returns>
        internal static string CreateXmlOpenTag(System.Xml.Linq.XElement element, CodeCommentOptions options)
        {
            var builder = new System.Text.StringBuilder();

            builder.Append("<");
            var name = element.Name.LocalName;

            builder.Append(options.XmlTagsToLowerCase ? name.ToLowerInvariant() : name);

            if (element.HasAttributes)
            {
                foreach (var attr in element.Attributes())
                {
                    builder.Append(CodeCommentHelper.Spacer);
                    builder.Append(attr.ToString());
                }
            }

            if (element.IsEmpty)
            {
                if (options.XmlSpaceSingleTags)
                {
                    builder.Append(CodeCommentHelper.Spacer);
                }

                builder.Append("/");
            }

            builder.Append(">");

            var result = builder.ToString();

            return(options.XmlKeepTagsTogether ? SpaceToFake(result) : result);
        }
Exemplo n.º 3
0
        /// <summary>
        /// Reformat all comments between the specified start and end point. Comments that start
        /// within the range, even if they overlap the end are included.
        /// </summary>
        /// <param name="textDocument">The text document.</param>
        /// <param name="start">The start point.</param>
        /// <param name="end">The end point.</param>
        public bool FormatComments(TextDocument textDocument, EditPoint start, EditPoint end)
        {
            var options = new CodeCommentOptions(Settings.Default, _package, textDocument);

            bool foundComments = false;

            while (start.Line <= end.Line)
            {
                if (CodeCommentHelper.IsCommentLine(start))
                {
                    var comment = new CodeComment(start);
                    if (comment.IsValid)
                    {
                        comment.Format(options);
                        foundComments = true;
                    }

                    if (comment.EndPoint != null)
                    {
                        start = comment.EndPoint.CreateEditPoint();
                    }
                }

                if (start.Line == textDocument.EndPoint.Line)
                {
                    break;
                }

                start.LineDown();
                start.StartOfLine();
            }

            return(foundComments);
        }
Exemplo n.º 4
0
        public static string Format(string text, CodeCommentOptions options)
        {
            var xml       = XElement.Parse(string.Format("<doc>{0}</doc>", text));
            var line      = new CommentLineXml(xml, options);
            var regex     = CodeCommentHelper.GetCommentRegex("CSharp", false);
            var formatter = new CommentFormatter(line, string.Empty, options, regex);

            return(formatter.ToString());
        }
Exemplo n.º 5
0
        /// <summary>
        /// Creates the XML close tag string for an XElement.
        /// </summary>
        /// <param name="element">The element.</param>
        /// <param name="options">The comment options used to contruct the tag.</param>
        /// <returns>
        /// The XML close tag, or <c>null</c> if the element has no value and is a self-closing tag.
        /// </returns>
        internal static string CreateXmlCloseTag(System.Xml.Linq.XElement element, CodeCommentOptions options)
        {
            if (element.IsEmpty)
            {
                return(null);
            }

            var name = element.Name.LocalName;

            var result = string.Format("</{0}>", options.XmlTagsToLowerCase ? name.ToLowerInvariant() : name);

            return(options.XmlKeepTagsTogether ? SpaceToFake(result) : result);
        }
Exemplo n.º 6
0
 public static string Format(IEnumerable <string> text, CodeCommentOptions options)
 {
     return(Format(string.Join(Environment.NewLine, text), options));
 }
Exemplo n.º 7
0
        public static void AssertEqualAfterFormat(string input, string expected, CodeCommentOptions options)
        {
            var result = Format(input, options);

            Assert.AreEqual(expected, result);
        }
Exemplo n.º 8
0
 public static void AssertEqualAfterFormat(string input, CodeCommentOptions options)
 {
     AssertEqualAfterFormat(input, input, options);
 }
Exemplo n.º 9
0
        /// <summary>
        /// Loads the settings.
        /// </summary>
        public override void LoadSettings()
        {
            _options = new CodeCommentOptions(4);

            UpdatePreviewText();
        }