private string GetObjectArrayCodegen(ICodegenContext context)
 {
     return context.AddMethod(typeof(Object), typeof(Object[]), "array", GetType())
         .DeclareVar(typeof(Object), "value", ArrayAtIndex(Ref("array"), Constant(_propertyIndex)))
         .IfRefNullReturnNull("value")
         .DeclareVarWCast(typeof(EventBean), "theEvent", "value")
         .MethodReturn(_eventBeanEntryGetter.CodegenEventBeanGet(Ref("theEvent"), context));
 }
Exemplo n.º 2
0
        public static string From(
            ICodegenContext context,
            Type expectedUnderlyingType,
            EventPropertyGetterSPI innerGetter,
            AccessType accessType,
            Type generator)
        {
            var block = context.AddMethod(accessType == AccessType.EXISTS ? typeof(bool) : typeof(object),
                                          typeof(object), "value", generator)
                        .IfNotInstanceOf("value", expectedUnderlyingType)
                        .IfInstanceOf("value", typeof(EventBean))
                        .DeclareVarWCast(typeof(EventBean), "bean", "value");

            switch (accessType)
            {
            case AccessType.GET:
                block = block.BlockReturn(innerGetter.CodegenEventBeanGet(Ref("bean"), context));
                break;

            case AccessType.EXISTS:
                block = block.BlockReturn(innerGetter.CodegenEventBeanExists(Ref("bean"), context));
                break;

            case AccessType.FRAGMENT:
                block = block.BlockReturn(innerGetter.CodegenEventBeanFragment(Ref("bean"), context));
                break;

            default:
                throw new UnsupportedOperationException("Invalid access type " + accessType);
            }

            block = block.BlockReturn(Constant(accessType == AccessType.EXISTS ? (object)false : null));

            ICodegenExpression expression;

            switch (accessType)
            {
            case AccessType.GET:
                expression = innerGetter.CodegenUnderlyingGet(Cast(
                                                                  expectedUnderlyingType, Ref("value")), context);
                break;

            case AccessType.EXISTS:
                expression = innerGetter.CodegenUnderlyingExists(Cast(
                                                                     expectedUnderlyingType, Ref("value")), context);
                break;

            case AccessType.FRAGMENT:
                expression = innerGetter.CodegenUnderlyingFragment(
                    Cast(expectedUnderlyingType, Ref("value")), context);
                break;

            default:
                throw new UnsupportedOperationException("Invalid access type " + accessType);
            }

            return(block.MethodReturn(expression));
        }
Exemplo n.º 3
0
 private string GetCodegen(ICodegenContext context)
 {
     return context.AddMethod(typeof(object), typeof(EventBean), "theEvent", GetType())
         .DeclareVarWCast(typeof(DecoratingEventBean), "wrapperEvent", "theEvent")
         .DeclareVar(typeof(EventBean), "wrappedEvent",
             ExprDotMethod(Ref("wrapperEvent"), "getUnderlyingEvent"))
         .IfRefNullReturnNull("wrappedEvent")
         .MethodReturn(_underlyingGetter.CodegenEventBeanGet(Ref("wrappedEvent"), context));
 }
Exemplo n.º 4
0
 private string GetCodegen(ICodegenContext context)
 {
     return context.AddMethod(typeof(object), typeof(EventBean), "eventBean", GetType())
         .DeclareVar(typeof(RevisionEventBeanDeclared), "riv",
             Cast(typeof(RevisionEventBeanDeclared), Ref("eventBean")))
         .DeclareVar(typeof(EventBean), "bean",
             ExprDotMethod(Ref("riv"), "getLastBaseEvent"))
         .IfRefNullReturnNull("bean")
         .MethodReturn(_fullGetter.CodegenEventBeanGet(Ref("bean"), context));
 }
