Package org.codehaus.groovy.ast.expr

Examples of org.codehaus.groovy.ast.expr.BooleanExpression


     *
     * @param method the {@link org.codehaus.groovy.ast.MethodNode} for assertion injection
     * @param precondition the {@link org.gcontracts.domain.Precondition} the assertion statement should be generated from
     */
    public void generatePreconditionAssertionStatement(final MethodNode method, final org.gcontracts.domain.Precondition precondition)  {
        final BooleanExpression preconditionBooleanExpression = addCallsToSuperMethodNodeAnnotationClosure(method.getDeclaringClass(), method, Precondition.class, precondition.booleanExpression(), false);

        BlockStatement blockStatement;

        final BlockStatement originalBlockStatement = precondition.originalBlockStatement();
        // if use execution tracker flag is found in the meta-data the annotation closure visitor discovered
View Full Code Here


        boolean isAnotherPreconditionAvailable = AnnotationUtils.getAnnotationNodeInHierarchyWithMetaAnnotation(type.getSuperClass(), methodNode, ClassHelper.makeWithoutCaching(Precondition.class)).size() > 0;
        if (!isAnotherPreconditionAvailable) return;

        // if there is another preconditio up the inheritance path, we need a default precondition with FALSE
        // e.g. C1 <no precondition> : C2 <item != null> == false || item != null
        BooleanExpression preconditionBooleanExpression = new BooleanExpression(ConstantExpression.FALSE);
        preconditionBooleanExpression = addCallsToSuperMethodNodeAnnotationClosure(type, methodNode, Precondition.class, preconditionBooleanExpression, false);
        // if precondition could not be found in parent class, let's return
        if (preconditionBooleanExpression.getExpression() == ConstantExpression.FALSE)
            return;

        final BlockStatement blockStatement = wrapAssertionBooleanExpression(type,  methodNode, preconditionBooleanExpression, "precondition");
       
        addPrecondition(methodNode, blockStatement);
View Full Code Here

    private BlockStatement originalBlockStatement;
    private BooleanExpression booleanExpression;

    public Assertion()  {
        this.booleanExpression = new BooleanExpression(ConstantExpression.TRUE);
    }
View Full Code Here

    }

    public void and(T other) {
        Validate.notNull(other);

        BooleanExpression newBooleanExpression =
                new BooleanExpression(
                        new BinaryExpression(
                                booleanExpression(),
                                Token.newSymbol(Types.LOGICAL_AND, -1, -1),
                                other.booleanExpression()
                        )
                );
        newBooleanExpression.setSourcePosition(booleanExpression());

        renew(newBooleanExpression);
    }
View Full Code Here

    }

    public void or(T other) {
        Validate.notNull(other);

        BooleanExpression newBooleanExpression =
                new BooleanExpression(
                        new BinaryExpression(
                                booleanExpression(),
                                Token.newSymbol(Types.LOGICAL_OR, -1, -1),
                                other.booleanExpression()
                        )
                );
        newBooleanExpression.setSourcePosition(booleanExpression());

        renew(newBooleanExpression);
    }
View Full Code Here

            first = false;
        } else {
            body.addStatement(append(result, new ConstantExpression(", ")));
        }
        body.addStatement(new IfStatement(
                new BooleanExpression(new VariableExpression(cNode.getField("$print$names"))),
                toStringPropertyName(result, name),
                new EmptyStatement()
        ));
        return first;
    }
View Full Code Here

        classNode.addConstructor(new ConstructorNode(ACC_PUBLIC, null));
        classNode.addProperty(new PropertyNode("bar", ACC_PUBLIC, ClassHelper.STRING_TYPE, classNode, null, null, null));

        classNode.addProperty(new PropertyNode("result", ACC_PUBLIC, ClassHelper.STRING_TYPE, classNode, null, null, null));

        BooleanExpression expression =
                new BooleanExpression(
                        new BinaryExpression(
                                new FieldExpression(
                                        new FieldNode("bar", ACC_PRIVATE, ClassHelper.STRING_TYPE, classNode, ConstantExpression.NULL)),
                                Token.newSymbol("==", 0, 0),
                                new ConstantExpression("abc")));
View Full Code Here

   
    private void writeSourcelessAssertText(AssertStatement statement) {
        MethodVisitor mv = controller.getMethodVisitor();
        OperandStack operandStack = controller.getOperandStack();
       
        BooleanExpression booleanExpression = statement.getBooleanExpression();
        // push expression string onto stack
        String expressionText = booleanExpression.getText();
        List<String> list = new ArrayList<String>();
        addVariableNames(booleanExpression, list);
        if (list.isEmpty()) {
            mv.visitLdcInsn(expressionText);
        } else {
View Full Code Here

        operandStack.remove(2);
    }
   
    private void addVariableNames(Expression expression, List<String> list) {
        if (expression instanceof BooleanExpression) {
            BooleanExpression boolExp = (BooleanExpression) expression;
            addVariableNames(boolExp.getExpression(), list);
        } else if (expression instanceof BinaryExpression) {
            BinaryExpression binExp = (BinaryExpression) expression;
            addVariableNames(binExp.getLeftExpression(), list);
            addVariableNames(binExp.getRightExpression(), list);
        } else if (expression instanceof VariableExpression) {
View Full Code Here

    private static Expression assignExpr(Expression expression, Expression value) {
        return new BinaryExpression(expression, ASSIGN, value);
    }

    public static BooleanExpression isInstanceOf(Expression objectExpression, ClassNode cNode) {
        return new BooleanExpression(new BinaryExpression(objectExpression, INSTANCEOF, new ClassExpression(cNode)));
    }
View Full Code Here

TOP

Related Classes of org.codehaus.groovy.ast.expr.BooleanExpression

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.