Search in sources :

Example 1 with SynchronizedStatement

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

the class OcniExtractor method endVisit.

@Override
public void endVisit(MethodDeclaration node) {
    int modifiers = node.getModifiers();
    if (Modifier.isNative(modifiers)) {
        NativeStatement nativeStmt = extractNativeStatement(node);
        if (nativeStmt != null) {
            Block body = new Block();
            body.addStatement(nativeStmt);
            node.setBody(body);
            node.removeModifiers(Modifier.NATIVE);
        }
    }
    if (Modifier.isSynchronized(modifiers)) {
        TypeElement declaringClass = ElementUtil.getDeclaringClass(node.getExecutableElement());
        SynchronizedStatement syncStmt = new SynchronizedStatement(Modifier.isStatic(modifiers) ? new TypeLiteral(declaringClass.asType(), typeUtil) : new ThisExpression(declaringClass.asType()));
        syncStmt.setBody(TreeUtil.remove(node.getBody()));
        Block newBody = new Block();
        newBody.addStatement(syncStmt);
        node.setBody(newBody);
        node.removeModifiers(Modifier.SYNCHRONIZED);
    }
}
Also used : ThisExpression(com.google.devtools.j2objc.ast.ThisExpression) NativeStatement(com.google.devtools.j2objc.ast.NativeStatement) TypeLiteral(com.google.devtools.j2objc.ast.TypeLiteral) TypeElement(javax.lang.model.element.TypeElement) Block(com.google.devtools.j2objc.ast.Block) SynchronizedStatement(com.google.devtools.j2objc.ast.SynchronizedStatement)

Aggregations

Block (com.google.devtools.j2objc.ast.Block)1 NativeStatement (com.google.devtools.j2objc.ast.NativeStatement)1 SynchronizedStatement (com.google.devtools.j2objc.ast.SynchronizedStatement)1 ThisExpression (com.google.devtools.j2objc.ast.ThisExpression)1 TypeLiteral (com.google.devtools.j2objc.ast.TypeLiteral)1 TypeElement (javax.lang.model.element.TypeElement)1