예제 #1
0
        public static void Parse(TheVariable pVariable, CodeBuilder pBuilder)
        {
            foreach (Variable declarator in pVariable.Variables)
            {
                StringBuilder sb = new StringBuilder();

                sb.AppendFormat("{0}var {1}:{2}",
                                As3Helpers.ConvertModifiers(pVariable.Modifiers, _notValidVariableMod),
                                declarator.Name,
                                As3Helpers.Convert(declarator.ReturnType)
                                );

                if (declarator.Initializer == null)
                {
                    sb.Append(";");
                }
                else
                {
                    sb.AppendFormat(" = {0};", declarator.Initializer.Value);
                }

                pBuilder.Append(sb.ToString());
                pBuilder.AppendLine();
            }
        }
예제 #2
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();
        }
예제 #3
0
        private static void parseLocalVariable(CsStatement pStatement, CodeBuilder pSb, FactoryExpressionCreator pCreator)
        {
            CsDeclarationStatement declarationStatement = (CsDeclarationStatement)pStatement;

            CsLocalVariableDeclaration localVariableDeclaration = declarationStatement.declaration as CsLocalVariableDeclaration;

            if (localVariableDeclaration == null)
            {
                parseLocalConstantDeclaration(pStatement, pSb, pCreator);
                return;
            }

            foreach (var declarator in localVariableDeclaration.declarators)
            {
                StringBuilder sb = new StringBuilder();

                sb.AppendFormat("var {0}:{1}",
                                declarator.identifier.identifier,
                                As3Helpers.Convert(Helpers.GetType(localVariableDeclaration.type))
                                );

                if (declarator.initializer == null)
                {
                    sb.Append(";");
                }
                else
                {
                    sb.AppendFormat(" = {0};", parseNode(declarator.initializer, pCreator));
                }

                pSb.Append(sb.ToString());
                pSb.AppendLine();
            }
        }
예제 #4
0
        private static void parseUsingStatement(CsStatement pArg1, CodeBuilder pSb, FactoryExpressionCreator pCreator)
        {
            CsUsingStatement           statement   = (CsUsingStatement)pArg1;
            CsLocalVariableDeclaration declaration = statement.resource as CsLocalVariableDeclaration;

            string varname;

            if (declaration == null)
            {
                varname = "$$using$$";
                Expression e = pCreator.Parse(statement.resource);

                pSb.AppendFormat("var {0}:{1} = {2};",
                                 varname,
                                 As3Helpers.Convert(Helpers.GetType(e.Type)),
                                 e.Value
                                 );

                pSb.AppendLine();
            }
            else
            {
                CsLocalVariableDeclarator declarator = declaration.declarators.First.Value;
                StringBuilder             sb         = new StringBuilder();

                sb.AppendFormat("var {0}:{1}",
                                declarator.identifier.identifier,
                                As3Helpers.Convert(Helpers.GetType(declaration.type))
                                );

                varname = declarator.identifier.identifier;

                if (declarator.initializer == null)
                {
                    sb.Append(";");
                }
                else
                {
                    sb.AppendFormat(" = {0};", parseNode(declarator.initializer, pCreator));
                }

                pSb.Append(sb.ToString());
                pSb.AppendLine();
            }

            pSb.Append("try {");
            pSb.AppendLine();

            ParseNode(statement.statement, pSb, pCreator);

            pSb.Append("} finally {");
            pSb.AppendLine();
            pSb.AppendFormat("	if ({0} != null) {0}.Dispose();", varname);
            pSb.AppendLine();

            pSb.Append("}");
            pSb.AppendLine();
            pSb.AppendLine();
        }
예제 #5
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();
        }
예제 #6
0
        public static void Parse(TheConstant pConstant, CodeBuilder pBuilder)
        {
            string modifiers = As3Helpers.ConvertModifiers(pConstant.Modifiers);

            foreach (Constant declarator in pConstant.Constants)
            {
                StringBuilder sb = new StringBuilder();

                sb.AppendFormat(@"{0}const {1}:{2} = {3};",
                                modifiers,
                                declarator.Name,
                                As3Helpers.Convert(declarator.ReturnType),
                                declarator.Initializer.Value
                                );

                pBuilder.Append(sb.ToString());
                pBuilder.AppendLine();
            }
        }
