private static JSDocNode GetSpecificType(JSDocItems items)
        {
            foreach (var item in items.List)
            {
                switch (item.Key)
                {
                case "function":
                case "func":
                case "method":
                case "name":
                case "param":
                case "returns":
                case "return":
                    return(new JSDocFunction());

                case "file":
                    return(new JSDocFile());
                }
            }

            if ((items.PreviousLine != null && items.PreviousLine.Contains("function")) ||
                (items.NextLine != null && items.NextLine.Contains("function")))
            {
                return(new JSDocFunction());
            }

            return(new JSDocNode());
        }
        internal virtual void Parse(JSDocItems items)
        {
            foreach (var item in items.List)
            {
                switch (item.Key)
                {
                case "name":
                {
                    if (!string.IsNullOrWhiteSpace(item.Value))
                    {
                        this.Name = item.Value;
                    }

                    break;
                }

                case "see":
                {
                    var ext = item.Value.ToLowerInvariant();
                    if (ext.EndsWith(".png") || ext.EndsWith(".jpg"))
                    {
                        this.Image = item.Value;
                    }
                    break;
                }

                case "":
                {
                    this.Description = item.Value;
                    break;
                }
                }
            }
        }
示例#3
0
        public static JSDocItems GetItems(JSDocSplitSet set)
        {
            var results = new JSDocItems();

            var sb  = new StringBuilder();
            var key = string.Empty;

            var lines = GetLines(set.Text);

            foreach (var line in lines)
            {
                if (line.StartsWith("@"))
                {
                    if (!string.IsNullOrWhiteSpace(key) || !string.IsNullOrWhiteSpace(sb.ToString()))
                    {
                        results.List.Add(new KeyValuePair <string, string>(key, sb.ToString().Trim()));
                    }

                    sb.Clear();

                    var index = line.IndexOf(' ');
                    if (index > -1)
                    {
                        key = line.Substring(1, index - 1);
                        sb.Append(line.Substring(index + 1) + ' ');
                    }
                    else
                    {
                        // issue: if an @indicator is alone on a line, followed by the actual text, this will miss it.
                        key = line.Substring(1).Trim();
                        results.List.Add(new KeyValuePair <string, string>(key, sb.ToString().Trim()));
                        key = string.Empty;
                    }
                }
                else
                {
                    sb.Append(line + ' ');
                }
            }

            if (!string.IsNullOrWhiteSpace(key) || sb.Length > 0)
            {
                results.List.Add(new KeyValuePair <string, string>(key, sb.ToString().Trim()));
            }

            results.PreviousLine = set.PreviousLine;
            results.NextLine     = set.NextLine;

            return(results);
        }
        internal override void Parse(JSDocItems items)
        {
            base.Parse(items);

            foreach (var item in items.List)
            {
                switch (item.Key)
                {
                case "param":
                {
                    this.Parameters.Add(JSDocParam.Parse(item.Value));
                    break;
                }

                case "function":
                case "method":
                {
                    if (!string.IsNullOrWhiteSpace(item.Value))
                    {
                        this.Method = item.Value;
                    }

                    break;
                }

                case "func":
                case "alias":
                {
                    if (!string.IsNullOrWhiteSpace(item.Value))
                    {
                        this.Name = item.Value;
                    }

                    break;
                }

                case "returns":
                case "return":
                {
                    this.Returns = JSDocParam.Parse(item.Value);

                    break;
                }
                }
            }

            if (string.IsNullOrWhiteSpace(this.Name))
            {
                var fnLine = (items.PreviousLine != null && items.PreviousLine.Contains("function")) ? items.PreviousLine :
                             (items.NextLine != null && items.NextLine.Contains("function")) ? items.NextLine : string.Empty;

                if (!string.IsNullOrWhiteSpace(fnLine))
                {
                    var index = fnLine.IndexOf("function");
                    if (index > 0)
                    {
                        var before = fnLine.Substring(0, index).Trim();
                        if (!string.IsNullOrWhiteSpace(before))
                        {
                            var iEquals      = before.IndexOf("=");
                            var beforeEquals = before.Substring(0, iEquals).Trim();
                            var lastWord     = beforeEquals.Split(new[] { ' ' }).LastOrDefault();

                            this.Name = lastWord;
                        }
                    }
                    else
                    {
                        var words = fnLine.Substring(index + 8).Trim().Split(new[] { ' ', '(' });
                        if (words.Length > 0)
                        {
                            this.Name = words[0];
                        }
                    }

                    if (fnLine.Contains("("))
                    {
                        var parmset = JSDocHelper.Split(fnLine, "(", ")");
                        if (parmset.Length > 0)
                        {
                            var parms = parmset[0].Split(new[] { ',' });
                            foreach (var parm in parms)
                            {
                                var segments = parm.Split(new[] { '=', ' ' }, StringSplitOptions.RemoveEmptyEntries);
                                if (segments.Length > 1)
                                {
                                    var subparm = this.Parameters.FirstOrDefault(p => p.Name.Equals(segments[0]));
                                    if (subparm != null)
                                    {
                                        subparm.Default = segments[1].Trim();
                                    }
                                }
                            }
                        }
                    }
                }
            }
        }