コード例 #1
0
        public static JAssignmentExpression Assign(this JExpression me, JExpression exp2)
        {
            var node = new JAssignmentExpression {
                Left = me, Right = exp2
            };

            return(node);
        }
コード例 #2
0
        public static JNewAnonymousClassExpression NewAnonymousType(JExpression type)
        {
            var x = New(type);

            return(new JNewAnonymousClassExpression {
                Type = x.Type, Invocation = x.Invocation
            });
        }
コード例 #3
0
 public static JJsonNameValue JsonNameValue(string name, JExpression value)
 {
     return(new JJsonNameValue {
         Name = new JJsonMember {
             Name = name
         }, Value = value
     });
 }
コード例 #4
0
 /// <summary>
 /// MyFunction(prm1, prm2) -> MyFunction.call(context, prm1, prm2)
 /// </summary>
 /// <param name="node"></param>
 /// <param name="context"></param>
 /// <returns></returns>
 public static void ToCallWithContext(JInvocationExpression node, JExpression context)
 {
     node.Member = node.Member.Member("call");
     if (node.Arguments == null)
     {
         node.Arguments = new List <JExpression>();
     }
     node.Arguments.Insert(0, J.This());
 }
コード例 #5
0
 public static JExpression NewArray(IType type, JExpression size, JExpression[] items)
 {
     if (items == null)
     {
         items = new JExpression[0];
     }
     return(new JNewArrayExpression {
         Type = type.JAccess(), Size = size, Items = items.ToList()
     });
 }
コード例 #6
0
 public static JStatement Statement(this JExpression exp)
 {
     if (exp != null && exp is JVariableDeclarationExpression)
     {
         return(((JVariableDeclarationExpression)exp).Statement());//new JsVariableDeclarationStatement { Declaration =  };
     }
     return(new JExpressionStatement {
         Expression = exp
     });
 }
コード例 #7
0
        void YieldReturnInCurrentStep(JExpression item)
        {
            var result    = J.Value(true);
            var stepIndex = Steps.Count - 1;

            AddToCurrentStep(J.This().Member("_current").Assign(item).Statement());
            AddToCurrentStep(_state().Assign(J.Value(stepIndex + 1)).Statement());
            AddToCurrentStep(J.Member("result").Assign(result).Statement());
            AddToCurrentStep(J.Return(result));
        }
コード例 #8
0
        public static JInvocationExpression InvokeWithContextIfNeeded(this JExpression me, JExpression context, params JExpression[] prms)
        {
            if (context == null)
            {
                return(me.Invoke(prms));
            }
            var prms2 = prms.ToList();

            prms2.Insert(0, context);
            return(me.Member("call").Invoke(prms2.ToArray()));
        }
コード例 #9
0
        public static JInvocationExpression Invoke(this JExpression me, params JExpression[] prms)
        {
            var x = new JInvocationExpression {
                Member = me, Arguments = prms == null ? null : prms.ToList()
            };
            var me2 = me as JMemberExpression;

            if (me2 != null)
            {
                x.Method = me2.Member as IMethod;
            }
            return(x);
        }
コード例 #10
0
ファイル: JCodeImporter.cs プロジェクト: wangchengqun/Cs2Java
 JExpression CreateAnonymousJsDelegate(JExpression instanceContext, JExpression func)
 {
     if (instanceContext == null)
     {
         return(func);
     }
     return(new JInvocationExpression {
         Member = new JMemberExpression {
             Name = "$CreateAnonymousDelegate"
         }, Arguments = new List <JExpression> {
             instanceContext, func
         }
     });
 }
コード例 #11
0
ファイル: JCodeImporter.cs プロジェクト: wangchengqun/Cs2Java
 JExpression CreateJsExtensionDelegate(JExpression prm1, JExpression func)
 {
     if (prm1 == null)
     {
         return(func);
     }
     return(new JInvocationExpression {
         Member = new JMemberExpression {
             Name = "$CreateExtensionDelegate"
         }, Arguments = new List <JExpression> {
             prm1, func
         }
     });
 }
コード例 #12
0
 public static JSwitchStatement Case(this JSwitchStatement node, JExpression value, List <JStatement> statements)
 {
     if (node.Sections == null)
     {
         node.Sections = new List <JSwitchSection>();
     }
     node.Sections.Add(new JSwitchSection {
         Labels = new List <JSwitchLabel> {
             new JSwitchLabel {
                 Expression = value
             }
         }, Statements = statements
     });
     return(node);
 }
コード例 #13
0
        public JNode VisitArrayCreateResolveResult(ArrayCreateResolveResult res)
        {
            JExpression[] items = null;
            JExpression   size  = null;

            if (res.InitializerElements.IsNotNullOrEmpty())
            {
                items = VisitExpressions(res.InitializerElements).ToArray();
            }
            else if (res.SizeArguments.IsNotNullOrEmpty())
            {
                size = VisitExpression(res.SizeArguments.Single());
            }

            return(J.NewArray(res.Type, size, items));
        }
コード例 #14
0
ファイル: JTypeImporter.cs プロジェクト: wangchengqun/Cs2Java
        public virtual List <JEntityDeclaration> _VisitField(IField fld)
        {
            var         init2       = GetCreateFieldInitializer(fld);
            JExpression initializer = null;

            if (init2 != null)
            {
                initializer = JsCodeImporter.VisitExpression(init2);
            }
            var fe2 = new JFieldDeclaration
            {
                FieldDefinition = fld,
                Initializer     = initializer,
                Type            = fld.Type.JAccess(),
                Name            = JNaming.JName(fld)
            };

            ImportModifiers(fld, fe2);
            return(new List <JEntityDeclaration> {
                fe2
            });
        }
