Package org.codehaus.groovy.ast.stmt

Examples of org.codehaus.groovy.ast.stmt.ReturnStatement


                    final Expression expression = ((ExpressionStatement) closureStatement).getExpression();
                    if (expression instanceof MethodCallExpression) {
                        methodExpressions.add((MethodCallExpression) expression);
                    }
                } else if (closureStatement instanceof ReturnStatement) {
                    final ReturnStatement returnStatement = (ReturnStatement) closureStatement;
                    Expression expression = returnStatement.getExpression();
                    if (expression instanceof MethodCallExpression) {
                        methodExpressions.add((MethodCallExpression) expression);
                    }
                }
View Full Code Here


            BinaryExpression testTargetAssignment = new BinaryExpression(fieldExpression, ASSIGN, new ConstructorCallExpression(targetClass.getType(), GrailsArtefactClassInjector.ZERO_ARGS));

            IfStatement autowiringIfStatement = getAutowiringIfStatement(targetClass,fieldExpression, testTargetAssignment);
            getterBody.addStatement(autowiringIfStatement);

            getterBody.addStatement(new ReturnStatement(fieldExpression));
            classNode.addMethod(getter);
            GrailsASTUtils.addCompileStaticAnnotation(getter);
        }

        return methodNode;
View Full Code Here

        final ASTNode getErrorsMethod = paramTypeClassNode.getMethod(HAS_ERRORS_METHOD_NAME, GrailsArtefactClassInjector.ZERO_PARAMETERS);
        if (getErrorsMethod == null) {
            final BlockStatement hasErrorsMethodCode = new BlockStatement();
            final Expression initErrorsMethodCallExpression = new MethodCallExpression(new VariableExpression("this"), INIT_ERRORS_METHOD_NAME, EMPTY_TUPLE);
            hasErrorsMethodCode.addStatement(new ExpressionStatement(initErrorsMethodCallExpression));
            final Statement returnStatement = new ReturnStatement(new BooleanExpression(new MethodCallExpression(ERRORS_EXPRESSION, HAS_ERRORS_METHOD_NAME, EMPTY_TUPLE)));
            hasErrorsMethodCode.addStatement(returnStatement);
            paramTypeClassNode.addMethod(new MethodNode(HAS_ERRORS_METHOD_NAME,
                    Modifier.PUBLIC, new ClassNode(Boolean.class),
                    GrailsArtefactClassInjector.ZERO_PARAMETERS, GrailsArtefactClassInjector.EMPTY_CLASS_ARRAY, hasErrorsMethodCode));
        }
View Full Code Here

        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);
            paramTypeClassNode.addMethod(new MethodNode(GET_ERRORS_METHOD_NAME,
                    Modifier.PUBLIC, ERRORS_CLASS_NODE,
                    GrailsArtefactClassInjector.ZERO_PARAMETERS, GrailsArtefactClassInjector.EMPTY_CLASS_ARRAY, getErrorsMethodCode));
        }
View Full Code Here

        if (!hasToString && !isEnum(classNode)) {
            GStringExpression ge = new GStringExpression(classNode.getName() + " : ${id ? id : '(unsaved)'}");
            ge.addString(new ConstantExpression(classNode.getName() + " : "));
            VariableExpression idVariable = new VariableExpression("id");
            ge.addValue(new TernaryExpression(new BooleanExpression(idVariable), idVariable, new ConstantExpression("(unsaved)")));
            Statement s = new ReturnStatement(ge);
            MethodNode mn = new MethodNode("toString", Modifier.PUBLIC, new ClassNode(String.class), new Parameter[0], new ClassNode[0], s);
            classNode.addMethod(mn);
            classesWithInjectedToString.add(classNode);
        }
    }
