示例#1
0
        public ScrapedProperty(ScrapedMember baseValues, HtmlNode node) : base(baseValues)
        {
            Description = node.SelectSingleNode("./div[@class='abstract']/p").RealInnerText();
            if (Description.Contains("Returns a dictionary that contains information about the receiver"))
            {
            }
            Deprecated = Description.ToLower().Contains("deprecat");
            var name = Declaration.Split("var ")[1].Split(':')[0].Trim();

            RawName    = name;
            CSharpName = (name.ToUpper()[0] + name.Substring(1)).Trim('`');

            if (new[] { "object", "string", "delegate", "int", "uint", "float", "class", "this", "new" }.Contains(CSharpName))
            {
                CSharpName = "@" + CSharpName;
            }

            var type = Declaration.SplitAtFirstOccurrence(':')[1].Trim().Split('{')[0].Split(';')[0].Trim();

            Type = ScrapedType.ScrapeType(type);

            PublicGetter = true;
            PublicSetter = !(Declaration.Contains("{ get }"));
            Public       = true;

            Static = Declaration.Contains("class var ");
        }
示例#2
0
        public ScrapedStruct(ScrapedMember baseValues, HtmlNode node) : base(baseValues)
        {
            Description = node.SelectSingleNode("./div[@class='abstract']/p").RealInnerText();
            Deprecated  = Description.ToLower().Contains("deprecat");

            if (Declaration.StartsWith("struct "))
            {
                var name = Declaration.Split("struct ")[1].Split(' ')[0].Trim();

                RawName    = name;
                CSharpName = name.ToUpper()[0] + name.Substring(1);

                Members = new List <ScrapedStructMember>();
                var members = Declaration.Split('\n').Select(str => str.Trim());
                foreach (var member in members)
                {
                    if (member.Contains("var "))
                    {
                        Members.Add(new ScrapedStructMember(member));
                    }
                }
            }

            var descriptions = node.SelectNodes("./ul[@class='list-bullet']/li");

            if (descriptions != null)
            {
                foreach (var desc in descriptions)
                {
                    var optName = desc.SelectSingleNode("./p[@class='para Swift']").RealInnerText().Trim();

                    var    definitionPs = desc.SelectNodes("./div[@class='definition']/p[@class='para']");
                    var    availability = definitionPs.Last().RealInnerText().Trim();
                    double?availNum     = null;
                    if (availability.Contains("in iOS "))
                    {
                        try
                        {
                            availNum = double.Parse(availability.Trim().Split("in iOS ")[1].Split(' ')[0]);
                            definitionPs.Remove(definitionPs.Last());
                        }
                        catch
                        {
                        }
                    }
                    var def = string.Join(Environment.NewLine, definitionPs.Select(defi => defi.RealInnerText().Trim()));

                    var memberWithName = Members.FirstOrDefault(mem => mem.RawName == optName);
                    if (memberWithName != null)
                    {
                        memberWithName.iOSVersion  = availNum;
                        memberWithName.Description = def;
                        memberWithName.Deprecated  = def.ToLower().Contains("deprec");
                    }
                }
            }

            Public = true;
            Static = true;
        }
示例#3
0
 public ScrapedMember(ScrapedMember baseValues)
 {
     Declaration = baseValues.Declaration;
     Description = baseValues.Description;
     iOSVersion  = baseValues.iOSVersion;
     Deprecated  = baseValues.Deprecated;
     Public      = baseValues.Public;
     Static      = baseValues.Static;
     RawName     = baseValues.RawName;
     CSharpName  = baseValues.CSharpName;
 }
示例#4
0
        public ScrapedNotification(ScrapedMember baseValues, HtmlNode node) : base(baseValues)
        {
            Description = node.SelectSingleNode("./div[@class='api-description']/p[@class='para']").RealInnerText();
            Deprecated  = Description.ToLower().Contains("deprecat");
            Declaration =
                node.ParentNode.ParentNode.SelectSingleNode(
                    "./div[@class='task-group-term']/code/a[@class='notification Swift']").RealInnerText();


            RawName    = Declaration;
            CSharpName = Declaration;

            Public = true;
            Static = true;
        }
示例#5
0
        public ScrapedTypedef(ScrapedMember baseValues, HtmlNode node) : base(baseValues)
        {
            Description = node.SelectSingleNode("./div[@class='abstract']/p").RealInnerText();
            Deprecated  = Description.ToLower().Contains("deprecat");
            iOSVersion  = double.Parse(node.SelectSingleNode("./div[@class='availability']/p").RealInnerText().Split("in iOS ")[1].Split(' ')[0]);

            var name = Declaration.Split("typealias ")[1].Split('=')[0].Trim();

            RawName    = name;
            CSharpName = name.ToUpper()[0] + name.Substring(1);
            Alias      = CSharpName;

            var type = Declaration.Split('=')[1].Trim().Split(' ')[0].Trim();

            RealType = ScrapedType.ScrapeType(type);

            Public = true;
            Static = true;
        }
