Search in sources :

Example 1 with SuperMethodInvocation

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

the class DestructorGenerator method addDeallocMethod.

private void addDeallocMethod(AbstractTypeDeclaration node) {
    TypeElement type = node.getTypeElement();
    boolean hasFinalize = hasFinalizeMethod(type);
    List<Statement> releaseStatements = createReleaseStatements(node);
    if (releaseStatements.isEmpty() && !hasFinalize) {
        return;
    }
    ExecutableElement deallocElement = GeneratedExecutableElement.newMethodWithSelector(NameTable.DEALLOC_METHOD, typeUtil.getVoid(), type).addModifiers(Modifier.PUBLIC);
    MethodDeclaration deallocDecl = new MethodDeclaration(deallocElement);
    deallocDecl.setHasDeclaration(false);
    Block block = new Block();
    deallocDecl.setBody(block);
    List<Statement> stmts = block.getStatements();
    if (hasFinalize) {
        String clsName = nameTable.getFullName(type);
        stmts.add(new NativeStatement("JreCheckFinalize(self, [" + clsName + " class]);"));
    }
    stmts.addAll(releaseStatements);
    if (options.useReferenceCounting()) {
        stmts.add(new ExpressionStatement(new SuperMethodInvocation(new ExecutablePair(superDeallocElement))));
    }
    node.addBodyDeclaration(deallocDecl);
}
Also used : NativeStatement(com.google.devtools.j2objc.ast.NativeStatement) ExecutablePair(com.google.devtools.j2objc.types.ExecutablePair) TypeElement(javax.lang.model.element.TypeElement) ExpressionStatement(com.google.devtools.j2objc.ast.ExpressionStatement) Statement(com.google.devtools.j2objc.ast.Statement) NativeStatement(com.google.devtools.j2objc.ast.NativeStatement) MethodDeclaration(com.google.devtools.j2objc.ast.MethodDeclaration) GeneratedExecutableElement(com.google.devtools.j2objc.types.GeneratedExecutableElement) ExecutableElement(javax.lang.model.element.ExecutableElement) ExpressionStatement(com.google.devtools.j2objc.ast.ExpressionStatement) Block(com.google.devtools.j2objc.ast.Block) SuperMethodInvocation(com.google.devtools.j2objc.ast.SuperMethodInvocation)

Example 2 with SuperMethodInvocation

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

the class JavaCloneWriter method endVisit.

@Override
public void endVisit(TypeDeclaration node) {
    TypeElement type = node.getTypeElement();
    VariableElement originalVar = GeneratedVariableElement.newParameter("original", type.asType(), null);
    List<Statement> adjustments = getFieldAdjustments(node, originalVar);
    if (adjustments.isEmpty()) {
        return;
    }
    TypeMirror voidType = typeUtil.getVoid();
    ExecutableElement javaCloneElement = GeneratedExecutableElement.newMethodWithSelector(JAVA_CLONE_METHOD, voidType, type).addParameter(originalVar);
    MethodDeclaration declaration = new MethodDeclaration(javaCloneElement);
    declaration.setHasDeclaration(false);
    node.addBodyDeclaration(declaration);
    declaration.addParameter(new SingleVariableDeclaration(originalVar));
    Block body = new Block();
    declaration.setBody(body);
    List<Statement> statements = body.getStatements();
    ExecutableElement javaCloneSuperElement = GeneratedExecutableElement.newMethodWithSelector(JAVA_CLONE_METHOD, voidType, typeUtil.getJavaObject());
    SuperMethodInvocation superCall = new SuperMethodInvocation(new ExecutablePair(javaCloneSuperElement));
    superCall.addArgument(new SimpleName(originalVar));
    statements.add(new ExpressionStatement(superCall));
    statements.addAll(adjustments);
}
Also used : ExecutablePair(com.google.devtools.j2objc.types.ExecutablePair) TypeElement(javax.lang.model.element.TypeElement) ExpressionStatement(com.google.devtools.j2objc.ast.ExpressionStatement) Statement(com.google.devtools.j2objc.ast.Statement) 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) SimpleName(com.google.devtools.j2objc.ast.SimpleName) VariableElement(javax.lang.model.element.VariableElement) GeneratedVariableElement(com.google.devtools.j2objc.types.GeneratedVariableElement) SuperMethodInvocation(com.google.devtools.j2objc.ast.SuperMethodInvocation) TypeMirror(javax.lang.model.type.TypeMirror) ExpressionStatement(com.google.devtools.j2objc.ast.ExpressionStatement) Block(com.google.devtools.j2objc.ast.Block)

