internal static XmlNameAttributeElementKind GetElementKind(this XmlNameAttributeSyntax attributeSyntax) { Debug.Assert(attributeSyntax.Parent is object); CSharpSyntaxNode parentSyntax = attributeSyntax.Parent; SyntaxKind parentKind = parentSyntax.Kind(); string parentName; if (parentKind == SyntaxKind.XmlEmptyElement) { var parent = (XmlEmptyElementSyntax)parentSyntax; parentName = parent.Name.LocalName.ValueText; Debug.Assert(parent.Name.Prefix is null); } else if (parentKind == SyntaxKind.XmlElementStartTag) { var parent = (XmlElementStartTagSyntax)parentSyntax; parentName = parent.Name.LocalName.ValueText; Debug.Assert(parent.Name.Prefix is null); } else { throw ExceptionUtilities.UnexpectedValue(parentKind); } if (DocumentationCommentXmlNames.ElementEquals(parentName, DocumentationCommentXmlNames.ParameterElementName)) { return(XmlNameAttributeElementKind.Parameter); } else if (DocumentationCommentXmlNames.ElementEquals(parentName, DocumentationCommentXmlNames.ParameterReferenceElementName)) { return(XmlNameAttributeElementKind.ParameterReference); } else if (DocumentationCommentXmlNames.ElementEquals(parentName, DocumentationCommentXmlNames.TypeParameterElementName)) { return(XmlNameAttributeElementKind.TypeParameter); } else if (DocumentationCommentXmlNames.ElementEquals(parentName, DocumentationCommentXmlNames.TypeParameterReferenceElementName)) { return(XmlNameAttributeElementKind.TypeParameterReference); } else { throw ExceptionUtilities.UnexpectedValue(parentName); } }
private static bool ElementNameIs(XElement element, string name) { return(string.IsNullOrEmpty(element.Name.NamespaceName) && DocumentationCommentXmlNames.ElementEquals(element.Name.LocalName, name)); }
public override void DefaultVisit(SyntaxNode node) { SyntaxKind nodeKind = node.Kind(); bool diagnose = node.SyntaxTree.ReportDocumentationCommentDiagnostics(); if (nodeKind == SyntaxKind.XmlCrefAttribute) { XmlCrefAttributeSyntax crefAttr = (XmlCrefAttributeSyntax)node; CrefSyntax cref = crefAttr.Cref; BinderFactory factory = _compilation.GetBinderFactory(cref.SyntaxTree); Binder binder = factory.GetBinder(cref); // Do this for the diagnostics, even if it won't be written. DiagnosticBag crefDiagnostics = DiagnosticBag.GetInstance(); string docCommentId = GetDocumentationCommentId(cref, binder, crefDiagnostics); if (diagnose) { _diagnostics.AddRange(crefDiagnostics); } crefDiagnostics.Free(); if (_writer != null) { Visit(crefAttr.Name); VisitToken(crefAttr.EqualsToken); // Not going to visit normally, because we want to skip trivia within // the attribute value. crefAttr.StartQuoteToken.WriteTo(_writer, leading: true, trailing: false); // We're not going to visit the cref because we want to bind it // and write a doc comment ID in its place. _writer.Write(docCommentId); // Not going to visit normally, because we want to skip trivia within // the attribute value. crefAttr.EndQuoteToken.WriteTo(_writer, leading: false, trailing: true); } // Don't descend - we've already written out everything necessary. return; } else if (diagnose && nodeKind == SyntaxKind.XmlNameAttribute) { XmlNameAttributeSyntax nameAttr = (XmlNameAttributeSyntax)node; BinderFactory factory = _compilation.GetBinderFactory(nameAttr.SyntaxTree); Binder binder = factory.GetBinder(nameAttr, nameAttr.Identifier.SpanStart); // Do this for diagnostics, even if we aren't writing. BindName(nameAttr, binder, _memberSymbol, ref _documentedParameters, ref _documentedTypeParameters, _diagnostics); // Do descend - we still need to write out the tokens of the attribute. } // NOTE: if we're recording any include element nodes (i.e. if includeElementsNodes is non-null), // then we want to record all of them, because we won't be able to distinguish in the XML DOM. if (_includeElementNodes != null) { XmlNameSyntax nameSyntax = null; if (nodeKind == SyntaxKind.XmlEmptyElement) { nameSyntax = ((XmlEmptyElementSyntax)node).Name; } else if (nodeKind == SyntaxKind.XmlElementStartTag) { nameSyntax = ((XmlElementStartTagSyntax)node).Name; } if (nameSyntax != null && nameSyntax.Prefix == null && DocumentationCommentXmlNames.ElementEquals(nameSyntax.LocalName.ValueText, DocumentationCommentXmlNames.IncludeElementName)) { _includeElementNodes.Add((CSharpSyntaxNode)node); } } base.DefaultVisit(node); }