Search in sources :

Example 1 with BooleanExpression

use of org.codehaus.groovy.ast.expr.BooleanExpression in project groovy by apache.

the class BinaryExpressionTransformer method convertInOperatorToTernary.

private Expression convertInOperatorToTernary(final BinaryExpression bin, final Expression rightExpression, final Expression leftExpression) {
    MethodCallExpression call = new MethodCallExpression(rightExpression, "isCase", leftExpression);
    call.setMethodTarget((MethodNode) bin.getNodeMetaData(StaticTypesMarker.DIRECT_METHOD_CALL_TARGET));
    call.setSourcePosition(bin);
    call.copyNodeMetaData(bin);
    TernaryExpression tExp = new TernaryExpression(new BooleanExpression(new BinaryExpression(rightExpression, Token.newSymbol("==", -1, -1), new ConstantExpression(null))), new BinaryExpression(leftExpression, Token.newSymbol("==", -1, -1), new ConstantExpression(null)), call);
    return staticCompilationTransformer.transform(tExp);
}
Also used : TernaryExpression(org.codehaus.groovy.ast.expr.TernaryExpression) BooleanExpression(org.codehaus.groovy.ast.expr.BooleanExpression) MethodCallExpression(org.codehaus.groovy.ast.expr.MethodCallExpression) BinaryExpression(org.codehaus.groovy.ast.expr.BinaryExpression) ConstantExpression(org.codehaus.groovy.ast.expr.ConstantExpression)

Example 2 with BooleanExpression

use of org.codehaus.groovy.ast.expr.BooleanExpression in project gcontracts by andresteingress.

the class Assertion method or.

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);
}
Also used : BooleanExpression(org.codehaus.groovy.ast.expr.BooleanExpression) BinaryExpression(org.codehaus.groovy.ast.expr.BinaryExpression)

Example 3 with BooleanExpression

use of org.codehaus.groovy.ast.expr.BooleanExpression in project gcontracts by andresteingress.

the class AssertStatementCreationUtility method getAssertionStatemens.

/**
 * Reusable method for creating assert statements for the given <tt>booleanExpression</tt>.
 *
 * @param booleanExpressions the assertion's {@link org.codehaus.groovy.ast.expr.BooleanExpression} instances
 *
 * @return a newly created {@link org.codehaus.groovy.ast.stmt.AssertStatement}
 */
public static BlockStatement getAssertionStatemens(final List<BooleanExpression> booleanExpressions) {
    List<AssertStatement> assertStatements = new ArrayList<AssertStatement>();
    for (BooleanExpression booleanExpression : booleanExpressions) {
        assertStatements.add(getAssertionStatement(booleanExpression));
    }
    final BlockStatement blockStatement = new BlockStatement();
    blockStatement.getStatements().addAll(assertStatements);
    return blockStatement;
}
Also used : BooleanExpression(org.codehaus.groovy.ast.expr.BooleanExpression) ArrayList(java.util.ArrayList)

Example 4 with BooleanExpression

use of org.codehaus.groovy.ast.expr.BooleanExpression in project grails-core by grails.

the class ASTValidationErrorsHelper method addInitErrorsMethod.

