Add FULL_JDK to tests in codegen/boxWithStdlib/fullJdk/
Drop the old scheme which relied on the directory name
This commit is contained in:
Vendored
+82
@@ -0,0 +1,82 @@
|
||||
//test for KT-3722 Write correct generic type information for generated fields
|
||||
import kotlin.properties.Delegates
|
||||
|
||||
class Z<T> {
|
||||
|
||||
}
|
||||
|
||||
class TParam {
|
||||
|
||||
}
|
||||
|
||||
class Zout<out T> {
|
||||
|
||||
}
|
||||
|
||||
class Zin<in T> {
|
||||
|
||||
}
|
||||
|
||||
|
||||
class Test<T>(val constructorProperty: T) {
|
||||
|
||||
val classField1 : Z<T>? = null
|
||||
|
||||
val classField2 : Z<String>? = null
|
||||
|
||||
val classField3 : Zout<String>? = null
|
||||
|
||||
val classField4 : Zin<TParam>? = null
|
||||
|
||||
val delegateLazy: Z<TParam>? by lazy {Z<TParam>()}
|
||||
|
||||
val delegateNotNull: Z<TParam>? by Delegates.notNull()
|
||||
|
||||
|
||||
}
|
||||
|
||||
fun box(): String {
|
||||
val clz = Test::class.java
|
||||
|
||||
val constructorProperty = clz.getDeclaredField("constructorProperty");
|
||||
|
||||
if (constructorProperty.getGenericType().toString() != "T")
|
||||
return "fail0: " + constructorProperty.getGenericType();
|
||||
|
||||
|
||||
val classField = clz.getDeclaredField("classField1");
|
||||
|
||||
if (classField.getGenericType().toString() != "Z<T>")
|
||||
return "fail1:" + classField.getGenericType();
|
||||
|
||||
|
||||
val classField2 = clz.getDeclaredField("classField2");
|
||||
|
||||
if (classField2.getGenericType().toString() != "Z<java.lang.String>")
|
||||
return "fail2:" + classField2.getGenericType();
|
||||
|
||||
|
||||
val classField3 = clz.getDeclaredField("classField3");
|
||||
|
||||
if (classField3.getGenericType().toString() != "Zout<java.lang.String>")
|
||||
return "fail3:" + classField3.getGenericType();
|
||||
|
||||
|
||||
val classField4 = clz.getDeclaredField("classField4");
|
||||
|
||||
if (classField4.getGenericType().toString() != "Zin<TParam>")
|
||||
return "fail4:" + classField4.getGenericType();
|
||||
|
||||
val classField5 = clz.getDeclaredField("delegateLazy\$delegate");
|
||||
|
||||
if (classField5.getGenericType().toString() != "kotlin.Lazy<Z<TParam>>")
|
||||
return "fail5:" + classField5.getGenericType();
|
||||
|
||||
val classField6 = clz.getDeclaredField("delegateNotNull\$delegate");
|
||||
|
||||
if (classField6.getGenericType().toString() != "kotlin.properties.ReadWriteProperty<java.lang.Object, Z<TParam>>")
|
||||
return "fail6:" + classField6.getGenericType();
|
||||
|
||||
|
||||
return "OK"
|
||||
}
|
||||
Vendored
+60
@@ -0,0 +1,60 @@
|
||||
class Z<T> {}
|
||||
|
||||
class TParam {}
|
||||
|
||||
class Zout<out T> {}
|
||||
|
||||
class Zin<in T> {}
|
||||
|
||||
class Params(val methodIndex: Int, val paramClass: Class<*>, val expectedReturnType: String, val expecedParamType: String)
|
||||
|
||||
class Test<T, X, in Y>() {
|
||||
|
||||
fun test1(p: T): T? = null
|
||||
|
||||
fun test2(p: Z<T>): Z<T>? = null
|
||||
|
||||
fun test3(p: Z<String>): Z<String>? = null
|
||||
|
||||
fun test4(p: X): Zout<out String>? = null
|
||||
|
||||
fun test5(p: Y): Zin<in TParam>? = null
|
||||
}
|
||||
|
||||
fun box(): String {
|
||||
val clz = Test::class.java
|
||||
|
||||
val params = listOf(
|
||||
Params(1, Any::class.java, "T", "T"),
|
||||
Params(2, Z::class.java, "Z<T>", "Z<T>"),
|
||||
Params(3, Z::class.java, "Z<java.lang.String>", "Z<java.lang.String>"),
|
||||
Params(4, Any::class.java, "Zout<java.lang.String>", "X"),
|
||||
Params(5, Any::class.java, "Zin<TParam>", "Y")
|
||||
)
|
||||
|
||||
|
||||
var result: String = ""
|
||||
for(p in params) {
|
||||
val fail = test(clz, p.methodIndex, p.paramClass, p.expectedReturnType, p.expecedParamType)
|
||||
if (fail != "OK") {
|
||||
result += fail + "\n";
|
||||
}
|
||||
}
|
||||
|
||||
return if (result.isEmpty()) "OK" else result;
|
||||
|
||||
}
|
||||
|
||||
fun test(clazz: Class<*>, methodIndex: Int, paramClass: Class<*>, expectedReturn : String, expectedParam : String): String {
|
||||
val method = clazz.getDeclaredMethod("test$methodIndex", paramClass)!!;
|
||||
|
||||
if (method.getGenericReturnType().toString() != expectedReturn)
|
||||
return "fail$methodIndex: " + method.getGenericReturnType();
|
||||
|
||||
val test1Param = method.getGenericParameterTypes()!![0];
|
||||
|
||||
if (test1Param.toString() != expectedParam)
|
||||
return "fail${methodIndex}_param: " + test1Param;
|
||||
|
||||
return "OK"
|
||||
}
|
||||
Reference in New Issue
Block a user