Search in sources :

Example 11 with MethodInvocation

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

the class ArrayRewriter method endVisit.

@Override
public void endVisit(InstanceofExpression node) {
    TypeMirror type = node.getRightOperand().getTypeMirror();
    if (!TypeUtil.isArray(type) || ((ArrayType) type).getComponentType().getKind().isPrimitive()) {
        return;
    }
    GeneratedExecutableElement element = GeneratedExecutableElement.newMethodWithSelector("isInstance", typeUtil.getBoolean(), TypeUtil.IOS_CLASS);
    element.addParameter(GeneratedVariableElement.newParameter("object", TypeUtil.ID_TYPE, element));
    MethodInvocation invocation = new MethodInvocation(new ExecutablePair(element), new TypeLiteral(type, typeUtil));
    invocation.addArgument(TreeUtil.remove(node.getLeftOperand()));
    node.replaceWith(invocation);
}
Also used : GeneratedExecutableElement(com.google.devtools.j2objc.types.GeneratedExecutableElement) TypeLiteral(com.google.devtools.j2objc.ast.TypeLiteral) TypeMirror(javax.lang.model.type.TypeMirror) ExecutablePair(com.google.devtools.j2objc.types.ExecutablePair) MethodInvocation(com.google.devtools.j2objc.ast.MethodInvocation)

Example 12 with MethodInvocation

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

the class ArrayRewriter method newInitializedArrayInvocation.

private MethodInvocation newInitializedArrayInvocation(ArrayType arrayType, List<Expression> elements, boolean retainedResult) {
    TypeMirror componentType = arrayType.getComponentType();
    TypeElement iosArrayElement = typeUtil.getIosArray(componentType);
    GeneratedExecutableElement methodElement = GeneratedExecutableElement.newMethodWithSelector(getInitializeSelector(componentType, retainedResult), iosArrayElement.asType(), iosArrayElement).addModifiers(Modifier.PUBLIC, Modifier.STATIC);
    methodElement.addParameter(GeneratedVariableElement.newParameter("values", new PointerType(componentType), methodElement));
    methodElement.addParameter(GeneratedVariableElement.newParameter("count", typeUtil.getInt(), methodElement));
    if (!componentType.getKind().isPrimitive()) {
        methodElement.addParameter(GeneratedVariableElement.newParameter("type", TypeUtil.IOS_CLASS.asType(), methodElement));
    }
    MethodInvocation invocation = new MethodInvocation(new ExecutablePair(methodElement), arrayType, new SimpleName(iosArrayElement));
    // Create the array initializer and add it as the first parameter.
    ArrayInitializer arrayInit = new ArrayInitializer(arrayType);
    for (Expression element : elements) {
        arrayInit.addExpression(element.copy());
    }
    invocation.addArgument(arrayInit);
    // Add the array size parameter.
    invocation.addArgument(NumberLiteral.newIntLiteral(arrayInit.getExpressions().size(), typeUtil));
    // Add the type argument for object arrays.
    if (!componentType.getKind().isPrimitive()) {
        invocation.addArgument(new TypeLiteral(componentType, typeUtil));
    }
    return invocation;
}
Also used : GeneratedExecutableElement(com.google.devtools.j2objc.types.GeneratedExecutableElement) TypeLiteral(com.google.devtools.j2objc.ast.TypeLiteral) TypeMirror(javax.lang.model.type.TypeMirror) ExecutablePair(com.google.devtools.j2objc.types.ExecutablePair) InstanceofExpression(com.google.devtools.j2objc.ast.InstanceofExpression) Expression(com.google.devtools.j2objc.ast.Expression) PrefixExpression(com.google.devtools.j2objc.ast.PrefixExpression) TypeElement(javax.lang.model.element.TypeElement) SimpleName(com.google.devtools.j2objc.ast.SimpleName) PointerType(com.google.devtools.j2objc.types.PointerType) MethodInvocation(com.google.devtools.j2objc.ast.MethodInvocation) ArrayInitializer(com.google.devtools.j2objc.ast.ArrayInitializer)

Example 13 with MethodInvocation

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

the class TreeConverter method convertMethodInvocation.

private static TreeNode convertMethodInvocation(org.eclipse.jdt.core.dom.MethodInvocation node) {
    MethodInvocation newNode = new MethodInvocation();
    convertExpression(node, newNode);
    for (Object argument : node.arguments()) {
        newNode.addArgument((Expression) TreeConverter.convert(argument));
    }
    IMethodBinding methodBinding = node.resolveMethodBinding();
    return newNode.setExecutablePair(new ExecutablePair(BindingConverter.getExecutableElement(methodBinding), BindingConverter.getType(methodBinding))).setTypeMirror(BindingConverter.getType(node.resolveTypeBinding())).setName((SimpleName) TreeConverter.convert(node.getName())).setExpression((Expression) TreeConverter.convert(node.getExpression())).setVarargsType(getVarargsType(methodBinding, node.arguments()));
}
Also used : IMethodBinding(org.eclipse.jdt.core.dom.IMethodBinding) ExecutablePair(com.google.devtools.j2objc.types.ExecutablePair) PostfixExpression(com.google.devtools.j2objc.ast.PostfixExpression) InstanceofExpression(com.google.devtools.j2objc.ast.InstanceofExpression) Expression(com.google.devtools.j2objc.ast.Expression) ConditionalExpression(com.google.devtools.j2objc.ast.ConditionalExpression) InfixExpression(com.google.devtools.j2objc.ast.InfixExpression) ParenthesizedExpression(com.google.devtools.j2objc.ast.ParenthesizedExpression) LambdaExpression(com.google.devtools.j2objc.ast.LambdaExpression) PrefixExpression(com.google.devtools.j2objc.ast.PrefixExpression) ThisExpression(com.google.devtools.j2objc.ast.ThisExpression) FunctionalExpression(com.google.devtools.j2objc.ast.FunctionalExpression) CastExpression(com.google.devtools.j2objc.ast.CastExpression) VariableDeclarationExpression(com.google.devtools.j2objc.ast.VariableDeclarationExpression) MethodInvocation(com.google.devtools.j2objc.ast.MethodInvocation) SuperMethodInvocation(com.google.devtools.j2objc.ast.SuperMethodInvocation)

