Search in sources :

Example 1 with ArrayAccess

use of com.google.devtools.j2objc.ast.ArrayAccess in project j2objc by google.

the class ArrayRewriter method visit.

// We must handle object array assignment before its children because if the
// rhs is an array creation, we can optimize with "SetAndConsume".
@Override
public boolean visit(Assignment node) {
    Expression lhs = node.getLeftHandSide();
    TypeMirror lhsType = lhs.getTypeMirror();
    if (lhs instanceof ArrayAccess && !lhsType.getKind().isPrimitive()) {
        FunctionInvocation newAssignment = newArrayAssignment(node, (ArrayAccess) lhs, lhsType);
        node.replaceWith(newAssignment);
        newAssignment.accept(this);
        return false;
    }
    return true;
}
Also used : ArrayAccess(com.google.devtools.j2objc.ast.ArrayAccess) FunctionInvocation(com.google.devtools.j2objc.ast.FunctionInvocation) InstanceofExpression(com.google.devtools.j2objc.ast.InstanceofExpression) Expression(com.google.devtools.j2objc.ast.Expression) PrefixExpression(com.google.devtools.j2objc.ast.PrefixExpression) TypeMirror(javax.lang.model.type.TypeMirror)

Example 2 with ArrayAccess

use of com.google.devtools.j2objc.ast.ArrayAccess in project j2objc by google.

the class TranslationUtil method getOperatorFunctionModifier.

/**
   * Returns the modifier for an assignment expression being converted to a
   * function. The result will be "Array" if the lhs is an array access,
   * "Strong" if the lhs is a field with a strong reference, and an empty string
   * for local variables and weak fields.
   */
public String getOperatorFunctionModifier(Expression expr) {
    VariableElement var = TreeUtil.getVariableElement(expr);
    if (var == null) {
        assert TreeUtil.trimParentheses(expr) instanceof ArrayAccess : "Expression cannot be resolved to a variable or array access.";
        return "Array";
    }
    String modifier = "";
    if (ElementUtil.isVolatile(var)) {
        modifier += "Volatile";
    }
    if (!ElementUtil.isWeakReference(var) && (var.getKind().isField() || options.useARC())) {
        modifier += "Strong";
    }
    return modifier;
}
Also used : ArrayAccess(com.google.devtools.j2objc.ast.ArrayAccess) VariableElement(javax.lang.model.element.VariableElement)

Aggregations

ArrayAccess (com.google.devtools.j2objc.ast.ArrayAccess)2 Expression (com.google.devtools.j2objc.ast.Expression)1 FunctionInvocation (com.google.devtools.j2objc.ast.FunctionInvocation)1 InstanceofExpression (com.google.devtools.j2objc.ast.InstanceofExpression)1 PrefixExpression (com.google.devtools.j2objc.ast.PrefixExpression)1 VariableElement (javax.lang.model.element.VariableElement)1 TypeMirror (javax.lang.model.type.TypeMirror)1