Пример #1
0
        private void AnalyzeTypeMemberDeclarationForMissingXmlComments(MemberDeclarationSyntax memberDeclaration, SyntaxTokenList modifiers,
                                                                       SyntaxToken identifier, bool reportDiagnostic, out bool checkChildNodes)
        {
            _syntaxContext.CancellationToken.ThrowIfCancellationRequested();

            if (!modifiers.Any(SyntaxKind.PublicKeyword) || CheckIfMemberAttributesDisableDiagnostic(memberDeclaration))
            {
                checkChildNodes = false;
                return;
            }

            XmlCommentParseResult thisDeclarationParseResult = AnalyzeDeclarationXmlComments(memberDeclaration);
            bool commentsAreValid;

            (commentsAreValid, checkChildNodes) = AnalyzeCommentParseResult(thisDeclarationParseResult);

            if (commentsAreValid)
            {
                return;
            }

            if (reportDiagnostic)
            {
                ReportDiagnostic(_syntaxContext, memberDeclaration, identifier.GetLocation(), thisDeclarationParseResult);
            }
        }
Пример #2
0
        private void AnalyzeTypeDeclarationForMissingXmlComments(TypeDeclarationSyntax typeDeclaration, bool reportDiagnostic, out bool checkChildNodes,
                                                                 INamedTypeSymbol typeSymbol = null)
        {
            _syntaxContext.CancellationToken.ThrowIfCancellationRequested();

            if (!typeDeclaration.IsPartial())
            {
                AnalyzeTypeMemberDeclarationForMissingXmlComments(typeDeclaration, typeDeclaration.Modifiers, typeDeclaration.Identifier,
                                                                  reportDiagnostic, out checkChildNodes);
                return;
            }

            typeSymbol = typeSymbol ?? _syntaxContext.SemanticModel.GetDeclaredSymbol(typeDeclaration, _syntaxContext.CancellationToken);

            if (typeSymbol == null || typeSymbol.DeclaringSyntaxReferences.Length < 2)                  //Case when type marked as partial but has only one declaration
            {
                AnalyzeTypeMemberDeclarationForMissingXmlComments(typeDeclaration, typeDeclaration.Modifiers, typeDeclaration.Identifier,
                                                                  reportDiagnostic, out checkChildNodes);
                return;
            }
            else if (typeSymbol.DeclaredAccessibility != Accessibility.Public || CheckIfTypeAttributesDisableDiagnostic(typeSymbol))
            {
                checkChildNodes = false;
                return;
            }

            XmlCommentParseResult thisDeclarationParseResult = AnalyzeDeclarationXmlComments(typeDeclaration);
            bool commentsAreValid;

            (commentsAreValid, checkChildNodes) = AnalyzeCommentParseResult(thisDeclarationParseResult);

            if (commentsAreValid)
            {
                return;
            }

            foreach (SyntaxReference reference in typeSymbol.DeclaringSyntaxReferences)
            {
                if (reference.SyntaxTree == typeDeclaration.SyntaxTree ||
                    !(reference.GetSyntax(_syntaxContext.CancellationToken) is TypeDeclarationSyntax partialTypeDeclaration))
                {
                    continue;
                }

                XmlCommentParseResult parseResult = AnalyzeDeclarationXmlComments(partialTypeDeclaration);
                (commentsAreValid, checkChildNodes) = AnalyzeCommentParseResult(parseResult);

                if (commentsAreValid)
                {
                    return;
                }
            }

            if (reportDiagnostic)
            {
                ReportDiagnostic(_syntaxContext, typeDeclaration, typeDeclaration.Identifier.GetLocation(), thisDeclarationParseResult);
            }
        }
Пример #3
0
        private SyntaxNode GetRootNodeSyntaxWithDescription(SyntaxNode rootNode, MemberDeclarationSyntax memberDeclaration,
                                                            string className, XmlCommentParseResult parseResult, CancellationToken cancellation)
        {
            cancellation.ThrowIfCancellationRequested();

            var description = GenerateDescriptionFromCamelCase(className);

            return(parseResult switch
            {
                XmlCommentParseResult.NoXmlComment => AddXmlCommentDescription(rootNode, memberDeclaration, description, cancellation),
                XmlCommentParseResult.NoSummaryTag => AddXmlCommentDescription(rootNode, memberDeclaration, description, cancellation),
                XmlCommentParseResult.EmptySummaryTag => AddDescription(rootNode, memberDeclaration, description, cancellation),
                _ => memberDeclaration
            });
Пример #4
0
        private async Task <Document> AddDescriptionAsync(Document document, TextSpan span, XmlCommentParseResult parseResult, CancellationToken cancellation)
        {
            cancellation.ThrowIfCancellationRequested();

            var rootNode = await document.GetSyntaxRootAsync(cancellation).ConfigureAwait(false);

            if (!(rootNode?.FindNode(span) is MemberDeclarationSyntax memberDeclaration))
            {
                return(document);
            }

            string memberName = memberDeclaration.GetIdentifiers().FirstOrDefault().ToString();

            if (memberName.IsNullOrWhiteSpace())
            {
                return(document);
            }

            var newRootNode = GetRootNodeSyntaxWithDescription(rootNode, memberDeclaration, memberName, parseResult, cancellation);
            var newDocument = document.WithSyntaxRoot(newRootNode);

            return(newDocument);
        }
Пример #5
0
 private (bool CommentsAreValid, bool CheckChildNodes) AnalyzeCommentParseResult(XmlCommentParseResult parseResult) =>