Example 3 with SuperMethodInvocation

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

the class TreeConverter method convertMethodInvocation.

private TreeNode convertMethodInvocation(JCTree.JCMethodInvocation node) {
    JCTree.JCExpression method = node.getMethodSelect();
    String methodName = getMemberName(method);
    ExecutableType type = (ExecutableType) method.type;
    Symbol.MethodSymbol sym = (Symbol.MethodSymbol) getMemberSymbol(method);
    JCTree.JCExpression target = method.getKind() == Kind.MEMBER_SELECT ? ((JCTree.JCFieldAccess) method).selected : null;
    if ("this".equals(methodName)) {
        ConstructorInvocation newNode = new ConstructorInvocation().setExecutablePair(new ExecutablePair(sym)).setVarargsType(node.varargsElement);
        for (JCTree.JCExpression arg : node.getArguments()) {
            newNode.addArgument((Expression) convert(arg));
        }
        return newNode;
    }
    if ("super".equals(methodName)) {
        SuperConstructorInvocation newNode = new SuperConstructorInvocation().setExecutablePair(new ExecutablePair(sym)).setVarargsType(node.varargsElement);
        if (target != null) {
            newNode.setExpression((Expression) convert(target));
        }
        for (JCTree.JCExpression arg : node.getArguments()) {
            newNode.addArgument((Expression) convert(arg));
        }
        return newNode;
    }
    if (target != null && "super".equals(getMemberName(target))) {
        SuperMethodInvocation newNode = new SuperMethodInvocation().setExecutablePair(new ExecutablePair(sym, type)).setVarargsType(node.varargsElement).setName(convertSimpleName(sym, type, getPosition(node)));
        if (target.getKind() == Kind.MEMBER_SELECT) {
            // foo.bar.MyClass.super.print(...):
            //   target: foo.bar.MyClass.super
            //   target.selected: foo.bar.MyClass
            newNode.setQualifier((Name) convert(((JCTree.JCFieldAccess) target).selected));
        }
        for (JCTree.JCExpression arg : node.getArguments()) {
            newNode.addArgument((Expression) convert(arg));
        }
        return newNode;
    }
    MethodInvocation newNode = new MethodInvocation();
    newNode.setName(convertSimpleName(sym, type, getPosition(method)));
    if (target != null) {
        newNode.setExpression((Expression) convert(target));
    }
    for (JCTree.JCExpression arg : node.getArguments()) {
        newNode.addArgument((Expression) convert(arg));
    }
    return newNode.setTypeMirror(node.type).setExecutablePair(new ExecutablePair(sym, type)).setVarargsType(node.varargsElement);
}
Also used : ExecutableType(javax.lang.model.type.ExecutableType) ConstructorInvocation(com.google.devtools.j2objc.ast.ConstructorInvocation) SuperConstructorInvocation(com.google.devtools.j2objc.ast.SuperConstructorInvocation) ExecutablePair(com.google.devtools.j2objc.types.ExecutablePair) Symbol(com.sun.tools.javac.code.Symbol) PackageSymbol(com.sun.tools.javac.code.Symbol.PackageSymbol) VarSymbol(com.sun.tools.javac.code.Symbol.VarSymbol) JCTree(com.sun.tools.javac.tree.JCTree) MethodInvocation(com.google.devtools.j2objc.ast.MethodInvocation) SuperMethodInvocation(com.google.devtools.j2objc.ast.SuperMethodInvocation) SuperConstructorInvocation(com.google.devtools.j2objc.ast.SuperConstructorInvocation) SuperMethodInvocation(com.google.devtools.j2objc.ast.SuperMethodInvocation)

Example 4 with SuperMethodInvocation

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

the class Functionizer method hasSuperMethodInvocation.

