protected Script CreateEmbeddedObjectInstance(PropertyInstance p_embeddedMemberTemplate, Member firstMember, String memberPath)
        {
            PropertyInstance property     = PropertyInstance.FindByTemplate(firstMember.Name, firstMember.RealType, false);
            PropertyInstance p_rootEntity = memberPathSplit == null ? null : EmbeddedTypeVisitor.GetRootEntityProperty(this);

            return(delegate(IMethodVisitor mg2)
            {
                mg2.CallThisSetter(property, delegate(IMethodVisitor mg)
                {
                    // Object p_embeddedMemberTemplate.createEmbeddedObject(Class<?> embeddedType, Class<?> entityType, Object parentObject, String
                    // memberPath)
                    mg.CallThisGetter(p_embeddedMemberTemplate);

                    mg.Push(firstMember.RealType);         // embeddedType

                    if (p_rootEntity != null)
                    {
                        mg.CallThisGetter(p_rootEntity);
                        mg.CheckCast(EntityMetaDataHolderVisitor.m_template_getEntityMetaData.Owner);
                        mg.InvokeInterface(EntityMetaDataHolderVisitor.m_template_getEntityMetaData);
                    }
                    else
                    {
                        mg.CallThisGetter(EntityMetaDataHolderVisitor.m_template_getEntityMetaData);
                    }
                    mg.InvokeInterface(new MethodInstance(null, typeof(IEntityMetaData), typeof(Type), "get_EnhancedType"));
                    mg.LoadThis();         // parentObject
                    mg.Push(memberPath);

                    mg.InvokeVirtual(template_m_createEmbeddedObject);
                    mg.CheckCast(firstMember.RealType);
                });
            });
        }
Example #2
0
        protected PropertyInstance ImplementTargetCache(PropertyInstance p_valueHolderContainerTemplate)
        {
            if (EmbeddedEnhancementHint.HasMemberPath(State.Context))
            {
                PropertyInstance p_rootEntity   = EmbeddedTypeVisitor.GetRootEntityProperty(this);
                PropertyInstance p_targetCache2 = ImplementProperty(p_template_targetCache, delegate(IMethodVisitor mv)
                {
                    Label l_finish = mv.NewLabel();
                    mv.CallThisGetter(p_rootEntity);
                    mv.Dup();
                    mv.IfNull(l_finish);
                    mv.CheckCast(typeof(IValueHolderContainer));
                    mv.InvokeInterface(p_template_targetCache.Getter);
                    mv.Mark(l_finish);
                    mv.ReturnValue();
                }, null);
                return(p_targetCache2);
            }
            ImplementSelfGetter(p_valueHolderContainerTemplate);

            FieldInstance f_targetCache = ImplementField(new FieldInstance(FieldAttributes.Private, "__targetCache", p_template_targetCache.PropertyType));

            PropertyInstance p_targetCache = ImplementProperty(p_template_targetCache, delegate(IMethodVisitor mv)
            {
                mv.GetThisField(f_targetCache);
                mv.ReturnValue();
            }, delegate(IMethodVisitor mv)
            {
                mv.PutThisField(f_targetCache, delegate(IMethodVisitor mv2)
                {
                    mv.LoadArg(0);
                });
                mv.ReturnValue();
            });

            {
                IMethodVisitor mg = VisitMethod(m_template_getCache);
                mg.CallThisGetter(p_targetCache);
                mg.ReturnValue();
                mg.EndMethod();
            }
            {
                IMethodVisitor mg = VisitMethod(m_template_detach);
                mg.CallThisSetter(p_targetCache, delegate(IMethodVisitor mg2)
                {
                    mg2.PushNull();
                });
                mg.ReturnValue();
                mg.EndMethod();
            }
            return(p_targetCache);
        }
