コード例 #1
0
        public static string GetName(XmlElementKind kind)
        {
            switch (kind)
            {
            case XmlElementKind.None:
                return("");

            case XmlElementKind.Exception:
                return("exception");

            case XmlElementKind.Exclude:
                return("exclude");

            case XmlElementKind.Include:
                return("include");

            case XmlElementKind.InheritDoc:
                return("inheritdoc");

            case XmlElementKind.Param:
                return("param");

            case XmlElementKind.Returns:
                return("returns");

            case XmlElementKind.Summary:
                return("summary");

            case XmlElementKind.TypeParam:
                return("typeparam");

            default:
                throw new ArgumentException("", nameof(kind));
            }
        }
コード例 #2
0
        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;
            }
        }
コード例 #3
0
        private int GetDefaultIndex(DocumentationCommentTriviaSyntax comment)
        {
            SyntaxList <XmlNodeSyntax> content = comment.Content;

            for (int i = content.Count - 1; i >= 0; i--)
            {
                if (content[i].IsKind(SyntaxKind.XmlElement))
                {
                    var xmlElement = (XmlElementSyntax)content[i];

                    XmlElementKind elementKind = xmlElement.GetElementKind();

                    if (elementKind == ElementKind ||
                        ShouldBeBefore(elementKind))
                    {
                        return(content[i].FullSpan.End);
                    }
                }
            }

            return(comment.FullSpan.Start);
        }
コード例 #4
0
 private XmlElementInfo(XmlNodeSyntax element, string localName, XmlElementKind elementKind)
 {
     Element     = element;
     LocalName   = localName;
     ElementKind = elementKind;
 }
コード例 #5
0
        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));
        }
コード例 #6
0
 public override bool ShouldBeBefore(XmlElementKind elementKind)
 {
     return(elementKind == XmlElementKind.Summary);
 }
コード例 #7
0
 public abstract bool ShouldBeBefore(XmlElementKind elementKind);
コード例 #8
0
        public static string GetName(XmlElementKind kind)
        {
            switch (kind)
            {
            case XmlElementKind.None:
                return("");

            case XmlElementKind.C:
                return("c");

            case XmlElementKind.Code:
                return("code");

            case XmlElementKind.Content:
                return("content");

            case XmlElementKind.Example:
                return("example");

            case XmlElementKind.Exception:
                return("exception");

            case XmlElementKind.Exclude:
                return("exclude");

            case XmlElementKind.Include:
                return("include");

            case XmlElementKind.InheritDoc:
                return("inheritdoc");

            case XmlElementKind.List:
                return("list");

            case XmlElementKind.Para:
                return("para");

            case XmlElementKind.Param:
                return("param");

            case XmlElementKind.ParamRef:
                return("paramref");

            case XmlElementKind.Permission:
                return("permission");

            case XmlElementKind.Remarks:
                return("remarks");

            case XmlElementKind.Returns:
                return("returns");

            case XmlElementKind.See:
                return("see");

            case XmlElementKind.SeeAlso:
                return("seealso");

            case XmlElementKind.Summary:
                return("summary");

            case XmlElementKind.TypeParam:
                return("typeparam");

            case XmlElementKind.TypeParamRef:
                return("typeparamref");

            case XmlElementKind.Value:
                return("value");

            default:
                throw new ArgumentException("", nameof(kind));
            }
        }
コード例 #9
0
 public static bool TryGetKind(string name, out XmlElementKind kind)
 {
     return(_map.TryGetValue(name, out kind));
 }
コード例 #10
0
        public static ImmutableArray <string> GetAttributeValues(DocumentationCommentTriviaSyntax comment, XmlElementKind elementKind, string attributeName)
        {
            HashSet <string> values = null;
            bool             containsIncludeOrExclude = false;
            bool             isFirst = true;

            foreach (XmlNodeSyntax node in comment.Content)
            {
                XmlElementInfo info = SyntaxInfo.XmlElementInfo(node);

                if (info.Success)
                {
                    XmlElementKind kind = info.GetElementKind();

                    switch (kind)
                    {
                    case XmlElementKind.Include:
                    case XmlElementKind.Exclude:
                    {
                        if (isFirst)
                        {
                            containsIncludeOrExclude = true;
                        }

                        break;
                    }

                    case XmlElementKind.InheritDoc:
                    {
                        return(default(ImmutableArray <string>));
                    }

                    default:
                    {
                        if (!info.IsEmptyElement &&
                            kind == elementKind)
                        {
                            string value = GetAttributeValue((XmlElementSyntax)info.Element, attributeName);

                            if (value != null)
                            {
                                (values ?? (values = new HashSet <string>())).Add(value);
                            }
                        }

                        break;
                    }
                    }

                    if (isFirst)
                    {
                        isFirst = false;
                    }
                    else
                    {
                        containsIncludeOrExclude = false;
                    }
                }
            }

            if (!containsIncludeOrExclude)
            {
                return(values?.ToImmutableArray() ?? ImmutableArray <string> .Empty);
            }

            return(default(ImmutableArray <string>));
        }
コード例 #11
0
 internal bool IsElementKind(XmlElementKind kind)
 {
     return(XmlElementNameKindMapper.GetKindOrDefault(LocalName) == kind);
 }