use of org.mule.mvel2.compiler.ExpressionCompiler in project mvel by mvel.
the class MVEL method analysisCompile.
/**
* Performs an analysis compileShared, which will populate the ParserContext with type, input and variable information,
* but will not produce a payload.
*
* @param expression - the expression to analyze
* @param ctx - the parser context
*/
public static void analysisCompile(char[] expression, ParserContext ctx) {
ExpressionCompiler compiler = new ExpressionCompiler(expression, ctx);
compiler.setVerifyOnly(true);
compiler.compile();
}
use of org.mule.mvel2.compiler.ExpressionCompiler in project mvel by mvel.
the class MVEL method analyze.
public static Class analyze(char[] expression, ParserContext ctx) {
ExpressionCompiler compiler = new ExpressionCompiler(expression, ctx);
compiler.setVerifyOnly(true);
compiler.compile();
return compiler.getReturnType();
}
use of org.mule.mvel2.compiler.ExpressionCompiler in project mvel by mvel.
the class CoreConfidenceTests method testParserErrorHandling.
public void testParserErrorHandling() {
final ParserContext ctx = new ParserContext();
ExpressionCompiler compiler = new ExpressionCompiler("a[", ctx);
try {
compiler.compile();
} catch (Exception e) {
return;
}
assertTrue(false);
}
use of org.mule.mvel2.compiler.ExpressionCompiler in project mvel by mvel.
the class CoreConfidenceTests method testListNestedInsideList.
public void testListNestedInsideList() {
ParserContext ctx = new ParserContext();
ctx.addImport("User", User.class);
ExpressionCompiler compiler = new ExpressionCompiler("users = [ new User('Darth', 'Vadar'), " + "new User('Bobba', 'Feta') ]; [ users.get( 0 ), users.get( 1 ) ]", ctx);
List list = (List) executeExpression(compiler.compile(), new HashMap());
User user = (User) list.get(0);
assertEquals("Darth", user.getFirstName());
user = (User) list.get(1);
assertEquals("Bobba", user.getFirstName());
compiler = new ExpressionCompiler("users = [ new User('Darth', 'Vadar'), " + "new User('Bobba', 'Feta') ]; [ users[0], users[1] ]", ctx);
list = (List) executeExpression(compiler.compile(), new HashMap());
user = (User) list.get(0);
assertEquals("Darth", user.getFirstName());
user = (User) list.get(1);
assertEquals("Bobba", user.getFirstName());
}
use of org.mule.mvel2.compiler.ExpressionCompiler in project mvel by mvel.
the class CoreConfidenceTests method testStaticNestedWithMethodCall.
public void testStaticNestedWithMethodCall() {
String expr = "item = new Item( \"Some Item\"); $msg.addItem( item ); return $msg";
ParserContext context = new ParserContext();
context.setStrictTypeEnforcement(false);
context.addImport("Message", Message.class);
context.addImport("Item", Item.class);
// Serializable compiledExpression = compiler.compileShared(context);
Map vars = new HashMap();
vars.put("$msg", new Message());
ExpressionCompiler compiler = new ExpressionCompiler(expr, context);
Message msg = (Message) executeExpression(compiler.compile(), vars);
Item item = (Item) msg.getItems().get(0);
assertEquals("Some Item", item.getName());
}
Aggregations