protected void addInitErrorsMethod(final ClassNode paramTypeClassNode) {
    final ASTNode initErrorsMethod = paramTypeClassNode.getMethod(INIT_ERRORS_METHOD_NAME, GrailsArtefactClassInjector.ZERO_PARAMETERS);
    if (initErrorsMethod == null) {
        final BlockStatement initErrorsMethodCode = new BlockStatement();
        final BinaryExpression errorsIsNullExpression = new BinaryExpression(ERRORS_EXPRESSION, Token.newSymbol(Types.COMPARE_EQUAL, 0, 0), NULL_EXPRESSION);
        Expression beanPropertyBindingResultConstructorArgs = new ArgumentListExpression(new VariableExpression("this"), new ConstantExpression(paramTypeClassNode.getName()));
        final Statement newEvaluatorExpression = new ExpressionStatement(new BinaryExpression(ERRORS_EXPRESSION, EQUALS_SYMBOL, new ConstructorCallExpression(new ClassNode(ValidationErrors.class), beanPropertyBindingResultConstructorArgs)));
        final Statement initErrorsIfNullStatement = new IfStatement(new BooleanExpression(errorsIsNullExpression), newEvaluatorExpression, new ExpressionStatement(new EmptyExpression()));
        initErrorsMethodCode.addStatement(initErrorsIfNullStatement);
        MethodNode methodNode = new MethodNode(INIT_ERRORS_METHOD_NAME, Modifier.PRIVATE, ClassHelper.VOID_TYPE, GrailsArtefactClassInjector.ZERO_PARAMETERS, GrailsArtefactClassInjector.EMPTY_CLASS_ARRAY, initErrorsMethodCode);
        paramTypeClassNode.addMethod(methodNode);
        AnnotatedNodeUtils.markAsGenerated(paramTypeClassNode, methodNode);
    }
}
Also used : ClassNode(org.codehaus.groovy.ast.ClassNode) ValidationErrors(grails.validation.ValidationErrors) Statement(org.codehaus.groovy.ast.stmt.Statement) ExpressionStatement(org.codehaus.groovy.ast.stmt.ExpressionStatement) ReturnStatement(org.codehaus.groovy.ast.stmt.ReturnStatement) IfStatement(org.codehaus.groovy.ast.stmt.IfStatement) BlockStatement(org.codehaus.groovy.ast.stmt.BlockStatement) ConstructorCallExpression(org.codehaus.groovy.ast.expr.ConstructorCallExpression) ConstantExpression(org.codehaus.groovy.ast.expr.ConstantExpression) ArgumentListExpression(org.codehaus.groovy.ast.expr.ArgumentListExpression) BlockStatement(org.codehaus.groovy.ast.stmt.BlockStatement) VariableExpression(org.codehaus.groovy.ast.expr.VariableExpression) EmptyExpression(org.codehaus.groovy.ast.expr.EmptyExpression) IfStatement(org.codehaus.groovy.ast.stmt.IfStatement) BooleanExpression(org.codehaus.groovy.ast.expr.BooleanExpression) BinaryExpression(org.codehaus.groovy.ast.expr.BinaryExpression) MethodNode(org.codehaus.groovy.ast.MethodNode) BooleanExpression(org.codehaus.groovy.ast.expr.BooleanExpression) ConstantExpression(org.codehaus.groovy.ast.expr.ConstantExpression) MethodCallExpression(org.codehaus.groovy.ast.expr.MethodCallExpression) EmptyExpression(org.codehaus.groovy.ast.expr.EmptyExpression) Expression(org.codehaus.groovy.ast.expr.Expression) ConstructorCallExpression(org.codehaus.groovy.ast.expr.ConstructorCallExpression) VariableExpression(org.codehaus.groovy.ast.expr.VariableExpression) ArgumentListExpression(org.codehaus.groovy.ast.expr.ArgumentListExpression) TupleExpression(org.codehaus.groovy.ast.expr.TupleExpression) BinaryExpression(org.codehaus.groovy.ast.expr.BinaryExpression) ExpressionStatement(org.codehaus.groovy.ast.stmt.ExpressionStatement) ASTNode(org.codehaus.groovy.ast.ASTNode)

Example 5 with BooleanExpression

use of org.codehaus.groovy.ast.expr.BooleanExpression in project grails-core by grails.

the class ASTValidationErrorsHelper method addHasErrorsMethod.