Example #3
0
        protected PropertyInstance ImplementNotifyPropertyChangedSource(PropertyInstance p_propertyChangeTemplate,
                                                                        FieldInstance f_propertyChangeSupport)
        {
            MethodInstance m_onPropertyChanged_Values = MethodInstance.FindByTemplate(template_m_onPropertyChanged_Values, true);

            if (m_onPropertyChanged_Values == null)
            {
                IMethodVisitor mv = VisitMethod(template_m_onPropertyChanged_Values);
                mv.CallThisGetter(p_propertyChangeTemplate);
                mv.LoadThis();
                mv.GetThisField(f_propertyChangeSupport);

                // getMethodHandle(sender, propertyName)
                mv.CallThisGetter(p_propertyChangeTemplate);
                mv.LoadThis();
                mv.LoadArg(0);
                mv.InvokeVirtual(m_getMethodHandle);

                mv.LoadArg(1);
                mv.LoadArg(2);
                // firePropertyChange(sender, propertyChangeSupport, property, oldValue, newValue)
                mv.InvokeVirtual(m_firePropertyChange);
                mv.PopIfReturnValue(m_firePropertyChange);
                mv.ReturnVoidOrThis();
                mv.EndMethod();
                m_onPropertyChanged_Values = mv.Method;
            }
            MethodInstance m_onPropertyChanged = MethodInstance.FindByTemplate(template_m_onPropertyChanged, true);

            if (m_onPropertyChanged == null)
            {
                IMethodVisitor mv = VisitMethod(template_m_onPropertyChanged);
                mv.LoadThis();
                mv.LoadArg(0);
                mv.PushNull();
                mv.PushNull();
                mv.InvokeVirtual(m_onPropertyChanged_Values);
                mv.PopIfReturnValue(m_onPropertyChanged_Values);
                mv.ReturnVoidOrThis();
                mv.EndMethod();
                m_onPropertyChanged = mv.Method;
            }
            PropertyInstance p_pceHandlers = PropertyInstance.FindByTemplate(p_propertyChangeSupport, true);

            if (p_pceHandlers == null)
            {
                HideFromDebug(ImplementGetter(p_propertyChangeSupport.Getter, f_propertyChangeSupport));
                p_pceHandlers = PropertyInstance.FindByTemplate(p_propertyChangeSupport, false);
            }
            if (EmbeddedEnhancementHint.HasMemberPath(State.Context))
            {
                PropertyInstance p_parentEntity = EmbeddedTypeVisitor.GetParentObjectProperty(this);
                if (MethodInstance.FindByTemplate(p_parentChildEventHandler.Getter, true) == null)
                {
                    IMethodVisitor mv = VisitMethod(p_parentChildEventHandler.Getter);
                    mv.CallThisGetter(p_parentEntity);
                    mv.InvokeInterface(p_parentChildEventHandler.Getter);
                    mv.ReturnValue();
                    mv.EndMethod();
                    HideFromDebug(mv.Method);
                }
                if (MethodInstance.FindByTemplate(p_collectionEventHandler.Getter, true) == null)
                {
                    IMethodVisitor mv = VisitMethod(p_collectionEventHandler.Getter);
                    mv.CallThisGetter(p_parentEntity);
                    mv.InvokeInterface(p_collectionEventHandler.Getter);
                    mv.ReturnValue();
                    mv.EndMethod();
                    HideFromDebug(mv.Method);
                }
            }
            else
            {
                if (MethodInstance.FindByTemplate(p_parentChildEventHandler.Getter, true) == null)
                {
                    HideFromDebug(ImplementLazyInitProperty(p_parentChildEventHandler, delegate(IMethodVisitor mv)
                    {
                        MethodInstance method = new MethodInstance(null, typeof(NotifyPropertyChangedClassVisitor), typeof(PropertyChangedEventHandler), "CreateParentChildEventHandler", typeof(Object));
                        mv.LoadThis();
                        mv.InvokeStatic(method);
                    }));
                }
                if (MethodInstance.FindByTemplate(p_collectionEventHandler.Getter, true) == null)
                {
                    HideFromDebug(ImplementLazyInitProperty(p_collectionEventHandler, delegate(IMethodVisitor mv)
                    {
                        MethodInstance method = new MethodInstance(null, typeof(NotifyPropertyChangedClassVisitor), typeof(NotifyCollectionChangedEventHandler), "CreateCollectionEventHandler", typeof(Object));
                        mv.LoadThis();
                        mv.InvokeStatic(method);
                    }));
                }
            }

            //MethodAttributes ma = MethodAttributes.Public | MethodAttributes.Virtual | MethodAttributes.HideBySig;
            //{
            //    ConstructorInfo pceaCI = typeof(PropertyChangedEventArgs).GetConstructor(new Type[] { typeof(String) });

            //    MethodBuilder mb = VisitorUtil.DefineMethod(vs, onPropertyChangedMI_string, ma);
            //    ILGenerator gen = mb.GetILGenerator();
            //    gen.Emit(OpCodes.Ldarg_0);
            //    gen.Emit(OpCodes.Ldarg_1);
            //    gen.Emit(OpCodes.Newobj, pceaCI);
            //    gen.Emit(OpCodes.Call, onPropertyChangedMI_pceArg);
            //    gen.Emit(OpCodes.Ret);
            //}
            //{
            //    MethodBuilder mb = VisitorUtil.DefineMethod(vs, onPropertyChangedMI_pceArg, ma);
            //    ILGenerator gen = mb.GetILGenerator();
            //    gen.Emit(OpCodes.Ldarg_0);
            //    gen.Emit(OpCodes.Call, pctPI.GetGetMethod());
            //    gen.Emit(OpCodes.Ldarg_0);
            //    gen.Emit(OpCodes.Ldarg_1);
            //    gen.Emit(OpCodes.Call, FirePropertyChangedMI);
            //    gen.Emit(OpCodes.Ret);
            //}
            //    List<PropertyChangedEventHandler> PropertyChangedEventHandlers { get; }

            //void OnPropertyChanged(String propertyName);

            //void OnPropertyChanged(PropertyChangedEventArgs args);
            return(p_pceHandlers);
        }
