Search in sources :

Example 16 with ExecutablePair

use of com.google.devtools.j2objc.types.ExecutablePair 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 17 with ExecutablePair

use of com.google.devtools.j2objc.types.ExecutablePair in project j2objc by google.

the class TreeConverter method convertSuperConstructorInvocation.

private static TreeNode convertSuperConstructorInvocation(org.eclipse.jdt.core.dom.SuperConstructorInvocation node) {
    IMethodBinding binding = node.resolveConstructorBinding();
    SuperConstructorInvocation newNode = new SuperConstructorInvocation().setExecutablePair(new ExecutablePair(BindingConverter.getExecutableElement(binding), BindingConverter.getType(binding))).setVarargsType(getVarargsType(binding, node.arguments()));
    for (Object argument : node.arguments()) {
        newNode.addArgument((Expression) convert(argument));
    }
    return newNode.setExpression((Expression) TreeConverter.convert(node.getExpression()));
}
Also used : IMethodBinding(org.eclipse.jdt.core.dom.IMethodBinding) ExecutablePair(com.google.devtools.j2objc.types.ExecutablePair) SuperConstructorInvocation(com.google.devtools.j2objc.ast.SuperConstructorInvocation)

Example 18 with ExecutablePair

use of com.google.devtools.j2objc.types.ExecutablePair in project j2objc by google.

the class TreeConverter method convertSuperMethodInvocation.

private static TreeNode convertSuperMethodInvocation(org.eclipse.jdt.core.dom.SuperMethodInvocation node) {
    SuperMethodInvocation newNode = new SuperMethodInvocation();
    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))).setVarargsType(getVarargsType(methodBinding, node.arguments())).setQualifier((Name) TreeConverter.convert(node.getQualifier())).setName((SimpleName) TreeConverter.convert(node.getName()));
}
Also used : IMethodBinding(org.eclipse.jdt.core.dom.IMethodBinding) ExecutablePair(com.google.devtools.j2objc.types.ExecutablePair) SuperMethodInvocation(com.google.devtools.j2objc.ast.SuperMethodInvocation) SimpleName(com.google.devtools.j2objc.ast.SimpleName) Name(com.google.devtools.j2objc.ast.Name) QualifiedName(com.google.devtools.j2objc.ast.QualifiedName)

Example 19 with ExecutablePair

use of com.google.devtools.j2objc.types.ExecutablePair 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 20 with ExecutablePair

use of com.google.devtools.j2objc.types.ExecutablePair in project j2objc by google.

the class TreeConverter method convertClassInstanceCreation.

private static TreeNode convertClassInstanceCreation(org.eclipse.jdt.core.dom.ClassInstanceCreation node) {
    ClassInstanceCreation newNode = new ClassInstanceCreation();
    convertExpression(node, newNode);
    for (Object argument : node.arguments()) {
        newNode.addArgument((Expression) TreeConverter.convert(argument));
    }
    IMethodBinding binding = node.resolveConstructorBinding();
    JdtExecutableElement element = (JdtExecutableElement) BindingConverter.getExecutableElement(binding);
    JdtExecutableType type = BindingConverter.getType(binding);
    newNode.setExecutablePair(new ExecutablePair(element, type)).setVarargsType(getVarargsType(binding, node.arguments())).setType((Type) TreeConverter.convert(node.getType()));
    Expression expression = (Expression) TreeConverter.convert(node.getExpression());
    org.eclipse.jdt.core.dom.AnonymousClassDeclaration anonymousClassDecl = node.getAnonymousClassDeclaration();
    if (anonymousClassDecl != null && expression != null) {
        VariableElement superOuterParam = GeneratedVariableElement.newParameter("superOuter$", expression.getTypeMirror(), element);
        element.setSuperOuterParam(superOuterParam);
        type.setSuperOuterParamType(superOuterParam.asType());
        newNode.addArgument(0, expression);
    } else {
        newNode.setExpression(expression);
    }
    if (anonymousClassDecl != null) {
        newNode.setAnonymousClassDeclaration(convertAnonymousClassDeclaration(anonymousClassDecl, element, binding));
    }
    return newNode;
}
Also used : ClassInstanceCreation(com.google.devtools.j2objc.ast.ClassInstanceCreation) 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) VariableElement(javax.lang.model.element.VariableElement) GeneratedVariableElement(com.google.devtools.j2objc.types.GeneratedVariableElement)

Aggregations

ExecutablePair (com.google.devtools.j2objc.types.ExecutablePair)25 MethodInvocation (com.google.devtools.j2objc.ast.MethodInvocation)14 SimpleName (com.google.devtools.j2objc.ast.SimpleName)12 ExecutableElement (javax.lang.model.element.ExecutableElement)11 GeneratedExecutableElement (com.google.devtools.j2objc.types.GeneratedExecutableElement)10 TypeMirror (javax.lang.model.type.TypeMirror)10 SuperMethodInvocation (com.google.devtools.j2objc.ast.SuperMethodInvocation)9 TypeElement (javax.lang.model.element.TypeElement)9 Expression (com.google.devtools.j2objc.ast.Expression)8 IMethodBinding (org.eclipse.jdt.core.dom.IMethodBinding)7 Block (com.google.devtools.j2objc.ast.Block)5 PrefixExpression (com.google.devtools.j2objc.ast.PrefixExpression)5 SuperConstructorInvocation (com.google.devtools.j2objc.ast.SuperConstructorInvocation)5 TypeLiteral (com.google.devtools.j2objc.ast.TypeLiteral)5 GeneratedVariableElement (com.google.devtools.j2objc.types.GeneratedVariableElement)5 VariableElement (javax.lang.model.element.VariableElement)5 InstanceofExpression (com.google.devtools.j2objc.ast.InstanceofExpression)4 MethodDeclaration (com.google.devtools.j2objc.ast.MethodDeclaration)4 DeclaredType (javax.lang.model.type.DeclaredType)4 ConditionalExpression (com.google.devtools.j2objc.ast.ConditionalExpression)3