コード例 #15
0
ファイル: JCodeImporter.cs プロジェクト: wangchengqun/Cs2Java
        private JExpression ParenthesizeIfNeeded(ResolveResult res, JExpression exp)
        {
            if (exp is JParenthesizedExpression)
            {
                return(exp);
            }
            var nodes = res.GetNodes();

            if (nodes == null)
            {
                return(exp);
            }
            var cspe = nodes.OfType <ParenthesizedExpression>().FirstOrDefault();

            if (cspe == null)
            {
                return(exp);
            }
            return(new JParenthesizedExpression {
                Expression = exp
            });
        }
コード例 #16
0
 public static JPostUnaryExpression PlusPlus(this JExpression exp)
 {
     return(new JPostUnaryExpression {
         Left = exp, Operator = "++"
     });
 }
コード例 #17
0
 public static JMemberExpression Member(this JExpression member, string name)
 {
     return(new JMemberExpression {
         Name = name, PreviousMember = member
     });
 }
コード例 #18
0
        public JNode VisitMethodGroupResolveResult(MethodGroupResolveResult res)
        {
            var     info = res.GetInfo();
            IMethod me;

            if (info != null && info.Conversion != null && info.Conversion.Method != null)
            {
                me = info.Conversion.Method;
            }
            else //happens when invoking a method with overloads, and a parameter is dynamic
            {
                var list = res.Methods.ToList();
                if (list.Count == 0)
                {
                    throw new Exception("Method group not resolved to any method");
                }
                else if (list.Count == 1)
                {
                    me = list[0];
                }
                else
                {
                    me = list[0];
                }
                //TODO: verify all methods has the same js name
            }
            var         isExtensionMethodStyle = me.IsExtensionMethod && !(res.TargetResult is TypeResolveResult);//TODO: IsExtensionMethodStyle(new CsInvocationExpression { entity = me, expression = node });
            JExpression firstPrm = null;

            if (isExtensionMethodStyle)
            {
                firstPrm = (JExpression)Visit(res.TargetResult);
            }
            var         node2 = JNaming.JAccess(me);
            JExpression node3;
            JExpression instanceContext = null;

            if (me.IsStatic || res.TargetResult == null) //getting ThisResolveResult even on static methods, getting TargetResult=null when MethodGroupResolveResult when using delegates
            {
                node3 = node2;
            }
            else
            {
                instanceContext = VisitExpression(res.TargetResult);
                node3           = instanceContext.Member(node2);
            }
            if (info != null && (instanceContext != null || firstPrm != null))
            {
                var conv = info.Conversion;
                if (info.ConversionTargetType != null && !UseNativeFunctions(info.ConversionTargetType))//delegate type
                {
                    var parentMethod = info.Nodes.FirstOrDefault().GetCurrentMethod();
                    if (parentMethod == null || !JMeta.ForceDelegatesAsNativeFunctions(parentMethod))
                    {
                        if (parentMethod == null)
                        {
                            Log.Warn(info.Nodes.FirstOrDefault(), "GetParentMethod() returned null");
                        }
                        var func = (JExpression)node2;
                        if (instanceContext != null)
                        {
                            node3 = CreateJsDelegate(instanceContext, func);
                        }
                        else if (firstPrm != null)
                        {
                            node3 = CreateJsExtensionDelegate(firstPrm, func);
                        }
                    }
                }
            }
            return(node3);
        }
コード例 #19
0
ファイル: JWriter.cs プロジェクト: wangchengqun/Cs2Java
 public void VisitExpression(JExpression node)
 {
 }
コード例 #20
0
 public static JBinaryExpression InstanceOf(this JExpression exp, JExpression exp2)
 {
     return(new JBinaryExpression {
         Left = exp, Operator = "instanceof", Right = exp2
     });
 }
コード例 #21
0
 public static JMemberExpression Member(this JExpression member, JMemberExpression exp)
 {
     exp.PreviousMember = member;
     return(exp);
 }
コード例 #22
0
 public static JCastExpression Cast(JExpression exp, JMemberExpression type)
 {
     return(new JCastExpression {
         Expression = exp, Type = type
     });
 }
コード例 #23
0
 public static JBinaryExpression NotEqual(this JExpression exp, JExpression exp2)
 {
     return(new JBinaryExpression {
         Left = exp, Operator = "!=", Right = exp2
     });
 }
コード例 #24
0
 public static JWhileStatement While(JExpression condition, JStatement statement = null)
 {
     return(new JWhileStatement {
         Condition = condition, Statement = statement
     });
 }
コード例 #25
0
 public static JExpression Conditional(this JExpression condition, JExpression trueExp, JExpression falseExp)
 {
     return(new JConditionalExpression {
         Condition = condition, TrueExpression = trueExp, FalseExpression = falseExp
     });
 }
コード例 #26
0
 public static JBinaryExpression BitwiseOr(this JExpression exp, JExpression exp2)
 {
     return(new JBinaryExpression {
         Left = exp, Operator = "|", Right = exp2
     });
 }
コード例 #27
0
 public static JParenthesizedExpression Parentheses(this JExpression exp)
 {
     return(new JParenthesizedExpression {
         Expression = exp
     });
 }
コード例 #28
0
 public static JPostUnaryExpression MinusMinus(this JExpression exp)
 {
     return(new JPostUnaryExpression {
         Left = exp, Operator = "--"
     });
 }
コード例 #29
0
 public static JBinaryExpression GreaterThan(this JExpression exp, JExpression exp2)
 {
     return(new JBinaryExpression {
         Left = exp, Operator = ">", Right = exp2
     });
 }
コード例 #30
0
 public static JBinaryExpression LessThanOrEqualTo(this JExpression exp, JExpression exp2)
 {
     return(new JBinaryExpression {
         Left = exp, Operator = "<=", Right = exp2
     });
 }