protected void addHasErrorsMethod(final ClassNode paramTypeClassNode) {
    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);
        MethodNode methodNode = new MethodNode(HAS_ERRORS_METHOD_NAME, Modifier.PUBLIC, new ClassNode(Boolean.class), GrailsArtefactClassInjector.ZERO_PARAMETERS, GrailsArtefactClassInjector.EMPTY_CLASS_ARRAY, hasErrorsMethodCode);
        paramTypeClassNode.addMethod(methodNode);
        AnnotatedNodeUtils.markAsGenerated(paramTypeClassNode, methodNode);
    }
}
Also used : ClassNode(org.codehaus.groovy.ast.ClassNode) BooleanExpression(org.codehaus.groovy.ast.expr.BooleanExpression) MethodCallExpression(org.codehaus.groovy.ast.expr.MethodCallExpression) MethodNode(org.codehaus.groovy.ast.MethodNode) BooleanExpression(org.codehaus.groovy.ast.expr.BooleanExpression) ConstantExpression(org.codehaus.groovy.ast.expr.ConstantExpression) MethodCallExpression(org.codehaus.groovy.ast.expr.MethodCallExpression) EmptyExpression(org.codehaus.groovy.ast.expr.EmptyExpression) Expression(org.codehaus.groovy.ast.expr.Expression) ConstructorCallExpression(org.codehaus.groovy.ast.expr.ConstructorCallExpression) VariableExpression(org.codehaus.groovy.ast.expr.VariableExpression) ArgumentListExpression(org.codehaus.groovy.ast.expr.ArgumentListExpression) TupleExpression(org.codehaus.groovy.ast.expr.TupleExpression) BinaryExpression(org.codehaus.groovy.ast.expr.BinaryExpression) Statement(org.codehaus.groovy.ast.stmt.Statement) ExpressionStatement(org.codehaus.groovy.ast.stmt.ExpressionStatement) ReturnStatement(org.codehaus.groovy.ast.stmt.ReturnStatement) IfStatement(org.codehaus.groovy.ast.stmt.IfStatement) BlockStatement(org.codehaus.groovy.ast.stmt.BlockStatement) ExpressionStatement(org.codehaus.groovy.ast.stmt.ExpressionStatement) ASTNode(org.codehaus.groovy.ast.ASTNode) ReturnStatement(org.codehaus.groovy.ast.stmt.ReturnStatement) BlockStatement(org.codehaus.groovy.ast.stmt.BlockStatement) VariableExpression(org.codehaus.groovy.ast.expr.VariableExpression)

Aggregations

BooleanExpression (org.codehaus.groovy.ast.expr.BooleanExpression)48 BinaryExpression (org.codehaus.groovy.ast.expr.BinaryExpression)30 VariableExpression (org.codehaus.groovy.ast.expr.VariableExpression)24 BlockStatement (org.codehaus.groovy.ast.stmt.BlockStatement)24 ConstantExpression (org.codehaus.groovy.ast.expr.ConstantExpression)23 MethodCallExpression (org.codehaus.groovy.ast.expr.MethodCallExpression)23 ClassExpression (org.codehaus.groovy.ast.expr.ClassExpression)19 ArgumentListExpression (org.codehaus.groovy.ast.expr.ArgumentListExpression)18 Expression (org.codehaus.groovy.ast.expr.Expression)18 ExpressionStatement (org.codehaus.groovy.ast.stmt.ExpressionStatement)16 IfStatement (org.codehaus.groovy.ast.stmt.IfStatement)16 ConstructorCallExpression (org.codehaus.groovy.ast.expr.ConstructorCallExpression)15 Statement (org.codehaus.groovy.ast.stmt.Statement)14 ReturnStatement (org.codehaus.groovy.ast.stmt.ReturnStatement)13 ClosureExpression (org.codehaus.groovy.ast.expr.ClosureExpression)12 DeclarationExpression (org.codehaus.groovy.ast.expr.DeclarationExpression)12 EmptyExpression (org.codehaus.groovy.ast.expr.EmptyExpression)12 PropertyExpression (org.codehaus.groovy.ast.expr.PropertyExpression)12 TernaryExpression (org.codehaus.groovy.ast.expr.TernaryExpression)12 TupleExpression (org.codehaus.groovy.ast.expr.TupleExpression)12