private static boolean hasSuperMethodInvocation(MethodDeclaration node) {
    final boolean[] result = new boolean[1];
    result[0] = false;
    node.accept(new TreeVisitor() {

        @Override
        public void endVisit(SuperMethodInvocation node) {
            result[0] = true;
        }
    });
    return result[0];
}
Also used : TreeVisitor(com.google.devtools.j2objc.ast.TreeVisitor) UnitTreeVisitor(com.google.devtools.j2objc.ast.UnitTreeVisitor) SuperMethodInvocation(com.google.devtools.j2objc.ast.SuperMethodInvocation)

Example 5 with SuperMethodInvocation

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

the class StatementGenerator method visit.

@Override
public boolean visit(ExpressionStatement node) {
    Expression expression = node.getExpression();
    TypeMirror type = expression.getTypeMirror();
    if (!type.getKind().isPrimitive() && !type.getKind().equals(TypeKind.VOID) && options.useARC() && (expression instanceof MethodInvocation || expression instanceof SuperMethodInvocation || expression instanceof FunctionInvocation)) {
        // Avoid clang warning that the return value is unused.
        buffer.append("(void) ");
    }
    expression.accept(this);
    buffer.append(";\n");
    return false;
}
Also used : FunctionInvocation(com.google.devtools.j2objc.ast.FunctionInvocation) LambdaExpression(com.google.devtools.j2objc.ast.LambdaExpression) PostfixExpression(com.google.devtools.j2objc.ast.PostfixExpression) InstanceofExpression(com.google.devtools.j2objc.ast.InstanceofExpression) Expression(com.google.devtools.j2objc.ast.Expression) PrefixExpression(com.google.devtools.j2objc.ast.PrefixExpression) ThisExpression(com.google.devtools.j2objc.ast.ThisExpression) NativeExpression(com.google.devtools.j2objc.ast.NativeExpression) CommaExpression(com.google.devtools.j2objc.ast.CommaExpression) ConditionalExpression(com.google.devtools.j2objc.ast.ConditionalExpression) CastExpression(com.google.devtools.j2objc.ast.CastExpression) VariableDeclarationExpression(com.google.devtools.j2objc.ast.VariableDeclarationExpression) InfixExpression(com.google.devtools.j2objc.ast.InfixExpression) ParenthesizedExpression(com.google.devtools.j2objc.ast.ParenthesizedExpression) TypeMirror(javax.lang.model.type.TypeMirror) MethodInvocation(com.google.devtools.j2objc.ast.MethodInvocation) SuperMethodInvocation(com.google.devtools.j2objc.ast.SuperMethodInvocation) SuperMethodInvocation(com.google.devtools.j2objc.ast.SuperMethodInvocation)

Aggregations

SuperMethodInvocation (com.google.devtools.j2objc.ast.SuperMethodInvocation)6 ExecutablePair (com.google.devtools.j2objc.types.ExecutablePair)4 Block (com.google.devtools.j2objc.ast.Block)2 ExpressionStatement (com.google.devtools.j2objc.ast.ExpressionStatement)2 MethodDeclaration (com.google.devtools.j2objc.ast.MethodDeclaration)2 MethodInvocation (com.google.devtools.j2objc.ast.MethodInvocation)2 SimpleName (com.google.devtools.j2objc.ast.SimpleName)2 Statement (com.google.devtools.j2objc.ast.Statement)2 GeneratedExecutableElement (com.google.devtools.j2objc.types.GeneratedExecutableElement)2 ExecutableElement (javax.lang.model.element.ExecutableElement)2 TypeElement (javax.lang.model.element.TypeElement)2 TypeMirror (javax.lang.model.type.TypeMirror)2 CastExpression (com.google.devtools.j2objc.ast.CastExpression)1 CommaExpression (com.google.devtools.j2objc.ast.CommaExpression)1 ConditionalExpression (com.google.devtools.j2objc.ast.ConditionalExpression)1 ConstructorInvocation (com.google.devtools.j2objc.ast.ConstructorInvocation)1 Expression (com.google.devtools.j2objc.ast.Expression)1 FunctionInvocation (com.google.devtools.j2objc.ast.FunctionInvocation)1 InfixExpression (com.google.devtools.j2objc.ast.InfixExpression)1 InstanceofExpression (com.google.devtools.j2objc.ast.InstanceofExpression)1