Exemplo n.º 5
0
 private string GetMapCodegen(ICodegenContext context)
 {
     return context.AddMethod(typeof(object), typeof(Map), "map", GetType())
         .DeclareVar(typeof(object), "value",
             ExprDotMethod(Ref("map"), "get",
                 Constant(_propertyMap)))
         .IfRefNullReturnNull("value")
         .DeclareVar(typeof(EventBean), "theEvent",
             Cast(typeof(EventBean), Ref("value")))
         .MethodReturn(_eventBeanEntryGetter.CodegenEventBeanGet(Ref("theEvent"), context));
 }
Exemplo n.º 6
0
 public static string GetArrayPropertyValueCodegen(ICodegenContext context, int index,
                                                   EventPropertyGetterSPI nestedGetter)
 {
     return(context.AddMethod(typeof(object), typeof(EventBean[]), "wrapper", typeof(BaseNestableEventUtil))
            .IfRefNullReturnNull("wrapper")
            .IfConditionReturnConst(
                Relational(ArrayLength(Ref("wrapper")), CodegenRelational.LE,
                           Constant(index)), null)
            .DeclareVar(typeof(EventBean), "inner",
                        ArrayAtIndex(Ref("wrapper"), Constant(index)))
            .MethodReturn(nestedGetter.CodegenEventBeanGet(Ref("inner"), context)));
 }
 private string GetCodegen(ICodegenContext context)
 {
     var mgetter = context.MakeAddMember(typeof(EventPropertyGetter), _nestedGetter);
     var msvc = context.MakeAddMember(typeof(EventAdapterService), _eventAdapterService);
     return context.AddMethod(typeof(object), typeof(EventBean), "obj", GetType())
         .DeclareVar(typeof(object), "result",
             _revisionGetter.CodegenEventBeanGet(Ref("obj"), context))
         .IfRefNullReturnNull("result")
         .DeclareVar(typeof(EventBean), "theEvent",
             ExprDotMethod(Ref(msvc.MemberName), "adapterForBean",
                 Ref("result")))
         .MethodReturn(ExprDotMethod(Ref(mgetter.MemberName), "get",
             Ref("theEvent")));
 }
Exemplo n.º 8
0
        public static EventPropertyGetter Compile(
            this ICodegenContext codegenContext,
            string engineURI,
            ClassLoaderProvider classLoaderProvider,
            EventPropertyGetterSPI getterSPI,
            string propertyExpression)
        {
            var get      = getterSPI.CodegenEventBeanGet(Ref("bean"), codegenContext);
            var exists   = getterSPI.CodegenEventBeanExists(Ref("bean"), codegenContext);
            var fragment = getterSPI.CodegenEventBeanFragment(Ref("bean"), codegenContext);

            var singleBeanParam = CodegenNamedParam.From(typeof(EventBean), "bean");

            // For: public object Get(EventBean eventBean) ;
            // For: public bool IsExistsProperty(EventBean eventBean);
            // For: public object GetFragment(EventBean eventBean) ;
            var getMethod = new CodegenMethod(typeof(object), "Get", singleBeanParam, null);

            getMethod.Statements.MethodReturn(get);
            var isExistsPropertyMethod = new CodegenMethod(typeof(bool), "IsExistsProperty", singleBeanParam, null);

            isExistsPropertyMethod.Statements.MethodReturn(exists);
            var fragmentMethod = new CodegenMethod(typeof(object), "GetFragment", singleBeanParam, null);

            fragmentMethod.Statements.MethodReturn(fragment);

            var clazz = new CodegenClass(
                "com.espertech.esper.codegen.uri_" + engineURI,
                typeof(EventPropertyGetter).Name + "_" + CodeGenerationIDGenerator.GenerateClass(),
                typeof(EventPropertyGetter),
                codegenContext.Members,
                new [] { getMethod, isExistsPropertyMethod, fragmentMethod },
                codegenContext.Methods
                );

            string debugInfo = null;

            if (codegenContext.IsDebugEnabled)
            {
                debugInfo = getterSPI.GetType().FullName + " for property '" + propertyExpression + "'";
            }

            return(codegenContext.Compiler.Compile(
                       clazz, classLoaderProvider, typeof(EventPropertyGetter), debugInfo));
        }