View Full Code Here

        BlockStatement ifBlock = new BlockStatement();
        ArgumentListExpression arguments = new ArgumentListExpression();
        arguments.addExpression(new ConstantExpression("Method on class ["+classNode+"] was used outside of a Grails application. If running in the context of a test using the mocking API or bootstrap Grails correctly."));
        ifBlock.addStatement(new ThrowStatement(new ConstructorCallExpression(new ClassNode(IllegalStateException.class), arguments)));       
        BlockStatement elseBlock = new BlockStatement();
        elseBlock.addStatement(new ReturnStatement(apiVar));
        methodBody.addStatement(new IfStatement(new BooleanExpression(new BinaryExpression(apiVar, GrailsASTUtils.EQUALS_OPERATOR, GrailsASTUtils.NULL_EXPRESSION)),ifBlock,elseBlock));
       
        MethodNode methodNode = new MethodNode(methodName, PUBLIC_STATIC_MODIFIER, implementationNode,ZERO_PARAMETERS,null,methodBody);       
        return methodNode;
    }
View Full Code Here

            GrailsASTUtils.addCompileStaticAnnotation(classNode.addMethod(setterName, Modifier.PUBLIC | Modifier.STATIC, ClassHelper.VOID_TYPE, new Parameter[]{setterParameter}, null, setterBody));
        }
    }

    protected MethodNode populateDefaultApiLookupMethod(ClassNode implementationNode, String apiInstanceProperty, String methodName, BlockStatement methodBody) {
        methodBody.addStatement(new ReturnStatement(new VariableExpression(apiInstanceProperty, implementationNode)));
        return new MethodNode(methodName, Modifier.PRIVATE, implementationNode,ZERO_PARAMETERS,null,methodBody);
    }
View Full Code Here

                                            checkDslProperty(parent,
                                                    (MethodCallExpression)e.getExpression());
                                        }
                                    } else if (statement instanceof ReturnStatement) {
                                        // Single item in block
                                        ReturnStatement e = (ReturnStatement)statement;
                                        if (e.getExpression() instanceof MethodCallExpression) {
                                            checkDslProperty(parent,
                                                    (MethodCallExpression)e.getExpression());
                                        }
                                    }
                                }
                            }
                        }
View Full Code Here

   */
  private void addFieldsAndConstructor(ClassNode classNode) {
    classNode.addField(EVENT_NAME_FIELD_NAME, Modifier.PRIVATE, EVENT_NAME_TYPE, null);
    classNode.addMethod("get"+StringUtils.capitalize(EVENT_NAME_FIELD_NAME), Modifier.PUBLIC,
        EVENT_NAME_TYPE, ZERO_PARAMETERS, EMPTY_CLASS_ARRAY,
        new ReturnStatement(new VariableExpression(EVENT_NAME_FIELD_NAME)));
    classNode.addField(SEVERITY_FIELD_NAME, Modifier.PRIVATE, SEVERITY_TYPE, null);
    classNode.addMethod("get"+StringUtils.capitalize(SEVERITY_FIELD_NAME), Modifier.PUBLIC,
        SEVERITY_TYPE, ZERO_PARAMETERS, EMPTY_CLASS_ARRAY,
        new ReturnStatement(new VariableExpression(SEVERITY_FIELD_NAME)));
    classNode.addField(E_LEVEL_FIELD_NAME, Modifier.PRIVATE, E_LEVEL_TYPE, null);
    classNode.addMethod("get"+StringUtils.capitalize(E_LEVEL_FIELD_NAME), Modifier.PUBLIC,
        E_LEVEL_TYPE, ZERO_PARAMETERS, EMPTY_CLASS_ARRAY,
        new ReturnStatement(new VariableExpression(E_LEVEL_FIELD_NAME)));

    String eventNameFieldName = "eventName";
    String severityFieldName = "severity";
    String escalationLevelFieldName = "escalationLevel";
    BlockStatement constructorStatements = new BlockStatement();
View Full Code Here

   * @param classNode
   */
  private void addEventCodeMethod(ClassNode classNode) {
    classNode.addMethod(GET_EVENT_CODE_METHOD_NAME, Modifier.PUBLIC, GET_EVENT_CODE_METHOD_TYPE,
        ZERO_PARAMETERS, EMPTY_CLASS_ARRAY,
        new ReturnStatement(
            new MethodCallExpression(
                VariableExpression.THIS_EXPRESSION,
                "ordinal",
                MethodCallExpression.NO_ARGUMENTS
            )
View Full Code Here

TOP

Related Classes of org.codehaus.groovy.ast.stmt.ReturnStatement

Copyright © 2018 www.massapicom. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.