Example 14 with MethodInvocation

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

the class ArrayRewriter method newMultiDimensionArrayInvocation.

private MethodInvocation newMultiDimensionArrayInvocation(ArrayType arrayType, List<Expression> dimensions, boolean retainedResult) {
    assert dimensions.size() > 1;
    TypeMirror componentType = arrayType;
    for (int i = 0; i < dimensions.size(); i++) {
        assert TypeUtil.isArray(componentType);
        componentType = ((ArrayType) componentType).getComponentType();
    }
    TypeElement iosArrayElement = typeUtil.getIosArray(componentType);
    ExecutableElement methodElement = getMultiDimensionMethod(componentType, iosArrayElement, retainedResult);
    MethodInvocation invocation = new MethodInvocation(new ExecutablePair(methodElement), arrayType, new SimpleName(iosArrayElement));
    // Add the dimension count argument.
    invocation.addArgument(NumberLiteral.newIntLiteral(dimensions.size(), typeUtil));
    // Create the dimensions array.
    ArrayInitializer dimensionsArg = new ArrayInitializer(typeUtil.getArrayType(typeUtil.getInt()));
    for (Expression e : dimensions) {
        dimensionsArg.addExpression(e.copy());
    }
    invocation.addArgument(dimensionsArg);
    if (!componentType.getKind().isPrimitive()) {
        invocation.addArgument(new TypeLiteral(componentType, typeUtil));
    }
    return invocation;
}
Also used : TypeLiteral(com.google.devtools.j2objc.ast.TypeLiteral) TypeMirror(javax.lang.model.type.TypeMirror) ExecutablePair(com.google.devtools.j2objc.types.ExecutablePair) InstanceofExpression(com.google.devtools.j2objc.ast.InstanceofExpression) Expression(com.google.devtools.j2objc.ast.Expression) PrefixExpression(com.google.devtools.j2objc.ast.PrefixExpression) TypeElement(javax.lang.model.element.TypeElement) GeneratedExecutableElement(com.google.devtools.j2objc.types.GeneratedExecutableElement) ExecutableElement(javax.lang.model.element.ExecutableElement) SimpleName(com.google.devtools.j2objc.ast.SimpleName) MethodInvocation(com.google.devtools.j2objc.ast.MethodInvocation) ArrayInitializer(com.google.devtools.j2objc.ast.ArrayInitializer)

Example 15 with MethodInvocation

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

the class SwitchRewriter method fixEnumValue.

private void fixEnumValue(SwitchStatement node) {
    Expression expr = node.getExpression();
    TypeMirror type = expr.getTypeMirror();
    if (!TypeUtil.isEnum(type)) {
        return;
    }
    DeclaredType enumType = typeUtil.getSuperclass(type);
    ExecutablePair ordinalMethod = typeUtil.findMethod(enumType, "ordinal");
    MethodInvocation invocation = new MethodInvocation(ordinalMethod, TreeUtil.remove(expr));
    node.setExpression(invocation);
}
Also used : Expression(com.google.devtools.j2objc.ast.Expression) NativeExpression(com.google.devtools.j2objc.ast.NativeExpression) TypeMirror(javax.lang.model.type.TypeMirror) ExecutablePair(com.google.devtools.j2objc.types.ExecutablePair) MethodInvocation(com.google.devtools.j2objc.ast.MethodInvocation) DeclaredType(javax.lang.model.type.DeclaredType)

Aggregations

MethodInvocation (com.google.devtools.j2objc.ast.MethodInvocation)17 ExecutablePair (com.google.devtools.j2objc.types.ExecutablePair)14 SimpleName (com.google.devtools.j2objc.ast.SimpleName)9 TypeMirror (javax.lang.model.type.TypeMirror)9 Expression (com.google.devtools.j2objc.ast.Expression)8 SuperMethodInvocation (com.google.devtools.j2objc.ast.SuperMethodInvocation)8 GeneratedExecutableElement (com.google.devtools.j2objc.types.GeneratedExecutableElement)8 ExecutableElement (javax.lang.model.element.ExecutableElement)7 PrefixExpression (com.google.devtools.j2objc.ast.PrefixExpression)5 TypeLiteral (com.google.devtools.j2objc.ast.TypeLiteral)5 TypeElement (javax.lang.model.element.TypeElement)5 InfixExpression (com.google.devtools.j2objc.ast.InfixExpression)4 InstanceofExpression (com.google.devtools.j2objc.ast.InstanceofExpression)4 PostfixExpression (com.google.devtools.j2objc.ast.PostfixExpression)4 FunctionInvocation (com.google.devtools.j2objc.ast.FunctionInvocation)3 VariableElement (javax.lang.model.element.VariableElement)3 ArrayInitializer (com.google.devtools.j2objc.ast.ArrayInitializer)2 Block (com.google.devtools.j2objc.ast.Block)2 CastExpression (com.google.devtools.j2objc.ast.CastExpression)2 ConditionalExpression (com.google.devtools.j2objc.ast.ConditionalExpression)2