private static void HandleIncludedDocumentation(SyntaxNodeAnalysisContext context, XmlEmptyElementSyntax elementSyntax, Location elementLocation)
        {
            var memberDeclaration = elementSyntax.FirstAncestorOrSelf <MemberDeclarationSyntax>();

            if (memberDeclaration == null)
            {
                return;
            }

            var declaration = context.SemanticModel.GetDeclaredSymbol(memberDeclaration, context.CancellationToken);

            if (declaration == null)
            {
                return;
            }

            var rawDocumentation      = declaration.GetDocumentationCommentXml(expandIncludes: true, cancellationToken: context.CancellationToken);
            var completeDocumentation = XElement.Parse(rawDocumentation, LoadOptions.None);

            if (completeDocumentation.Nodes().OfType <XElement>().Any(element => element.Name == XmlCommentHelper.InheritdocXmlTag))
            {
                // Ignore nodes with an <inheritdoc/> tag in the included XML.
                return;
            }

            var emptyElements = completeDocumentation.Nodes()
                                .OfType <XElement>()
                                .Where(element => ElementsToCheck.Contains(element.Name.ToString()))
                                .Where(x => XmlCommentHelper.IsConsideredEmpty(x));

            foreach (var emptyElement in emptyElements)
            {
                context.ReportDiagnostic(Diagnostic.Create(Descriptor, elementLocation, emptyElement.Name.ToString()));
            }
        }
Ejemplo n.º 2
0
        private static Task <Document> GetTransformedDocumentAsync(Document document, SyntaxNode root, XmlEmptyElementSyntax node)
        {
            var  typeDeclaration   = node.FirstAncestorOrSelf <BaseTypeDeclarationSyntax>();
            var  declarationSyntax = node.FirstAncestorOrSelf <BaseMethodDeclarationSyntax>();
            bool isStruct          = typeDeclaration.IsKind(SyntaxKind.StructDeclaration);

            TypeParameterListSyntax typeParameterList;

            if (typeDeclaration is ClassDeclarationSyntax classDeclaration)
            {
                typeParameterList = classDeclaration.TypeParameterList;
            }
            else
            {
                typeParameterList = (typeDeclaration as StructDeclarationSyntax)?.TypeParameterList;
            }

            var newRoot = root.ReplaceNode(node, BuildSeeElement(typeDeclaration.Identifier, typeParameterList));

            var newDocument = document.WithSyntaxRoot(newRoot);

            return(Task.FromResult(newDocument));
        }
        private static Task<Document> GetTransformedDocumentAsync(Document document, SyntaxNode root, XmlEmptyElementSyntax node)
        {
            var typeDeclaration = node.FirstAncestorOrSelf<BaseTypeDeclarationSyntax>();
            var declarationSyntax = node.FirstAncestorOrSelf<BaseMethodDeclarationSyntax>();
            bool isStruct = typeDeclaration.IsKind(SyntaxKind.StructDeclaration);

            TypeParameterListSyntax typeParameterList;
            ClassDeclarationSyntax classDeclaration = typeDeclaration as ClassDeclarationSyntax;
            if (classDeclaration != null)
            {
                typeParameterList = classDeclaration.TypeParameterList;
            }
            else
            {
                typeParameterList = (typeDeclaration as StructDeclarationSyntax)?.TypeParameterList;
            }

            var newRoot = root.ReplaceNode(node, BuildSeeElement(typeDeclaration.Identifier, typeParameterList));

            var newDocument = document.WithSyntaxRoot(newRoot);

            return Task.FromResult(newDocument);
        }