use of com.google.devtools.j2objc.ast.StringLiteral 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.StringLiteral in project j2objc by google.
the class AnnotationRewriter method createDescriptionMethod.
private MethodDeclaration createDescriptionMethod(TypeElement type) {
ExecutableElement descriptionElement = GeneratedExecutableElement.newMethodWithSelector("description", typeUtil.getJavaString().asType(), type);
MethodDeclaration descriptionMethod = new MethodDeclaration(descriptionElement);
descriptionMethod.setHasDeclaration(false);
Block descriptionBody = new Block();
descriptionMethod.setBody(descriptionBody);
descriptionBody.addStatement(new ReturnStatement(new StringLiteral("@" + elementUtil.getBinaryName(type) + "()", typeUtil)));
return descriptionMethod;
}
Aggregations