use of org.mule.mvel2.compiler.CompiledExpression in project drools by kiegroup.
the class ResultVerifier method isSuccess.
protected Boolean isSuccess(VerifyField currentField) {
String s = "__fact__." + currentField.getFieldName() + " " + currentField.getOperator() + " __expected__";
CompiledExpression expression = new ExpressionCompiler(s, parserContext).compile();
return (Boolean) MVELSafeHelper.getEvaluator().executeExpression(expression, variables);
}
use of org.mule.mvel2.compiler.CompiledExpression in project drools by kiegroup.
the class MVELDebugTest method testDebug.
@Test
public void testDebug() throws Exception {
String rule = "package com.sample; dialect \"mvel\" rule myRule when then\n System.out.println( \"test\" ); end";
KnowledgeBuilderImpl builder = new KnowledgeBuilderImpl();
DrlParser parser = new DrlParser(LanguageLevelOption.DRL5);
PackageDescr packageDescr = parser.parse(null, rule);
RuleDescr ruleDescr = packageDescr.getRules().get(0);
builder = new KnowledgeBuilderImpl();
builder.addPackage(packageDescr);
InternalKnowledgePackage pkg = builder.getPackage("com.sample");
MVELConsequence consequence = (MVELConsequence) pkg.getRule("myRule").getConsequence();
String sourceName = ((CompiledExpression) consequence.getCompExpr()).getSourceName();
System.out.println(sourceName);
String ruleName = ruleDescr.getNamespace() + "." + ruleDescr.getClassName();
System.out.println(ruleName);
assertEquals(sourceName, ruleName);
}
use of org.mule.mvel2.compiler.CompiledExpression in project drools by kiegroup.
the class ConditionAnalyzer method analyzeNodeAccessor.
private Expression analyzeNodeAccessor(Accessor accessor, ASTNode node) {
AccessorNode accessorNode;
if (accessor instanceof DynamicGetAccessor) {
accessorNode = (AccessorNode) ((DynamicGetAccessor) accessor).getSafeAccessor();
} else if (accessor instanceof AccessorNode) {
accessorNode = (AccessorNode) accessor;
} else if (accessor instanceof CompiledExpression) {
return analyzeNode(((CompiledExpression) accessor).getFirstNode());
} else if (accessor instanceof ListCreator) {
return analyzeListCreation(((ListCreator) accessor));
} else if (accessor instanceof ArrayCreator) {
return analyzeArrayCreation(((ArrayCreator) accessor));
} else {
throw new RuntimeException("Unknown accessor type: " + accessor);
}
if (accessorNode instanceof VariableAccessor) {
if (isStaticAccessor(accessorNode)) {
while (accessorNode instanceof VariableAccessor) {
accessorNode = accessorNode.getNextNode();
}
} else {
return analyzeNodeAccessor(accessorNode, node);
}
}
while (accessorNode instanceof StaticReferenceAccessor) {
StaticReferenceAccessor staticReferenceAccessor = ((StaticReferenceAccessor) accessorNode);
Object literal = staticReferenceAccessor.getLiteral();
accessorNode = accessorNode.getNextNode();
if (accessorNode == null) {
return new FixedExpression(literal.getClass(), literal);
}
}
return analyzeExpressionNode(accessorNode, node, null);
}
use of org.mule.mvel2.compiler.CompiledExpression in project drools by kiegroup.
the class MvelConstraint method createMvelConditionEvaluator.
protected ConditionEvaluator createMvelConditionEvaluator(InternalWorkingMemory workingMemory) {
if (compilationUnit != null) {
MVELDialectRuntimeData data = getMVELDialectRuntimeData(workingMemory);
ExecutableStatement statement = (ExecutableStatement) compilationUnit.getCompiledExpression(data, evaluationContext);
ParserConfiguration configuration = statement instanceof CompiledExpression ? ((CompiledExpression) statement).getParserConfiguration() : data.getParserConfiguration();
return new MvelConditionEvaluator(compilationUnit, configuration, statement, declarations, operators, getAccessedClass());
} else {
return new MvelConditionEvaluator(getParserConfiguration(workingMemory), expression, declarations, operators, getAccessedClass());
}
}
use of org.mule.mvel2.compiler.CompiledExpression in project mvel by mvel.
the class CoreConfidenceTests method testJIRA168.
public void testJIRA168() {
boolean before = MVEL.COMPILER_OPT_ALLOW_NAKED_METH_CALL;
try {
Map<String, Object> st = new HashMap<String, Object>();
st.put("__fact__", new ArrayList());
st.put("__expected__", 0);
String expressionNaked = "__fact__.size == __expected__";
String expressionNonNaked = "__fact__.size() == __expected__";
MVEL.COMPILER_OPT_ALLOW_NAKED_METH_CALL = true;
// the following works fine
ParserContext ctx = new ParserContext();
for (Map.Entry<String, Object> entry : st.entrySet()) {
ctx.addInput(entry.getKey(), entry.getValue().getClass());
}
CompiledExpression expr = new ExpressionCompiler(expressionNaked, ctx).compile();
Boolean result = (Boolean) executeExpression(expr, st);
assertTrue(result);
// the following works fine
result = (Boolean) MVEL.eval(expressionNonNaked, st);
assertTrue(result);
// the following fails
result = (Boolean) MVEL.eval(expressionNaked, st);
assertTrue(result);
} finally {
MVEL.COMPILER_OPT_ALLOW_NAKED_METH_CALL = before;
}
}
Aggregations