Java Code Examples for org.mvel2.MVEL#COMPILER_OPT_ALLOW_NAKED_METH_CALL
The following examples show how to use
org.mvel2.MVEL#COMPILER_OPT_ALLOW_NAKED_METH_CALL .
You can vote up the ones you like or vote down the ones you don't like,
and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: PatternBuilder.java From kogito-runtimes with Apache License 2.0 | 6 votes |
private FieldValue getFieldValue(RuleBuildContext context, ValueType vtype, String value) { try { MVEL.COMPILER_OPT_ALLOW_NAKED_METH_CALL = true; MVEL.COMPILER_OPT_ALLOW_OVERRIDE_ALL_PROPHANDLING = true; MVEL.COMPILER_OPT_ALLOW_RESOLVE_INNERCLASSES_WITH_DOTNOTATION = true; MVEL.COMPILER_OPT_SUPPORT_JAVA_STYLE_CLASS_LITERALS = true; MVELDialectRuntimeData data = (MVELDialectRuntimeData) context.getPkg().getDialectRuntimeRegistry().getDialectData("mvel"); ParserConfiguration pconf = data.getParserConfiguration(); ParserContext pctx = new ParserContext(pconf); Object o = MVELSafeHelper.getEvaluator().executeExpression(MVEL.compileExpression(value, pctx)); if (o != null && vtype == null) { // was a compilation problem else where, so guess valuetype so we can continue vtype = ValueType.determineValueType(o.getClass()); } return context.getCompilerFactory().getFieldFactory().getFieldValue(o, vtype); } catch (final Exception e) { // we will fallback to regular preducates, so don't raise an error } return null; }
Example 2
Source File: MVELObjectClassFieldReader.java From kogito-runtimes with Apache License 2.0 | 6 votes |
public static void doCompile(MVELClassFieldReader target, MVELDialectRuntimeData runtimeData, Object evaluationContext) { Class cls; try { cls = runtimeData.getRootClassLoader().loadClass( target.getClassName() ); } catch ( ClassNotFoundException e ) { throw new IllegalStateException( "Unable to compile as Class could not be found '" + target.getClassName() + "'"); } ParserContext context = new ParserContext(runtimeData.getParserConfiguration(), evaluationContext); context.addInput( "this", cls ); context.setStrongTyping( target.isTypeSafe() ); MVEL.COMPILER_OPT_ALLOW_NAKED_METH_CALL = true; MVEL.COMPILER_OPT_ALLOW_OVERRIDE_ALL_PROPHANDLING = true; MVEL.COMPILER_OPT_ALLOW_RESOLVE_INNERCLASSES_WITH_DOTNOTATION = true; MVEL.COMPILER_OPT_SUPPORT_JAVA_STYLE_CLASS_LITERALS = true; ExecutableStatement mvelExpression = (ExecutableStatement)MVEL.compileExpression( target.getExpression(), context); Class returnType = mvelExpression.getKnownEgressType(); target.setExecutableStatement( mvelExpression ); target.setFieldType( returnType ); target.setValueType( ValueType.determineValueType( returnType ) ); target.setEvaluationContext(evaluationContext); }
Example 3
Source File: MVELCompilationUnit.java From kogito-runtimes with Apache License 2.0 | 5 votes |
private static Serializable compile( final String text, final ParserContext parserContext ) { MVEL.COMPILER_OPT_ALLOW_NAKED_METH_CALL = true; MVEL.COMPILER_OPT_ALLOW_OVERRIDE_ALL_PROPHANDLING = true; MVEL.COMPILER_OPT_ALLOW_RESOLVE_INNERCLASSES_WITH_DOTNOTATION = true; MVEL.COMPILER_OPT_SUPPORT_JAVA_STYLE_CLASS_LITERALS = true; if ( MVELDebugHandler.isDebugMode() ) { parserContext.setDebugSymbols( true ); } return MVEL.compileExpression( text.trim(), parserContext ); }
Example 4
Source File: PatternBuilder.java From kogito-runtimes with Apache License 2.0 | 4 votes |
protected void setInputs(RuleBuildContext context, ExprBindings descrBranch, Class<?> thisClass, String expr) { MVELDialectRuntimeData data = (MVELDialectRuntimeData) context.getPkg().getDialectRuntimeRegistry().getDialectData("mvel"); ParserConfiguration conf = data.getParserConfiguration(); conf.setClassLoader(context.getKnowledgeBuilder().getRootClassLoader()); final ParserContext pctx = new ParserContext(conf); pctx.setStrictTypeEnforcement(false); pctx.setStrongTyping(false); pctx.addInput("this", thisClass); pctx.addInput("empty", boolean.class); // overrides the mvel empty label MVEL.COMPILER_OPT_ALLOW_NAKED_METH_CALL = true; MVEL.COMPILER_OPT_ALLOW_OVERRIDE_ALL_PROPHANDLING = true; MVEL.COMPILER_OPT_ALLOW_RESOLVE_INNERCLASSES_WITH_DOTNOTATION = true; MVEL.COMPILER_OPT_SUPPORT_JAVA_STYLE_CLASS_LITERALS = true; try { MVEL.analysisCompile(expr, pctx); } catch (Exception e) { // There is a problem in setting the inputs for this expression, but it will be // reported during expression analysis, so swallow it at the moment return; } if (!pctx.getInputs().isEmpty()) { for (String v : pctx.getInputs().keySet()) { // in the following if, we need to check that the expr actually contains a reference // to an "empty" property, or the if will evaluate to true even if it doesn't if ("this".equals(v) || (PropertyTools.getFieldOrAccessor(thisClass, v) != null && expr.matches("(^|.*\\W)empty($|\\W.*)"))) { descrBranch.getFieldAccessors().add(v); } else if ("empty".equals(v)) { // do nothing } else if (!context.getPkg().getGlobals().containsKey(v)) { descrBranch.getRuleBindings().add(v); } else { descrBranch.getGlobalBindings().add(v); } } } }
Example 5
Source File: MVELDialect.java From kogito-runtimes with Apache License 2.0 | 4 votes |
public MVELDialect(ClassLoader rootClassLoader, KnowledgeBuilderConfigurationImpl pkgConf, PackageRegistry pkgRegistry, InternalKnowledgePackage pkg, String id) { this.id = id; this.pkg = pkg; this.packageRegistry = pkgRegistry; this.configuration = (MVELDialectConfiguration) pkgConf.getDialectConfiguration("mvel"); setLanguageLevel(this.configuration.getLangLevel()); this.strictMode = this.configuration.isStrict(); // setting MVEL option directly MVEL.COMPILER_OPT_ALLOW_NAKED_METH_CALL = true; this.results = new ArrayList<KnowledgeBuilderResult>(); // this.data = new MVELDialectRuntimeData( // this.pkg.getDialectRuntimeRegistry() ); // // this.pkg.getDialectRuntimeRegistry().setDialectData( ID, // this.data ); // initialise the dialect runtime data if it doesn't already exist if (pkg.getDialectRuntimeRegistry().getDialectData(getId()) == null) { data = new MVELDialectRuntimeData(); this.pkg.getDialectRuntimeRegistry().setDialectData(getId(), data); data.onAdd(this.pkg.getDialectRuntimeRegistry(), rootClassLoader); } else { data = (MVELDialectRuntimeData) this.pkg.getDialectRuntimeRegistry().getDialectData("mvel"); } this.results = new ArrayList<KnowledgeBuilderResult>(); this.src = new MemoryResourceReader(); if (this.pkg != null) { this.addImport(new ImportDescr(this.pkg.getName() + ".*")); } this.addImport(new ImportDescr("java.lang.*")); }