AddType() public method

public AddType ( string ns, string name, string kind, string docPath, System.Version apiVersion ) : UnityApiType
ns string
name string
kind string
docPath string
apiVersion System.Version
return UnityApiType
示例#1
0
        private void ParseFile(string filename, Version apiVersion)
        {
            var document = ApiNode.Load(filename);
            var section  = document?.SelectOne(@"//div.content/div.section");
            var header   = section?.SelectOne(@"div.mb20.clear");
            var name     = header?.SelectOne(@"h1.heading.inherit"); // Type or type member name
            var ns       = header?.SelectOne(@"p");                  // "class in {ns}"

            // Only interested in types at this point
            if (name == null || ns == null)
            {
                return;
            }

            // Only types that have messages
            var messages = section.Subsection("Messages").ToArray();

            if (messages.Length == 0)
            {
                return;
            }

            var match   = NsRegex.Match(ns.Text);
            var clsType = match.Groups["type"].Value;
            var nsName  = match.Groups["namespace"].Value;

            var unityApiType = api.AddType(nsName, name.Text, clsType, filename, apiVersion);

            foreach (var message in messages)
            {
                var eventFunction = ParseMessage(message, apiVersion, nsName);
                unityApiType.MergeEventFunction(eventFunction, apiVersion);
            }
        }
示例#2
0
        public void ParseFolder(string path, Version apiVersion)
        {
            var currentDirectory = Directory.GetCurrentDirectory();

            try
            {
                Directory.SetCurrentDirectory(path);

                var links = LoadTypes(Path.Combine(ScriptReferenceRelativePath, "docdata/toc.json"), apiVersion)
                            .Select(f => (file: Path.Combine(ScriptReferenceRelativePath, f.link) + ".html", f.fullName)).ToArray();

                Console.WriteLine("Number of types: {0}", links.Length);

                var messages = new List <TypeDocument>();
                var progress = 1;
                for (int i = 0; i < links.Length; ++i)
                {
                    // Some of the links in toc.json aren't valid...
                    if (!File.Exists(links[i].file))
                    {
                        Console.WriteLine($"Cannot find file {links[i].file}");
                        progress++;
                        continue;
                    }

                    var document = TypeDocument.Load(links[i].file, links[i].fullName);
                    progress++;
                    if (document != null)
                    {
                        if (document.IsRemoved)
                        {
                            myTypeResolver.MarkObsolete(document.FullName, apiVersion);
                            if (document.Messages.Length != 0)
                            {
                                Console.WriteLine(
                                    $"{document.FullName} is documented but no longer available in {apiVersion}");
                            }
                        }
                        else if (document.Messages.Length > 0)
                        {
                            messages.Add(document);
                            progress--;
                        }
                    }
                    ReportProgress(progress, links.Length);
                }

                foreach (var document in messages)
                {
                    ReportProgress(progress++, links.Length);

                    var unityApiType =
                        myApi.AddType(document.Namespace, document.ShortName, document.Kind, document.DocPath, apiVersion);

                    foreach (var message in document.Messages)
                    {
                        var eventFunction =
                            ParseMessage(document.ShortName, message, apiVersion, document.Namespace);
                        if (eventFunction == null)
                        {
                            continue;
                        }

                        unityApiType.MergeEventFunction(eventFunction, apiVersion);
                    }
                }
            }
            finally
            {
                Directory.SetCurrentDirectory(currentDirectory);
            }

            Console.WriteLine();
        }
示例#3
0
        private void ParseFile(string filename, Version apiVersion, HashSet <string> processed)
        {
            if (processed.Contains(filename))
            {
                return;
            }

            processed.Add(filename);

            // We're only interested in the file if it contains messages. Bail early
            // so we don't have to parse it to HTML
            var content = File.ReadAllText(filename);

            if (!content.Contains("Messages"))
            {
                return;
            }

            var document = ApiNode.LoadContent(content);
            var section  = document?.SelectOne(@"//div.content/div.section");
            var header   = section?.SelectOne(@"div.mb20.clear");
            var removed  = header?.SelectOne(@"div[@class='message message-error mb20']");
            var name     = header?.SelectOne(@"h1.heading.inherit"); // Type or type member name
            var ns       = header?.SelectOne(@"p");                  // "class in {ns}"/"struct in {ns}"/"Namespace: {ns}"

            // Only interested in types at this point
            if (name == null || ns == null)
            {
//                Console.WriteLine("File has no types: {0}", filename);
                return;
            }

            // Only types that have messages
            var messages = section.Subsection("Messages").ToArray();

            if (messages.Length == 0)
            {
                return;
            }

            var match   = CaptureKindAndNamespaceRegex.Match(ns.Text);
            var clsType = match.Groups["type"].Value;
            var nsName  = match.Groups["namespace"].Value;

            if (string.IsNullOrEmpty(clsType))
            {
                clsType = "class";
            }
            if (string.IsNullOrEmpty(nsName))
            {
                // Quick fix up for the 5.0 docs, which don't specify a namespace for AssetModificationProcessor
                if (apiVersion == new Version(5, 0) && name.Text == "AssetModificationProcessor")
                {
                    nsName = "UnityEditor";
                }
                else
                {
                    Console.WriteLine("Missing namespace: {0}", name.Text);
                    return;
                }
            }

            if (removed != null && removed.Text.StartsWith("Removed"))
            {
                Console.WriteLine($"{nsName}.{name.Text} no longer available in {apiVersion}: {removed.Text}");
                return;
            }

            var unityApiType = myApi.AddType(nsName, name.Text, clsType, filename, apiVersion);

            foreach (var message in messages)
            {
                var eventFunction = ParseMessage(name.Text, message, apiVersion, nsName, processed);
                unityApiType.MergeEventFunction(eventFunction, apiVersion);
            }
        }