Ejemplo n.º 1
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);
        }
Ejemplo n.º 2
0
        public void Parse(CsNamespace pNameSpace, IEnumerable <CsUsingDirective> pUsing, string pOutputFolder)
        {
            if (pNameSpace == null)
            {
                return;
            }

            _outputFolder = pOutputFolder;
            string name    = getNamespace(pNameSpace);
            string packDir = pOutputFolder + name.Replace('.', '\\');

            Directory.CreateDirectory(packDir);
            CodeBuilder builder = new CodeBuilder();

            foreach (CsNode cn in pNameSpace.member_declarations)
            {
                builder.Append("package ");

                builder.Append(name);
                builder.AppendLineAndIndent(" {");

                StringBuilder usings = new StringBuilder();

                parseUsing(pUsing, usings);
                parseUsing(pNameSpace.using_directives, usings);
                Using = usings.ToString();

                builder.Append(usings);

                builder.AppendLine(ClassParser.IMPORT_MARKER);
                ImportStatementList.Init();

                CsClass csClass = cn as CsClass;

                if (csClass != null)
                {
                    ClassParser.Parse(csClass, builder, _creator);
                    if (ClassParser.IsExtension)
                    {
                        File.WriteAllText(packDir + "\\" + ClassParser.ExtensionName + ".as", builder.ToString());
                    }
                    else
                    {
                        File.WriteAllText(packDir + "\\" + csClass.identifier.identifier + ".as", builder.ToString());
                    }

                    builder.Length = 0;
                    continue;
                }

                CsInterface csInterface = cn as CsInterface;
                if (csInterface != null)
                {
                    InterfaceParser.Parse(csInterface, builder, _creator);
                    File.WriteAllText(packDir + "\\" + csInterface.identifier.identifier + ".as", builder.ToString());
                    builder.Length = 0;
                    continue;
                }

                if (csClass == null)
                {
                    throw new Exception("Unknown type");
                }
            }
        }