static List<String> getBlocks(String exp) { return getBlocks(exp, false); }
static List<String> getBlocks(String exp) { return getBlocks(exp, false); }
public Expression prepare(Map<String, Object> model, Map<String, UserFunction> functions, List<String> imports) { switch (type) { case IF: { List<String> args = getBlocks(statement, true); if (args.size() > 1) throw new IllegalStateException("more then one statement in condition: " + statement); AsBooleanExpression condition = new AsBooleanExpression(EvalTools.prepare(args.get(0), model, functions, imports)); Expression then = bodyStatement != null ? bodyStatement.prepare(model, functions, imports) : EvalTools.prepare(body, model, functions, imports); Expression elseExpression = optionalStatement != null ? optionalStatement.prepare(model, functions, imports) : EvalTools.prepare(optional, model, functions, imports); if (elseExpression == null) return new IfExpression(condition, then); else return new IfExpression(condition, then, elseExpression); } default: throw new IllegalStateException("not implemented yet"); } }
public Expression prepare(Map<String, Object> model, Map<String, UserFunction> functions, List<String> imports) { switch (type) { case IF: { List<String> args = getBlocks(statement, true); if (args.size() > 1) throw new IllegalStateException("more then one statement in condition: " + statement); AsBooleanExpression condition = new AsBooleanExpression(EvalTools.prepare(args.get(0), model, functions, imports)); Expression then = bodyStatement != null ? bodyStatement.prepare(model, functions, imports) : EvalTools.prepare(body, model, functions, imports); Expression elseExpression = optionalStatement != null ? optionalStatement.prepare(model, functions, imports) : EvalTools.prepare(optional, model, functions, imports); if (elseExpression == null) return new IfExpression(condition, then); else return new IfExpression(condition, then, elseExpression); } default: throw new IllegalStateException("not implemented yet"); } }
exp = exp.substring(1, exp.length() - 1).trim(); ClosureExpression closure = new ClosureExpression(); List<String> lines = getBlocks(exp); if (lines.isEmpty()) return new ClosureHolder(closure); List<String> lines = getBlocks(s.statement); if (lines.size() > 1) { ClosureExpression inner = new ClosureExpression();
exp = exp.substring(1, exp.length() - 1).trim(); ClosureExpression closure = new ClosureExpression(); List<String> lines = getBlocks(exp); if (lines.isEmpty()) return new ClosureHolder(closure); List<String> lines = getBlocks(s.statement); if (lines.size() > 1) { ClosureExpression inner = new ClosureExpression();
l = EvalTools.getBlocks(s); Assert.assertEquals(1, l.size()); Assert.assertEquals(s, l.get(0)); l = EvalTools.getBlocks(s); Assert.assertEquals(2, l.size()); Assert.assertEquals("int i = 1", l.get(0)); l = EvalTools.getBlocks(s); Assert.assertEquals(1, l.size()); Assert.assertEquals(s, l.get(0)); l = EvalTools.getBlocks(s); Assert.assertEquals(3, l.size()); Assert.assertEquals("int i = 1", l.get(0)); l = EvalTools.getBlocks(s); Assert.assertEquals(3, l.size()); Assert.assertEquals("def a = new A()", l.get(0));