예제 #7
0
        private static void parseLocalConstantDeclaration(CsStatement pStatement, CodeBuilder pSb, FactoryExpressionCreator pCreator)
        {
            CsDeclarationStatement declarationStatement = (CsDeclarationStatement)pStatement;

            CsLocalConstantDeclaration lcd = (CsLocalConstantDeclaration)declarationStatement.declaration;

            foreach (CsLocalConstantDeclarator declarator in lcd.declarators)
            {
                StringBuilder sb = new StringBuilder();

                sb.AppendFormat(@"const {0}:{1} = {2};",
                                declarator.identifier.identifier,
                                As3Helpers.Convert(Helpers.GetType(lcd.type)),
                                pCreator.Parse(declarator.expression).Value
                                );

                pSb.Append(sb.ToString());
                pSb.AppendLine();
            }
        }
예제 #8
0
        private static void parseUsing(IEnumerable <CsUsingDirective> pNn, StringBuilder pStrb)
        {
            if (pNn == null)
            {
                return;
            }

            foreach (CsUsingDirective directive in pNn)
            {
                if (directive is CsUsingNamespaceDirective)
                {
                    string name = As3Helpers.Convert(Helpers.GetType(directive));
                    if (name.StartsWith("flash.Global", StringComparison.Ordinal) ||
                        //name.StartsWith("System", StringComparison.Ordinal) ||
                        name.Equals("flash.", StringComparison.Ordinal))
                    {
                        continue;
                    }

                    pStrb.AppendFormat("import {0}*;", name);
                    pStrb.AppendLine();
                    continue;
                }

                if (directive is CsUsingAliasDirective)
                {
                    string name = As3Helpers.Convert(Helpers.GetType(directive));
                    if (name.StartsWith("flash.Global", StringComparison.Ordinal) || name.Equals("flash.", StringComparison.Ordinal))
                    {
                        continue;
                    }

                    pStrb.AppendFormat("import {0}*;", name);
                    pStrb.AppendLine();
                    continue;
                }

                throw new Exception(@"Unhandled using type");
            }
        }
예제 #9
0
        public static void Parse(TheEvent pEvent, CodeBuilder pBuilder)
        {
            if (pEvent.IsFlashEvent)
            {
                return;
            }

            ImportStatementList.AddImport(@"System.EventHandler");

            bool isStatic = pEvent.Modifiers.Contains("static");

            pBuilder.AppendFormat(@"private {1} var _e{0}:EventHandler;
		{2}{1} function get {0}():EventHandler {{
			if (_e{0} == null) _e{0} = new EventHandler();
			return _e{0};
		}}"        ,
                                  pEvent.Name,
                                  isStatic ? "static" : string.Empty,
                                  As3Helpers.ConvertModifiers(pEvent.Modifiers, _notValidClassMod)
                                  //,isStatic ? pEvent.MyClass.Name : "this"
                                  );

            pBuilder.AppendLine();
        }
예제 #10
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();
        }
예제 #11
0
        public static void Parse(CsInterface pCsInterface, CodeBuilder pBuilder, FactoryExpressionCreator pCreator)
        {
            StringBuilder sb      = new StringBuilder();
            TheClass      myClass = TheClassFactory.Get(pCsInterface, pCreator);

            sb.AppendFormat("{1}interface {0}",
                            myClass.Name,
                            As3Helpers.ConvertModifiers(myClass.Modifiers, _notValidClassMod));

            if (myClass.Implements.Count != 0)
            {
                sb.Append(" extends ");
                foreach (string s in myClass.Implements)
                {
                    sb.Append(As3Helpers.Convert(s));
                    sb.Append(", ");
                }

                sb.Remove(sb.Length - 2, 2);
            }

            sb.Append(" {");
            sb.AppendLine();

            pBuilder.Append(sb.ToString());
            pBuilder.AppendLineAndIndent();

            if (pCsInterface.member_declarations != null)
            {
                foreach (CsNode memberDeclaration in pCsInterface.member_declarations)
                {
                    //if (memberDeclaration is CsConstructor) {
                    //    MethodParser.Parse(myClass.GetConstructor((CsConstructor)memberDeclaration), pBuilder);
                    //} else
                    if (memberDeclaration is CsMethod)
                    {
                        MethodParser.Parse(myClass.GetMethod((CsMethod)memberDeclaration), pBuilder, pCreator);
                    }
                    else if (memberDeclaration is CsIndexer)
                    {
                        IndexerParser.Parse(myClass.GetIndexer((CsIndexer)memberDeclaration), pBuilder, pCreator);
                    }
                    else if (memberDeclaration is CsVariableDeclaration)
                    {
                        VariableParser.Parse(myClass.GetVariable((CsVariableDeclaration)memberDeclaration), pBuilder);
                    }
                    else
                    //if (memberDeclaration is CsConstantDeclaration) {
                    //    ConstantParser.Parse(myClass.GetConstant((CsConstantDeclaration)memberDeclaration), pBuilder);
                    //} else
                    //if (memberDeclaration is CsDelegate) {
                    //    DelegateParser.Parse(myClass.GetDelegate((CsDelegate)memberDeclaration), pBuilder);
                    //} else
                    //if (memberDeclaration is CsEvent) {
                    //    EventParser.Parse(myClass.GetEvent(((CsEvent)memberDeclaration).declarators.First.Value.identifier.identifier),
                    //                      pBuilder);
                    //} else
                    if (memberDeclaration is CsProperty)
                    {
                        PropertyParser.Parse(myClass.GetProperty((CsProperty)memberDeclaration), pBuilder, pCreator);
                        //} else if (memberDeclaration is CsInterface) {
                        //    Parse((CsInterface)memberDeclaration, privateClasses);
                    }
                    else
                    {
                        throw new NotSupportedException();
                    }
                }
            }

            pBuilder.AppendLineAndUnindent("}");
            pBuilder.AppendLineAndUnindent("}");
            pBuilder.AppendLine();
            string imports = ClassParser.getImports();

            pBuilder.Replace(ClassParser.IMPORT_MARKER, imports);
        }
