Exemplo n.º 1
0
  @Override
  public void endVisit(TypeDeclaration node) {
    List<Statement> adjustments = getFieldAdjustments(node);
    if (adjustments.isEmpty()) {
      return;
    }
    ITypeBinding type = node.getTypeBinding();

    ITypeBinding voidType = typeEnv.resolveJavaType("void");
    int modifiers = Modifier.PUBLIC | BindingUtil.ACC_SYNTHETIC;
    IOSMethodBinding methodBinding =
        IOSMethodBinding.newMethod(JAVA_CLONE_METHOD, modifiers, voidType, type);

    MethodDeclaration declaration = new MethodDeclaration(methodBinding);
    node.getBodyDeclarations().add(declaration);

    Block body = new Block();
    declaration.setBody(body);
    List<Statement> statements = body.getStatements();

    ITypeBinding nsObjectType = typeEnv.resolveIOSType("NSObject");
    IOSMethodBinding cloneMethod =
        IOSMethodBinding.newMethod(JAVA_CLONE_METHOD, Modifier.PUBLIC, voidType, nsObjectType);
    SuperMethodInvocation superCall = new SuperMethodInvocation(cloneMethod);
    statements.add(new ExpressionStatement(superCall));

    statements.addAll(adjustments);
  }
Exemplo n.º 2
0
 private FunctionInvocation createCastCheck(ITypeBinding type, Expression expr) {
   type = type.getErasure();
   ITypeBinding idType = typeEnv.resolveIOSType("id");
   FunctionInvocation invocation = null;
   if ((type.isInterface() && !type.isAnnotation())
       || (type.isArray() && !type.getComponentType().isPrimitive())) {
     FunctionBinding binding = new FunctionBinding("cast_check", idType, null);
     binding.addParameters(idType, typeEnv.getIOSClass());
     invocation = new FunctionInvocation(binding, idType);
     invocation.getArguments().add(TreeUtil.remove(expr));
     invocation.getArguments().add(new TypeLiteral(type, typeEnv));
   } else if (type.isClass() || type.isArray() || type.isAnnotation() || type.isEnum()) {
     FunctionBinding binding = new FunctionBinding("cast_chk", idType, null);
     binding.addParameters(idType, idType);
     invocation = new FunctionInvocation(binding, idType);
     invocation.getArguments().add(TreeUtil.remove(expr));
     IOSMethodBinding classBinding =
         IOSMethodBinding.newMethod("class", Modifier.STATIC, idType, type);
     MethodInvocation classInvocation = new MethodInvocation(classBinding, new SimpleName(type));
     invocation.getArguments().add(classInvocation);
   }
   return invocation;
 }