use of org.mvel2.compiler.CompiledExpression in project mvel by mikebrock.
the class GenericsTypeInferenceTest method testInferLastTypeParametersFromPropertyMethod.
public final void testInferLastTypeParametersFromPropertyMethod() {
ParserContext context = new ParserContext();
context.setStrongTyping(true);
context.addInput("a", A.class);
final CompiledExpression compiledExpression = new ExpressionCompiler("a.getFooMap()[\"key\"].someMethod()").compile(context);
final Object val = MVEL.executeExpression(compiledExpression, new AWrapper());
assertEquals("Expression did not evaluate correctly: ", "bar", val);
assertNotNull("No type parameters detected", context.getLastTypeParameters());
assertEquals("Wrong parametric type inferred", String.class, context.getLastTypeParameters()[0]);
}
use of org.mvel2.compiler.CompiledExpression in project mvel by mikebrock.
the class GenericsTypeInferenceTest method testInferLastTypeParametersFromProperty.
public final void testInferLastTypeParametersFromProperty() {
ParserContext context = new ParserContext();
context.setStrongTyping(true);
context.addInput("a", A.class);
final CompiledExpression compiledExpression = new ExpressionCompiler("a.strings").compile(context);
final Object val = MVEL.executeExpression(compiledExpression, new AWrapper());
assertTrue("Expression did not evaluate correctly: " + val, STRINGS.equals(val));
assertTrue("No type parameters detected", null != context.getLastTypeParameters());
assertTrue("Wrong parametric type inferred", String.class.equals(context.getLastTypeParameters()[0]));
}
use of org.mvel2.compiler.CompiledExpression in project mvel by mikebrock.
the class CoreConfidenceTests method testTestIntToLong.
public void testTestIntToLong() {
String s = "1+(long)a";
ParserContext pc = new ParserContext();
pc.addInput("a", Integer.class);
ExpressionCompiler compiler = new ExpressionCompiler(s, pc);
CompiledExpression expr = compiler.compile();
Map vars = new HashMap();
vars.put("a", 1);
Object r = ((ExecutableStatement) expr).getValue(null, new MapVariableResolverFactory(vars));
assertEquals(new Long(2), r);
}
use of org.mvel2.compiler.CompiledExpression in project mvel by mikebrock.
the class ArithmeticTests method testJIRA161.
public void testJIRA161() {
Serializable s = MVEL.compileExpression("1==-(-1)", ParserContext.create().stronglyTyped());
assertEquals(1 == -(-1), MVEL.executeExpression(s));
ParserContext ctx = new ParserContext();
ctx.setStrongTyping(true);
CompiledExpression compiledExpression = new ExpressionCompiler("1==-(-1)").compile(ctx);
assertEquals(1 == -(-1), MVEL.executeExpression(compiledExpression));
}
use of org.mvel2.compiler.CompiledExpression in project mvel by mikebrock.
the class ArithmeticTests method testStrongTypingModeComparison.
public void testStrongTypingModeComparison() {
ParserContext parserContext = new ParserContext();
parserContext.setStrongTyping(true);
parserContext.addInput("a", Long.class);
CompiledExpression compiledExpression = new ExpressionCompiler("a==0").compile(parserContext);
HashMap<String, Object> variables = new HashMap<String, Object>();
variables.put("a", 0l);
MVEL.executeExpression(compiledExpression, variables);
}
Aggregations