Esempio n. 1
0
        public MetaClass(Node node) : base(node)
        {
            Usings       = new List <string>();
            Methods      = new List <MetaMethod>();
            Properties   = new List <MetaProperty>();
            Events       = new List <MetaEvent>();
            MixinClasses = new List <MetaClass>();

            OriginalFullName = node.Attributes["fullName"];
            FullName         = TypeMapper.MapType(OriginalFullName);
            BaseClass        = TypeMapper.MapType(node.GetAttributeValue("superClass"));
            Namespace        = TypeMapper.MapNamespace(node.Attributes["packageName"]);
            if (String.IsNullOrWhiteSpace(Namespace))
            {
                Namespace = "qx";
                if (!FullName.Contains("."))
                {
                    FullName = Namespace + "." + FullName;
                }
            }

            IsStatic    = node.Attributes.ContainsKey("isStatic") && node.GetAttributeValue("isStatic") == "True";
            IsAbstract  = node.Attributes.ContainsKey("isAbstract") && node.GetAttributeValue("isAbstract") == "True";
            IsMixin     = node.Attributes.ContainsKey("type") && node.GetAttributeValue("type") == "mixin";
            IsInterface = node.Attributes.ContainsKey("type") && node.GetAttributeValue("type") == "interface";

            if (BaseClass != null)
            {
                InheritanceList = ": " + TypeMapper.MapNamespace(BaseClass);
            }

            var interfaceList = node.GetAttributeValue("interfaces");

            if (interfaceList != null)
            {
                Interfaces = interfaceList.Split(',').ToList();
                for (int i = 0; i < Interfaces.Count; i++)
                {
                    Interfaces[i] = TypeMapper.MapNamespace(Interfaces[i]);
                }

                if (InheritanceList == null)
                {
                    InheritanceList = ": " + String.Join(", ", Interfaces);
                }
                else
                {
                    InheritanceList += ", " + String.Join(", ", Interfaces);
                }
            }
            else
            {
                Interfaces = new List <string>();
            }
            if (InheritanceList == null)
            {
                InheritanceList = "";
            }

            var mixinList = node.GetAttributeValue("mixins");

            if (mixinList != null)
            {
                Mixins = mixinList.Split(',').ToList();
                for (int i = 0; i < Mixins.Count; i++)
                {
                    Mixins[i] = TypeMapper.MapNamespace(Mixins[i]);
                }
            }
            else
            {
                Mixins = new List <string>();
            }

            // Add all the properties first (some methods depend on them for lookups)
            foreach (var child in node.Children)
            {
                switch (child.Type)
                {
                case NodeType.Properties:
                    foreach (var propNode in child.Children)
                    {
                        var metaProperty = new MetaProperty(propNode);
                        // Add 'x' in the end if property name = class name
                        if (metaProperty.FormattedName == FormattedName)
                        {
                            metaProperty.FormattedName += "x";
                        }
                        Properties.Add(metaProperty);
                    }
                    break;
                }
            }

            // Add methods and events
            foreach (var child in node.Children)
            {
                switch (child.Type)
                {
                case NodeType.Constructor:
                    var ctorNode = child.GetChildByType(NodeType.Method);
                    Methods.Add(new MetaMethod(ctorNode, this));
                    break;

                case NodeType.Methods:
                case NodeType.MethodsStatic:
                    foreach (var methodNode in child.Children)
                    {
                        var attachStatic = methodNode.GetChildByType(NodeType.AttachStatic);
                        if (attachStatic == null)     // Not sure what is attackStatic, but we don't need them
                        {
                            var metaMethod = new MetaMethod(methodNode, this);
                            // Add all public methods
                            if (metaMethod.AccessType == "public")
                            {
                                // Add 'x' in the end if method name = class name
                                if (metaMethod.FormattedName == FormattedName)
                                {
                                    metaMethod.FormattedName += "x";
                                }
                                Methods.Add(metaMethod);
                            }
                        }
                    }
                    break;

                case NodeType.Events:
                    foreach (var eventNode in child.Children)
                    {
                        if (Events.FirstOrDefault(e => e.Name == eventNode.GetAttributeValue("name")) == null)
                        {
                            Events.Add(new MetaEvent(eventNode));
                        }
                    }
                    break;
                }
            }

            // In some cases there will be instance & static methods with the same name, adding 'S' in the end for those
            foreach (var method in Methods)
            {
                if (method.IsStatic)
                {
                    var existingNonStatic = Methods.FirstOrDefault(m => !m.IsStatic && m.FormattedName == method.FormattedName);
                    if (existingNonStatic != null)
                    {
                        method.FormattedName += "S";
                    }
                }
            }

            // Adding parameterless constructor if not present
            if (!IsInterface)
            {
                var parameterlessConstructor = Methods.FirstOrDefault(m => m.IsConstructor && m.Parameters.Count == 0);
                if (parameterlessConstructor == null)
                {
                    Methods.Insert(0, new MetaMethod
                    {
                        IsConstructor = true,
                        AccessType    = "public",
                        Name          = Name,
                        FormattedName = Name,
                        ReturnType    = "",
                        Parameters    = new List <MetaMethodParameter>(),
                        AutoInsert    = true
                    });
                }
            }
        }
