/// <summary>
		/// Create a Class pattern
		/// Established the namespace (Ext.ns)
		/// Extends the base class (Ext.extend)
		/// </summary>
		/// <param name="className">the name (including namespace) for the new class</param>
		/// <param name="baseClass">the class this inherits from</param>
		/// <param name="parameters">The parameters for the constructor function</param>
		/// <param name="constructor">the constructor code</param>
        public ExtJsClass(object className, object baseClass, JsParameters parameters, JsBlock constructor)
			: base()
        {
            ClassName = className;
            BaseClass = baseClass;
			Parameters = parameters;
			Constructor = constructor;
		}
 public virtual void Visit(JsBlock node)
 {
     if (node != null)
     {
         foreach (var childNode in node.Children)
         {
             childNode.Accept(this);
         }
     }
 }
Example #3
0
 public static void Ctor(IMethod method, JsBlock code)
 {
 }
Example #4
0
        protected JsBlock ExportConstructorBody(IMethod ctor)
        {
            var            ctorNode = (ConstructorDeclaration)ctor.GetDeclaration();
            BlockStatement ccc      = null;

            if (ctorNode != null)
            {
                ccc = ctorNode.Body;
            }
            //var ccc = ctor.GetDefinition();//.decl as CsConstructor;
            //var ccc = ctor.GetDefinition();
            var block2 = (JsBlock)AstNodeConverter.Visit(ccc);

            if (block2 == null)
            {
                block2 = new JsBlock {
                    Statements = new List <JsStatement>()
                }
            }
            ;
            var ce          = ctor.GetDeclaringTypeDefinition();
            var isClr       = Sk.IsClrType(ce);
            var isPrototype = Sk.IsNativeType(ce);
            var statements  = new List <JsStatement>();

            //instance fields initializations
            if (!Sk.InlineFields(ce))
            {
                var isGlobal = Sk.IsGlobalType(ce);
                var fields   = GetExportedDeclaredAndGeneratedFields(ce, ctor.IsStatic);
                //var fields = ctor.GetDeclaringTypeDefinition().GetFields(null, GetMemberOptions.IgnoreInheritedMembers).Where(t => t.IsStatic() == ctor.IsStatic).ToList();
                //fields = fields.Where(ShouldExportField).ToList();
                //fields.AddRange(GeneratePropertyFields(ctor.DeclaringTypeDefinition, ctor.IsStatic));

                //var props = ctor.GetDeclaringTypeDefinition().GetProperties(null, GetMemberOptions.IgnoreInheritedMembers).Where(t => t.IsStatic() == ctor.IsStatic).ToList();
                //props = props.Where(t=>Sk.IsNativeField(t)).ToList();
                //props = props.Where(t => Sk.IsJsExported(t)).ToList();
                //var fieldsAndProperties = fields.Cast<IEntity>().Concat(props.Cast<IEntity>());
                var initializers = fields.Select(fe => ExportInitializer(fe, null, isGlobal, false)).Cast <JsStatement>().ToList();
                if (initializers.Contains(null))
                {
                    Log.Warn("Some field initializers were not exported");
                }
                statements.AddRange(initializers.Where(t => t != null));
            }

            if (!ctor.IsStatic)
            {
                //base/this ctor invocation
                var invocation = GetConstructorBaseOrThisInvocation2(ctor);
                if (invocation != null)
                {
                    var baseThisCe      = invocation.Member.DeclaringType;
                    var isBaseClr       = Sk.IsClrType(baseThisCe.GetDefinition());
                    var isBasePrototype = Sk.IsNativeType(baseThisCe.GetDefinition()) && !Sk.IsJsonMode(baseThisCe.GetDefinition()) && !Sk.IsGlobalType(baseThisCe.GetDefinition()); //happens when prototype inherits from json
                    if (isBaseClr == isClr && isBasePrototype == isPrototype)                                                                                                        //base and derived are both prototype, or both are clr
                    {
                        var newObjExp2 = AstNodeConverter.VisitExpression(invocation);
                        JsInvocationExpression invocation2;
                        if (newObjExp2 is JsNewObjectExpression)
                        {
                            var newObjExp = (JsNewObjectExpression)newObjExp2;
                            invocation2 = newObjExp.Invocation;
                        }
                        else if (newObjExp2 is JsInvocationExpression)
                        {
                            invocation2 = (JsInvocationExpression)newObjExp2;
                        }
                        else
                        {
                            throw new Exception("Unexpected node: " + newObjExp2);
                        }
                        if (Sk.IsExtJsType(ce))
                        {
                            var invocation3 = Js.This().Member("callParent").Invoke();
                            if (invocation2.Arguments.IsNotNullOrEmpty())
                            {
                                invocation3.Arguments = new List <JsExpression> {
                                    Js.NewJsonArray(invocation2.Arguments.NotNull().ToArray())
                                }
                            }
                            ;
                            statements.Add(invocation3.Statement());
                        }
                        else
                        {
                            JsRefactorer.ToCallWithContext(invocation2, new JsThis());
                            statements.Add(invocation2.Statement());
                        }
                    }
                }
            }
            if (block2.Statements == null)
            {
                block2.Statements = new List <JsStatement>();
            }
            block2.Statements.InsertRange(0, statements);

            return(block2);
        }

        void ExportConstructorParameters(IMethod ctor, JsFunction func)
        {
            var ce   = ctor.GetDeclaringTypeDefinition();
            var list = new List <string>();

            if (!Sk.IgnoreTypeArguments(ce))
            {
                //danel
                var gprms = ce.TypeParameters.ToList();//.GetGenericArguments().Where(ga => ga.isGenericParam()).ToList();
                if (gprms.IsNotNullOrEmpty())
                {
                    var i = 0;
                    foreach (var gprm in gprms)
                    {
                        func.Parameters.Add(gprm.Name);
                        if (!ctor.IsStatic && func.Block != null)
                        {
                            func.Block.Statements.Insert(i, Js.This().Member(gprm.Name).Assign(Js.Member(gprm.Name)).Statement());
                            i++;
                        }
                    }
                }
            }
            var prms = ctor.Parameters;

            if (prms != null)
            {
                func.Parameters.AddRange(prms.Select(t => t.Name));
            }
        }
