static IEnumerable <T> InnerFoo <T> (XElement parent, string innerName, ModuleDeclaration module, BaseDeclaration parDecl) where T : TypeDeclaration { var inner = parent.Elements(innerName).SelectMany(el => el.Elements("typedeclaration")); var innerList = inner.Select(elem => FromXElement(elem, module, parDecl)).ToList(); var innerCast = innerList.Cast <T> ().ToList(); return(innerCast); }
public static BaseDeclaration FromXElement(XElement elem, ModuleDeclaration module, BaseDeclaration parent) { var generics = GenericDeclaration.FromXElement(elem.Element("genericparameters")); BaseDeclaration decl = null; switch (elem.Name.ToString()) { case "func": decl = FunctionDeclaration.FuncFromXElement(elem, module, parent); break; case "typedeclaration": decl = TypeDeclaration.TypeFromXElement(elem, module, parent); break; case "property": decl = PropertyDeclaration.PropFromXElement(elem, module, parent); break; default: decl = new BaseDeclaration { Name = (string)elem.Attribute("name"), Access = TypeDeclaration.AccessibilityFromString((string)elem.Attribute("accessibility")) }; break; } decl.Generics.AddRange(generics); return(decl); }
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"); } } var protoDecl = decl as ProtocolDeclaration; if (protoDecl != null) { if (elem.Element("associatedtypes") != null) { var assocElements = from assocElem in elem.Element("associatedtypes").Elements() select AssociatedTypeDeclaration.FromXElement(assocElem); protoDecl.AssociatedTypes.AddRange(assocElements); } } return(decl); }