use of org.codehaus.groovy.classgen.ReturnAdder in project groovy by apache.
the class ReturnAdderForClosures method visitClosureExpression.
@Override
public void visitClosureExpression(ClosureExpression expression) {
// Create a dummy method with the closure's code as the method's code. Then user ReturnAdder, which only works for methods.
MethodNode node = new MethodNode("dummy", 0, ClassHelper.OBJECT_TYPE, Parameter.EMPTY_ARRAY, ClassNode.EMPTY_ARRAY, expression.getCode());
new ReturnAdder().visitMethod(node);
super.visitClosureExpression(expression);
}
use of org.codehaus.groovy.classgen.ReturnAdder in project groovy by apache.
the class StaticTypeCheckingVisitor method isTypeSource.
private static boolean isTypeSource(final Expression expr, final MethodNode mNode) {
boolean[] returned = new boolean[1];
mNode.getCode().visit(new CodeVisitorSupport() {
@Override
public void visitReturnStatement(final ReturnStatement returnStatement) {
if (isTypeSource(expr, returnStatement.getExpression())) {
returned[0] = true;
}
}
@Override
public void visitClosureExpression(final ClosureExpression expression) {
}
});
if (!returned[0]) {
new ReturnAdder(returnStatement -> {
if (isTypeSource(expr, returnStatement.getExpression())) {
returned[0] = true;
}
}).visitMethod(mNode);
}
return returned[0];
}
use of org.codehaus.groovy.classgen.ReturnAdder in project groovy by apache.
the class TailRecursiveASTTransformation method addMissingDefaultReturnStatement.
private void addMissingDefaultReturnStatement(MethodNode method) {
new ReturnAdder().visitMethod(method);
new ReturnAdderForClosures().visitMethod(method);
}
Aggregations