Пример #1
0
        public static void Parse(TheConstructor pConstructor, CodeBuilder pBuilder, FactoryExpressionCreator pCreator)
        {
            if (pConstructor.IsStaticConstructor)
            {
                pBuilder.Append("{");
            }
            else
            {
                pBuilder.AppendFormat("{4}{0}function {1}({2}){3} {{",
                                      ClassParser.IsMainClass ? "private " : As3Helpers.ConvertModifiers(pConstructor.Modifiers, _notValidConstructorMod),
                                      ClassParser.IsMainClass ? @"$ctor" : pConstructor.Name,
                                      As3Helpers.GetParameters(pConstructor.Arguments),
                                      ClassParser.IsMainClass ? ":void" : string.Empty,                          // pConstructor.MyClass.Name,
                                      pConstructor.OverridesBaseConstructor ? "override " : string.Empty
                                      );
            }

            pBuilder.AppendLine();

            if (pConstructor.HasBaseCall)
            {
                pBuilder.AppendFormat("\tsuper({0});", As3Helpers.GetCallingArguments(pConstructor.BaseArguments));
                pBuilder.AppendLine();
            }

            BlockParser.Parse(pConstructor.CodeBlock, pBuilder, pCreator);

            pBuilder.AppendLine("}");
            pBuilder.AppendLine();
        }
Пример #2
0
        public static void Parse(TheIndexer pGetIndexer, CodeBuilder pBuilder, FactoryExpressionCreator pCreator)
        {
            bool isInterface = pGetIndexer.MyClass.IsInterface;

            if (pGetIndexer.Getter != null)
            {
                pBuilder.AppendFormat("{0}function {1}({2}):{3}{4}",
                                      As3Helpers.ConvertModifiers(pGetIndexer.Getter.Modifiers, _notValidMod),
                                      pGetIndexer.Getter.Name,
                                      As3Helpers.GetParameters(pGetIndexer.Getter.Arguments),
                                      As3Helpers.Convert(pGetIndexer.ReturnType),
                                      isInterface ? ";":" {"
                                      );
                pBuilder.AppendLine();

                if (!isInterface)
                {
                    BlockParser.Parse(pGetIndexer.Getter.CodeBlock, pBuilder, pCreator);
                    pBuilder.AppendLine();
                    pBuilder.AppendLine("}");
                    pBuilder.AppendLine();
                }
            }

            if (pGetIndexer.Setter == null)
            {
                return;
            }

            pBuilder.AppendFormat(
                "{0}function {1}({2}):void{3}",
                As3Helpers.ConvertModifiers(pGetIndexer.Setter.Modifiers, _notValidMod),
                pGetIndexer.Setter.Name,
                As3Helpers.GetParameters(pGetIndexer.Setter.Arguments),
                isInterface ? ";" : " {"
                );

            pBuilder.AppendLine();
            if (isInterface)
            {
                return;
            }
            //BlockParser.InsideSetter = true;
            BlockParser.Parse(pGetIndexer.Setter.CodeBlock, pBuilder, pCreator);
            //BlockParser.InsideSetter = false;
            pBuilder.AppendLine();
            pBuilder.AppendLine("}");
            pBuilder.AppendLine();
        }
Пример #3
0
        public static void Parse(TheMethod pMethod, CodeBuilder pBuilder, FactoryExpressionCreator pCreator)
        {
            if (pMethod == null)
            {
                return;
            }
            bool isInterface = pMethod.MyClass.IsInterface;

            Dictionary <string, string> nonValidMethod = new Dictionary <string, string>(_notValidMethodMod);

            if (ClassParser.IsExtension)
            {
                nonValidMethod.Add("static", string.Empty);
            }

            pBuilder.AppendFormat("{0}function {1}({2}):{3}{4}",
                                  As3Helpers.ConvertModifiers(pMethod.Modifiers, nonValidMethod),
                                  pMethod.Name,
                                  As3Helpers.GetParameters(pMethod.Arguments),
                                  As3Helpers.Convert(pMethod.ReturnType),
                                  isInterface ? ";":" {"
                                  );

            pBuilder.AppendLine();

            if (isInterface)
            {
                return;
            }

            pBuilder.AppendLine();
            BlockParser.Parse(pMethod.CodeBlock, pBuilder, pCreator);
            pBuilder.AppendLine();
            pBuilder.AppendLine("}");
            pBuilder.AppendLine();
        }