Esempio n. 2
0
        public MetaClass(Node node) : base(node)
        {
            Usings = new List<string>();
            Methods = new List<MetaMethod>();
            Properties = new List<MetaProperty>();
            Events = new List<MetaEvent>();
            MixinClasses = new List<MetaClass>();

            OriginalFullName = node.Attributes["fullName"];
            FullName = TypeMapper.MapType(OriginalFullName);
            BaseClass = TypeMapper.MapType(node.GetAttributeValue("superClass"));
            Namespace = TypeMapper.MapNamespace(node.Attributes["packageName"]);
            if (String.IsNullOrWhiteSpace(Namespace))
            {
                Namespace = "qx";
                if (!FullName.Contains(".")) FullName = Namespace + "." + FullName;
            }

            IsStatic = node.Attributes.ContainsKey("isStatic") && node.GetAttributeValue("isStatic") == "True";
            IsAbstract = node.Attributes.ContainsKey("isAbstract") && node.GetAttributeValue("isAbstract") == "True";
            IsMixin = node.Attributes.ContainsKey("type") && node.GetAttributeValue("type") == "mixin";
            IsInterface = node.Attributes.ContainsKey("type") && node.GetAttributeValue("type") == "interface";

            if (BaseClass != null)
            {
                InheritanceList = ": " + TypeMapper.MapNamespace(BaseClass);
            }

            var interfaceList = node.GetAttributeValue("interfaces");
            if (interfaceList != null)
            {
                Interfaces = interfaceList.Split(',').ToList();
                for (int i = 0; i < Interfaces.Count; i++)
                    Interfaces[i] = TypeMapper.MapNamespace(Interfaces[i]);

                if (InheritanceList == null)
                    InheritanceList = ": " + String.Join(", ", Interfaces);
                else
                    InheritanceList += ", " + String.Join(", ", Interfaces);
            }
            else
            {
                Interfaces = new List<string>();
            }
            if (InheritanceList == null) InheritanceList = "";

            var mixinList = node.GetAttributeValue("mixins");
            if (mixinList != null)
            {
                Mixins = mixinList.Split(',').ToList();
                for (int i = 0; i < Mixins.Count; i++)
                    Mixins[i] = TypeMapper.MapNamespace(Mixins[i]);
            }
            else
            {
                Mixins = new List<string>();
            }

            // Add all the properties first (some methods depend on them for lookups)
            foreach (var child in node.Children)
            {
                switch (child.Type)
                {
                    case NodeType.Properties:
                        foreach (var propNode in child.Children)
                        {
                            var metaProperty = new MetaProperty(propNode);
                            // Add 'x' in the end if property name = class name
                            if (metaProperty.FormattedName == FormattedName)
                            {
                                metaProperty.FormattedName += "x";
                            }
                            Properties.Add(metaProperty);
                        }
                        break;
                }
            }

            // Add methods and events 
            foreach (var child in node.Children)
            {
                switch (child.Type)
                {
                    case NodeType.Constructor:
                        var ctorNode = child.GetChildByType(NodeType.Method);
                        Methods.Add(new MetaMethod(ctorNode, this));
                        break;

                    case NodeType.Methods:
                    case NodeType.MethodsStatic:
                        foreach (var methodNode in child.Children)
                        {
                            var attachStatic = methodNode.GetChildByType(NodeType.AttachStatic);
                            if (attachStatic == null) // Not sure what is attackStatic, but we don't need them
                            {
                                var metaMethod = new MetaMethod(methodNode, this);
                                // Add all public methods
                                if (metaMethod.AccessType == "public")
                                {
                                    // Add 'x' in the end if method name = class name
                                    if (metaMethod.FormattedName == FormattedName)
                                    {
                                        metaMethod.FormattedName += "x";
                                    }
                                    Methods.Add(metaMethod);
                                }
                            }
                        }
                        break;

                    case NodeType.Events:
                        foreach (var eventNode in child.Children)
                        {
                            if (Events.FirstOrDefault(e => e.Name == eventNode.GetAttributeValue("name")) == null)
                            {
                                Events.Add(new MetaEvent(eventNode));
                            }
                        }
                        break;
                }
            }

            // In some cases there will be instance & static methods with the same name, adding 'S' in the end for those
            foreach (var method in Methods)
            {
                if (method.IsStatic)
                {
                    var existingNonStatic = Methods.FirstOrDefault(m => !m.IsStatic && m.FormattedName == method.FormattedName);
                    if (existingNonStatic != null)
                    {
                        method.FormattedName += "S";
                    }
                }
            }

            // Adding parameterless constructor if not present
            if (!IsInterface)
            {
                var parameterlessConstructor = Methods.FirstOrDefault(m => m.IsConstructor && m.Parameters.Count == 0);
                if (parameterlessConstructor == null)
                {
                    Methods.Insert(0, new MetaMethod
                    {
                        IsConstructor = true,
                        AccessType = "public",
                        Name = Name,
                        FormattedName = Name,
                        ReturnType = "",
                        Parameters = new List<MetaMethodParameter>(),
                        AutoInsert = true
                    });
                }
            }
        }