/** * Extract a top-level <code>beans{}</code> closure from inside this block if * there is one. Removes it from the block at the same time. * @param block a block statement (class definition) * @return a beans Closure if one can be found, null otherwise */ private ClosureExpression beans(BlockStatement block) { return AstUtils.getClosure(block, BEANS, true); }
/** * Extract a top-level <code>ratpack{}</code> closure from inside this block if * there is one. Removes it from the block at the same time. * @param block a block statement (class definition) * @return a beans Closure if one can be found, null otherwise */ private ClosureExpression ratpack(BlockStatement block) { return AstUtils.getClosure(block, RATPACK, true); } }
public static ClosureExpression getClosure(BlockStatement block, String name) { return getClosure(block, name, false); }
/** * Extract a top-level {@code name} closure from inside this block if there is one, * optionally removing it from the block at the same time. * @param block a block statement (class definition) * @param name the name to look for * @param remove whether or not the extracted closure should be removed * @return a beans Closure if one can be found, null otherwise */ public static ClosureExpression getClosure(BlockStatement block, String name, boolean remove) { for (ExpressionStatement statement : getExpressionStatements(block)) { Expression expression = statement.getExpression(); if (expression instanceof MethodCallExpression) { ClosureExpression closure = getClosure(name, (MethodCallExpression) expression); if (closure != null) { if (remove) { block.getStatements().remove(statement); } return closure; } } } return null; }