Пример #4
0
        public static void Parse(TheProperty pProperty, CodeBuilder pBuilder, FactoryExpressionCreator pCreator)
        {
            if (pProperty == null)
            {
                return;
            }
            bool   isInterface = pProperty.MyClass.IsInterface;
            string type        = As3Helpers.Convert(pProperty.ReturnType);

            if (pProperty.IsEmpty && !isInterface)
            {
                pBuilder.AppendFormat("private var _{0}:{1};", pProperty.Name, type);
                pBuilder.AppendLine();
            }

            TheClass parent           = pProperty.MyClass;
            bool     isStandardGetSet = false;

            while (parent.Base != null)
            {
                isStandardGetSet |= parent.FullName.StartsWith("flash.");
                parent            = parent.Base;
            }

            if (pProperty.Getter != null)              //Getter
            {
                if (isStandardGetSet)                  //base is flash, use standard setter/getter
                {
                    pBuilder.AppendFormat("{0}function get {1}():{2}{3}",
                                          As3Helpers.ConvertModifiers(pProperty.Getter.Modifiers, _notValidPropertyMod),
                                          pProperty.Name,
                                          type,
                                          isInterface ? ";" : " {"
                                          );
                }
                else
                {
                    bool isEnum = false;

                    foreach (string s in pProperty.MyClass.Implements)
                    {
                        if (!s.StartsWith("IEnumerator", StringComparison.Ordinal))
                        {
                            continue;
                        }

                        isEnum = true;
                        break;
                    }

                    isEnum &= pProperty.Getter.Name.Equals("get_Current");

                    //bool isEnum =
                    //    pProperty.Getter.Name.Equals("get_Current") &&
                    //    pProperty.MyClass.Implements.Contains()

                    pBuilder.AppendFormat("{0}function {1}():{2}{3}",
                                          As3Helpers.ConvertModifiers(pProperty.Getter.Modifiers, _notValidPropertyMod),
                                          pProperty.Getter.Name,
                                          isEnum ? "*" : type,
                                          isInterface ? ";" : " {"
                                          );
                }

                pBuilder.AppendLine();

                if (!isInterface)
                {
                    if (pProperty.IsEmpty)
                    {
                        pBuilder.Indent();
                        pBuilder.AppendFormat("return _{0};", pProperty.Name);
                        pBuilder.Unindent();
                    }
                    else
                    {
                        BlockParser.Parse(pProperty.Getter.CodeBlock, pBuilder, pCreator);
                    }

                    pBuilder.AppendLine();
                    pBuilder.AppendLine("}");
                    pBuilder.AppendLine();
                }
            }

            if (pProperty.Setter == null)
            {
                return;
            }

            if (isStandardGetSet)              //Setter
//base is flash, use standard setter/getter
            {
                pBuilder.AppendFormat("{0}function set {1}(value:{2}):void{3}",
                                      As3Helpers.ConvertModifiers(pProperty.Setter.Modifiers, _notValidPropertyMod),
                                      pProperty.Name,
                                      type,
                                      isInterface ? ";" : " {"
                                      );
            }
            else
            {
                pBuilder.AppendFormat("{0}function {1}(value:{2}):{2}{3}",
                                      As3Helpers.ConvertModifiers(pProperty.Setter.Modifiers, _notValidPropertyMod),
                                      pProperty.Setter.Name,
                                      type,
                                      isInterface ? ";" : " {"
                                      );
            }

            pBuilder.AppendLine();

            if (!isInterface)
            {
                if (pProperty.IsEmpty)
                {
                    pBuilder.Indent();
                    pBuilder.AppendFormat("_{0} = value;", pProperty.Name);
                    pBuilder.AppendLine();
                    pBuilder.Append("return value;");
                    pBuilder.Unindent();
                }
                else
                {
                    BlockParser.InsideSetter = !isStandardGetSet;
                    BlockParser.Parse(pProperty.Setter.CodeBlock, pBuilder, pCreator);
                    BlockParser.InsideSetter = false;
                    if (!isStandardGetSet)
                    {
                        pBuilder.AppendLine("	return value;");
                    }
                }

                pBuilder.AppendLine();
                pBuilder.AppendLine("}");
            }

            pBuilder.AppendLine();
        }