private static void Analyze <TNode>( SyntaxNodeAnalysisContext context, SyntaxList <XmlNodeSyntax> xmlNodes, SeparatedSyntaxList <TNode> nodes, XmlElementKind kind, Func <SeparatedSyntaxList <TNode>, string, int> indexOf) where TNode : SyntaxNode { XmlNodeSyntax firstElement = null; int firstIndex = -1; for (int i = 0; i < xmlNodes.Count; i++) { XmlElementInfo elementInfo = SyntaxInfo.XmlElementInfo(xmlNodes[i]); if (!elementInfo.Success) { continue; } if (!elementInfo.IsElementKind(kind)) { firstIndex = -1; continue; } XmlNodeSyntax element = elementInfo.Element; string name = (element.IsKind(SyntaxKind.XmlElement)) ? ((XmlElementSyntax)element).GetAttributeValue("name") : ((XmlEmptyElementSyntax)element).GetAttributeValue("name"); if (name == null) { firstIndex = -1; continue; } int index = indexOf(nodes, name); if (index == -1) { ReportUnusedElement(context, element, i, xmlNodes); } else if (index < firstIndex) { ReportDiagnosticIfNotSuppressed(context, DiagnosticDescriptors.OrderElementsInDocumentationComment, firstElement); return; } else { firstElement = element; } firstIndex = index; } }
private static bool IsMissing(DocumentationCommentTriviaSyntax documentationComment, TypeParameterSyntax typeParameter) { foreach (XmlNodeSyntax xmlNode in documentationComment.Content) { XmlElementInfo elementInfo = SyntaxInfo.XmlElementInfo(xmlNode); if (elementInfo.Success && !elementInfo.IsEmptyElement && elementInfo.IsElementKind(XmlElementKind.TypeParam)) { var element = (XmlElementSyntax)elementInfo.Element; string value = element.GetAttributeValue("name"); if (value != null && string.Equals(typeParameter.Identifier.ValueText, value, StringComparison.Ordinal)) { return(false); } } } return(true); }
private static SyntaxList <XmlNodeSyntax> SortElements <TNode>( SeparatedSyntaxList <TNode> nodes, SyntaxList <XmlNodeSyntax> content, int firstIndex, XmlElementKind kind, Func <SeparatedSyntaxList <TNode>, string, int> indexOf) where TNode : SyntaxNode { var xmlNodes = new List <XmlNodeSyntax>(); var ranks = new Dictionary <XmlNodeSyntax, int>(); for (int i = firstIndex; i < content.Count; i++) { XmlElementInfo elementInfo = SyntaxInfo.XmlElementInfo(content[i]); if (elementInfo.Success) { if (elementInfo.IsElementKind(kind)) { XmlNodeSyntax element = elementInfo.Element; string value = (element.IsKind(SyntaxKind.XmlElement)) ? ((XmlElementSyntax)element).GetAttributeValue("name") : ((XmlEmptyElementSyntax)element).GetAttributeValue("name"); if (value != null) { ranks[element] = indexOf(nodes, value); } else { break; } } else { break; } } xmlNodes.Add(content[i]); } for (int i = 0; i < xmlNodes.Count - 1; i++) { for (int j = 0; j < xmlNodes.Count - i - 1; j++) { XmlNodeSyntax node1 = xmlNodes[j]; if (ranks.TryGetValue(node1, out int rank1)) { int k = j + 1; while (k < xmlNodes.Count - i - 1) { XmlNodeSyntax node2 = xmlNodes[k]; if (ranks.TryGetValue(node2, out int rank2)) { if (rank1 > rank2) { xmlNodes[k] = node1; xmlNodes[j] = node2; } break; } k++; } } } } return(content.ReplaceRange(firstIndex, xmlNodes.Count, xmlNodes)); }