Example #5
0
 public static void get_Length(JsBlock code)
 {
     //TODO: use field instead of "m_value" const
     code.Add("this".Id().Get("m_value").Get("length").Return());
 }
Example #6
0
 public static void ToString(JsBlock code)
 {
     code.Add("String.fromCharCode".Id().Call("this".Id().Get(SpecialFields.BoxValue)).Return());
 }
Example #7
0
        public static void ReferenceEquals(IMethod method, JsBlock code)
        {
            var args = method.JsArgs();

            code.Add(new JsBinaryOperator(args[0], args[1], "===").Return());
        }
Example #8
0
        public static void set_InternalMessage(IMethod method, JsBlock code)
        {
            var value = method.JsArgs()[0];

            code.Add("this.$message".Id().Set(value));
        }
Example #9
0
 public static void ReturnValue(JsBlock code)
 {
     throw new NotImplementedException();
 }
Example #10
0
        public static void op_Inequality(IMethod method, JsBlock code)
        {
            var args = method.JsArgs();

            code.Add(args[0].Op(args[1], "!=").Return());
        }
Example #11
0
 public static void op_Equality(IMethod method, JsBlock code)
 {
     Equals(method, code);
 }
Example #12
0
        public static void op_Implicit(IMethod method, JsBlock code)
        {
            var args = method.JsArgs();

            code.Add(args[0].Return());
        }
Example #13
0
        public static void Equals(IMethod method, JsBlock code)
        {
            var args = method.JsArgs();

            code.Add(args[0].Op(args[1], "==").Return());
        }
Example #14
0
 public static void GetInternalStackTrace(IMethod method, JsBlock code)
 {
     code.Add("".Return());
 }
		public JsBlock CreateBlock(JsFormat format, params object[] lines)
		{
			JsBlock m = new JsBlock(this, lines);
			m.SetFormat(format);
			return m;
		}
Example #16
0
        public static void InitializeArray(IMethod method, JsBlock code)
        {
            var args = method.JsArgs();

            code.Add("$initarr".Id().Call(args).AsStatement());
        }
Example #17
0
 public static void MemberwiseClone(JsBlock code)
 {
     code.Add("$clone".Id().Call("this".Id()).Return());
 }
		/// <summary>
		/// Script Item designed to help construct the class pattern often used in ExtJs
		/// aka pre-configured classes
		/// </summary>
		/// <param name="className">name to give the class</param>
		/// <param name="baseClass">base class to extend</param>
		/// <param name="parameters">constructor parameters</param>
		/// <param name="constructor">constructor script</param>
		/// <returns></returns>
        public static ExtJsClass Class(object className, object baseClass, JsParameters parameters, JsBlock constructor)
		{
			return new ExtJsClass(className, baseClass, parameters, constructor);
		}
Example #19
0
 public static void get_InternalMessage(IMethod method, JsBlock code)
 {
     code.Add("this.$message".Id().Return());
 }