Exemple #1
0
        static JMemberExpression JName2(IProperty pe)
        {
            var name = pe.Name;
            var att  = pe.GetMetadata <JPropertyAttribute>();

            if (att != null && att.Name != null)
            {
                name = att.Name;
            }
            else if (JMeta.IsNativeField(pe))
            {
                name = name.ToJavaNaming();
            }

            return(J.Member(JCodeImporter.JsIdentifier(name)));
        }
        protected JBlock ExportMethodBody(IMethod me)
        {
            if (me.DeclaringTypeDefinition.IsInterface())
            {
                return(null);
            }
            if (CompilerConfig.Current.EnableLogging)
            {
                Log.Debug("JsTypeImporter: Visit Method: " + me.ToString());
            }
            var nativeCode = JMeta.GetNativeCode(me);

            if (nativeCode != null)
            {
                var block = J.Block().Add(J.Code(nativeCode).Statement()); //TODO: double semicolon?
                var x     = block.ToJs();
                return(block);
            }
            var def = me.GetDefinition();

            if (def == null || def.IsNull)
            {
                if (me.DeclaringTypeDefinition.IsDelegate())
                {
                    var block = J.Block();
                    if (!me.ReturnType.IsVoid())
                    {
                        block.Add(J.Return(J.Null()));
                    }
                    return(block);
                }
                if (me.IsAutomaticEventAccessor())
                {
                    if (me.IsEventAddAccessor())
                    {
                        var node = GenerateAutomaticEventAccessor((IEvent)me.GetOwner(), false);
                        return(node.Block);
                    }
                    else if (me.IsEventRemoveAccessor())
                    {
                        var node = GenerateAutomaticEventAccessor((IEvent)me.GetOwner(), true);
                        return(node.Block);
                    }
                }
                else if (me.IsAutomaticPropertyAccessor())
                {
                    var bf = J.Member(JNaming.JName(me.AccessorOwner).ToJavaNaming());
                    if (!me.IsStatic)
                    {
                        bf.PreviousMember = J.This();
                    }
                    else if (!JMeta.IsGlobalMethod(me))
                    {
                        bf.PreviousMember = JNaming.JAccess(me.DeclaringType);
                    }
                    if (me.IsGetter())
                    {
                        return(J.Block().Add(J.Return(bf)));
                    }
                    else
                    {
                        return(J.Block().Add(bf.Assign(J.Member("value")).Statement()));
                    }
                }
                return(null);
            }
            var block2 = (JBlock)JsCodeImporter.Visit(def);

            if (def.Descendants.OfType <YieldReturnStatement>().FirstOrDefault() != null)
            {
                if (!JsCodeImporter.SupportClrYield)
                {
                    if (block2.Statements == null)
                    {
                        block2.Statements = new List <JStatement>();
                    }
                    var arg      = me.ReturnType.TypeArguments[0].JAccess();
                    var listType = J.Members("java.util.ArrayList").AddGenericArg(arg);
                    var yieldVar = J.Var("$yield", listType, J.New(listType)).Statement();
                    block2.Statements.Insert(0, yieldVar);
                    block2.Statements.Add(JCodeImporter.GenerateYieldReturnStatement(me));
                }
            }
            return(block2);
        }