use of org.codehaus.groovy.ast.stmt.ReturnStatement in project grails-core by grails.
the class TagLibraryTransformer method addGetTagLibNamespaceMethod.
private void addGetTagLibNamespaceMethod(final ClassNode classNode, final String namespace) {
final ConstantExpression namespaceConstantExpression = new ConstantExpression(namespace);
Statement returnNamespaceStatement = new ReturnStatement(namespaceConstantExpression);
final MethodNode m = new MethodNode(GET_TAG_LIB_NAMESPACE_METHOD_NAME, Modifier.PROTECTED, new ClassNode(String.class), Parameter.EMPTY_ARRAY, null, returnNamespaceStatement);
classNode.addMethod(m);
}
use of org.codehaus.groovy.ast.stmt.ReturnStatement in project grails-core by grails.
the class TestMixinTransformation method getOrCreateMethodBody.
protected static BlockStatement getOrCreateMethodBody(ClassNode classNode, MethodNode methodNode, String name) {
BlockStatement methodBody;
if (!methodNode.getDeclaringClass().equals(classNode)) {
methodBody = new BlockStatement();
methodNode = new MethodNode(name, Modifier.PUBLIC, methodNode.getReturnType(), GrailsArtefactClassInjector.ZERO_PARAMETERS, null, methodBody);
classNode.addMethod(methodNode);
} else {
final Statement setupMethodBody = methodNode.getCode();
if (!(setupMethodBody instanceof BlockStatement)) {
methodBody = new BlockStatement();
if (setupMethodBody != null) {
if (!(setupMethodBody instanceof ReturnStatement)) {
methodBody.addStatement(setupMethodBody);
}
}
methodNode.setCode(methodBody);
} else {
methodBody = (BlockStatement) setupMethodBody;
}
}
return methodBody;
}
use of org.codehaus.groovy.ast.stmt.ReturnStatement in project groovy by apache.
the class Java5 method setMethodDefaultValue.
private static void setMethodDefaultValue(MethodNode mn, Method m) {
Object defaultValue = m.getDefaultValue();
ConstantExpression cExp = ConstantExpression.NULL;
if (defaultValue != null)
cExp = new ConstantExpression(defaultValue);
mn.setCode(new ReturnStatement(cExp));
mn.setAnnotationDefault(true);
}
use of org.codehaus.groovy.ast.stmt.ReturnStatement in project groovity by disney.
the class StatsASTTransformation method createImplicitReturn.
private Statement createImplicitReturn(Statement st) {
if (st instanceof ExpressionStatement) {
return new ReturnStatement(((ExpressionStatement) st).getExpression());
}
if (st instanceof BlockStatement) {
List<Statement> ls = ((BlockStatement) st).getStatements();
int pos = ls.size() - 1;
if (pos >= 0) {
Statement li;
if (((li = ls.get(pos)) instanceof ExpressionStatement)) {
// convert to return, groovy will miss this since we are wrapping in try/catch
ls.set(pos, new ReturnStatement(((ExpressionStatement) li).getExpression()));
}
}
}
return st;
}
use of org.codehaus.groovy.ast.stmt.ReturnStatement in project grails-core by grails.
the class ASTValidationErrorsHelper method addGetErrorsMethod.
protected void addGetErrorsMethod(final ClassNode paramTypeClassNode) {
final ASTNode getErrorsMethod = paramTypeClassNode.getMethod(GET_ERRORS_METHOD_NAME, GrailsArtefactClassInjector.ZERO_PARAMETERS);
if (getErrorsMethod == null) {
final BlockStatement getErrorsMethodCode = new BlockStatement();
final Expression initErrorsMethodCallExpression = new MethodCallExpression(new VariableExpression("this"), INIT_ERRORS_METHOD_NAME, EMPTY_TUPLE);
getErrorsMethodCode.addStatement(new ExpressionStatement(initErrorsMethodCallExpression));
final Statement returnStatement = new ReturnStatement(ERRORS_EXPRESSION);
getErrorsMethodCode.addStatement(returnStatement);
MethodNode methodNode = new MethodNode(GET_ERRORS_METHOD_NAME, Modifier.PUBLIC, ERRORS_CLASS_NODE, GrailsArtefactClassInjector.ZERO_PARAMETERS, GrailsArtefactClassInjector.EMPTY_CLASS_ARRAY, getErrorsMethodCode);
paramTypeClassNode.addMethod(methodNode);
AnnotatedNodeUtils.markAsGenerated(paramTypeClassNode, methodNode);
}
}
Aggregations