private static SyntaxNode ReplaceWellFormedMultiLineCommentHeader(Document document, SyntaxNode root, StyleCopSettings settings, int commentIndex, XmlFileHeader header)
        {
            SyntaxTriviaList trivia = root.GetLeadingTrivia();
            var commentTrivia = trivia[commentIndex];

            // Is the comment pushed in by a prefix?
            var commentIndentation = string.Empty;
            if (commentIndex > 0)
            {
                var prefixTrivia = trivia[commentIndex - 1];
                if (prefixTrivia.IsKind(SyntaxKind.WhitespaceTrivia))
                {
                    commentIndentation = prefixTrivia.ToFullString();
                }
            }

            var triviaString = commentTrivia.ToFullString();
            var startIndex = triviaString.IndexOf("/*", StringComparison.Ordinal) + 2;
            var endIndex = triviaString.LastIndexOf("*/", StringComparison.Ordinal);
            var commentContext = triviaString.Substring(startIndex, endIndex - startIndex).Trim(' ', '\t').TrimEnd();
            var triviaStringParts = commentContext.Replace("\r\n", "\n").Split('\n');

            // Assume we have comments that have a leading *
            string interlinePadding = " *";

            int minExpectedLength = (commentIndentation + interlinePadding).Length;
            string newLineText = document.Project.Solution.Workspace.Options.GetOption(FormattingOptions.NewLine, LanguageNames.CSharp);

            // Examine second line to see if we should have stars or not if it's blank
            // set the interline padding to be blank also.
            if ((triviaStringParts.Length > 2) &&
                (triviaStringParts[1].Length > minExpectedLength) &&
                string.IsNullOrWhiteSpace(triviaStringParts[1].Substring(0, minExpectedLength)))
            {
                interlinePadding = "  ";
            }

            // Pad line that used to be next to a /*
            triviaStringParts[0] = commentIndentation + interlinePadding + " " + triviaStringParts[0];
            StringBuilder sb = StringBuilderPool.Allocate();
            var copyrightText = commentIndentation + interlinePadding + " " +
                GetCopyrightText(commentIndentation + interlinePadding, settings.DocumentationRules.CopyrightText, newLineText);
            var newHeader = WrapInXmlComment(commentIndentation + interlinePadding, copyrightText, document.Name, settings, newLineText);

            sb.Append(commentIndentation);
            sb.Append("/*");
            if (header.GetElement("copyright") == null)
            {
                // No copyright element at the moment so add us.
                sb.Append(newHeader.Substring(minExpectedLength));
                sb.Append(newLineText);

                // Append the original stuff
                foreach (var oldLine in triviaStringParts)
                {
                    sb.Append(oldLine.TrimEnd());
                    sb.Append(newLineText);
                }
            }
            else
            {
                bool firstLine = true;
                bool inCopyright = false;
                foreach (var oldLine in triviaStringParts)
                {
                    var openingTag = oldLine.Contains("<copyright ");
                    var closingTag = oldLine.Contains("</copyright>") ||
                        (openingTag && oldLine.Trim().EndsWith("/>"));
                    if (openingTag)
                    {
                        inCopyright = !closingTag;
                        sb.Append(newHeader.Substring(firstLine ? minExpectedLength : 0));
                        sb.Append(newLineText);
                    }

                    if (inCopyright)
                    {
                        inCopyright = !closingTag;
                    }
                    else
                    {
                        sb.Append(oldLine.Substring(firstLine ? minExpectedLength : 0));
                        sb.Append(newLineText);
                    }

                    firstLine = false;
                }
            }

            sb.Append(commentIndentation);
            sb.Append(" */");

            // Get rid of any trailing spaces.
            var lines = sb.ToString().Split(new string[] { newLineText }, StringSplitOptions.None);
            sb.Clear();
            for (int i = 0; i < lines.Length; i++)
            {
                sb.Append((i == 0 ? string.Empty : newLineText) + lines[i].TrimEnd());
            }

            var newTrivia = SyntaxFactory.SyntaxTrivia(SyntaxKind.MultiLineCommentTrivia, StringBuilderPool.ReturnAndFree(sb));
            return root.WithLeadingTrivia(trivia.Replace(commentTrivia, newTrivia));
        }
        private static void CheckCompanyName(SyntaxTreeAnalysisContext context, Compilation compilation, XmlFileHeader fileHeader, XElement copyrightElement, StyleCopSettings settings)
        {
            var companyName = copyrightElement.Attribute("company")?.Value;
            if (string.IsNullOrWhiteSpace(companyName))
            {
                var location = fileHeader.GetElementLocation(context.Tree, copyrightElement);
                context.ReportDiagnostic(Diagnostic.Create(SA1640Descriptor, location));
                return;
            }

            if (compilation.IsAnalyzerSuppressed(SA1641Identifier))
            {
                return;
            }

            if (string.CompareOrdinal(companyName, settings.DocumentationRules.CompanyName) != 0)
            {
                var location = fileHeader.GetElementLocation(context.Tree, copyrightElement);
                context.ReportDiagnostic(Diagnostic.Create(SA1641Descriptor, location));
            }
        }
        private static void CheckSummaryHeader(SyntaxTreeAnalysisContext context, Compilation compilation, XmlFileHeader fileHeader)
        {
            var summaryElement = fileHeader.GetElement("summary");
            if (summaryElement == null)
            {
                context.ReportDiagnostic(Diagnostic.Create(SA1639Descriptor, fileHeader.GetLocation(context.Tree)));
                return;
            }

            if (string.IsNullOrWhiteSpace(summaryElement.Value))
            {
                var location = fileHeader.GetElementLocation(context.Tree, summaryElement);
                context.ReportDiagnostic(Diagnostic.Create(SA1639Descriptor, location));
            }
        }
        private static void CheckFile(SyntaxTreeAnalysisContext context, Compilation compilation, XmlFileHeader fileHeader, XElement copyrightElement, StyleCopSettings settings)
        {
            var fileAttribute = copyrightElement.Attribute("file");
            if (fileAttribute == null)
            {
                var location = fileHeader.GetElementLocation(context.Tree, copyrightElement);
                context.ReportDiagnostic(Diagnostic.Create(SA1637Descriptor, location));
                return;
            }

            if (compilation.IsAnalyzerSuppressed(SA1638Identifier))
            {
                return;
            }

            var fileName = Path.GetFileName(context.Tree.FilePath);
            if (string.CompareOrdinal(fileAttribute.Value, fileName) != 0)
            {
                var location = fileHeader.GetElementLocation(context.Tree, copyrightElement);
                context.ReportDiagnostic(Diagnostic.Create(SA1638Descriptor, location));
            }
        }
        private static void CheckCopyrightHeader(SyntaxTreeAnalysisContext context, Compilation compilation, StyleCopSettings settings, XmlFileHeader fileHeader)
        {
            var copyrightElement = fileHeader.GetElement("copyright");
            if (copyrightElement == null)
            {
                context.ReportDiagnostic(Diagnostic.Create(SA1634Descriptor, fileHeader.GetLocation(context.Tree)));
                return;
            }

            if (!compilation.IsAnalyzerSuppressed(SA1637Identifier))
            {
                CheckFile(context, compilation, fileHeader, copyrightElement, settings);
            }

            if (!compilation.IsAnalyzerSuppressed(SA1640Identifier))
            {
                CheckCompanyName(context, compilation, fileHeader, copyrightElement, settings);
            }

            if (!compilation.IsAnalyzerSuppressed(SA1635Identifier))
            {
                CheckCopyrightText(context, compilation, fileHeader, copyrightElement, settings);
            }
        }
        private static void CheckCopyrightText(SyntaxTreeAnalysisContext context, Compilation compilation, XmlFileHeader fileHeader, XElement copyrightElement, StyleCopSettings settings)
        {
            var copyrightText = copyrightElement.Value;
            if (string.IsNullOrWhiteSpace(copyrightText))
            {
                var location = fileHeader.GetElementLocation(context.Tree, copyrightElement);
                context.ReportDiagnostic(Diagnostic.Create(SA1635Descriptor, location));
                return;
            }

            if (compilation.IsAnalyzerSuppressed(SA1636Identifier))
            {
                return;
            }

            if (string.Equals(settings.DocumentationRules.CopyrightText, DocumentationSettings.DefaultCopyrightText, StringComparison.OrdinalIgnoreCase))
            {
                // The copyright text is meaningless until the company name is configured by the user.
                return;
            }

            if (string.CompareOrdinal(copyrightText.Trim(' ', '\r', '\n'), settings.DocumentationRules.CopyrightText) != 0)
            {
                var location = fileHeader.GetElementLocation(context.Tree, copyrightElement);
                context.ReportDiagnostic(Diagnostic.Create(SA1636Descriptor, location));
            }
        }
            private static void CheckCompanyName(SyntaxTreeAnalysisContext context, DocumentationSettings documentationSettings, Compilation compilation, XmlFileHeader fileHeader, XElement copyrightElement)
            {
                var companyName = copyrightElement.Attribute("company")?.Value;
                if (string.IsNullOrWhiteSpace(companyName))
                {
                    var location = fileHeader.GetElementLocation(context.Tree, copyrightElement);
                    context.ReportDiagnostic(Diagnostic.Create(SA1640Descriptor, location));
                    return;
                }

                if (compilation.IsAnalyzerSuppressed(SA1641Identifier))
                {
                    return;
                }

                if (string.Equals(documentationSettings.CompanyName, DocumentationSettings.DefaultCompanyName, StringComparison.OrdinalIgnoreCase))
                {
                    // The company name is meaningless until configured by the user.
                    return;
                }

                if (string.CompareOrdinal(companyName, documentationSettings.CompanyName) != 0)
                {
                    var location = fileHeader.GetElementLocation(context.Tree, copyrightElement);
                    context.ReportDiagnostic(Diagnostic.Create(SA1641Descriptor, location));
                }
            }
            private static void CheckCopyrightText(SyntaxTreeAnalysisContext context, DocumentationSettings documentationSettings, Compilation compilation, XmlFileHeader fileHeader, XElement copyrightElement)
            {
                var copyrightText = copyrightElement.Value;
                if (string.IsNullOrWhiteSpace(copyrightText))
                {
                    var location = fileHeader.GetElementLocation(context.Tree, copyrightElement);
                    context.ReportDiagnostic(Diagnostic.Create(SA1635Descriptor, location));
                    return;
                }

                if (compilation.IsAnalyzerSuppressed(SA1636Identifier))
                {
                    return;
                }

                var settingsCopyrightText = documentationSettings.CopyrightText;
                if (string.Equals(settingsCopyrightText, DocumentationSettings.DefaultCopyrightText, StringComparison.OrdinalIgnoreCase))
                {
                    // The copyright text is meaningless until the company name is configured by the user.
                    return;
                }

                // trim any leading / trailing new line or whitespace characters (those are a result of the XML formatting)
                if (!CompareCopyrightText(documentationSettings, copyrightText.Trim('\r', '\n', ' ', '\t')))
                {
                    var location = fileHeader.GetElementLocation(context.Tree, copyrightElement);
                    context.ReportDiagnostic(Diagnostic.Create(SA1636Descriptor, location));
                }
            }