public static void LoadReferences(this JavaApi api, GenBase [] gens)
        {
            JavaPackage pkg = null;

            foreach (var gen in gens.Where(_ => _.IsAcw))
            {
                pkg = api.Packages.FirstOrDefault(_ => _.Name == gen.PackageName);
                if (pkg == null)
                {
                    pkg = new JavaPackage(api)
                    {
                        Name = gen.PackageName
                    };
                    api.Packages.Add(pkg);
                }
                if (gen is InterfaceGen)
                {
                    var iface = new JavaInterface(pkg);
                    pkg.Types.Add(iface);
                    iface.Load(gen);
                }
                else if (gen is ClassGen)
                {
                    var kls = new JavaClass(pkg);
                    pkg.Types.Add(kls);
                    kls.Load(gen);
                }
                else
                {
                    throw new InvalidOperationException();
                }
            }
        }
        public static void Load(this JavaPackage package, XmlReader reader, bool isReferenceOnly)
        {
            reader.MoveToContent();
            package.Name    = XmlUtil.GetRequiredAttribute(reader, "name");
            package.JniName = reader.GetAttribute("jni-name");
            if (reader.MoveToFirstAttribute())
            {
                if (reader.LocalName != "name")
                {
                    throw XmlUtil.UnexpectedAttribute(reader, "package");
                }
            }
            reader.MoveToElement();
            if (reader.IsEmptyElement)
            {
                reader.Read();
            }
            else
            {
                reader.Read();
                do
                {
                    reader.MoveToContent();
                    if (reader.NodeType == XmlNodeType.EndElement)
                    {
                        break;                         // </package>
                    }
                    if (reader.NodeType != XmlNodeType.Element)
                    {
                        throw XmlUtil.UnexpectedElementOrContent("package", reader, "class", "interface");
                    }
                    if (reader.LocalName == "class")
                    {
                        var kls = new JavaClass(package)
                        {
                            IsReferenceOnly = isReferenceOnly
                        };
                        kls.Load(reader);
                        package.AddType(kls);
                    }
                    else if (reader.LocalName == "interface")
                    {
                        var iface = new JavaInterface(package)
                        {
                            IsReferenceOnly = isReferenceOnly
                        };
                        iface.Load(reader);
                        package.AddType(iface);
                    }
                    else
                    {
                        throw XmlUtil.UnexpectedElementOrContent("package", reader, "class", "interface");
                    }
                } while (true);

                XmlUtil.VerifyEndElement(reader, "package");
                reader.Read();
            }
        }
Esempio n. 3
0
        public static void LoadReferences(this JavaApi api, CodeGenerationOptions opt, IEnumerable <GenBase> gens)
        {
            JavaPackage pkg = null;

            foreach (var gen in gens.Where(_ => _.IsAcw))
            {
                if (!api.Packages.TryGetValue(gen.PackageName, out pkg))
                {
                    pkg = new JavaPackage(api)
                    {
                        Name = gen.PackageName
                    };
                    api.Packages.Add(pkg.Name, pkg);
                }

                if (gen is InterfaceGen iface_gen)
                {
                    var iface = new JavaInterface(pkg);
                    iface.Load(iface_gen);

                    pkg.AddType(iface);
                }
                else if (gen is ClassGen class_gen)
                {
                    var kls = new JavaClass(pkg);
                    kls.Load(opt, class_gen);

                    pkg.AddType(kls);
                }
                else
                {
                    throw new InvalidOperationException();
                }
                api.LoadReferences(opt, gen.NestedTypes);
            }
        }