use of org.mule.mvel2.ParserConfiguration in project mvel by mvel.
the class CoreConfidenceTests method testGenericsMap.
public void testGenericsMap() throws Exception {
try {
String str = "triangle.deliveries[0].containsKey( \"x\" )";
ParserConfiguration pconf = new ParserConfiguration();
ParserContext pctx = new ParserContext(pconf);
pctx.setStrongTyping(true);
pctx.addInput("triangle", Triangle.class);
ExecutableStatement stmt = (ExecutableStatement) MVEL.compileExpression(str, pctx);
} catch (Exception e) {
// it should not raise CCE
e.printStackTrace();
throw e;
}
}
use of org.mule.mvel2.ParserConfiguration in project mvel by mvel.
the class CoreConfidenceTests method testEmptyOperatorOnStrings.
public void testEmptyOperatorOnStrings() {
ParserConfiguration conf = new ParserConfiguration();
ParserContext pctx = new ParserContext(conf);
pctx.setStrictTypeEnforcement(true);
pctx.setStrongTyping(true);
pctx.addInput("nullString", String.class);
pctx.addInput("emptyString", String.class);
pctx.addInput("blankString", String.class);
pctx.addInput("nonEmptyString", String.class);
Map vars = new HashMap() {
{
put("nullString", null);
put("emptyString", "");
put("blankString", " ");
put("nonEmptyString", "abc");
}
};
assertEquals(true, MVEL.executeExpression(MVEL.compileExpression("nullString == empty", pctx), vars));
assertEquals(true, MVEL.executeExpression(MVEL.compileExpression("emptyString == empty", pctx), vars));
assertEquals(true, MVEL.executeExpression(MVEL.compileExpression("blankString == empty", pctx), vars));
assertEquals(false, MVEL.executeExpression(MVEL.compileExpression("nonEmptyString == empty", pctx), vars));
}
use of org.mule.mvel2.ParserConfiguration in project mvel by mvel.
the class CoreConfidenceTests method testStrTriangleEqualsEquals.
public void testStrTriangleEqualsEquals() {
MVEL.COMPILER_OPT_ALLOW_NAKED_METH_CALL = true;
try {
ParserConfiguration pconf = new ParserConfiguration();
ParserContext pctx = new ParserContext(pconf);
pctx.addInput("this", Triangle.class);
pctx.setStrongTyping(true);
String str = "this.strLabel == this";
try {
ExecutableStatement stmt = (ExecutableStatement) MVEL.compileExpression(str, pctx);
fail("should have failed");
} catch (CompileException e) {
System.out.println();
return;
}
} finally {
MVEL.COMPILER_OPT_ALLOW_NAKED_METH_CALL = false;
}
}
use of org.mule.mvel2.ParserConfiguration in project mvel by mvel.
the class CoreConfidenceTests method testContextObjMethodCall.
public void testContextObjMethodCall() {
String str = "getName() == \"bob\"";
ParserConfiguration pconf = new ParserConfiguration();
ParserContext pctx = new ParserContext(pconf);
pctx.setStrongTyping(true);
pctx.addInput("this", Bar.class);
ExecutableStatement stmt = (ExecutableStatement) MVEL.compileExpression(str, pctx);
Bar ctx = new Bar();
ctx.setName("bob");
Boolean result = (Boolean) MVEL.executeExpression(stmt, ctx);
assertTrue(result);
}
use of org.mule.mvel2.ParserConfiguration in project mvel by mvel.
the class ASTNode method optimize.
private Object optimize(Object ctx, Object thisValue, VariableResolverFactory factory) {
if ((fields & DEOP) != 0) {
fields ^= DEOP;
}
AccessorOptimizer optimizer;
Object retVal = null;
if ((fields & NOJIT) != 0 || factory != null && factory.isResolveable(nameCache)) {
optimizer = getAccessorCompiler(SAFE_REFLECTIVE);
} else {
optimizer = getDefaultAccessorCompiler();
}
ParserContext pCtx;
if ((fields & PCTX_STORED) != 0) {
pCtx = (ParserContext) literal;
} else {
pCtx = new ParserContext(new ParserConfiguration(getInjectedImports(factory), null));
}
try {
pCtx.optimizationNotify();
setAccessor(optimizer.optimizeAccessor(pCtx, expr, start, offset, ctx, thisValue, factory, true, egressType));
} catch (OptimizationNotSupported ne) {
setAccessor((optimizer = getAccessorCompiler(SAFE_REFLECTIVE)).optimizeAccessor(pCtx, expr, start, offset, ctx, thisValue, factory, true, null));
}
if (accessor == null) {
return get(expr, start, offset, ctx, factory, thisValue, pCtx);
}
if (retVal == null) {
retVal = optimizer.getResultOptPass();
}
if (egressType == null) {
egressType = optimizer.getEgressType();
}
return retVal;
}
Aggregations