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);
}
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);
}
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;
}
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);
}
}
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);
}
}
Aggregations