private string GetFragmentCodegen(ICodegenContext context)
 {
     return context.AddMethod(typeof(Object), typeof(Object[]), "array", this.GetType())
         .DeclareVar(typeof(Object), "value", ArrayAtIndex(Ref("array"), Constant(_propertyIndex)))
         .IfRefNullReturnNull("value")
         .DeclareVarWCast(typeof(EventBean), "theEvent", "value")
         .MethodReturn(_eventBeanEntryGetter.CodegenEventBeanFragment(Ref("theEvent"), context));
 }
Esempio 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));
        }
Esempio n. 3
0
 private string GetFragmentCodegen(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.CodegenEventBeanFragment(Ref("wrappedEvent"), context));
 }
Esempio n. 4
0
 private string GetFragmentCodegen(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.CodegenEventBeanFragment(Ref("theEvent"), context));
 }
Esempio n. 5
0
 public static string GetArrayPropertyFragmentCodegen(
     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.CodegenEventBeanFragment(Ref("inner"), context)));
 }
Esempio n. 6
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));
        }