Search in sources :

Example 1 with GeneratedExecutableElement

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

the class BindingConverter method unwrapGeneratedElement.

private static IBinding unwrapGeneratedElement(GeneratedElement element) {
    IBinding binding = generatedBindingCache.get(element);
    if (binding != null) {
        return binding;
    }
    if (element instanceof GeneratedVariableElement) {
        binding = new GeneratedVariableBinding((GeneratedVariableElement) element);
        generatedBindingCache.put(element, binding);
        return binding;
    }
    if (element instanceof GeneratedExecutableElement) {
        binding = new GeneratedMethodBinding((GeneratedExecutableElement) element);
        generatedBindingCache.put(element, binding);
        return binding;
    }
    if (element instanceof GeneratedTypeElement) {
        throw new AssertionError("not supported");
    }
    if (element instanceof GeneratedPackageElement) {
        binding = new GeneratedPackageBinding(((GeneratedPackageElement) element).getName());
        generatedBindingCache.put(element, binding);
        return binding;
    }
    throw new AssertionError("unknown generated element kind");
}
Also used : GeneratedExecutableElement(com.google.devtools.j2objc.types.GeneratedExecutableElement) GeneratedPackageElement(com.google.devtools.j2objc.types.GeneratedPackageElement) GeneratedTypeElement(com.google.devtools.j2objc.types.GeneratedTypeElement) GeneratedVariableElement(com.google.devtools.j2objc.types.GeneratedVariableElement) IBinding(org.eclipse.jdt.core.dom.IBinding)

Example 2 with GeneratedExecutableElement

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

the class JavaToIOSMethodTranslator method addCopyWithZoneMethod.

private void addCopyWithZoneMethod(TypeDeclaration node) {
    // Create copyWithZone: method.
    GeneratedExecutableElement copyElement = GeneratedExecutableElement.newMethodWithSelector("copyWithZone:", TypeUtil.ID_TYPE, node.getTypeElement());
    MethodDeclaration copyDecl = new MethodDeclaration(copyElement);
    copyDecl.setHasDeclaration(false);
    // Add NSZone *zone parameter.
    VariableElement zoneParam = GeneratedVariableElement.newParameter("zone", NSZONE_TYPE, copyElement);
    copyElement.addParameter(zoneParam);
    copyDecl.addParameter(new SingleVariableDeclaration(zoneParam));
    Block block = new Block();
    copyDecl.setBody(block);
    ExecutableElement cloneElement = ElementUtil.findMethod(typeUtil.getJavaObject(), "clone");
    MethodInvocation invocation = new MethodInvocation(new ExecutablePair(cloneElement), null);
    if (options.useReferenceCounting()) {
        invocation = new MethodInvocation(new ExecutablePair(RETAIN_METHOD), invocation);
    }
    block.addStatement(new ReturnStatement(invocation));
    node.addBodyDeclaration(copyDecl);
}
Also used : GeneratedExecutableElement(com.google.devtools.j2objc.types.GeneratedExecutableElement) ExecutablePair(com.google.devtools.j2objc.types.ExecutablePair) MethodDeclaration(com.google.devtools.j2objc.ast.MethodDeclaration) SingleVariableDeclaration(com.google.devtools.j2objc.ast.SingleVariableDeclaration) 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) MethodInvocation(com.google.devtools.j2objc.ast.MethodInvocation) VariableElement(javax.lang.model.element.VariableElement) GeneratedVariableElement(com.google.devtools.j2objc.types.GeneratedVariableElement)

Example 3 with GeneratedExecutableElement

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

the class AbstractMethodRewriter method newReturnTypeNarrowingDeclaration.

private MethodDeclaration newReturnTypeNarrowingDeclaration(String selector, ExecutablePair method, TypeElement declaringClass) {
    GeneratedExecutableElement element = GeneratedExecutableElement.newMethodWithSelector(selector, method.type().getReturnType(), declaringClass).addModifiers(ElementUtil.getVisibilityModifiers(method.element())).addModifiers(Modifier.ABSTRACT);
    MethodDeclaration decl = new MethodDeclaration(element);
    if (!declaringClass.getKind().isInterface()) {
        unit.setHasIncompleteImplementation();
    }
    int argCount = 0;
    for (TypeMirror paramType : method.type().getParameterTypes()) {
        VariableElement param = GeneratedVariableElement.newParameter("arg" + argCount++, paramType, element);
        element.addParameter(param);
        decl.addParameter(new SingleVariableDeclaration(param));
    }
    return decl;
}
Also used : GeneratedExecutableElement(com.google.devtools.j2objc.types.GeneratedExecutableElement) TypeMirror(javax.lang.model.type.TypeMirror) MethodDeclaration(com.google.devtools.j2objc.ast.MethodDeclaration) SingleVariableDeclaration(com.google.devtools.j2objc.ast.SingleVariableDeclaration) VariableElement(javax.lang.model.element.VariableElement) GeneratedVariableElement(com.google.devtools.j2objc.types.GeneratedVariableElement)

