use of org.mule.mvel2.ParserContext in project mvel by mvel.
the class NewObjectNode method getReducedValueAccelerated.
public Object getReducedValueAccelerated(Object ctx, Object thisValue, VariableResolverFactory factory) {
if (newObjectOptimizer == null) {
if (egressType == null) {
if (factory != null && factory.isResolveable(typeDescr.getClassName())) {
try {
egressType = (Class) factory.getVariableResolver(typeDescr.getClassName()).getValue();
rewriteClassReferenceToFQCN(COMPILE_IMMEDIATE);
if (typeDescr.isArray()) {
try {
egressType = findClass(factory, repeatChar('[', typeDescr.getArrayLength()) + "L" + egressType.getName() + ";", pCtx);
} catch (Exception e) {
// for now, don't handle this.
}
}
} catch (ClassCastException e) {
throw new CompileException("cannot construct object: " + typeDescr.getClassName() + " is not a class reference", expr, start, e);
}
}
}
if (typeDescr.isArray()) {
return (newObjectOptimizer = new NewObjectArray(getBaseComponentType(egressType.getComponentType()), typeDescr.getCompiledArraySize())).getValue(ctx, thisValue, factory);
}
try {
AccessorOptimizer optimizer = getThreadAccessorOptimizer();
ParserContext pCtx = this.pCtx;
if (pCtx == null) {
pCtx = new ParserContext();
pCtx.getParserConfiguration().setAllImports(getInjectedImports(factory));
}
newObjectOptimizer = optimizer.optimizeObjectCreation(pCtx, name, 0, name.length, ctx, thisValue, factory);
/**
* Check to see if the optimizer actually produced the object during optimization. If so,
* we return that value now.
*/
if (optimizer.getResultOptPass() != null) {
egressType = optimizer.getEgressType();
return optimizer.getResultOptPass();
}
} catch (CompileException e) {
throw ErrorUtil.rewriteIfNeeded(e, expr, start);
} finally {
OptimizerFactory.clearThreadAccessorOptimizer();
}
}
return newObjectOptimizer.getValue(ctx, thisValue, factory);
}
use of org.mule.mvel2.ParserContext 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.ParserContext in project mvel by mvel.
the class CoreConfidenceTests method testContextFieldNotFound.
public void testContextFieldNotFound() {
String str = "'stilton'.equals( type );";
ParserConfiguration pconf = new ParserConfiguration();
ParserContext pctx = new ParserContext(pconf);
pctx.addInput("this", Cheese.class);
pctx.setStrictTypeEnforcement(true);
pctx.setStrongTyping(true);
ExecutableStatement stmt = (ExecutableStatement) MVEL.compileExpression(str, pctx);
MVEL.executeExpression(stmt, new Cheese(), new HashMap());
}
use of org.mule.mvel2.ParserContext in project mvel by mvel.
the class CoreConfidenceTests method testFieldNameWithUnderscore.
public void testFieldNameWithUnderscore() {
final ParserContext parserContext = new ParserContext();
parserContext.setStrictTypeEnforcement(true);
parserContext.setStrongTyping(true);
parserContext.addInput("this", Underscore.class);
Underscore underscore = new Underscore();
assertEquals(true, MVEL.executeExpression(MVEL.compileExpression("_id == \"test\"", parserContext), underscore));
}
use of org.mule.mvel2.ParserContext in project mvel by mvel.
the class CoreConfidenceTests method testRegExWithCast.
public void testRegExWithCast() {
final ParserContext parserContext = new ParserContext();
parserContext.setStrongTyping(true);
parserContext.addInput("this", Foo.class);
assertEquals(Boolean.class, MVEL.analyze("(String)bar.name ~= '[a-z].+'", parserContext));
}
Aggregations