Example #4
0
        protected void ImplementRelationGetter(String propertyName, MethodInstance m_getMethod_template, MethodInstance m_setMethod, int relationIndex,
                                               PropertyInstance p_valueHolderContainerTemplate, PropertyInstance p_targetCache, PropertyInstance p_relationMembers, FieldInstance f_initialized,
                                               FieldInstance f_objRefs)
        {
            // public String getPropertyName()
            // {
            // if (!PropertyName$initialized)
            // {
            // setPropertyName(RelationsGetterVisitor.valueHolderContainer_getValue(this, $relationMembers, get__IndexOfPropertyName(), $targetCache, $beanContext,
            // propertyName$objRefs));
            // }
            // return super.getPropertyName();
            // }
            Script script_getVHC;

            if (EmbeddedEnhancementHint.HasMemberPath(State.Context))
            {
                PropertyInstance p_rootEntity = EmbeddedTypeVisitor.GetRootEntityProperty(this);
                script_getVHC = delegate(IMethodVisitor mv)
                {
                    mv.CallThisGetter(p_rootEntity);
                };
            }
            else
            {
                script_getVHC = delegate(IMethodVisitor mv)
                {
                    // this
                    mv.LoadThis();
                };
            }

            MethodInstance m_getMethod;
            {
                PropertyInstance p_cacheModification = SetCacheModificationMethodCreator.GetCacheModificationPI(this);
                MethodInstance   m_getMethod_scoped  = new MethodInstance(State.NewType,
                                                                          MethodAttributes.HideBySig | MethodAttributes.Private | MethodAttributes.Final, NewType.VOID_TYPE, propertyName + "$DoInitialize");
                {
                    IMethodVisitor mg = VisitMethod(m_getMethod_scoped);

                    // this => for this.setPropertyName(...)
                    mg.LoadThis();
                    // call template.getValue(..)
                    mg.CallThisGetter(p_valueHolderContainerTemplate);
                    // getVhc()
                    script_getVHC.Invoke(mg);
                    // $relationMembers
                    mg.CallThisGetter(p_relationMembers);
                    // get__IndexOfPropertyName()
                    mg.Push(relationIndex);
                    // $targetCache
                    mg.CallThisGetter(p_targetCache);
                    // propertyName$objRefs
                    mg.GetThisField(f_objRefs);
                    mg.InvokeVirtual(m_template_getValue);
                    mg.CheckCast(m_setMethod.Parameters[0].Type);
                    mg.InvokeVirtual(m_setMethod);
                    mg.ReturnValue();
                    mg.EndMethod();
                }
                {
                    IMethodVisitor mg = base.VisitMethod(m_getMethod_template);
                    m_getMethod = mg.Method;
                    HideFromDebug(m_getMethod);
                    Label l_initialized = mg.NewLabel();
                    mg.GetThisField(f_initialized);
                    mg.PushEnum(ValueHolderState.INIT);
                    mg.IfCmp(typeof(ValueHolderState), CompareOperator.EQ, l_initialized);

                    SetCacheModificationMethodCreator.CacheModificationInternalUpdate(p_cacheModification, mg,
                                                                                      delegate(IMethodVisitor mv2)
                    {
                        mv2.LoadThis();
                        mv2.InvokeOnExactOwner(m_getMethod_scoped);
                    });

                    mg.Mark(l_initialized);
                    mg.LoadThis();
                    mg.InvokeSuperOfCurrentMethod();
                    mg.ReturnValue();
                    mg.EndMethod();
                }
            }

            // public String getPropertyName$NoInit()
            // {
            // return super.getPropertyName();
            // }
            {
                MethodInstance   m_getNoInit = m_getMethod_template.DeriveName(ValueHolderIEC.GetGetterNameOfRelationPropertyWithNoInit(propertyName));
                IMethodVisitor   mg          = base.VisitMethod(m_getNoInit);
                PropertyInstance p_getNoInit = PropertyInstance.FindByTemplate(propertyName + ValueHolderIEC.GetNoInitSuffix(), m_getNoInit.ReturnType, false);
                p_getNoInit.AddAnnotation(c_fireThisOPC, propertyName);
                p_getNoInit.AddAnnotation(c_fireTargetOPC, propertyName);
                mg.LoadThis();
                mg.InvokeSuper(m_getMethod);
                mg.ReturnValue();
                mg.EndMethod();
            }
        }