예제 #1
0
        public static TypeDeclaration TypeFromXElement(XElement elem, ModuleDeclaration module, BaseDeclaration parent /* can be null */)
        {
            var  decl       = FromKind((string)elem.Attribute("kind"));
            bool isUnrooted = elem.Attribute("module") != null;

            decl.Module = module;
            decl.Parent = parent;
            if (isUnrooted)
            {
                decl.IsUnrooted       = true;
                decl.fullUnrootedName = (string)elem.Attribute("name");
                decl.unrootedName     = decl.fullUnrootedName.NameWithoutModule();
                decl.Name             = decl.fullUnrootedName.Contains('.') ? decl.fullUnrootedName.Substring(decl.fullUnrootedName.LastIndexOf('.') + 1)
                                        : decl.fullUnrootedName;
            }
            else
            {
                decl.Name = (string)elem.Attribute("name");
            }
            decl.Access        = AccessibilityFromString((string)elem.Attribute("accessibility"));
            decl.IsObjC        = elem.BoolAttribute("isObjC");
            decl.IsFinal       = elem.BoolAttribute("isFinal");
            decl.IsDeprecated  = elem.BoolAttribute("isDeprecated");
            decl.IsUnavailable = elem.BoolAttribute("isUnavailable");

            decl.InnerClasses.AddRange(InnerFoo <ClassDeclaration> (elem, "innerclasses", module, decl));
            decl.InnerStructs.AddRange(InnerFoo <StructDeclaration> (elem, "innerstructs", module, decl));
            decl.InnerEnums.AddRange(InnerFoo <EnumDeclaration> (elem, "innerenums", module, decl));
            if (elem.Element("members") != null)
            {
                var members = from mem in elem.Element("members").Elements()
                              select Member.FromXElement(mem, module, decl) as Member;

                decl.Members.AddRange(members);
            }
            if (elem.Element("inherits") != null)
            {
                var inherits = from inherit in elem.Element("inherits").Elements()
                               select SwiftReflector.SwiftXmlReflection.Inheritance.FromXElement(inherit) as Inheritance;

                decl.Inheritance.AddRange(inherits);
            }
            EnumDeclaration edecl = decl as EnumDeclaration;

            if (edecl != null)
            {
                var enumElements = (from enumElement in elem.Element("elements").Elements()
                                    select new EnumElement((string)enumElement.Attribute("name"), (string)enumElement.Attribute("type"),
                                                           (long?)enumElement.Attribute("intValue"))).ToList();;
                edecl.Elements.AddRange(enumElements);
                if (elem.Attribute("rawType") != null)
                {
                    edecl.RawTypeName = (string)elem.Attribute("rawType");
                }
            }

            return(decl);
        }
예제 #2
0
        protected override void CompleteUnrooting(TypeDeclaration unrooted)
        {
            base.CompleteUnrooting(unrooted);
            EnumDeclaration enumDecl = unrooted as EnumDeclaration;

            if (enumDecl == null)
            {
                throw new ArgumentException("unrooted type was not constructed by EnumDeclaration");
            }
            enumDecl.Elements.AddRange(Elements);
        }