public void AddMethod(ClassMethod method)
 {
     if (method.Type == ClassMethod.MethodType.Regular)
     {
         Methods.Add(method);
     }
     else if (method.Type == ClassMethod.MethodType.Constructor)
     {
         Constructors.Add(method);
     }
     else
     {
         Destructors.Add(method);
     }
 }
Beispiel #2
0
        public void Add(TLDefinition tld, Stream srcStm)
        {
            TLFunction tlf = tld as TLFunction;

            if (tlf != null)
            {
                if (IsConstructor(tlf.Signature, tlf.Class))
                {
                    Constructors.Add(tlf, srcStm);
                }
                else if (tlf.Signature is SwiftClassConstructorType)
                {
                    if (ClassConstructor.Values.Count() == 0)
                    {
                        ClassConstructor.Add(tlf, srcStm);
                    }
                    else
                    {
                        throw ErrorHelper.CreateError(ReflectorError.kInventoryBase + 12, $"multiple type metadata accessors for {tlf.Class.ClassName.ToFullyQualifiedName ()}");
                    }
                }
                else if (IsDestructor(tlf.Signature, tlf.Class))
                {
                    Destructors.Add(tlf, srcStm);
                }
                else if (IsProperty(tlf.Signature, tlf.Class))
                {
                    if (IsSubscript(tlf.Signature, tlf.Class))
                    {
                        if (IsPrivateProperty(tlf.Signature, tlf.Class))
                        {
                            PrivateSubscripts.Add(tlf);
                        }
                        else
                        {
                            Subscripts.Add(tlf);
                        }
                    }
                    else
                    {
                        if (IsStaticProperty(tlf.Signature, tlf.Class))
                        {
                            if (IsPrivateProperty(tlf.Signature, tlf.Class))
                            {
                                StaticPrivateProperties.Add(tlf, srcStm);
                            }
                            else
                            {
                                StaticProperties.Add(tlf, srcStm);
                            }
                        }
                        else
                        {
                            if (IsPrivateProperty(tlf.Signature, tlf.Class))
                            {
                                PrivateProperties.Add(tlf, srcStm);
                            }
                            else
                            {
                                Properties.Add(tlf, srcStm);
                            }
                        }
                    }
                }
                else if (IsMethodOnClass(tlf.Signature, tlf.Class))
                {
                    if (tlf is TLMethodDescriptor)
                    {
                        MethodDescriptors.Add(tlf, srcStm);
                    }
                    else
                    {
                        Methods.Add(tlf, srcStm);
                    }
                }
                else if (IsStaticMethod(tlf.Signature, tlf.Class))
                {
                    StaticFunctions.Add(tlf, srcStm);
                }
                else if (IsWitnessTable(tlf.Signature, tlf.Class))
                {
                    WitnessTable.Add(tlf, srcStm);
                }
                else if (IsInitializer(tlf.Signature, tlf.Class))
                {
                    Initializers.Add(tlf, srcStm);
                }
                else
                {
                    FunctionsOfUnknownDestination.Add(tlf);
                }
                return;
            }
            var meta = tld as TLDirectMetadata;

            if (meta != null)
            {
                if (DirectMetadata != null)
                {
                    throw ErrorHelper.CreateError(ReflectorError.kInventoryBase + 13, $"duplicate direct metadata in class {DirectMetadata.Class.ClassName.ToFullyQualifiedName ()}");
                }
                DirectMetadata = meta;
                return;
            }
            var lazy = tld as TLLazyCacheVariable;

            if (lazy != null)
            {
                if (LazyCacheVariable != null)
                {
                    throw ErrorHelper.CreateError(ReflectorError.kInventoryBase + 14, $"duplicate lazy cache variable in class {LazyCacheVariable.Class.ClassName.ToFullyQualifiedName ()}");
                }
                LazyCacheVariable = lazy;
                return;
            }
            var mc = tld as TLMetaclass;

            if (mc != null)
            {
                if (Metaclass != null)
                {
                    throw ErrorHelper.CreateError(ReflectorError.kInventoryBase + 15, $"duplicate type meta data descriptor in class {Metaclass.Class.ClassName.ToFullyQualifiedName ()}");
                }
                Metaclass = mc;
                return;
            }
            var nom = tld as TLNominalTypeDescriptor;

            if (nom != null)
            {
                if (TypeDescriptor != null)
                {
                    throw ErrorHelper.CreateError(ReflectorError.kInventoryBase + 16, $"duplicate nominal type descriptor in class {TypeDescriptor.Class.ClassName.ToFullyQualifiedName ()}");
                }
                TypeDescriptor = nom;
                return;
            }
            var tlvar = tld as TLVariable;

            if (tlvar != null)
            {
                if (tlvar is TLPropertyDescriptor tlpropDesc)
                {
                    PropertyDescriptors.Add(tlpropDesc);
                }
                else
                {
                    Variables.Add(tlvar, srcStm);
                }
                return;
            }
            var tlprot = tld as TLProtocolConformanceDescriptor;

            if (tlprot != null)
            {
                ProtocolConformanceDescriptors.Add(tlprot);
                return;
            }
            DefinitionsOfUnknownDestination.Add(tld);
        }