Restore and deprecate Function{n}/ExtensionFunction{n} classes for easier migration

Users' Java code will not break in common cases (when passing functions to
Kotlin), and deprecation warnings will be reported.

Provide an inspection with a quick fix which allows to replace deprecated
function class usages to the new classes. Include this fix to the "code
cleanup" action
This commit is contained in:
Alexander Udalov
2015-05-25 21:56:48 +03:00
parent 851007cc6c
commit d14e5b8a72
64 changed files with 1596 additions and 14 deletions
@@ -0,0 +1,35 @@
// FILE: J.java
import kotlin.ExtensionFunction0;
import kotlin.ExtensionFunction1;
import kotlin.Function0;
import kotlin.Function1;
import kotlin.Unit;
public class J {
public static void f1(Function0<Unit> f) {
f.invoke();
}
public static void f2(Function1<String, String> f) {
f.invoke("");
}
public static void ef1(ExtensionFunction1<Integer, Integer, Integer> ef) {
ef.invoke(42, -42);
}
public static ExtensionFunction0<String, Unit> ef2() {
return null;
}
}
// FILE: K.kt
fun foo() = J.<!JAVA_METHOD_USES_DEPRECATED_FUNCTION_CLASS!>f1 { }<!>
fun bar() = J.<!JAVA_METHOD_USES_DEPRECATED_FUNCTION_CLASS!>f2 { it }<!>
fun baz() = J.<!JAVA_METHOD_USES_DEPRECATED_FUNCTION_CLASS!>ef1 <!EXPECTED_PARAMETERS_NUMBER_MISMATCH!>{<!> <!NO_THIS!>this<!> }<!>
fun quux() = J.<!JAVA_METHOD_USES_DEPRECATED_FUNCTION_CLASS!>ef2()<!>