Skip to content

Instantly share code, notes, and snippets.

@tarilabs
Created July 19, 2016 10:30
Show Gist options
  • Save tarilabs/822866f745182710f2c21d8d39eaeefe to your computer and use it in GitHub Desktop.
Save tarilabs/822866f745182710f2c21d8d39eaeefe to your computer and use it in GitHub Desktop.
public void testMatteo() {
ParserConfiguration conf = new ParserConfiguration();
boolean doImportNameMethod = true;
if (doImportNameMethod) {
Class<?> clazz = CoreConfidenceTests.class;
Method nameMethod = null;
for (Method m : clazz.getMethods()) {
if (m.getName() == "name") {
nameMethod = m;
}
}
System.out.println(nameMethod);
conf.addImport("name", nameMethod);
}
ParserContext pctx = new ParserContext( conf );
pctx.setStrictTypeEnforcement(true);
pctx.setStrongTyping(true);
pctx.addInput("this", MyPerson.class);
ExecutableStatement stmt = (ExecutableStatement) MVEL.compileExpression("name == \"Matteo\"", pctx);
System.out.println("stmt: " + stmt.getClass() + stmt);
ExecutableStatement stmt2 = (ExecutableStatement) MVEL.compileExpression("name() == \"Matteo\"", pctx);
System.out.println("stmt2: " + stmt2.getClass() + stmt2);
ExecutableStatement stmt3 = (ExecutableStatement) MVEL.compileExpression("Name == \"Matteo\"", pctx);
System.out.println("stmt3: " + stmt3.getClass() + stmt3);
MyPerson ctx = new MyPerson("Matteo");
System.out.println(MVEL.executeExpression(stmt, ctx));
System.out.println(MVEL.executeExpression(stmt2, ctx));
System.out.println(MVEL.executeExpression(stmt3, ctx));
}
public static String name() {
System.out.println("myNAME");
return "Matteo";
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment