use of org.codehaus.groovy.ast.expr.BinaryExpression in project groovy by apache.
the class BinaryExpressionTransformer method transformDeclarationExpression.
private static Expression transformDeclarationExpression(final BinaryExpression bin) {
Expression leftExpression = bin.getLeftExpression();
if (leftExpression instanceof VariableExpression) {
if (ClassHelper.char_TYPE.equals(((VariableExpression) leftExpression).getOriginType())) {
Expression rightExpression = bin.getRightExpression();
if (rightExpression instanceof ConstantExpression && ClassHelper.STRING_TYPE.equals(rightExpression.getType())) {
String text = (String) ((ConstantExpression) rightExpression).getValue();
if (text.length() == 1) {
// optimize char initialization
ConstantExpression ce = new ConstantExpression(text.charAt(0), true);
ce.setSourcePosition(rightExpression);
bin.setRightExpression(ce);
return bin;
}
}
}
}
return null;
}
use of org.codehaus.groovy.ast.expr.BinaryExpression 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.BinaryExpression 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.BinaryExpression in project spock by spockframework.
the class AbstractDeepBlockRewriter method visitBinaryExpression.
@Override
public final void visitBinaryExpression(BinaryExpression expr) {
BinaryExpression oldBinaryExpression = currBinaryExpr;
currBinaryExpr = expr;
try {
doVisitBinaryExpression(expr);
} finally {
currBinaryExpr = oldBinaryExpression;
}
}
use of org.codehaus.groovy.ast.expr.BinaryExpression in project groovy by apache.
the class BinaryExpressionHelper method evaluateBinaryExpression.
protected void evaluateBinaryExpression(String message, BinaryExpression binExp) {
CompileStack compileStack = controller.getCompileStack();
Expression receiver = binExp.getLeftExpression();
Expression arguments = binExp.getRightExpression();
// ensure VariableArguments are read, not stored
compileStack.pushLHS(false);
controller.getInvocationWriter().makeSingleArgumentCall(receiver, message, arguments);
compileStack.popLHS();
}
Aggregations