Search in sources :

Example 1 with GeneratedVariableElement

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

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

the class MethodTranslator method visitVariableDeclaration.

@Override
public TreeNode visitVariableDeclaration(com.strobel.decompiler.languages.java.ast.VariableDeclarationStatement node, Void data) {
    VariableDeclarationStatement varDecl = new VariableDeclarationStatement().setModifiers(ElementUtil.fromModifierSet(new HashSet<>(node.getModifiers())));
    AstType astType = node.getType();
    Type type = (Type) astType.acceptVisitor(this, null);
    for (VariableInitializer init : node.getVariables()) {
        Expression expr = (Expression) init.acceptVisitor(this, null);
        String varName = init.getName();
        GeneratedVariableElement elem = GeneratedVariableElement.newLocalVar(varName, type.getTypeMirror(), executableElement);
        elem.addModifiers(node.getModifiers());
        localVariableTable.put(varName, elem);
        varDecl.addFragment(new VariableDeclarationFragment(elem, expr));
    }
    return varDecl;
}
Also used : AstType(com.strobel.decompiler.languages.java.ast.AstType) ComposedType(com.strobel.decompiler.languages.java.ast.ComposedType) AstType(com.strobel.decompiler.languages.java.ast.AstType) Type(com.google.devtools.j2objc.ast.Type) SimpleType(com.google.devtools.j2objc.ast.SimpleType) DeclaredType(javax.lang.model.type.DeclaredType) ArrayType(com.google.devtools.j2objc.ast.ArrayType) WildcardType(com.strobel.decompiler.languages.java.ast.WildcardType) ExecutableType(javax.lang.model.type.ExecutableType) SuperReferenceExpression(com.strobel.decompiler.languages.java.ast.SuperReferenceExpression) PostfixExpression(com.google.devtools.j2objc.ast.PostfixExpression) AnonymousObjectCreationExpression(com.strobel.decompiler.languages.java.ast.AnonymousObjectCreationExpression) Expression(com.google.devtools.j2objc.ast.Expression) TypeReferenceExpression(com.strobel.decompiler.languages.java.ast.TypeReferenceExpression) UnaryOperatorExpression(com.strobel.decompiler.languages.java.ast.UnaryOperatorExpression) ConditionalExpression(com.google.devtools.j2objc.ast.ConditionalExpression) BinaryOperatorExpression(com.strobel.decompiler.languages.java.ast.BinaryOperatorExpression) ClassOfExpression(com.strobel.decompiler.languages.java.ast.ClassOfExpression) ThisReferenceExpression(com.strobel.decompiler.languages.java.ast.ThisReferenceExpression) AssignmentExpression(com.strobel.decompiler.languages.java.ast.AssignmentExpression) InfixExpression(com.google.devtools.j2objc.ast.InfixExpression) PrimitiveExpression(com.strobel.decompiler.languages.java.ast.PrimitiveExpression) ParenthesizedExpression(com.google.devtools.j2objc.ast.ParenthesizedExpression) MemberReferenceExpression(com.strobel.decompiler.languages.java.ast.MemberReferenceExpression) PrefixExpression(com.google.devtools.j2objc.ast.PrefixExpression) ObjectCreationExpression(com.strobel.decompiler.languages.java.ast.ObjectCreationExpression) InvocationExpression(com.strobel.decompiler.languages.java.ast.InvocationExpression) ThisExpression(com.google.devtools.j2objc.ast.ThisExpression) ArrayCreationExpression(com.strobel.decompiler.languages.java.ast.ArrayCreationExpression) MethodGroupExpression(com.strobel.decompiler.languages.java.ast.MethodGroupExpression) IdentifierExpression(com.strobel.decompiler.languages.java.ast.IdentifierExpression) IndexerExpression(com.strobel.decompiler.languages.java.ast.IndexerExpression) NullReferenceExpression(com.strobel.decompiler.languages.java.ast.NullReferenceExpression) ArrayInitializerExpression(com.strobel.decompiler.languages.java.ast.ArrayInitializerExpression) VariableDeclarationExpression(com.google.devtools.j2objc.ast.VariableDeclarationExpression) GeneratedVariableElement(com.google.devtools.j2objc.types.GeneratedVariableElement) VariableDeclarationFragment(com.google.devtools.j2objc.ast.VariableDeclarationFragment) VariableDeclarationStatement(com.google.devtools.j2objc.ast.VariableDeclarationStatement) VariableInitializer(com.strobel.decompiler.languages.java.ast.VariableInitializer) HashSet(java.util.HashSet)

Example 3 with GeneratedVariableElement

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

the class JavaToIOSMethodTranslator method addCopyWithZoneMethod.

