use of com.google.devtools.j2objc.ast.InfixExpression in project j2objc by google.
the class StatementGenerator method visit.
@Override
public boolean visit(InfixExpression node) {
InfixExpression.Operator op = node.getOperator();
List<Expression> operands = node.getOperands();
assert operands.size() >= 2;
if ((op.equals(InfixExpression.Operator.EQUALS) || op.equals(InfixExpression.Operator.NOT_EQUALS))) {
Expression lhs = operands.get(0);
Expression rhs = operands.get(1);
if (lhs instanceof StringLiteral || rhs instanceof StringLiteral) {
if (!(lhs instanceof StringLiteral)) {
// In case the lhs can't call isEqual.
lhs = operands.get(1);
rhs = operands.get(0);
}
buffer.append(op.equals(InfixExpression.Operator.NOT_EQUALS) ? "![" : "[");
lhs.accept(this);
buffer.append(" isEqual:");
rhs.accept(this);
buffer.append("]");
return false;
}
}
String opStr = ' ' + op.toString() + ' ';
boolean isFirst = true;
for (Expression operand : operands) {
if (!isFirst) {
buffer.append(opStr);
}
isFirst = false;
operand.accept(this);
}
return false;
}
use of com.google.devtools.j2objc.ast.InfixExpression in project j2objc by google.
the class TreeConverter method convertInfixExpression.
private static TreeNode convertInfixExpression(org.eclipse.jdt.core.dom.InfixExpression node) {
InfixExpression newNode = new InfixExpression();
convertExpression(node, newNode);
newNode.setTypeMirror(BindingConverter.getType(node.resolveTypeBinding())).setOperator(InfixExpression.Operator.parse(node.getOperator().toString()));
// The JDT parser apparently does not always take advantage of extended
// operands, resulting in potentially very deep trees that can overflow the
// stack. This code traverses the subtree non-recursively and merges all
// children that have the same operator into this node using extended
// operands.
List<StackState> stack = Lists.newArrayList();
stack.add(new StackState(node));
while (!stack.isEmpty()) {
StackState currentState = stack.get(stack.size() - 1);
org.eclipse.jdt.core.dom.Expression child = currentState.nextChild();
if (child == null) {
stack.remove(stack.size() - 1);
continue;
}
if (child instanceof org.eclipse.jdt.core.dom.InfixExpression) {
org.eclipse.jdt.core.dom.InfixExpression infixChild = (org.eclipse.jdt.core.dom.InfixExpression) child;
if (infixChild.getOperator().equals(node.getOperator())) {
stack.add(new StackState(infixChild));
continue;
}
}
newNode.addOperand((Expression) TreeConverter.convert(child));
}
return newNode;
}
use of com.google.devtools.j2objc.ast.InfixExpression in project j2objc by google.
the class Autoboxer method endVisit.
@Override
public void endVisit(InfixExpression node) {
InfixExpression.Operator op = node.getOperator();
List<Expression> operands = node.getOperands();
// Don't unbox for equality tests where both operands are boxed types.
if ((op == InfixExpression.Operator.EQUALS || op == InfixExpression.Operator.NOT_EQUALS) && !operands.get(0).getTypeMirror().getKind().isPrimitive() && !operands.get(1).getTypeMirror().getKind().isPrimitive()) {
return;
}
// Don't unbox for string concatenation.
if (op == InfixExpression.Operator.PLUS && typeUtil.isString(node.getTypeMirror())) {
return;
}
for (Expression operand : operands) {
if (!operand.getTypeMirror().getKind().isPrimitive()) {
unbox(operand);
}
}
}
Aggregations