use of org.mvel2.compiler.ExpressionCompiler in project mvel by mikebrock.
the class TypesAndInferenceTests method testDetermineEgressParametricType.
public final void testDetermineEgressParametricType() {
final ParserContext parserContext = new ParserContext();
parserContext.setStrongTyping(true);
parserContext.addInput("strings", List.class, new Class[] { String.class });
final CompiledExpression expr = new ExpressionCompiler("strings").compile(parserContext);
assertTrue(STRINGS.equals(executeExpression(expr, new A())));
final Type[] typeParameters = expr.getParserContext().getLastTypeParameters();
assertTrue(typeParameters != null);
assertTrue(String.class.equals(typeParameters[0]));
}
use of org.mvel2.compiler.ExpressionCompiler in project mvel by mikebrock.
the class TypesAndInferenceTests method testStrictTypingCompilation3.
public void testStrictTypingCompilation3() throws NoSuchMethodException {
ParserContext ctx = new ParserContext();
ctx.setStrictTypeEnforcement(true);
ExpressionCompiler compiler = new ExpressionCompiler("message='Hello';b=7;\nSystem.out.println(message + ';' + b);\n" + "System.out.println(message + ';' + b); b");
assertEquals(7, executeExpression(compiler.compile(ctx), new DefaultLocalVariableResolverFactory()));
}
use of org.mvel2.compiler.ExpressionCompiler in project mvel by mikebrock.
the class TypesAndInferenceTests method testTypeVarDeclr.
public void testTypeVarDeclr() {
String ex = "String a;";
ParserContext ctx = new ParserContext();
ExpressionCompiler compiler = new ExpressionCompiler(ex);
compiler.compile(ctx);
assertNotNull(ctx.getVariables());
assertEquals(1, ctx.getVariables().entrySet().size());
for (Map.Entry<String, Class> entry : ctx.getVariables().entrySet()) {
assertEquals(String.class, entry.getValue());
}
}
use of org.mvel2.compiler.ExpressionCompiler in project mvel by mikebrock.
the class TypesAndInferenceTests method testAnalysisCompile.
public void testAnalysisCompile() {
ParserContext pCtx = new ParserContext();
ExpressionCompiler e = new ExpressionCompiler("foo.aValue = 'bar'");
e.setVerifyOnly(true);
e.compile(pCtx);
assertTrue(pCtx.getInputs().keySet().contains("foo"));
assertEquals(1, pCtx.getInputs().size());
assertEquals(0, pCtx.getVariables().size());
}
use of org.mvel2.compiler.ExpressionCompiler in project mvel by mikebrock.
the class DebuggerTests method testDebugSymbolsWithMixedLinedEndings.
public void testDebugSymbolsWithMixedLinedEndings() throws Exception {
String expr = " System.out.println( \"a1\" );\n" + " System.out.println( \"a2\" );\r\n" + " System.out.println( \"a3\" );\n" + " System.out.println( \"a4\" );\r\n";
ExpressionCompiler compiler = new ExpressionCompiler(expr);
ParserContext ctx = new ParserContext();
ctx.setStrictTypeEnforcement(true);
ctx.setDebugSymbols(true);
ctx.setSourceFile("mysource");
String s = org.mvel2.debug.DebugTools.decompile(compiler.compile(ctx));
System.out.println(s);
int fromIndex = 0;
int count = 0;
while ((fromIndex = s.indexOf("DEBUG_SYMBOL", fromIndex + 1)) > -1) {
count++;
}
assertEquals(4, count);
}
Aggregations