Пример #1
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));
        }
Пример #2
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));
        }