Package org.codehaus.groovy.ast.stmt

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


    classNode.addMethod(GET_EVENT_TYPE_METHOD_NAME,
        Modifier.PUBLIC,
        GET_EVENT_TYPE_METHOD_TYPE,
        ZERO_PARAMETERS,
        EMPTY_CLASS_ARRAY,
        new ReturnStatement(expression)
    );
  }
View Full Code Here


    classNode.addMethod(GET_ORIGIN_SUFFIX_METHOD_NAME,
        Modifier.PUBLIC,
        GET_ORIGIN_SUFFIX_METHOD_TYPE,
        ZERO_PARAMETERS,
        EMPTY_CLASS_ARRAY,
        new ReturnStatement(expression)
    );
  }
View Full Code Here

            )
        )
    );
    classNode.addMethod(GET_MESSAGE_CODE_METHOD_NAME, Modifier.PUBLIC, GET_MESSAGE_CODE_METHOD_TYPE,
        ZERO_PARAMETERS, EMPTY_CLASS_ARRAY,
        new ReturnStatement(new BinaryExpression(
            getMessagePrefixExpression,
            PLUS_OPERATOR,
            new ConstantExpression(MESSAGE_CODE_SUFFIX)
        )));
    classNode.addMethod(GET_COMMENT_CODE_METHOD_NAME, Modifier.PUBLIC, GET_COMMENT_CODE_METHOD_TYPE,
        ZERO_PARAMETERS, EMPTY_CLASS_ARRAY,
        new ReturnStatement(new BinaryExpression(
            getMessagePrefixExpression,
            PLUS_OPERATOR,
            new ConstantExpression(COMMENT_CODE_SUFFIX)
        )));
  }
View Full Code Here

    public void testMethods() throws Exception {
        ClassNode classNode = new ClassNode("Foo", ACC_PUBLIC, ClassHelper.OBJECT_TYPE);
        classNode.addConstructor(new ConstructorNode(ACC_PUBLIC, null));

        Statement statementA = new ReturnStatement(new ConstantExpression("calledA"));
        Statement statementB = new ReturnStatement(new ConstantExpression("calledB"));
        Statement emptyStatement = new BlockStatement();

        classNode.addMethod(new MethodNode("a", ACC_PUBLIC, ClassHelper.OBJECT_TYPE, Parameter.EMPTY_ARRAY, ClassNode.EMPTY_ARRAY, statementA));
        classNode.addMethod(new MethodNode("b", ACC_PUBLIC, null, Parameter.EMPTY_ARRAY, ClassNode.EMPTY_ARRAY, statementB));
View Full Code Here

     * @return the result of the expression
     */
    public static Object evaluateExpression(Expression expr, CompilerConfiguration config) {
        String className = "Expression$" + UUID.randomUUID().toString().replace('-', '$');
        ClassNode node = new ClassNode(className, Opcodes.ACC_PUBLIC, ClassHelper.OBJECT_TYPE);
        ReturnStatement code = new ReturnStatement(expr);
        node.addMethod(new MethodNode("eval", Opcodes.ACC_PUBLIC+Opcodes.ACC_STATIC, ClassHelper.OBJECT_TYPE, Parameter.EMPTY_ARRAY, ClassNode.EMPTY_ARRAY, code));
        CompilerConfiguration copyConf = new CompilerConfiguration(config);
        CompilationUnit cu = new CompilationUnit(copyConf);
        cu.addClassNode(node);
        cu.compile(Phases.CLASS_GENERATION);
View Full Code Here

        gStringStrings.add(new ConstantExpression(""));
        gStringStrings.add(new ConstantExpression(""));
        List<Expression> gStringValues = new ArrayList<Expression>();
        gStringValues.add(new VariableExpression(parameters[0]));
        block.addStatement(
                new ReturnStatement(
                        new PropertyExpression(
                                thiz,
                                new GStringExpression("$name", gStringStrings, gStringValues)
                        )
                )
View Full Code Here

        gStringStrings.add(new ConstantExpression(""));
        gStringStrings.add(new ConstantExpression(""));
        List<Expression> gStringValues = new ArrayList<Expression>();
        gStringValues.add(new VariableExpression(parameters[0]));
        block.addStatement(
                new ReturnStatement(
                        new MethodCallExpression(
                                thiz,
                                new GStringExpression("$name", gStringStrings, gStringValues),
                                new ArgumentListExpression(
                                        new SpreadExpression(new VariableExpression(parameters[1]))
View Full Code Here

    public static Expression propX(Expression owner, Expression property) {
        return new PropertyExpression(owner, property);
    }

    public static Statement returnS(Expression expr) {
        return new ReturnStatement(new ExpressionStatement(expr));
    }
View Full Code Here

                expression.setImplicitThis(true);

                if (method.isVoidMethod()) {
                    code.addStatement(new ExpressionStatement(expression));
                } else {
                    code.addStatement(new ReturnStatement(expression));
                }

                List<AnnotationNode> annotations = method.getAnnotations();
                if(annotations != null) {
                    newMethod.addAnnotations(annotations);
View Full Code Here

                        newParams = new Parameter[]{new Parameter(fixedType, "val")};
                    }

                    Expression fieldExpr = new VariableExpression(cNode.getField(fieldName));
                    Statement body =
                            getter ? new ReturnStatement(fieldExpr) :
                                    new ExpressionStatement(
                                            new BinaryExpression(
                                                    fieldExpr,
                                                    Token.newSymbol(Types.EQUAL, 0, 0),
                                                    new VariableExpression(newParams[0])
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.