use of org.mule.mvel2.ParserContext 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.mule.mvel2.ParserContext 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);
}
use of org.mule.mvel2.ParserContext in project stargate-core by tuplejump.
the class AggregateFunction method init.
@Override
public void init(Options options) {
this.options = options;
int k = 0;
positions = new HashMap<>();
aggregateFields = new String[aggregates.length];
for (AggregateFactory aggregateFactory : aggregates) {
String field = aggregateFactory.getField();
if (field != null) {
aggregateFields[k] = field;
positions.put(field, k++);
}
}
ParserConfiguration parserConfig = getParserConfiguration();
if (groupBy != null) {
this.groupByExpressions = new ExecutableStatement[groupBy.length];
this.simpleExpressions = new boolean[groupBy.length];
groupByFields = new ArrayList<>();
for (int i = 0; i < groupBy.length; i++) {
String groupByField = groupBy[i];
String groupByCol = getGroupBy(groupByField);
boolean isSimpleExpression = options.types.containsKey(getColumnName(groupByCol));
ParserContext parserContext = new ParserContext(parserConfig);
groupByExpressions[i] = (ExecutableStatement) MVEL.compileExpression(groupByField, parserContext);
if (isSimpleExpression) {
simpleExpressions[i] = true;
int pos = k++;
positions.put(groupByCol, pos);
groupByFields.add(groupByCol);
} else {
simpleExpressions[i] = false;
Set<String> keys = parserContext.getInputs().keySet();
for (String key : keys) {
int pos = k++;
boolean canResolve = options.types.containsKey(getColumnName(key));
if (canResolve) {
String groupByColField = getGroupBy(key);
positions.put(key, pos);
groupByFields.add(groupByColField);
}
}
}
}
}
group = new Group(options, aggregates, groupBy, groupByExpressions);
}
use of org.mule.mvel2.ParserContext in project mvel by mikebrock.
the class FailureTests method testShouldFail8.
public void testShouldFail8() {
try {
ParserContext pCtx = new ParserContext();
pCtx.setStrongTyping(true);
MVEL.compileExpression("for (String s : new java.util.HashMap()) { }", pCtx);
} catch (Exception e) {
// e.printStackTrace();
return;
}
shouldThrowException();
}
use of org.mule.mvel2.ParserContext in project mvel by mikebrock.
the class FailureTests method testShouldFail7.
public void testShouldFail7() {
try {
ParserContext pctx = new ParserContext();
pctx.setStrongTyping(true);
MVEL.compileExpression("String x = 'foo'; int y = 2; new int[] { x, y }", pctx);
} catch (Exception e) {
// e.printStackTrace();
return;
}
shouldThrowException();
}
Aggregations