use of org.mvel2.ParserContext 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.mvel2.ParserContext in project drools by kiegroup.
the class DefaultEnumClassBuilder method buildFields.
protected void buildFields(ClassWriter cw, EnumClassDefinition classDef) {
FieldVisitor fv;
for (FieldDefinition fld : classDef.getFieldsDefinitions()) {
fv = cw.visitField(ACC_PRIVATE + ACC_FINAL, fld.getName(), BuildUtils.getTypeDescriptor(fld.getTypeName()), null, null);
fv.visitEnd();
}
{
fv = cw.visitField(ACC_PRIVATE + ACC_STATIC, "$context", "Lorg/mvel2/ParserContext;", null, null);
fv.visitEnd();
}
}
use of org.mvel2.ParserContext in project drools by kiegroup.
the class DefaultEnumClassBuilder method buildGettersAndSetters.
protected void buildGettersAndSetters(ClassWriter cw, EnumClassDefinition classDef) {
MethodVisitor mv;
{
mv = cw.visitMethod(ACC_PUBLIC + ACC_STATIC, "values", "()[" + BuildUtils.getTypeDescriptor(classDef.getClassName()), null, null);
mv.visitCode();
mv.visitFieldInsn(GETSTATIC, BuildUtils.getInternalType(classDef.getClassName()), "$VALUES", "[" + BuildUtils.getTypeDescriptor(classDef.getClassName()));
mv.visitMethodInsn(INVOKEVIRTUAL, "[" + BuildUtils.getTypeDescriptor(classDef.getClassName()), "clone", "()Ljava/lang/Object;");
mv.visitTypeInsn(CHECKCAST, "[" + BuildUtils.getTypeDescriptor(classDef.getClassName()));
mv.visitInsn(ARETURN);
mv.visitMaxs(1, 0);
mv.visitEnd();
}
for (FieldDefinition fld : classDef.getFieldsDefinitions()) {
mv = cw.visitMethod(ACC_PUBLIC, BuildUtils.getterName(fld.getName(), fld.getTypeName()), "()" + BuildUtils.getTypeDescriptor(fld.getTypeName()), null, null);
mv.visitCode();
mv.visitVarInsn(ALOAD, 0);
mv.visitFieldInsn(GETFIELD, BuildUtils.getInternalType(classDef.getName()), fld.getName(), BuildUtils.getTypeDescriptor(fld.getTypeName()));
mv.visitInsn(BuildUtils.returnType(fld.getTypeName()));
mv.visitMaxs(BuildUtils.sizeOf(fld.getTypeName()), 1);
mv.visitEnd();
mv = cw.visitMethod(ACC_PUBLIC, BuildUtils.setterName(fld.getName(), fld.getTypeName()), "(" + BuildUtils.getTypeDescriptor(fld.getTypeName()) + ")V", null, null);
mv.visitCode();
mv.visitInsn(RETURN);
mv.visitMaxs(0, 1 + BuildUtils.sizeOf(fld.getTypeName()));
mv.visitEnd();
}
{
mv = cw.visitMethod(ACC_PUBLIC + ACC_STATIC, "get$context", "()Lorg/mvel2/ParserContext;", null, null);
mv.visitCode();
mv.visitFieldInsn(GETSTATIC, BuildUtils.getInternalType(classDef.getName()), "$context", "Lorg/mvel2/ParserContext;");
mv.visitInsn(ARETURN);
mv.visitMaxs(1, 0);
mv.visitEnd();
}
{
mv = cw.visitMethod(ACC_PUBLIC + ACC_STATIC, "set$context", "(Lorg/mvel2/ParserContext;)V", null, null);
mv.visitCode();
mv.visitVarInsn(ALOAD, 0);
mv.visitFieldInsn(PUTSTATIC, BuildUtils.getInternalType(classDef.getName()), "$context", "Lorg/mvel2/ParserContext;");
mv.visitInsn(RETURN);
mv.visitMaxs(1, 1);
mv.visitEnd();
}
}
use of org.mvel2.ParserContext in project drools by kiegroup.
the class MVELTest method test1.
@Test
public void test1() {
final ParserContext pc = new ParserContext();
pc.addInput("x", String.class);
pc.setStrongTyping(true);
final Object o = MVEL.compileExpression("x.startsWith('d')", pc);
final Map vars = new HashMap();
vars.put("x", "d");
MVEL.executeExpression(o, vars);
System.out.println(o);
}
use of org.mvel2.ParserContext in project drools by kiegroup.
the class QueryElementBuilder method getParserContext.
private ParserContext getParserContext(RuleBuildContext context) {
MVELDialectRuntimeData data = (MVELDialectRuntimeData) context.getPkg().getDialectRuntimeRegistry().getDialectData("mvel");
ParserConfiguration conf = data.getParserConfiguration();
conf.setClassLoader(context.getKnowledgeBuilder().getRootClassLoader());
return new ParserContext(conf);
}
Aggregations