Example 4 with GeneratedExecutableElement

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

the class ArrayRewriter method getMultiDimensionMethod.

private ExecutableElement getMultiDimensionMethod(TypeMirror componentType, TypeElement iosArrayType, boolean retainedResult) {
    boolean isPrimitive = componentType.getKind().isPrimitive();
    String selector = (retainedResult ? "newArray" : "array") + "WithDimensions:lengths:" + (isPrimitive ? "" : "type:");
    GeneratedExecutableElement element = GeneratedExecutableElement.newMethodWithSelector(selector, TypeUtil.IOS_OBJECT_ARRAY.asType(), iosArrayType).addModifiers(Modifier.PUBLIC, Modifier.STATIC);
    TypeMirror intType = typeUtil.getInt();
    element.addParameter(GeneratedVariableElement.newParameter("dimensions", intType, element));
    element.addParameter(GeneratedVariableElement.newParameter("dimensionLengths", new PointerType(intType), element));
    if (!isPrimitive) {
        element.addParameter(GeneratedVariableElement.newParameter("type", TypeUtil.IOS_CLASS.asType(), element));
    }
    return element;
}
Also used : GeneratedExecutableElement(com.google.devtools.j2objc.types.GeneratedExecutableElement) TypeMirror(javax.lang.model.type.TypeMirror) PointerType(com.google.devtools.j2objc.types.PointerType)

Example 5 with GeneratedExecutableElement

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

the class ArrayRewriter method newSingleDimensionArrayInvocation.

private MethodInvocation newSingleDimensionArrayInvocation(ArrayType arrayType, Expression dimensionExpr, boolean retainedResult) {
    TypeMirror componentType = arrayType.getComponentType();
    TypeElement iosArrayElement = typeUtil.getIosArray(componentType);
    boolean isPrimitive = componentType.getKind().isPrimitive();
    String selector = (retainedResult ? "newArray" : "array") + "WithLength:" + (isPrimitive ? "" : "type:");
    GeneratedExecutableElement methodElement = GeneratedExecutableElement.newMethodWithSelector(selector, iosArrayElement.asType(), iosArrayElement).addModifiers(Modifier.PUBLIC, Modifier.STATIC);
    methodElement.addParameter(GeneratedVariableElement.newParameter("length", typeUtil.getInt(), methodElement));
    if (!isPrimitive) {
        methodElement.addParameter(GeneratedVariableElement.newParameter("type", TypeUtil.IOS_CLASS.asType(), methodElement));
    }
    MethodInvocation invocation = new MethodInvocation(new ExecutablePair(methodElement), arrayType, new SimpleName(iosArrayElement));
    // Add the array length argument.
    invocation.addArgument(dimensionExpr.copy());
    // Add the type argument for object arrays.
    if (!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) TypeElement(javax.lang.model.element.TypeElement) SimpleName(com.google.devtools.j2objc.ast.SimpleName) MethodInvocation(com.google.devtools.j2objc.ast.MethodInvocation)

Aggregations

GeneratedExecutableElement (com.google.devtools.j2objc.types.GeneratedExecutableElement)9 TypeMirror (javax.lang.model.type.TypeMirror)6 MethodInvocation (com.google.devtools.j2objc.ast.MethodInvocation)4 ExecutablePair (com.google.devtools.j2objc.types.ExecutablePair)4 GeneratedVariableElement (com.google.devtools.j2objc.types.GeneratedVariableElement)4 TypeElement (javax.lang.model.element.TypeElement)4 MethodDeclaration (com.google.devtools.j2objc.ast.MethodDeclaration)3 SingleVariableDeclaration (com.google.devtools.j2objc.ast.SingleVariableDeclaration)3 TypeLiteral (com.google.devtools.j2objc.ast.TypeLiteral)3 ExecutableElement (javax.lang.model.element.ExecutableElement)3 VariableElement (javax.lang.model.element.VariableElement)3 SimpleName (com.google.devtools.j2objc.ast.SimpleName)2 PointerType (com.google.devtools.j2objc.types.PointerType)2 ArrayInitializer (com.google.devtools.j2objc.ast.ArrayInitializer)1 Block (com.google.devtools.j2objc.ast.Block)1 Expression (com.google.devtools.j2objc.ast.Expression)1 InstanceofExpression (com.google.devtools.j2objc.ast.InstanceofExpression)1 PrefixExpression (com.google.devtools.j2objc.ast.PrefixExpression)1 ReturnStatement (com.google.devtools.j2objc.ast.ReturnStatement)1 GeneratedPackageElement (com.google.devtools.j2objc.types.GeneratedPackageElement)1