예제 #12
0
        private static void parseForeachStatement(CsStatement pStatement, CodeBuilder pSb, FactoryExpressionCreator pCreator)
        {
            CsForeachStatement fes = (CsForeachStatement)pStatement;

            Expression ex   = pCreator.Parse(fes.expression);
            string     type = As3Helpers.Convert(Helpers.GetType(fes.type));

            pSb.AppendLine();

            TheClass theClass = TheClassFactory.Get(ex.Type, pCreator);

            if (ex.Type.type == cs_entity_type.et_array || ex.IsAs3Generic ||
                (theClass != null && @"System.Array".Equals(theClass.FullName)))                     //foreach
            {
                pSb.AppendFormat("for each(var {0}:{1} in {2}){{",
                                 fes.identifier.identifier,
                                 type,
                                 ex.Value);
                pSb.AppendLine();
            }
            else if (ex.Type.type == cs_entity_type.et_object ||
                     ex.Type.type == cs_entity_type.et_generic_param ||
                     (theClass != null && @"flash.utils.Dictionary".Equals(theClass.FullName)))
            {
                pSb.AppendFormat("for (var {0}:{1} in {2}){{",
                                 fes.identifier.identifier,
                                 type,
                                 ex.Value);

                pSb.AppendLine();
                if (ex.Type.type == cs_entity_type.et_object)
                {
                    pSb.AppendFormat("	if (!{1}.hasOwnProperty({0})) continue;",
                                     fes.identifier.identifier,
                                     ex.Value
                                     );
                }

                pSb.AppendLine();
            }
            else
            {
                _enumCount++;
                //TheClass theClass = TheClassFactory.Get(fes.expression.entity_typeref);

                string enumName = String.Format(@"__ie{0}", _enumCount);
                pSb.AppendFormat("var {0}:IEnumerator = {1}.GetEnumerator();", enumName, ex.Value);
                pSb.AppendLine();
                pSb.AppendFormat("while ({0}.MoveNext()){{", enumName);
                pSb.AppendLine();

                pSb.AppendFormat("\tvar {1}:{2} = {0}.get_Current() as {2};",
                                 enumName,
                                 fes.identifier.identifier,
                                 type
                                 );

                pSb.AppendLine();
            }

            ParseNode(fes.statement, pSb, pCreator);
            pSb.AppendLine("}");
            pSb.AppendLine();
        }