示例#6
0
        public static ScrapedMember ScrapeMember(HtmlNode node)
        {
            var    baseMember       = new ScrapedMember();
            var    availabilityNode = node.GetAttributeValue("data-availability", "not a number");
            double availability;

            if (!double.TryParse(availabilityNode, out availability))
            {
                baseMember.iOSVersion = null;

                try
                {
                    if (double.TryParse(
                            node.SelectSingleNode("./div[@class='availability']/p").RealInnerText().Split("in iOS ")[1]
                            .Split(' ')[0], out availability))
                    {
                        baseMember.iOSVersion = availability;
                    }
                }
                catch
                {
                    // ignored
                }
            }
            else
            {
                baseMember.iOSVersion = availability;
            }

            var realNode = node.SelectSingleNode("./div[@class='height-container']/section");

            var declarationNode =
                realNode.SelectSingleNode("./div[@class='declaration']/div[@class='Swift']/p[@class='para']");

            baseMember.Declaration = declarationNode.RealInnerText().Trim();

            //Enums
            if ((baseMember.Declaration.StartsWith("struct ") && baseMember.Declaration.Contains("Option")) ||
                (baseMember.Declaration.StartsWith("enum") && baseMember.Declaration.Contains("case")))
            {
                return(new ScrapedEnum(baseMember, realNode));
            }
            if (baseMember.Declaration.Contains("struct ") && baseMember.Declaration.Contains("var "))
            {
                return(new ScrapedStruct(baseMember, realNode));
            }
            if ((baseMember.Declaration.Contains("init(") || baseMember.Declaration.Contains("func ")))
            {
                return(new ScrapedMethod(baseMember, realNode));
            }
            if (baseMember.Declaration.Contains("var "))
            {
                return(new ScrapedProperty(baseMember, realNode));
            }
            if (baseMember.Declaration.Contains("typealias "))
            {
                return(new ScrapedTypedef(baseMember, realNode));
            }
            if (baseMember.Declaration == "" && realNode.SelectSingleNode("./div[@class='api-description']") != null)
            {
                return(new ScrapedNotification(baseMember, realNode));
            }

            return(baseMember);
        }
示例#7
0
        public ScrapedMethod(ScrapedMember baseValues, HtmlNode node) : base(baseValues)
        {
            Description = node.SelectSingleNode("./div[@class='abstract']/p").RealInnerText();
            Deprecated  = Description.ToLower().Contains("deprecat");
            IsOptional  = Declaration.Contains("optional ");
            RawName     = Declaration.Split('(')[0].Split("func ").Last().Trim().Trim('`').Trim();
            CSharpName  = RawName.ToUpper()[0] + RawName.Substring(1);

            if (new[] { "object", "string", "delegate", "int", "uint", "float", "class", "this", "new", "event" }.Contains(CSharpName))
            {
                CSharpName = "@" + CSharpName;
            }

            if (Declaration.ToLower().Contains("init("))
            {
                CSharpName = "init";
            }


            var parameters = Declaration.Substring(Declaration.IndexOf('(') + 1);

            parameters = parameters.Substring(0, parameters.LastIndexOf(')'));

            var separatedParameters = ScrapedParameter.ScrapeParameters(parameters);

            Parameters = new List <ScrapedParameter>();
            foreach (var param in separatedParameters)
            {
                Parameters.Add(new ScrapedParameter(param));
            }

            var parameterTableRows = node.SelectNodes("./div[@class='parameters']/table/tbody/tr");

            if (parameterTableRows != null)
            {
                foreach (var row in parameterTableRows)
                {
                    var name       = row.SelectNodes("./td").First().RealInnerText().Trim();
                    var definition = row.SelectNodes("./td").Last().RealInnerText().Trim();
                    if (name != definition)
                    {
                        var matchingParameter = Parameters.FirstOrDefault(param => param.InternalName == name);
                        if (matchingParameter != null)
                        {
                            matchingParameter.Description = definition;
                        }
                    }
                }
            }

            var returns = node.SelectSingleNode("./result-description/p");

            if (returns != null)
            {
                ReturnDescription = returns.RealInnerText().Trim();
            }
            else
            {
                ReturnDescription = null;
            }

            if (Declaration.ToLower().Contains("allocwithzone"))
            {
                var m = 1;
            }

            if (Declaration.Contains("->"))
            {
                var returnType = Declaration.Split("->").Last();
                if (!returnType.EndsWith(")"))
                {
                    ReturnType = ScrapedType.ScrapeType(returnType);
                }
            }
            if (ReturnType == null || ReturnType.CSharpType.Trim() == "")
            {
                ReturnType = ScrapedType.ScrapeType("void");
            }

            var objCDeclaration =
                node.SelectSingleNode("./div[@class='declaration']/div[@class='Objective-C']/p[@class='para']").RealInnerText().Trim();

            if (objCDeclaration.StartsWith("-") || !Declaration.Contains("class "))
            {
                Static = false;
            }
            else
            {
                Static = true;
            }
            Public = true;
        }