Esempio n. 1
0
 public YuiCodeGenerator()
 {
     Context = new AssemblyContext();
     Assembly = new Assembly
     {
         Usings = new List<string> 
             { 
                 "System",
                 "System.Collections.Generic",
             }
     };
     Context.Assemblies.Add(Assembly);
     var asm = new Assembly
     {
         Classes = new List<Class>
         {
             new Class{Name="void"},
             new Class{Name="object"},
             new Class{Name="bool"},
             new Class{Name="string"},
             new Class{Name="int"},
             new Class{Name="Function", IsDelegate=true},
         }
     };
     Context.Assemblies.Add(asm);
     ObjectClass = Context.GetClass("object");
 }
Esempio n. 2
0
        private static void InitAssemlyContext()
        {
            Assembly = new Assembly
            {
                Usings = new List<string> 
                { 
                    "SharpKit.JavaScript",
             }
            };
            Context = new AssemblyContext
            {
                ClassMappings = new Dictionary<string, string>
                {
                    {"object", "object"},
                    {"Object", "object"},
                    {"Element", "Ext.dom.Element"},
                    {"Ext.Element", "Ext.dom.Element"},
                    {"Ext.core.Element", "Ext.dom.Element"},
                    {"Ext.dom.ElementLoader", "Ext.ElementLoader"},
                    {"Ext.ux.form.FileUploadField","Ext.form.field.File"},
                    {"HTMLElement", "Ext.dom.Element"},
                    {"Function", "System.Delegate"},
                    {"Array", "JsArray"},
                    {"String", "JsString"},
                    {"string", "JsString"},
                    {"Boolean", "bool"},
                    {"Boolan", "bool"},
                    {"boolean", "bool"},
                    {"Float", "JsNumber"},
                    {"integer", "JsNumber"},
                    {"Number", "JsNumber"},
                    {"number", "JsNumber"},
                    {"int", "JsNumber"},
                    {"Date", "JsDate"},
                    {"RegExp", "JsRegExp"},
                    {"Mixed", "JsObject"},
                    {"Ext.fx.target", "Ext.fx.target.Target"},
                    {"Ext", "Ext.ExtContext"},
                    {"Ext.Container", "Ext.container.Container"},
                    {"Container", "Ext.container.Container"},
                    {"Mixed component", "JsObject"},
                    {"Ext.TabBar", "Ext.tab.Bar"},
                    {"Component", "Ext.Component"},
                    {"Region", "Ext.util.Region"},
                    {"ResizeTracker", "Ext.resizer.ResizeTracker"},
                    {"Regexp", "JsRegExp"},
                    {"Menu", "Ext.menu.Menu"},
                    {"Store", "Ext.data.Store"},
                    {"CompositeElement", "Ext.dom.CompositeElement"},
                    {"Ext.CompositeElement", "Ext.dom.CompositeElement"},
                    {"Label", "Ext.form.Label"},
                    {"Model", "Ext.data.Model"},
                    {"Ext.grid.Grid", "Ext.grid.property.Grid"},
                    //{"*", "JsObject"},
                    {"ColorPicker", "Ext.menu.ColorPicker"},
                    {"MultiSlider", "Ext.slider.Multi"},
                    {"XMLElement", "JsObject"},
                    {"CSSStyleSheet", "JsObject"},
                    {"CSSStyleRule", "JsObject"},
                  }
            };
            Context.Assemblies.Add( Assembly );
            var asm = new Assembly
            {
                Classes = new List<Class>
                {
                    new Class{Name="void"},
                    new Class{Name="object"},
                    new Class{Name="object"},
                    new Class{Name="JsObject"},
                    new Class{Name="JsArray"},
                    new Class{Name="JsArray`1"},
                    new Class{Name="JsDate"},
                    new Class{Name="JsRegExp"},
                    new Class{Name="JsFunc`1`1"},
                    new Class{Name="JsFunc`1`2"},
                    new Class{Name="JsFunc`1`3"},
                    new Class{Name="JsFunc`1`4"},
                    new Class{Name="JsAction"},
                    new Class{Name="JsAction`1"},
                    new Class{Name="JsAction`2"},
                    new Class{Name="JsAction`3"},
                    new Class{Name="JsAction`4"},
                    new Class{Name="bool"},
                    new Class{Name="JsString"},
                    new Class{Name="JsNumber"},
                    new Class{Name="JsContext"},
                    new Class{Name="Delegate", FullName = "System.Delegate"},
               }
            };
            Context.Assemblies.Add( asm );
            ObjectClass = Context.GetClass( "object" );
            VoidClass = Context.GetClass( "void" );

        }
        static void Generate(string[] args)
        {
            var dir = @"D:\Projects\JsParser\SharpKit.ExtJs4.Generator\output\";

            foreach (var filename in Directory.GetFiles(dir, "*.js"))
            {

                var code = File.ReadAllText(filename);
                var code2 = code.SubstringBetween(code.IndexOf("(") + 1, code.LastIndexOf(");"));
                var obj = new JavaScriptSerializer().Deserialize(code2, null) as Dictionary<string, object>;
                //var obj2 = new JavaScriptSerializer().Deserialize(code2, null) as Dictionary<string, object>;

                Assembly = new Assembly
                {
                    Usings = new List<string> 
                { 
                    "System",
                    "System.Collections.Generic",

                }
                };
                Context = new AssemblyContext
                {
                    //    ClassMappings = new Dictionary<string, string>
                    //{
                    //    {"Object", "object"},
                    //    {"Element", "Ext.Element"},
                    //    {"HTMLElement", "HtmlElement"},
                    //    {"Function", "JsAction"},
                    //    {"Array", "JsArray"},
                    //    {"String", "JsString"},
                    //    {"string", "JsString"},
                    //    {"Boolean", "bool"},
                    //    {"Number", "JsNumber"},
                    //    {"int", "JsNumber"},
                    //    {"Date", "JsDate"},
                    //    {"RegExp", "JsRegExp"},
                    //}
                };
                Context.Assemblies.Add(Assembly);
                var asm = new Assembly
                {
                    Classes = new List<Class>
                {
                    new Class{Name="void"},
                    new Class{Name="object"},
                    //new Class{Name="JsObject"},
                    //new Class{Name="HtmlElement"},
                    //new Class{Name="JsArray"},
                    //new Class{Name="JsAction"},
                    new Class{Name="bool"},
                    new Class{Name="string"},
                    new Class{Name="int"},
                }
                };
                Context.Assemblies.Add(asm);
                ObjectClass = Context.GetClass("object");


                var ce = GenerateClass(obj);
                var i = 0;
                Assembly.Classes.Where(t => t.Name.IsNullOrEmpty()).ForEach(t => t.Name = "Class" + i++);

                Assembly.Classes.ForEach(x =>
                {
                    var doubles = Assembly.Classes.Where(y => x != y && x.Members.TrueForAllTwice(y.Members, (mx, my) => mx.Name == my.Name)).ToList();
                    if (doubles.Count > 0)
                    {
                    }
                });

                var writer = new StringWriter();
                new CodeModelExporter { Assembly = Assembly, Writer = new IndentedTextWriter(writer) }.Export();
                //var block = new JsParser().Parse(code);
                File.WriteAllText("output.cs", writer.GetStringBuilder().ToString());
                return;
            }

        }