예제 #13
0
        private static void parseForStatement(CsStatement pStatement, CodeBuilder pSb, FactoryExpressionCreator pCreator)
        {
            CsForStatement forStatement = (CsForStatement)pStatement;

            StringBuilder sb = new StringBuilder("for (");

            CsLocalVariableDeclaration localVariableDeclaration = forStatement.initializer as CsLocalVariableDeclaration;
            CsStatementExpressionList  expressionList;

            if (localVariableDeclaration == null)
            {
                expressionList = forStatement.initializer as CsStatementExpressionList;
                foreach (CsExpression expression in expressionList.expressions)
                {
                    Expression ex = pCreator.Parse(expression);
                    sb.Append(ex.Value);
                    sb.Append(", ");
                }

                sb.Remove(sb.Length - 2, 2);
                sb.Append("; ");
            }
            else if (localVariableDeclaration.declarators.Count > 0)
            {
                sb.Append("var ");
                int count = localVariableDeclaration.declarators.Count;
                int now   = 0;

                foreach (CsLocalVariableDeclarator declarator in localVariableDeclaration.declarators)
                {
                    sb.AppendFormat("{0}:{1}",
                                    declarator.identifier.identifier,
                                    As3Helpers.Convert(Helpers.GetType(localVariableDeclaration.type))
                                    );

                    now++;

                    if (declarator.initializer != null)
                    {
                        sb.AppendFormat(" = {0}", parseNode(declarator.initializer, pCreator));
                    }

                    if (now < count)
                    {
                        sb.Append(", ");
                    }
                }

                sb.Append("; ");
            }

            sb.Append(pCreator.Parse(forStatement.condition).Value);
            sb.Append("; ");

            expressionList = (CsStatementExpressionList)forStatement.iterator;

            if (expressionList != null)
            {
                foreach (CsExpression expression in expressionList.expressions)
                {
                    Expression ex = pCreator.Parse(expression);
                    sb.Append(ex.Value);
                    sb.Append(", ");
                }

                sb.Remove(sb.Length - 2, 2);
            }

            sb.Append("){");
            pSb.AppendLine(sb.ToString());
            ParseNode(forStatement.statement, pSb, pCreator);
            pSb.AppendLine("}");
            pSb.AppendLine();
        }
예제 #14
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();
        }
