def transform_method_call(self, expr):
        if isinstance(expr.object, refs.ClassReference) or isinstance(
                expr.object, refs.StaticThisReference):
            cls_ = expr.object.decl if isinstance(
                expr.object,
                refs.ClassReference) else expr.object.cls_ if isinstance(
                    expr.object, refs.StaticThisReference) else None
            method = self.find_method(cls_, expr.method_name, True, expr.args)
            result = exprs.StaticMethodCallExpression(
                method, expr.type_args, expr.args,
                isinstance(expr.object, refs.StaticThisReference))
            self.resolve_return_type(result, genRes.GenericsResolver())
            return result
        else:
            resolved_object = expr.object if expr.object.actual_type != None else self.main.run_plugins_on(
                expr.object)
            object_type = resolved_object.get_type()
            intf_type = object_type.decl if isinstance(
                object_type,
                astTypes.ClassType) else object_type.decl if isinstance(
                    object_type, astTypes.InterfaceType) else None

            if intf_type != None:
                lambda_field = next(
                    filter(
                        lambda x: x.name == expr.method_name and isinstance(
                            x.type, astTypes.LambdaType) and len(
                                x.type.parameters) == len(expr.args),
                        intf_type.fields), None)
                if lambda_field != None:
                    lambda_call = exprs.LambdaCallExpression(
                        refs.InstanceFieldReference(expr.object, lambda_field),
                        expr.args)
                    lambda_call.set_actual_type(
                        (lambda_field.type).return_type, True)
                    return lambda_call

                method = self.find_method(intf_type, expr.method_name, False,
                                          expr.args)
                result = exprs.InstanceMethodCallExpression(
                    resolved_object, method, expr.type_args, expr.args)
                self.resolve_return_type(
                    result,
                    genRes.GenericsResolver.from_object(resolved_object))
                return result
            elif isinstance(object_type, astTypes.AnyType):
                expr.set_actual_type(astTypes.AnyType.instance)
                return expr
            else:
                pass
            return resolved_object
Beispiel #2
0
 def transform(self, expr):
     call_expr = expr
     if isinstance(call_expr.func, refs.GlobalFunctionReference):
         new_expr = exprs.GlobalFunctionCallExpression(
             call_expr.func.decl, call_expr.args)
         call_expr.args = list(
             map(lambda arg: self.main.run_plugins_on(arg), call_expr.args))
         new_expr.set_actual_type(call_expr.func.decl.returns)
         return new_expr
     else:
         self.main.process_expression(expr)
         if isinstance(call_expr.func.actual_type, astTypes.LambdaType):
             new_expr = exprs.LambdaCallExpression(call_expr.func,
                                                   call_expr.args)
             new_expr.set_actual_type(
                 call_expr.func.actual_type.return_type)
             return new_expr
         else:
             return expr