@Override
  public void endVisit(SuperMethodInvocation node) {
    Name qualifier = node.getQualifier();
    if (qualifier == null) {
      return;
    }
    IMethodBinding method = node.getMethodBinding();
    ITypeBinding exprType = node.getTypeBinding();
    IVariableBinding var = TreeUtil.getVariableBinding(qualifier);
    assert var != null : "Expected qualifier to be a variable";
    ITypeBinding qualifierType = var.getType();

    SuperMethodBindingPair superMethod = new SuperMethodBindingPair(qualifierType, method);
    superMethods.add(superMethod);

    FunctionBinding binding =
        new FunctionBinding(getSuperFunctionName(superMethod), exprType, qualifierType);
    binding.addParameters(qualifierType, typeEnv.getIdType());
    binding.addParameters(method.getParameterTypes());
    FunctionInvocation invocation = new FunctionInvocation(binding, exprType);
    List<Expression> args = invocation.getArguments();
    args.add(TreeUtil.remove(qualifier));
    String selectorExpr = UnicodeUtils.format("@selector(%s)", nameTable.getMethodSelector(method));
    args.add(new NativeExpression(selectorExpr, typeEnv.getIdType()));
    TreeUtil.copyList(node.getArguments(), args);
    node.replaceWith(invocation);
  }
예제 #2
0
 private Expression rewriteFloatToIntegralCast(
     ITypeBinding castType, Expression expr, String funcName, ITypeBinding funcReturnType) {
   FunctionBinding binding = new FunctionBinding(funcName, funcReturnType, null);
   binding.addParameter(typeEnv.resolveJavaType("double"));
   FunctionInvocation invocation = new FunctionInvocation(binding, funcReturnType);
   invocation.getArguments().add(TreeUtil.remove(expr));
   Expression newExpr = invocation;
   if (!castType.isEqualTo(funcReturnType)) {
     newExpr = new CastExpression(castType, newExpr);
   }
   return newExpr;
 }
예제 #3
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;
 }