Search in sources :

Example 6 with FieldAccess

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

the class ArrayRewriter method maybeRewriteArrayLength.

private void maybeRewriteArrayLength(Expression node, SimpleName name, Expression expr) {
    TypeMirror exprType = expr.getTypeMirror();
    if (name.getIdentifier().equals("length") && TypeUtil.isArray(exprType)) {
        VariableElement sizeField = GeneratedVariableElement.newField("size", typeUtil.getInt(), typeUtil.getIosArray(((ArrayType) exprType).getComponentType()));
        node.replaceWith(new FieldAccess(sizeField, TreeUtil.remove(expr)));
    }
}
Also used : ArrayType(javax.lang.model.type.ArrayType) TypeMirror(javax.lang.model.type.TypeMirror) VariableElement(javax.lang.model.element.VariableElement) GeneratedVariableElement(com.google.devtools.j2objc.types.GeneratedVariableElement) FieldAccess(com.google.devtools.j2objc.ast.FieldAccess)

Aggregations

FieldAccess (com.google.devtools.j2objc.ast.FieldAccess)6 VariableElement (javax.lang.model.element.VariableElement)5 Expression (com.google.devtools.j2objc.ast.Expression)4 InfixExpression (com.google.devtools.j2objc.ast.InfixExpression)4 PrefixExpression (com.google.devtools.j2objc.ast.PrefixExpression)4 SimpleName (com.google.devtools.j2objc.ast.SimpleName)4 GeneratedVariableElement (com.google.devtools.j2objc.types.GeneratedVariableElement)3 TypeMirror (javax.lang.model.type.TypeMirror)3 ParenthesizedExpression (com.google.devtools.j2objc.ast.ParenthesizedExpression)2 PostfixExpression (com.google.devtools.j2objc.ast.PostfixExpression)2 SuperFieldAccess (com.google.devtools.j2objc.ast.SuperFieldAccess)2 ThisExpression (com.google.devtools.j2objc.ast.ThisExpression)2 VariableDeclarationExpression (com.google.devtools.j2objc.ast.VariableDeclarationExpression)2 VariableDeclarationStatement (com.google.devtools.j2objc.ast.VariableDeclarationStatement)2 PointerType (com.google.devtools.j2objc.types.PointerType)2 ArrayType (javax.lang.model.type.ArrayType)2 Assignment (com.google.devtools.j2objc.ast.Assignment)1 Block (com.google.devtools.j2objc.ast.Block)1 CastExpression (com.google.devtools.j2objc.ast.CastExpression)1 CommaExpression (com.google.devtools.j2objc.ast.CommaExpression)1