public ExtensionDeclaration(ExtensionDeclaration other) : this() { Inheritance.AddRange(other.Inheritance); Members.AddRange(other.Members); ExtensionOnTypeName = other.ExtensionOnTypeName; Module = other.Module; }
void GatherXObjects(List <XObject> xobjects) { xobjects.Add(new XAttribute("onType", ExtensionOnTypeName)); List <XObject> memcontents = new List <XObject> (Members.Select(m => m.ToXElement())); xobjects.Add(new XElement("members", memcontents.ToArray())); List <XObject> inherits = new List <XObject> (Inheritance.Select(i => i.ToXElement())); xobjects.Add(new XElement("inherits", inherits.ToArray())); }
public bool IsSwiftBaseClass() { // this predicate determines if a TypeDeclaration is: // * a ClassDeclaration // * an all swift object // * no inheritance or any inheritance is not class inheritance if (!(this is ClassDeclaration)) { return(false); } if (IsObjC) { return(false); } return(Inheritance == null || !Inheritance.Any(inh => inh.InheritanceKind == InheritanceKind.Class)); }
public bool ProtectedObjCCtorIsInThis(TypeMapper typeMapper) { // this predicate determines if this type has a protected objc ctor in this. // it's used to determine if, when writing the C# binding, if we need to call base () or this () var classDecl = this as ClassDeclaration; if (classDecl == null) { return(false); } if (!IsObjC) { return(false); } // no inheritance // this : (nothing) -> IsImportedBinding if (Inheritance == null || Inheritance.FirstOrDefault(inh => inh.InheritanceKind == InheritanceKind.Class) == null) { // if there's no inheritance, then the protected ctor is in this if it wasn't imported return(!classDecl.IsImportedBinding); } // this : import -> true // this : binding : binding : import -> false var classInherit = Inheritance.First(inh => inh.InheritanceKind == InheritanceKind.Class); var entity = typeMapper.GetEntityForTypeSpec(classInherit.InheritedTypeSpec); if (entity == null) { throw ErrorHelper.CreateError(ReflectorError.kCompilerBase + 9, $"Unable to find entity for class inheritance on type {classInherit.InheritedTypeName}"); } var inheritedClass = entity.Type as ClassDeclaration; if (inheritedClass == null) { throw ErrorHelper.CreateError(ReflectorError.kCompilerBase + 10, $"Expected a ClassDeclaration in inheritance chain but got {entity.Type.ToFullyQualifiedName (true)} of {entity.Type.GetType ().Name}"); } return(inheritedClass.IsImportedBinding); }
public bool VirtualMethodExistsInInheritedBoundType(FunctionDeclaration func, TypeMapper typeMapper) { // virtual methods are only in classes if (!(this is ClassDeclaration)) { return(false); } var classInheritance = Inheritance.FirstOrDefault(inh => inh.InheritanceKind == InheritanceKind.Class); if (classInheritance == null) { return(false); } var inheritedEntity = typeMapper.GetEntityForTypeSpec(classInheritance.InheritedTypeSpec); if (inheritedEntity == null) { throw ErrorHelper.CreateError(ReflectorError.kTypeMapBase + 18, $"Unable to find type database entry for class {classInheritance.InheritedTypeName} while searching inheritance."); } // if we get here, the Type has to be a ClassDeclaration var inheritedClass = inheritedEntity.Type as ClassDeclaration; var methods = inheritedClass.AllVirtualMethods().FindAll(fn => fn.Name == func.Name && fn.ParameterLists.Last().Count == func.ParameterLists.Last().Count).ToList(); foreach (var method in methods) { if (ParmsMatchWithNames(method.ParameterLists.Last(), func.ParameterLists.Last()) && method.ReturnTypeSpec.Equals(func.ReturnTypeSpec)) { return(true); } } return(inheritedClass.VirtualMethodExistsInInheritedBoundType(func, typeMapper)); }
protected virtual void GatherXObjects(List <XObject> xobjects) { XElement generics = Generics.ToXElement(); if (generics != null) { xobjects.Add(generics); } xobjects.Add(new XAttribute("kind", ToString(Kind))); xobjects.Add(new XAttribute("name", fullUnrootedName)); xobjects.Add(new XAttribute("module", Module.Name)); xobjects.Add(new XAttribute("accessibility", TypeDeclaration.ToString(Access))); xobjects.Add(new XAttribute("isObjC", IsObjC ? "true" : "false")); xobjects.Add(new XAttribute("isFinal", IsFinal ? "true" : "false")); xobjects.Add(new XAttribute("isDeprecated", IsDeprecated ? "true" : "false")); xobjects.Add(new XAttribute("isUnavailable", IsUnavailable ? "true" : "false")); // DO NOT INCLUDE Inner[Classes,Structs,Enums] List <XObject> memcontents = new List <XObject> (Members.Select(m => m.ToXElement())); xobjects.Add(new XElement("members", memcontents.ToArray())); List <XObject> inherits = new List <XObject> (Inheritance.Select(i => i.ToXElement())); xobjects.Add(new XElement("inherits", inherits.ToArray())); }