Search in sources :

Example 6 with StringLiteral

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;
}
Also used : StringLiteral(com.google.devtools.j2objc.ast.StringLiteral) CStringLiteral(com.google.devtools.j2objc.ast.CStringLiteral) LambdaExpression(com.google.devtools.j2objc.ast.LambdaExpression) PostfixExpression(com.google.devtools.j2objc.ast.PostfixExpression) InstanceofExpression(com.google.devtools.j2objc.ast.InstanceofExpression) Expression(com.google.devtools.j2objc.ast.Expression) PrefixExpression(com.google.devtools.j2objc.ast.PrefixExpression) ThisExpression(com.google.devtools.j2objc.ast.ThisExpression) NativeExpression(com.google.devtools.j2objc.ast.NativeExpression) CommaExpression(com.google.devtools.j2objc.ast.CommaExpression) ConditionalExpression(com.google.devtools.j2objc.ast.ConditionalExpression) CastExpression(com.google.devtools.j2objc.ast.CastExpression) VariableDeclarationExpression(com.google.devtools.j2objc.ast.VariableDeclarationExpression) InfixExpression(com.google.devtools.j2objc.ast.InfixExpression) ParenthesizedExpression(com.google.devtools.j2objc.ast.ParenthesizedExpression) InfixExpression(com.google.devtools.j2objc.ast.InfixExpression)

Example 7 with StringLiteral

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;
}
Also used : StringLiteral(com.google.devtools.j2objc.ast.StringLiteral) MethodDeclaration(com.google.devtools.j2objc.ast.MethodDeclaration) GeneratedExecutableElement(com.google.devtools.j2objc.types.GeneratedExecutableElement) ExecutableElement(javax.lang.model.element.ExecutableElement) ReturnStatement(com.google.devtools.j2objc.ast.ReturnStatement) Block(com.google.devtools.j2objc.ast.Block)

Aggregations

StringLiteral (com.google.devtools.j2objc.ast.StringLiteral)7 ExecutableElement (javax.lang.model.element.ExecutableElement)4 SimpleName (com.google.devtools.j2objc.ast.SimpleName)3 GeneratedExecutableElement (com.google.devtools.j2objc.types.GeneratedExecutableElement)3 Assignment (com.google.devtools.j2objc.ast.Assignment)2 Block (com.google.devtools.j2objc.ast.Block)2 CommaExpression (com.google.devtools.j2objc.ast.CommaExpression)2 EnumConstantDeclaration (com.google.devtools.j2objc.ast.EnumConstantDeclaration)2 Expression (com.google.devtools.j2objc.ast.Expression)2 ExpressionStatement (com.google.devtools.j2objc.ast.ExpressionStatement)2 ForStatement (com.google.devtools.j2objc.ast.ForStatement)2 MethodDeclaration (com.google.devtools.j2objc.ast.MethodDeclaration)2 NativeExpression (com.google.devtools.j2objc.ast.NativeExpression)2 NativeStatement (com.google.devtools.j2objc.ast.NativeStatement)2 NumberLiteral (com.google.devtools.j2objc.ast.NumberLiteral)2 ReturnStatement (com.google.devtools.j2objc.ast.ReturnStatement)2 Statement (com.google.devtools.j2objc.ast.Statement)2 VariableDeclarationStatement (com.google.devtools.j2objc.ast.VariableDeclarationStatement)2 GeneratedVariableElement (com.google.devtools.j2objc.types.GeneratedVariableElement)2 VariableElement (javax.lang.model.element.VariableElement)2