private void addCopyWithZoneMethod(TypeDeclaration node, boolean singleton) {
    TypeElement type = node.getTypeElement();
    // Create copyWithZone: method.
    GeneratedExecutableElement copyElement = GeneratedExecutableElement.newMethodWithSelector("copyWithZone:", TypeUtil.ID_TYPE, type);
    MethodDeclaration copyDecl = new MethodDeclaration(copyElement);
    copyDecl.setHasDeclaration(false);
    // Add NSZone *zone parameter.
    GeneratedVariableElement zoneParam = GeneratedVariableElement.newParameter("zone", NSZONE_TYPE, copyElement);
    copyElement.addParameter(zoneParam);
    copyDecl.addParameter(new SingleVariableDeclaration(zoneParam));
    Block block = new Block();
    copyDecl.setBody(block);
    if (singleton) {
        block.addStatement(new ReturnStatement(new ThisExpression(type.asType())));
    } else {
        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) ThisExpression(com.google.devtools.j2objc.ast.ThisExpression) GeneratedVariableElement(com.google.devtools.j2objc.types.GeneratedVariableElement) ExecutablePair(com.google.devtools.j2objc.types.ExecutablePair) TypeElement(javax.lang.model.element.TypeElement) 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)

Example 4 with GeneratedVariableElement

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

the class NumberMethodRewriter method addEqualsMethod.

private void addEqualsMethod(TypeDeclaration node) {
    TypeElement typeElement = node.getTypeElement();
    GeneratedExecutableElement equalsElement = GeneratedExecutableElement.newMethodWithSelector("isEqual:", typeUtil.getBoolean(), typeElement);
    GeneratedVariableElement paramElement = GeneratedVariableElement.newParameter("obj", typeUtil.getJavaObject().asType(), equalsElement);
    equalsElement.addParameter(paramElement);
    node.addBodyDeclaration(new MethodDeclaration(equalsElement).addParameter(new SingleVariableDeclaration(paramElement)).setBody(new Block().addStatement(new NativeStatement("return self == obj;"))).setModifiers(Modifier.PUBLIC));
}
Also used : GeneratedExecutableElement(com.google.devtools.j2objc.types.GeneratedExecutableElement) NativeStatement(com.google.devtools.j2objc.ast.NativeStatement) GeneratedVariableElement(com.google.devtools.j2objc.types.GeneratedVariableElement) TypeElement(javax.lang.model.element.TypeElement) MethodDeclaration(com.google.devtools.j2objc.ast.MethodDeclaration) SingleVariableDeclaration(com.google.devtools.j2objc.ast.SingleVariableDeclaration) Block(com.google.devtools.j2objc.ast.Block)

Example 5 with GeneratedVariableElement

use of com.google.devtools.j2objc.types.GeneratedVariableElement 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);
    element.addAnnotationMirrors(method.element().getAnnotationMirrors());
    MethodDeclaration decl = new MethodDeclaration(element);
    if (!declaringClass.getKind().isInterface()) {
        unit.setHasIncompleteImplementation();
    }
    int argCount = 0;
    for (VariableElement param : method.element().getParameters()) {
        GeneratedVariableElement newParam = GeneratedVariableElement.newParameter("arg" + argCount++, param.asType(), element);
        newParam.addAnnotationMirrors(param.getAnnotationMirrors());
        element.addParameter(newParam);
        decl.addParameter(new SingleVariableDeclaration(newParam));
    }
    return decl;
}
Also used : GeneratedExecutableElement(com.google.devtools.j2objc.types.GeneratedExecutableElement) GeneratedVariableElement(com.google.devtools.j2objc.types.GeneratedVariableElement) 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)

Aggregations

GeneratedVariableElement (com.google.devtools.j2objc.types.GeneratedVariableElement)8 SingleVariableDeclaration (com.google.devtools.j2objc.ast.SingleVariableDeclaration)5 GeneratedExecutableElement (com.google.devtools.j2objc.types.GeneratedExecutableElement)5 Block (com.google.devtools.j2objc.ast.Block)4 MethodDeclaration (com.google.devtools.j2objc.ast.MethodDeclaration)4 Expression (com.google.devtools.j2objc.ast.Expression)3 InfixExpression (com.google.devtools.j2objc.ast.InfixExpression)3 NativeStatement (com.google.devtools.j2objc.ast.NativeStatement)3 ParenthesizedExpression (com.google.devtools.j2objc.ast.ParenthesizedExpression)3 PostfixExpression (com.google.devtools.j2objc.ast.PostfixExpression)3 ThisExpression (com.google.devtools.j2objc.ast.ThisExpression)3 VariableDeclarationExpression (com.google.devtools.j2objc.ast.VariableDeclarationExpression)3 ArrayType (com.google.devtools.j2objc.ast.ArrayType)2 ConditionalExpression (com.google.devtools.j2objc.ast.ConditionalExpression)2 PrefixExpression (com.google.devtools.j2objc.ast.PrefixExpression)2 SimpleType (com.google.devtools.j2objc.ast.SimpleType)2 Type (com.google.devtools.j2objc.ast.Type)2 VariableDeclarationFragment (com.google.devtools.j2objc.ast.VariableDeclarationFragment)2 VariableDeclarationStatement (com.google.devtools.j2objc.ast.VariableDeclarationStatement)2 AnonymousObjectCreationExpression (com.strobel.decompiler.languages.java.ast.AnonymousObjectCreationExpression)2