@NotNull public static JetType createCorrespondingExtensionFunctionType( @NotNull JetType functionType, @NotNull JetType receiverType) { assert KotlinBuiltIns.getInstance().isFunctionType(functionType); List<TypeProjection> typeArguments = functionType.getArguments(); assert !typeArguments.isEmpty(); List<JetType> arguments = Lists.newArrayList(); // excluding the last type argument of the function type, which is the return type int index = 0; int lastIndex = typeArguments.size() - 1; for (TypeProjection typeArgument : typeArguments) { if (index < lastIndex) { arguments.add(typeArgument.getType()); } index++; } JetType returnType = typeArguments.get(lastIndex).getType(); return KotlinBuiltIns.getInstance() .getFunctionType(functionType.getAnnotations(), receiverType, arguments, returnType); }