Support JvmSuppressWildcards and JvmWildcard annotations

#KT-9898 Fixed
This commit is contained in:
Denis Zharkov
2015-11-27 11:49:36 +03:00
parent 6292833a69
commit ddb67d6c9c
14 changed files with 279 additions and 5 deletions
@@ -0,0 +1,23 @@
public class JavaClass {
public static class C extends B {
public OutPair<String, Integer> foo() {
return super.foo();
}
public In<Object> bar() {
return super.bar();
}
}
public static String test() {
A a = new C();
if (!a.foo().getX().equals("OK")) return "fail 1";
if (!a.foo().getY().equals(123)) return "fail 2";
if (!a.bar().make("123").equals("123")) return "fail 3";
return "OK";
}
}
@@ -0,0 +1,19 @@
class OutPair<out X, out Y>(val x: X, val y: Y)
class In<in Z> {
fun make(x: Z): String = x.toString()
}
@JvmSuppressWildcards(suppress = false)
interface A {
fun foo(): OutPair<CharSequence, Number>
fun bar(): In<String>
}
abstract class B : A {
override fun foo(): OutPair<String, Int> = OutPair("OK", 123)
override fun bar(): In<Any> = In()
}
fun box(): String {
return JavaClass.test();
}
@@ -7,11 +7,12 @@ public abstract class AImpl {
throw UnsupportedOperationException()
}
@JvmSuppressWildcards(suppress = false)
fun addAll(elements: Collection<String>): Boolean {
throw UnsupportedOperationException()
}
fun addAll(index: Int, elements: Collection<String>): Boolean {
fun addAll(index: Int, elements: Collection<@JvmWildcard String>): Boolean {
throw UnsupportedOperationException()
}
@@ -0,0 +1,23 @@
public class JavaClass {
public static class C extends B {
public OutPair<String, Integer> foo() {
return super.foo();
}
public In<Object> bar() {
return super.bar();
}
}
public static String test() {
A a = new C();
if (!a.foo().getX().equals("OK")) return "fail 1";
if (!a.foo().getY().equals(123)) return "fail 2";
if (!a.bar().make("123").equals("123")) return "fail 3";
return "OK";
}
}
@@ -0,0 +1,18 @@
class OutPair<out X, out Y>(val x: X, val y: Y)
class In<in Z> {
fun make(x: Z): String = x.toString()
}
interface A {
fun foo(): OutPair<@JvmWildcard CharSequence, @JvmSuppressWildcards(false) Number>
fun bar(): In<@JvmWildcard String>
}
abstract class B : A {
override fun foo(): OutPair<String, Int> = OutPair("OK", 123)
override fun bar(): In<Any> = In()
}
fun box(): String {
return JavaClass.test();
}
@@ -0,0 +1,27 @@
class Out<out T>
class In<in R>
open class Open
@JvmSuppressWildcards(true)
fun deepOpen(x: Out<Out<Out<Open>>>) {}
// method: OnFunctionKt::deepOpen
// generic signature: (LOut<LOut<LOut<LOpen;>;>;>;)V
interface A<T> {
@JvmSuppressWildcards(true)
fun foo(): Out<T>
}
// method: A::foo
// generic signature: ()LOut<TT;>;
interface B {
@JvmSuppressWildcards(true)
fun foo(): In<Open>
}
// method: B::foo
// generic signature: ()LIn<LOpen;>;
@JvmSuppressWildcards(false)
fun bar(): Out<Open> = null!!
// method: OnFunctionKt::bar
// generic signature: ()LOut<+LOpen;>;
@@ -0,0 +1,22 @@
class OutPair<out T, out E>
class Out<out F>
class In<in H>
class X
fun simpleOut(x: Out<@JvmWildcard X>) {}
// method: OnTypesKt::simpleOut
// generic signature: (LOut<+LX;>;)V
fun simpleIn(x: In<@JvmWildcard Any?>) {}
// method: OnTypesKt::simpleIn
// generic signature: (LIn<-Ljava/lang/Object;>;)V
fun falseTrueFalse(): @JvmSuppressWildcards(false) OutPair<X, @JvmSuppressWildcards OutPair<Out<X>, Out<@JvmSuppressWildcards(false) X>>> = null!!
// method: OnTypesKt::falseTrueFalse
// generic signature: ()LOutPair<+LX;LOutPair<LOut<LX;>;LOut<+LX;>;>;>;
open class Open
fun combination(): @JvmSuppressWildcards OutPair< Open, @JvmWildcard OutPair<Open, @JvmWildcard Out<Open>>> = null!!
// method: OnTypesKt::combination
// generic signature: ()LOutPair<LOpen;+LOutPair<LOpen;+LOut<LOpen;>;>;>;
@@ -0,0 +1,12 @@
class Out<out T>
class In<in E>
@JvmSuppressWildcards(false)
fun foo(x: Boolean, y: Out<Int>): Int = 1
// method: PrimitiveTypesKt::foo
// generic signature: (ZLOut<+Ljava/lang/Integer;>;)I
@JvmSuppressWildcards(true)
fun bar(x: Boolean, y: In<Long>, z: @JvmSuppressWildcards(false) Long): Int = 1
// method: PrimitiveTypesKt::bar
// generic signature: (ZLIn<Ljava/lang/Long;>;J)I