예제 #15
0
        public static void Parse(CsClass pCsClass, CodeBuilder pBuilder, FactoryExpressionCreator pCreator)
        {
            ExtensionName = null;

            StringBuilder sb             = new StringBuilder();
            CodeBuilder   privateClasses = new CodeBuilder();

            TheClass myClass = TheClassFactory.Get(pCsClass, pCreator);

            IsMainClass = Helpers.HasAttribute(pCsClass.attributes, "As3MainClassAttribute");
            bool isResource = Helpers.HasAttribute(pCsClass.attributes, "As3EmbedAttribute");

            IsExtension = Helpers.HasAttribute(pCsClass.attributes, "As3ExtensionAttribute");

            if (IsMainClass)
            {
                As3NamespaceParser.MainClassName = myClass.FullName;
                AttributeItem vals = Helpers.GetAttributeValue(pCsClass.attributes, "As3MainClassAttribute", pCreator)[0];
                sb.AppendFormat(@"[SWF(width=""{0}"", height=""{1}"", frameRate=""{2}"", backgroundColor=""{3}"")]",
                                vals.Parameters[0],
                                vals.Parameters[1],
                                vals.Parameters[2],
                                vals.Parameters[3]
                                );
                sb.AppendLine();
                sb.Append("\t");
            }

            if (isResource)
            {
                AttributeItem vals = Helpers.GetAttributeValue(pCsClass.attributes, "As3EmbedAttribute", pCreator)[0];

                string path = vals.Parameters[0] as String;
                if (!string.IsNullOrEmpty(path))
                {
                    path = Path.Combine(Project.Root, path);
                    string ex = Path.GetExtension(path).Substring(1);
                    string mimeType;

                    if (vals.NamedArguments.ContainsKey("mimeType"))
                    {
                        mimeType = vals.NamedArguments["mimeType"].Value;
                    }
                    else
                    {
                        switch (ex)
                        {
                        case @"gif":
                        case @"png":
                        case @"jpg":
                        case @"jpeg":
                        case @"svg":
                            mimeType = "image/" + ex;
                            break;

                        case @"mp3":
                            mimeType = @"audio/mpeg";
                            break;

                        case @"swf":
                            mimeType = @"application/x-shockwave-flash";
                            break;

                        case @"ttf":
                        case @"otf":
                            mimeType = @"application/x-font";
                            break;

                        default:
                            mimeType = @"application/octet-stream";
                            break;
                        }
                    }

                    StringBuilder addParams = new StringBuilder();
                    foreach (var item in vals.NamedArguments.Where(pItem => !pItem.Key.Equals("mimeType")))
                    {
                        addParams.AppendFormat(@", {0}=""{1}""", item.Key, item.Value.Value);
                    }

                    sb.AppendFormat(@"[Embed(source=""{0}"", mimeType=""{1}""{2})]",
                                    path.Replace("\\", "\\\\"),
                                    mimeType,
                                    addParams
                                    );

                    sb.AppendLine();
                    sb.Append("\t");
                }
            }

            if (!IsExtension)
            {
                sb.AppendFormat("{1}class {0}",
                                myClass.Name,
                                As3Helpers.ConvertModifiers(myClass.Modifiers, _notValidClassMod));

                if (myClass.Extends.Count != 0)
                {
                    sb.AppendFormat(" extends {0}", As3Helpers.Convert(myClass.Extends[0]));
                }

                if (myClass.Implements.Count != 0)
                {
                    sb.Append(" implements ");
                    foreach (string s in myClass.Implements)
                    {
                        sb.Append(As3Helpers.Convert(s));
                        sb.Append(", ");
                    }

                    sb.Remove(sb.Length - 2, 2);
                }

                sb.Append(" {");
                sb.AppendLine();

                pBuilder.Append(sb.ToString());
                pBuilder.AppendLineAndIndent();
            }

            if (IsMainClass)
            {
                ImportStatementList.List.Add("flash.events.Event");
                pBuilder.AppendFormat(
                    @"public function {0}() {{
			if (stage) $ctor();
			else addEventListener(Event.ADDED_TO_STAGE, __loaded);
		}}

		private function __loaded(e:Event = null):void {{
			removeEventListener(Event.ADDED_TO_STAGE, __loaded);
			$ctor();
		}}
",
                    myClass.Name);
                pBuilder.AppendLine();
            }

            if (pCsClass.member_declarations != null)
            {
                if (!myClass.IsPrivate)
                {
                    ImportStatementList.List.Add(myClass.NameSpace + ".*");
                }

                foreach (CsNode memberDeclaration in pCsClass.member_declarations)
                {
                    if (memberDeclaration is CsConstructor)
                    {
                        MethodParser.Parse(myClass.GetConstructor((CsConstructor)memberDeclaration), pBuilder, pCreator);
                    }
                    else if (memberDeclaration is CsMethod)
                    {
                        MethodParser.Parse(myClass.GetMethod((CsMethod)memberDeclaration), pBuilder, pCreator);
                        if (IsExtension && string.IsNullOrEmpty(ExtensionName))
                        {
                            ExtensionName = ((CsMethod)memberDeclaration).identifier.identifier;
                        }
                    }
                    else if (memberDeclaration is CsIndexer)
                    {
                        IndexerParser.Parse(myClass.GetIndexer((CsIndexer)memberDeclaration), pBuilder, pCreator);
                    }
                    else if (memberDeclaration is CsVariableDeclaration)
                    {
                        VariableParser.Parse(myClass.GetVariable((CsVariableDeclaration)memberDeclaration), pBuilder);
                    }
                    else if (memberDeclaration is CsConstantDeclaration)
                    {
                        ConstantParser.Parse(myClass.GetConstant((CsConstantDeclaration)memberDeclaration), pBuilder);
                    }
                    else if (memberDeclaration is CsDelegate)
                    {
                        DelegateParser.Parse(myClass.GetDelegate((CsDelegate)memberDeclaration), pBuilder);
                    }
                    else if (memberDeclaration is CsEvent)
                    {
                        EventParser.Parse(myClass.GetEvent(((CsEvent)memberDeclaration).declarators.First.Value.identifier.identifier), pBuilder);
                    }
                    else if (memberDeclaration is CsProperty)
                    {
                        PropertyParser.Parse(myClass.GetProperty((CsProperty)memberDeclaration), pBuilder, pCreator);
                    }
                    else if (memberDeclaration is CsClass)
                    {
                        Parse((CsClass)memberDeclaration, privateClasses, pCreator);
                    }
                    else
                    {
                        throw new NotSupportedException();
                    }
                }
            }

            string imports = getImports();

            pBuilder.Replace(IMPORT_MARKER, imports);

            pBuilder.AppendLineAndUnindent("}");

            if (IsExtension)
            {
                return;
            }

            if (!myClass.IsPrivate)
            {
                pBuilder.AppendLineAndUnindent("}");
            }

            if (privateClasses.Length == 0)
            {
                return;
            }

            pBuilder.AppendLine();
            pBuilder.Append(As3NamespaceParser.Using);
            pBuilder.AppendLine(imports);
            pBuilder.Append(privateClasses);
        }