Merge boxWithJava testData into box, delete BoxWithJava test
This commit is contained in:
committed by
Alexander Udalov
parent
16a0ddd2fb
commit
f8dfaf4599
+46
@@ -0,0 +1,46 @@
|
||||
// WITH_RUNTIME
|
||||
// FILE: Test.java
|
||||
|
||||
class Test {
|
||||
public static Class<?> apply(Runnable x) {
|
||||
return x.getClass();
|
||||
}
|
||||
|
||||
public static interface ABC {
|
||||
void apply(String x1, String x2);
|
||||
}
|
||||
|
||||
public static Class<?> applyABC(ABC x) {
|
||||
return x.getClass();
|
||||
}
|
||||
}
|
||||
|
||||
// FILE: test.kt
|
||||
|
||||
import java.lang.reflect.Method
|
||||
import kotlin.test.assertEquals
|
||||
|
||||
@Retention(AnnotationRetention.RUNTIME)
|
||||
annotation class Ann(val x: String)
|
||||
|
||||
fun testMethod(method: Method, name: String) {
|
||||
assertEquals("OK", method.getAnnotation(Ann::class.java).x, "On method of test named `$name`")
|
||||
|
||||
for ((index, annotations) in method.getParameterAnnotations().withIndex()) {
|
||||
val ann = annotations.filterIsInstance<Ann>().single()
|
||||
assertEquals("OK$index", ann.x, "On parameter $index of test named `$name`")
|
||||
}
|
||||
}
|
||||
|
||||
fun testClass(clazz: Class<*>, name: String) {
|
||||
val invokes = clazz.getDeclaredMethods().single() { !it.isBridge() }
|
||||
testMethod(invokes, name)
|
||||
}
|
||||
|
||||
fun box(): String {
|
||||
testClass(Test.apply(@Ann("OK") fun(){}), "1")
|
||||
|
||||
testClass(Test.applyABC(@Ann("OK") fun(@Ann("OK0") x: String, @Ann("OK1") y: String){}), "2")
|
||||
|
||||
return "OK"
|
||||
}
|
||||
@@ -0,0 +1,37 @@
|
||||
// WITH_RUNTIME
|
||||
// FILE: Test.java
|
||||
|
||||
class Test {
|
||||
public static Class<?> apply(Runnable x) {
|
||||
return x.getClass();
|
||||
}
|
||||
}
|
||||
|
||||
// FILE: test.kt
|
||||
|
||||
import java.lang.reflect.Method
|
||||
import kotlin.test.assertEquals
|
||||
|
||||
@Target(AnnotationTarget.FUNCTION)
|
||||
@Retention(AnnotationRetention.RUNTIME)
|
||||
annotation class Ann(val x: String)
|
||||
|
||||
fun testMethod(method: Method, name: String) {
|
||||
assertEquals("OK", method.getAnnotation(Ann::class.java).x, "On method of test named `$name`")
|
||||
|
||||
for ((index, annotations) in method.getParameterAnnotations().withIndex()) {
|
||||
val ann = annotations.filterIsInstance<Ann>().single()
|
||||
assertEquals("OK$index", ann.x, "On parameter $index of test named `$name`")
|
||||
}
|
||||
}
|
||||
|
||||
fun testClass(clazz: Class<*>, name: String) {
|
||||
val invokes = clazz.getDeclaredMethods().single() { !it.isBridge() }
|
||||
testMethod(invokes, name)
|
||||
}
|
||||
|
||||
fun box(): String {
|
||||
testClass(Test.apply(@Ann("OK") {}), "1")
|
||||
testClass(Test.apply @Ann("OK") {}, "2")
|
||||
return "OK"
|
||||
}
|
||||
@@ -0,0 +1,33 @@
|
||||
// WITH_RUNTIME
|
||||
// FILE: JavaClass.java
|
||||
|
||||
import java.lang.annotation.Retention;
|
||||
import java.lang.annotation.RetentionPolicy;
|
||||
|
||||
public class JavaClass {
|
||||
|
||||
@Retention(RetentionPolicy.RUNTIME)
|
||||
@interface Foo {
|
||||
int value();
|
||||
}
|
||||
|
||||
@Foo(KotlinClass.FOO_INT)
|
||||
public String test() throws NoSuchMethodException {
|
||||
return KotlinClass.FOO_STRING +
|
||||
JavaClass.class.getMethod("test").getAnnotation(Foo.class).value();
|
||||
}
|
||||
}
|
||||
|
||||
// FILE: kotlinClass.kt
|
||||
|
||||
class KotlinClass {
|
||||
companion object {
|
||||
const val FOO_INT: Int = 10
|
||||
@JvmField val FOO_STRING: String = "OK"
|
||||
}
|
||||
}
|
||||
|
||||
fun box(): String {
|
||||
val test = JavaClass().test()
|
||||
return if (test == "OK10") "OK" else "fail : $test"
|
||||
}
|
||||
Vendored
+32
@@ -0,0 +1,32 @@
|
||||
// FILE: JavaClass.java
|
||||
|
||||
import java.lang.annotation.Retention;
|
||||
import java.lang.annotation.RetentionPolicy;
|
||||
|
||||
public class JavaClass {
|
||||
|
||||
@Retention(RetentionPolicy.RUNTIME)
|
||||
@interface Foo {
|
||||
int value();
|
||||
}
|
||||
|
||||
@Foo(KotlinInterface.FOO_INT)
|
||||
public String test() throws NoSuchMethodException {
|
||||
return KotlinInterface.FOO_STRING +
|
||||
JavaClass.class.getMethod("test").getAnnotation(Foo.class).value();
|
||||
}
|
||||
}
|
||||
|
||||
// FILE: KotlinInterface.kt
|
||||
|
||||
interface KotlinInterface {
|
||||
companion object {
|
||||
const val FOO_INT: Int = 10
|
||||
const val FOO_STRING: String = "OK"
|
||||
}
|
||||
}
|
||||
|
||||
fun box(): String {
|
||||
val test = JavaClass().test()
|
||||
return if (test == "OK10") "OK" else "fail : $test"
|
||||
}
|
||||
+28
@@ -0,0 +1,28 @@
|
||||
// FILE: Test.java
|
||||
|
||||
import java.lang.*;
|
||||
import java.util.*;
|
||||
|
||||
public class Test {
|
||||
public static class MapEntryImpl implements Map.Entry<String, String> {
|
||||
public String getKey() { return null; }
|
||||
public String getValue() { return null; }
|
||||
public String setValue(String s) { return null; }
|
||||
}
|
||||
}
|
||||
|
||||
// FILE: main.kt
|
||||
|
||||
//class MyIterable : Test.IterableImpl()
|
||||
//class MyIterator : Test.IteratorImpl()
|
||||
class MyMapEntry : Test.MapEntryImpl()
|
||||
|
||||
fun box(): String {
|
||||
|
||||
val b = MyMapEntry()
|
||||
b.key
|
||||
b.value
|
||||
b.setValue(null)
|
||||
|
||||
return "OK"
|
||||
}
|
||||
@@ -0,0 +1,28 @@
|
||||
// FILE: Test.java
|
||||
|
||||
public class Test {
|
||||
public static void checkCallFromJava() {
|
||||
try {
|
||||
String x = TestKt.foo().iterator().next();
|
||||
throw new AssertionError("E should have been thrown");
|
||||
} catch (E e) { }
|
||||
}
|
||||
}
|
||||
|
||||
// FILE: test.kt
|
||||
|
||||
interface MyIterable<T> : Iterable<T>
|
||||
|
||||
class E : RuntimeException()
|
||||
fun foo(): MyIterable<String> = throw E()
|
||||
|
||||
fun box(): String {
|
||||
try {
|
||||
foo().iterator().next()
|
||||
return "Fail: E should have been thrown"
|
||||
} catch (e: E) {}
|
||||
|
||||
Test.checkCallFromJava()
|
||||
|
||||
return "OK"
|
||||
}
|
||||
+39
@@ -0,0 +1,39 @@
|
||||
// FILE: Test.java
|
||||
|
||||
class Test {
|
||||
interface A {
|
||||
boolean add(String s);
|
||||
}
|
||||
|
||||
static class D extends C {}
|
||||
|
||||
void test() {
|
||||
A a = new D();
|
||||
a.add("lol");
|
||||
}
|
||||
}
|
||||
|
||||
// FILE: test.kt
|
||||
|
||||
abstract class C : Test.A, List<String> {
|
||||
override val size: Int get() = null!!
|
||||
override fun isEmpty(): Boolean = null!!
|
||||
override fun contains(o: String): Boolean = null!!
|
||||
override fun iterator(): Iterator<String> = null!!
|
||||
override fun containsAll(c: Collection<String>): Boolean = null!!
|
||||
override fun get(index: Int): String = null!!
|
||||
override fun indexOf(o: String): Int = null!!
|
||||
override fun lastIndexOf(o: String): Int = null!!
|
||||
override fun listIterator(): ListIterator<String> = null!!
|
||||
override fun listIterator(index: Int): ListIterator<String> = null!!
|
||||
override fun subList(fromIndex: Int, toIndex: Int): List<String> = null!!
|
||||
}
|
||||
|
||||
fun box(): String {
|
||||
try {
|
||||
Test().test()
|
||||
return "Fail"
|
||||
} catch (e: UnsupportedOperationException) {
|
||||
return "OK"
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,16 @@
|
||||
// FILE: JFun.java
|
||||
|
||||
class JFun implements kotlin.jvm.functions.Function0<String> {
|
||||
public String invoke() {
|
||||
return "OK";
|
||||
}
|
||||
}
|
||||
|
||||
// FILE: test.kt
|
||||
|
||||
fun box(): String {
|
||||
val jfun = JFun()
|
||||
val jf = jfun as Any
|
||||
if (jf is Function0<*>) return jfun()
|
||||
else return "Failed: jf is Function0<*>"
|
||||
}
|
||||
+25
@@ -0,0 +1,25 @@
|
||||
// FILE: Box.java
|
||||
|
||||
public class Box<T> {
|
||||
private final T value;
|
||||
|
||||
public Box(T value) {
|
||||
this.value = value;
|
||||
}
|
||||
|
||||
public static <T> Box<T> create(T defaultValue) {
|
||||
return new Box(defaultValue);
|
||||
}
|
||||
|
||||
public T getValue() {
|
||||
return value;
|
||||
}
|
||||
}
|
||||
|
||||
// FILE: test.kt
|
||||
// See KT-10313: ClassCastException with Generics
|
||||
|
||||
fun box(): String {
|
||||
val sub = Box<Long>(-1)
|
||||
return if (sub.value == -1L) "OK" else "fail"
|
||||
}
|
||||
+33
@@ -0,0 +1,33 @@
|
||||
// TARGET_BACKEND: JVM
|
||||
// FILE: CompanionInitialization.java
|
||||
|
||||
public class CompanionInitialization {
|
||||
|
||||
public static Object getCompanion() {
|
||||
return ConcreteWithStatic.Companion;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
// FILE: CompanionInitialization.kt
|
||||
|
||||
interface IStatic
|
||||
|
||||
open class Static(x: IStatic) {
|
||||
fun doSth() {
|
||||
}
|
||||
}
|
||||
|
||||
class ConcreteWithStatic : IStatic {
|
||||
companion object : Static(ConcreteWithStatic())
|
||||
}
|
||||
|
||||
fun box(): String {
|
||||
ConcreteWithStatic.doSth()
|
||||
|
||||
val companion: Any? = CompanionInitialization.getCompanion()
|
||||
if (companion == null) return "fail 1"
|
||||
if (companion != ConcreteWithStatic) return "fail 2"
|
||||
|
||||
return "OK"
|
||||
}
|
||||
+36
@@ -0,0 +1,36 @@
|
||||
// TARGET_BACKEND: JVM
|
||||
// WITH_RUNTIME
|
||||
// FILE: CompanionInitialization.java
|
||||
|
||||
public class CompanionInitialization {
|
||||
|
||||
public static Object getCompanion() {
|
||||
return IStatic.Companion;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
// FILE: CompanionInitialization.kt
|
||||
|
||||
open class Static(): IStatic {
|
||||
val p = IStatic::class.java.getDeclaredField("const").get(null)
|
||||
}
|
||||
|
||||
interface IStatic {
|
||||
fun doSth() {
|
||||
}
|
||||
|
||||
companion object : Static() {
|
||||
const val const = 1;
|
||||
}
|
||||
}
|
||||
|
||||
fun box(): String {
|
||||
IStatic.doSth()
|
||||
|
||||
val companion: Any? = CompanionInitialization.getCompanion()
|
||||
if (companion == null) return "fail 1"
|
||||
if (companion != IStatic) return "fail 2"
|
||||
|
||||
return "OK"
|
||||
}
|
||||
@@ -0,0 +1,68 @@
|
||||
// FILE: J.java
|
||||
|
||||
import java.util.*;
|
||||
|
||||
public class J {
|
||||
|
||||
public static class B extends A {
|
||||
public int getLength() { return 456; }
|
||||
public char get(int index) {
|
||||
if (index == 1) return 'a';
|
||||
return super.get(index);
|
||||
}
|
||||
}
|
||||
|
||||
public static String foo() {
|
||||
B b = new B();
|
||||
CharSequence cs = (CharSequence) b;
|
||||
|
||||
if (cs.length() != 456) return "fail 01";
|
||||
if (b.length() != 456) return "fail 02";
|
||||
if (b.getLength() != 456) return "fail 03";
|
||||
|
||||
if (cs.charAt(0) != 'z') return "fail 1";
|
||||
if (b.get(0) != 'z') return "fail 2";
|
||||
|
||||
if (cs.charAt(1) != 'a') return "fail 3";
|
||||
if (b.get(1) != 'a') return "fail 4";
|
||||
|
||||
return "OK";
|
||||
}
|
||||
}
|
||||
|
||||
// FILE: test.kt
|
||||
|
||||
open class A : CharSequence {
|
||||
override val length: Int = 123
|
||||
|
||||
override fun get(index: Int) = 'z';
|
||||
|
||||
override fun subSequence(start: Int, end: Int): CharSequence {
|
||||
throw UnsupportedOperationException()
|
||||
}
|
||||
}
|
||||
|
||||
fun box(): String {
|
||||
val b = J.B()
|
||||
val a = A()
|
||||
|
||||
if (b[0] != 'z') return "fail 6"
|
||||
if (a[0] != 'z') return "fail 7"
|
||||
if (b[1] != 'a') return "fail 8"
|
||||
if (a[0] != 'z') return "fail 9"
|
||||
|
||||
if (b.get(0) != 'z') return "fail 10"
|
||||
if (a.get(0) != 'z') return "fail 11"
|
||||
if (b.get(1) != 'a') return "fail 12"
|
||||
if (a.get(1) != 'z') return "fail 13"
|
||||
|
||||
var cs: CharSequence = a
|
||||
if (a.length != 123) return "fail 14"
|
||||
if (cs.length != 123) return "fail 15"
|
||||
|
||||
cs = b
|
||||
if (b.length != 456) return "fail 16"
|
||||
if (b.length != 456) return "fail 17"
|
||||
|
||||
return J.foo();
|
||||
}
|
||||
+95
@@ -0,0 +1,95 @@
|
||||
// FILE: J.java
|
||||
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
|
||||
import java.util.Collection;
|
||||
import java.util.Iterator;
|
||||
import java.util.List;
|
||||
import java.util.ListIterator;
|
||||
|
||||
public class J extends MyList {
|
||||
@Override
|
||||
public int getSize() {
|
||||
return 55;
|
||||
}
|
||||
|
||||
@Override
|
||||
public int lastIndexOf(String s) {
|
||||
return 0;
|
||||
}
|
||||
|
||||
@Override
|
||||
public int indexOf(String s) {
|
||||
return 0;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean contains(String s) {
|
||||
return true;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean isEmpty() {
|
||||
return false;
|
||||
}
|
||||
|
||||
@NotNull
|
||||
@Override
|
||||
public Iterator<String> iterator() {
|
||||
return null;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean containsAll(Collection<?> c) {
|
||||
return false;
|
||||
}
|
||||
|
||||
@Override
|
||||
public String get(int index) {
|
||||
return null;
|
||||
}
|
||||
|
||||
@Override
|
||||
public List<String> subList(int i, int i1) {
|
||||
return super.subList(i, i1);
|
||||
}
|
||||
|
||||
@Override
|
||||
public ListIterator<String> listIterator(int i) {
|
||||
return super.listIterator(i);
|
||||
}
|
||||
|
||||
@Override
|
||||
public ListIterator<String> listIterator() {
|
||||
return super.listIterator();
|
||||
}
|
||||
}
|
||||
|
||||
// FILE: test.kt
|
||||
|
||||
abstract class MyList : List<String>
|
||||
|
||||
class ListImpl : J() {
|
||||
override val size: Int get() = super.size + 1
|
||||
}
|
||||
|
||||
fun box(): String {
|
||||
val impl = ListImpl()
|
||||
if (impl.size != 56) return "fail 1"
|
||||
if (!impl.contains("abc")) return "fail 2"
|
||||
|
||||
val l: List<String> = impl
|
||||
|
||||
if (l.size != 56) return "fail 3"
|
||||
if (!l.contains("abc")) return "fail 4"
|
||||
|
||||
val anyList: List<Any?> = impl as List<Any?>
|
||||
|
||||
if (anyList.size != 56) return "fail 5"
|
||||
if (!anyList.contains("abc")) return "fail 6"
|
||||
|
||||
if (anyList.contains(1)) return "fail 7"
|
||||
if (anyList.contains(null)) return "fail 8"
|
||||
|
||||
return "OK"
|
||||
}
|
||||
@@ -0,0 +1,28 @@
|
||||
// FILE: J.java
|
||||
|
||||
public class J {
|
||||
abstract static public class AImpl {
|
||||
public char charAt(int index) {
|
||||
return 'A';
|
||||
}
|
||||
|
||||
public final int length() { return 56; }
|
||||
}
|
||||
|
||||
public static class A extends AImpl implements CharSequence {
|
||||
public CharSequence subSequence(int start, int end) {
|
||||
return null;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// FILE: test.kt
|
||||
|
||||
class X : J.A()
|
||||
|
||||
fun box(): String {
|
||||
val x = X()
|
||||
if (x.length != 56) return "fail 1"
|
||||
if (x[0] != 'A') return "fail 2"
|
||||
return "OK"
|
||||
}
|
||||
+30
@@ -0,0 +1,30 @@
|
||||
// FILE: J.java
|
||||
|
||||
public class J {
|
||||
public static class A extends AImpl implements CharSequence {
|
||||
public CharSequence subSequence(int start, int end) {
|
||||
return null;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// FILE: test.kt
|
||||
|
||||
abstract class AImpl {
|
||||
fun charAt(index: Int): Char {
|
||||
return 'A'
|
||||
}
|
||||
|
||||
fun length(): Int {
|
||||
return 56
|
||||
}
|
||||
}
|
||||
|
||||
class X : J.A()
|
||||
|
||||
fun box(): String {
|
||||
val x = X()
|
||||
if (x.length != 56) return "fail 1"
|
||||
if (x[0] != 'A') return "fail 2"
|
||||
return "OK"
|
||||
}
|
||||
@@ -0,0 +1,113 @@
|
||||
// FILE: J.java
|
||||
|
||||
import java.util.*;
|
||||
public class J {
|
||||
abstract static public class AImpl {
|
||||
public final int size() {
|
||||
return 56;
|
||||
}
|
||||
|
||||
public boolean isEmpty() {
|
||||
return false;
|
||||
}
|
||||
|
||||
public final boolean contains(Object o) {
|
||||
return true;
|
||||
}
|
||||
|
||||
public Iterator<String> iterator() {
|
||||
return null;
|
||||
}
|
||||
|
||||
public Object[] toArray() {
|
||||
return new Object[0];
|
||||
}
|
||||
|
||||
public <T> T[] toArray(T[] a) {
|
||||
return null;
|
||||
}
|
||||
|
||||
public boolean add(String s) {
|
||||
return false;
|
||||
}
|
||||
|
||||
public boolean remove(Object o) {
|
||||
return false;
|
||||
}
|
||||
|
||||
public boolean containsAll(Collection<?> c) {
|
||||
return false;
|
||||
}
|
||||
|
||||
public boolean addAll(Collection<? extends String> c) {
|
||||
return false;
|
||||
}
|
||||
|
||||
public boolean addAll(int index, Collection<? extends String> c) {
|
||||
return false;
|
||||
}
|
||||
|
||||
public boolean removeAll(Collection<?> c) {
|
||||
return false;
|
||||
}
|
||||
|
||||
public boolean retainAll(Collection<?> c) {
|
||||
return false;
|
||||
}
|
||||
|
||||
public void clear() {
|
||||
|
||||
}
|
||||
|
||||
public String get(int index) {
|
||||
return null;
|
||||
}
|
||||
|
||||
public String set(int index, String element) {
|
||||
return null;
|
||||
}
|
||||
|
||||
public void add(int index, String element) {
|
||||
|
||||
}
|
||||
|
||||
public String remove(int index) {
|
||||
return null;
|
||||
}
|
||||
|
||||
public int indexOf(Object o) {
|
||||
return 0;
|
||||
}
|
||||
|
||||
public int lastIndexOf(Object o) {
|
||||
return 0;
|
||||
}
|
||||
|
||||
public ListIterator<String> listIterator() {
|
||||
return null;
|
||||
}
|
||||
|
||||
public ListIterator<String> listIterator(int index) {
|
||||
return null;
|
||||
}
|
||||
|
||||
public List<String> subList(int fromIndex, int toIndex) {
|
||||
return null;
|
||||
}
|
||||
}
|
||||
|
||||
public static class A extends AImpl implements List<String> {
|
||||
}
|
||||
}
|
||||
|
||||
// FILE: test.kt
|
||||
|
||||
class X : J.A()
|
||||
|
||||
fun box(): String {
|
||||
val x = X()
|
||||
if (x.size != 56) return "fail 1"
|
||||
if (!x.contains("")) return "fail 2"
|
||||
|
||||
return "OK"
|
||||
}
|
||||
+102
@@ -0,0 +1,102 @@
|
||||
// WITH_RUNTIME
|
||||
// FILE: A.java
|
||||
|
||||
public class A extends AImpl implements java.util.List<String> {
|
||||
public <T> T[] toArray(T[] a) {return null;}
|
||||
public Object[] toArray() {return null;}
|
||||
}
|
||||
|
||||
// FILE: test.kt
|
||||
|
||||
public abstract class AImpl {
|
||||
fun add(element: String): Boolean {
|
||||
throw UnsupportedOperationException()
|
||||
}
|
||||
|
||||
fun remove(element: Any?): Boolean {
|
||||
throw UnsupportedOperationException()
|
||||
}
|
||||
|
||||
@JvmSuppressWildcards(suppress = false)
|
||||
fun addAll(elements: Collection<String>): Boolean {
|
||||
throw UnsupportedOperationException()
|
||||
}
|
||||
|
||||
fun addAll(index: Int, elements: Collection<@JvmWildcard String>): Boolean {
|
||||
throw UnsupportedOperationException()
|
||||
}
|
||||
|
||||
fun removeAll(elements: Collection<*>): Boolean {
|
||||
throw UnsupportedOperationException()
|
||||
}
|
||||
|
||||
fun retainAll(elements: Collection<*>): Boolean {
|
||||
throw UnsupportedOperationException()
|
||||
}
|
||||
|
||||
fun clear() {
|
||||
throw UnsupportedOperationException()
|
||||
}
|
||||
|
||||
fun set(index: Int, element: String): String {
|
||||
throw UnsupportedOperationException()
|
||||
}
|
||||
|
||||
fun add(index: Int, element: String) {
|
||||
throw UnsupportedOperationException()
|
||||
}
|
||||
|
||||
fun remove(index: Int): String {
|
||||
throw UnsupportedOperationException()
|
||||
}
|
||||
|
||||
fun listIterator(): MutableListIterator<String> {
|
||||
throw UnsupportedOperationException()
|
||||
}
|
||||
|
||||
fun listIterator(index: Int): MutableListIterator<String> {
|
||||
throw UnsupportedOperationException()
|
||||
}
|
||||
|
||||
fun subList(fromIndex: Int, toIndex: Int): MutableList<String> {
|
||||
throw UnsupportedOperationException()
|
||||
}
|
||||
|
||||
fun size(): Int = 56
|
||||
|
||||
fun isEmpty(): Boolean {
|
||||
throw UnsupportedOperationException()
|
||||
}
|
||||
|
||||
fun contains(element: Any?) = true
|
||||
|
||||
fun containsAll(elements: Collection<*>): Boolean {
|
||||
throw UnsupportedOperationException()
|
||||
}
|
||||
|
||||
fun get(index: Int): String {
|
||||
throw UnsupportedOperationException()
|
||||
}
|
||||
|
||||
fun indexOf(element: Any?): Int {
|
||||
throw UnsupportedOperationException()
|
||||
}
|
||||
|
||||
fun lastIndexOf(element: Any?): Int {
|
||||
throw UnsupportedOperationException()
|
||||
}
|
||||
|
||||
fun iterator(): MutableIterator<String> {
|
||||
throw UnsupportedOperationException()
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
class X : A()
|
||||
|
||||
fun box(): String {
|
||||
val x = X()
|
||||
if (x.size != 56) return "fail 1"
|
||||
if (!x.contains("")) return "fail 2"
|
||||
return "OK"
|
||||
}
|
||||
+113
@@ -0,0 +1,113 @@
|
||||
// FILE: J.java
|
||||
|
||||
import java.util.*;
|
||||
public class J {
|
||||
abstract static public class AImpl<E> {
|
||||
public int size() {
|
||||
return 56;
|
||||
}
|
||||
|
||||
public boolean isEmpty() {
|
||||
return false;
|
||||
}
|
||||
|
||||
public final boolean contains(Object o) {
|
||||
return true;
|
||||
}
|
||||
|
||||
public Iterator<E> iterator() {
|
||||
return null;
|
||||
}
|
||||
|
||||
public Object[] toArray() {
|
||||
return new Object[0];
|
||||
}
|
||||
|
||||
public <T> T[] toArray(T[] a) {
|
||||
return null;
|
||||
}
|
||||
|
||||
public boolean add(E s) {
|
||||
return false;
|
||||
}
|
||||
|
||||
public boolean remove(Object o) {
|
||||
return false;
|
||||
}
|
||||
|
||||
public boolean containsAll(Collection<?> c) {
|
||||
return false;
|
||||
}
|
||||
|
||||
public boolean addAll(Collection<? extends E> c) {
|
||||
return false;
|
||||
}
|
||||
|
||||
public boolean addAll(int index, Collection<? extends E> c) {
|
||||
return false;
|
||||
}
|
||||
|
||||
public boolean removeAll(Collection<?> c) {
|
||||
return false;
|
||||
}
|
||||
|
||||
public boolean retainAll(Collection<?> c) {
|
||||
return false;
|
||||
}
|
||||
|
||||
public void clear() {
|
||||
|
||||
}
|
||||
|
||||
public E get(int index) {
|
||||
return null;
|
||||
}
|
||||
|
||||
public E set(int index, E element) {
|
||||
return null;
|
||||
}
|
||||
|
||||
public void add(int index, E element) {
|
||||
|
||||
}
|
||||
|
||||
public E remove(int index) {
|
||||
return null;
|
||||
}
|
||||
|
||||
public int indexOf(Object o) {
|
||||
return 0;
|
||||
}
|
||||
|
||||
public int lastIndexOf(Object o) {
|
||||
return 0;
|
||||
}
|
||||
|
||||
public ListIterator<E> listIterator() {
|
||||
return null;
|
||||
}
|
||||
|
||||
public ListIterator<E> listIterator(int index) {
|
||||
return null;
|
||||
}
|
||||
|
||||
public List<E> subList(int fromIndex, int toIndex) {
|
||||
return null;
|
||||
}
|
||||
}
|
||||
|
||||
public static class A<E> extends AImpl<E> implements List<E> {
|
||||
}
|
||||
}
|
||||
|
||||
// FILE: test.kt
|
||||
|
||||
class X : J.A<Any?>()
|
||||
|
||||
fun box(): String {
|
||||
val x = X()
|
||||
if (x.size != 56) return "fail 1"
|
||||
if (!x.contains(null)) return "fail 2"
|
||||
|
||||
return "OK"
|
||||
}
|
||||
+110
@@ -0,0 +1,110 @@
|
||||
// FILE: J.java
|
||||
|
||||
import java.util.*;
|
||||
|
||||
public class J implements Container {
|
||||
final public String removeAt(int index) { return "abc"; }
|
||||
}
|
||||
|
||||
// FILE: test.kt
|
||||
|
||||
interface Container {
|
||||
fun removeAt(x: Int): String
|
||||
}
|
||||
|
||||
class A : J(), MutableList<String> {
|
||||
override fun isEmpty(): Boolean {
|
||||
throw UnsupportedOperationException()
|
||||
}
|
||||
|
||||
override val size: Int
|
||||
get() = throw UnsupportedOperationException()
|
||||
|
||||
override fun contains(element: String): Boolean {
|
||||
throw UnsupportedOperationException()
|
||||
}
|
||||
|
||||
override fun containsAll(elements: Collection<String>): Boolean {
|
||||
throw UnsupportedOperationException()
|
||||
}
|
||||
|
||||
override fun get(index: Int): String {
|
||||
throw UnsupportedOperationException()
|
||||
}
|
||||
|
||||
override fun indexOf(element: String): Int {
|
||||
throw UnsupportedOperationException()
|
||||
}
|
||||
|
||||
override fun lastIndexOf(element: String): Int {
|
||||
throw UnsupportedOperationException()
|
||||
}
|
||||
|
||||
override fun add(element: String): Boolean {
|
||||
throw UnsupportedOperationException()
|
||||
}
|
||||
|
||||
override fun remove(element: String): Boolean {
|
||||
throw UnsupportedOperationException()
|
||||
}
|
||||
|
||||
override fun addAll(elements: Collection<String>): Boolean {
|
||||
throw UnsupportedOperationException()
|
||||
}
|
||||
|
||||
override fun addAll(index: Int, elements: Collection<String>): Boolean {
|
||||
throw UnsupportedOperationException()
|
||||
}
|
||||
|
||||
override fun removeAll(elements: Collection<String>): Boolean {
|
||||
throw UnsupportedOperationException()
|
||||
}
|
||||
|
||||
override fun retainAll(elements: Collection<String>): Boolean {
|
||||
throw UnsupportedOperationException()
|
||||
}
|
||||
|
||||
override fun clear() {
|
||||
throw UnsupportedOperationException()
|
||||
}
|
||||
|
||||
override fun set(index: Int, element: String): String {
|
||||
throw UnsupportedOperationException()
|
||||
}
|
||||
|
||||
override fun add(index: Int, element: String) {
|
||||
throw UnsupportedOperationException()
|
||||
}
|
||||
|
||||
override fun listIterator(): MutableListIterator<String> {
|
||||
throw UnsupportedOperationException()
|
||||
}
|
||||
|
||||
override fun listIterator(index: Int): MutableListIterator<String> {
|
||||
throw UnsupportedOperationException()
|
||||
}
|
||||
|
||||
override fun subList(fromIndex: Int, toIndex: Int): MutableList<String> {
|
||||
throw UnsupportedOperationException()
|
||||
}
|
||||
|
||||
override fun iterator(): MutableIterator<String> {
|
||||
throw UnsupportedOperationException()
|
||||
}
|
||||
}
|
||||
|
||||
fun box(): String {
|
||||
val a = A()
|
||||
if (a.removeAt(0) != "abc") return "fail 1"
|
||||
|
||||
val l: MutableList<String> = a
|
||||
if (l.removeAt(0) != "abc") return "fail 2"
|
||||
|
||||
val anyList: MutableList<Any?> = a as MutableList<Any?>
|
||||
if (anyList.removeAt(0) != "abc") return "fail 3"
|
||||
|
||||
val container: Container = a
|
||||
if (container.removeAt(0) != "abc") return "fail 4"
|
||||
|
||||
return "OK"
|
||||
}
|
||||
@@ -0,0 +1,44 @@
|
||||
// FILE: J.java
|
||||
|
||||
import java.util.*;
|
||||
|
||||
public class J implements Sized {
|
||||
final public int getSize() { return 123; }
|
||||
}
|
||||
|
||||
// FILE: test.kt
|
||||
|
||||
interface Sized {
|
||||
val size: Int
|
||||
}
|
||||
|
||||
class A<T> : J(), Collection<T> {
|
||||
override fun isEmpty(): Boolean {
|
||||
throw UnsupportedOperationException()
|
||||
}
|
||||
|
||||
override fun contains(element: T): Boolean {
|
||||
throw UnsupportedOperationException()
|
||||
}
|
||||
|
||||
override fun iterator(): Iterator<T> {
|
||||
throw UnsupportedOperationException()
|
||||
}
|
||||
|
||||
override fun containsAll(elements: Collection<T>): Boolean {
|
||||
throw UnsupportedOperationException()
|
||||
}
|
||||
}
|
||||
|
||||
fun box(): String {
|
||||
val a = A<String>()
|
||||
if (a.size != 123) return "fail 1"
|
||||
|
||||
val c: Collection<String> = a
|
||||
if (c.size != 123) return "fail 2"
|
||||
|
||||
val sized: Sized = a
|
||||
if (sized.size != 123) return "fail 3"
|
||||
|
||||
return "OK"
|
||||
}
|
||||
@@ -0,0 +1,99 @@
|
||||
// FILE: J.java
|
||||
|
||||
import java.util.*;
|
||||
|
||||
public class J {
|
||||
|
||||
private static class MyList<E> extends KList<E> {}
|
||||
|
||||
public static String foo() {
|
||||
Collection<String> collection = new MyList<String>();
|
||||
if (!collection.contains("ABCDE")) return "fail 1";
|
||||
if (!collection.containsAll(Arrays.asList(1, 2, 3))) return "fail 2";
|
||||
return "OK";
|
||||
}
|
||||
}
|
||||
|
||||
// FILE: test.kt
|
||||
|
||||
open class KList<E> : MutableList<E> {
|
||||
override fun add(e: E): Boolean {
|
||||
throw UnsupportedOperationException()
|
||||
}
|
||||
|
||||
override fun remove(o: E): Boolean {
|
||||
throw UnsupportedOperationException()
|
||||
}
|
||||
|
||||
override fun addAll(c: Collection<E>): Boolean {
|
||||
throw UnsupportedOperationException()
|
||||
}
|
||||
|
||||
override fun addAll(index: Int, c: Collection<E>): Boolean {
|
||||
throw UnsupportedOperationException()
|
||||
}
|
||||
|
||||
override fun removeAll(c: Collection<E>): Boolean {
|
||||
throw UnsupportedOperationException()
|
||||
}
|
||||
|
||||
override fun retainAll(c: Collection<E>): Boolean {
|
||||
throw UnsupportedOperationException()
|
||||
}
|
||||
|
||||
override fun clear() {
|
||||
throw UnsupportedOperationException()
|
||||
}
|
||||
|
||||
override fun set(index: Int, element: E): E {
|
||||
throw UnsupportedOperationException()
|
||||
}
|
||||
|
||||
override fun add(index: Int, element: E) {
|
||||
throw UnsupportedOperationException()
|
||||
}
|
||||
|
||||
override fun removeAt(index: Int): E {
|
||||
throw UnsupportedOperationException()
|
||||
}
|
||||
|
||||
override fun listIterator(): MutableListIterator<E> {
|
||||
throw UnsupportedOperationException()
|
||||
}
|
||||
|
||||
override fun listIterator(index: Int): MutableListIterator<E> {
|
||||
throw UnsupportedOperationException()
|
||||
}
|
||||
|
||||
override fun subList(fromIndex: Int, toIndex: Int): MutableList<E> {
|
||||
throw UnsupportedOperationException()
|
||||
}
|
||||
|
||||
override fun iterator(): MutableIterator<E> {
|
||||
throw UnsupportedOperationException()
|
||||
}
|
||||
|
||||
override val size: Int
|
||||
get() = throw UnsupportedOperationException()
|
||||
|
||||
override fun isEmpty(): Boolean {
|
||||
throw UnsupportedOperationException()
|
||||
}
|
||||
|
||||
override fun contains(o: E) = true
|
||||
override fun containsAll(c: Collection<E>) = true
|
||||
|
||||
override fun get(index: Int): E {
|
||||
throw UnsupportedOperationException()
|
||||
}
|
||||
|
||||
override fun indexOf(o: E): Int {
|
||||
throw UnsupportedOperationException()
|
||||
}
|
||||
|
||||
override fun lastIndexOf(o: E): Int {
|
||||
throw UnsupportedOperationException()
|
||||
}
|
||||
}
|
||||
|
||||
fun box() = J.foo()
|
||||
@@ -0,0 +1,52 @@
|
||||
// FILE: J.java
|
||||
|
||||
import java.util.*;
|
||||
|
||||
public class J {
|
||||
public static String nullValue() {
|
||||
return null;
|
||||
}
|
||||
}
|
||||
|
||||
// FILE: test.kt
|
||||
|
||||
class MySet : Set<String> {
|
||||
override val size: Int
|
||||
get() = throw UnsupportedOperationException()
|
||||
|
||||
override fun isEmpty(): Boolean {
|
||||
throw UnsupportedOperationException()
|
||||
}
|
||||
|
||||
override fun contains(o: String): Boolean {
|
||||
throw UnsupportedOperationException()
|
||||
}
|
||||
|
||||
override fun iterator(): Iterator<String> {
|
||||
throw UnsupportedOperationException()
|
||||
}
|
||||
|
||||
override fun containsAll(c: Collection<String>): Boolean {
|
||||
throw UnsupportedOperationException()
|
||||
}
|
||||
}
|
||||
|
||||
fun box(): String {
|
||||
val mySet = MySet()
|
||||
|
||||
// no UnsupportedOperationException thrown
|
||||
mySet.contains(J.nullValue())
|
||||
J.nullValue() in mySet
|
||||
|
||||
val set: Set<String> = mySet
|
||||
set.contains(J.nullValue())
|
||||
J.nullValue() in set
|
||||
|
||||
val anySet: Set<Any?> = mySet as Set<Any?>
|
||||
anySet.contains(J.nullValue())
|
||||
anySet.contains(null)
|
||||
J.nullValue() in anySet
|
||||
null in anySet
|
||||
|
||||
return "OK"
|
||||
}
|
||||
@@ -0,0 +1,58 @@
|
||||
// FILE: J.java
|
||||
|
||||
import java.util.*;
|
||||
|
||||
public class J {
|
||||
|
||||
private static class MyList<E> extends KList<E> {}
|
||||
|
||||
public static String foo() {
|
||||
Collection<String> collection = new MyList<String>();
|
||||
if (!collection.contains("ABCDE")) return "fail 1";
|
||||
if (!collection.containsAll(Arrays.asList(1, 2, 3))) return "fail 2";
|
||||
return "OK";
|
||||
}
|
||||
}
|
||||
|
||||
// FILE: test.kt
|
||||
|
||||
open class KList<E> : List<E> {
|
||||
override val size: Int
|
||||
get() = throw UnsupportedOperationException()
|
||||
|
||||
override fun isEmpty(): Boolean {
|
||||
throw UnsupportedOperationException()
|
||||
}
|
||||
override fun contains(o: E) = true
|
||||
override fun containsAll(c: Collection<E>) = true
|
||||
|
||||
override fun iterator(): Iterator<E> {
|
||||
throw UnsupportedOperationException()
|
||||
}
|
||||
|
||||
override fun get(index: Int): E {
|
||||
throw UnsupportedOperationException()
|
||||
}
|
||||
|
||||
override fun indexOf(element: E): Int {
|
||||
throw UnsupportedOperationException()
|
||||
}
|
||||
|
||||
override fun lastIndexOf(element: E): Int {
|
||||
throw UnsupportedOperationException()
|
||||
}
|
||||
|
||||
override fun listIterator(): ListIterator<E> {
|
||||
throw UnsupportedOperationException()
|
||||
}
|
||||
|
||||
override fun listIterator(index: Int): ListIterator<E> {
|
||||
throw UnsupportedOperationException()
|
||||
}
|
||||
|
||||
override fun subList(fromIndex: Int, toIndex: Int): List<E> {
|
||||
throw UnsupportedOperationException()
|
||||
}
|
||||
}
|
||||
|
||||
fun box() = J.foo()
|
||||
@@ -0,0 +1,42 @@
|
||||
// FILE: J.java
|
||||
|
||||
import java.util.*;
|
||||
|
||||
public class J {
|
||||
|
||||
private static class MyMap<K, V> extends KMap<K, V> {}
|
||||
|
||||
public static String foo() {
|
||||
Map<String, Integer> collection = new MyMap<String, Integer>();
|
||||
if (!collection.containsKey("ABCDE")) return "fail 1";
|
||||
if (!collection.containsValue(1)) return "fail 2";
|
||||
return "OK";
|
||||
}
|
||||
}
|
||||
|
||||
// FILE: test.kt
|
||||
|
||||
open class KMap<K, V> : Map<K, V> {
|
||||
override val size: Int
|
||||
get() = throw UnsupportedOperationException()
|
||||
|
||||
override fun isEmpty(): Boolean {
|
||||
throw UnsupportedOperationException()
|
||||
}
|
||||
|
||||
override fun containsKey(key: K) = true
|
||||
override fun containsValue(value: V) = true
|
||||
|
||||
override fun get(key: K): V? {
|
||||
throw UnsupportedOperationException()
|
||||
}
|
||||
|
||||
override val keys: Set<K>
|
||||
get() = throw UnsupportedOperationException()
|
||||
override val values: Collection<V>
|
||||
get() = throw UnsupportedOperationException()
|
||||
override val entries: Set<Map.Entry<K, V>>
|
||||
get() = throw UnsupportedOperationException()
|
||||
}
|
||||
|
||||
fun box() = J.foo()
|
||||
@@ -0,0 +1,104 @@
|
||||
// FILE: J.java
|
||||
|
||||
import java.util.*;
|
||||
|
||||
public class J {
|
||||
|
||||
private static class MyList extends A {}
|
||||
|
||||
public static String foo() {
|
||||
MyList myList = new MyList();
|
||||
List<Integer> list = (List<Integer>) myList;
|
||||
|
||||
if (!list.remove((Integer) 1)) return "fail 1";
|
||||
if (list.remove((int) 1) != 123) return "fail 2";
|
||||
|
||||
if (!myList.remove((Integer) 1)) return "fail 3";
|
||||
if (myList.remove((int) 1) != 123) return "fail 4";
|
||||
|
||||
if (myList.removeAt(1) != 123) return "fail 5";
|
||||
return "OK";
|
||||
}
|
||||
}
|
||||
|
||||
// FILE: test.kt
|
||||
|
||||
open class A : MutableList<Int> {
|
||||
override val size: Int
|
||||
get() = throw UnsupportedOperationException()
|
||||
override fun isEmpty(): Boolean = throw UnsupportedOperationException()
|
||||
|
||||
override fun contains(o: Int): Boolean {
|
||||
throw UnsupportedOperationException()
|
||||
}
|
||||
|
||||
override fun containsAll(c: Collection<Int>): Boolean {
|
||||
throw UnsupportedOperationException()
|
||||
}
|
||||
|
||||
override fun get(index: Int): Int {
|
||||
throw UnsupportedOperationException()
|
||||
}
|
||||
|
||||
override fun indexOf(o: Int): Int {
|
||||
throw UnsupportedOperationException()
|
||||
}
|
||||
|
||||
override fun lastIndexOf(o: Int): Int {
|
||||
throw UnsupportedOperationException()
|
||||
}
|
||||
|
||||
override fun add(e: Int): Boolean {
|
||||
throw UnsupportedOperationException()
|
||||
}
|
||||
|
||||
override fun remove(o: Int) = true
|
||||
|
||||
override fun removeAt(index: Int): Int = 123
|
||||
|
||||
override fun addAll(c: Collection<Int>): Boolean {
|
||||
throw UnsupportedOperationException()
|
||||
}
|
||||
|
||||
override fun addAll(index: Int, c: Collection<Int>): Boolean {
|
||||
throw UnsupportedOperationException()
|
||||
}
|
||||
|
||||
override fun removeAll(c: Collection<Int>): Boolean {
|
||||
throw UnsupportedOperationException()
|
||||
}
|
||||
|
||||
override fun retainAll(c: Collection<Int>): Boolean {
|
||||
throw UnsupportedOperationException()
|
||||
}
|
||||
|
||||
override fun clear() {
|
||||
throw UnsupportedOperationException()
|
||||
}
|
||||
|
||||
override fun set(index: Int, element: Int): Int {
|
||||
throw UnsupportedOperationException()
|
||||
}
|
||||
|
||||
override fun add(index: Int, element: Int) {
|
||||
throw UnsupportedOperationException()
|
||||
}
|
||||
|
||||
override fun listIterator(): MutableListIterator<Int> {
|
||||
throw UnsupportedOperationException()
|
||||
}
|
||||
|
||||
override fun listIterator(index: Int): MutableListIterator<Int> {
|
||||
throw UnsupportedOperationException()
|
||||
}
|
||||
|
||||
override fun subList(fromIndex: Int, toIndex: Int): MutableList<Int> {
|
||||
throw UnsupportedOperationException()
|
||||
}
|
||||
|
||||
override fun iterator(): MutableIterator<Int> {
|
||||
throw UnsupportedOperationException()
|
||||
}
|
||||
}
|
||||
|
||||
fun box() = J.foo()
|
||||
@@ -0,0 +1,99 @@
|
||||
// FILE: J.java
|
||||
|
||||
import java.util.*;
|
||||
|
||||
public class J {
|
||||
|
||||
private static class MyList extends KList {}
|
||||
|
||||
public static String foo() {
|
||||
Collection<String> collection = new MyList();
|
||||
if (!collection.contains("ABCDE")) return "fail 1";
|
||||
if (!collection.containsAll(Arrays.asList(1, 2, 3))) return "fail 2";
|
||||
return "OK";
|
||||
}
|
||||
}
|
||||
|
||||
// FILE: test.kt
|
||||
|
||||
abstract class KList : MutableList<String> {
|
||||
override val size: Int
|
||||
get() = throw UnsupportedOperationException()
|
||||
|
||||
override fun isEmpty(): Boolean {
|
||||
throw UnsupportedOperationException()
|
||||
}
|
||||
|
||||
override fun contains(o: String) = true
|
||||
override fun containsAll(c: Collection<String>) = true
|
||||
|
||||
override fun get(index: Int): String {
|
||||
throw UnsupportedOperationException()
|
||||
}
|
||||
|
||||
override fun indexOf(o: String): Int {
|
||||
throw UnsupportedOperationException()
|
||||
}
|
||||
|
||||
override fun lastIndexOf(o: String): Int {
|
||||
throw UnsupportedOperationException()
|
||||
}
|
||||
|
||||
override fun iterator(): MutableIterator<String> {
|
||||
throw UnsupportedOperationException()
|
||||
}
|
||||
|
||||
override fun add(e: String): Boolean {
|
||||
throw UnsupportedOperationException()
|
||||
}
|
||||
|
||||
override fun remove(o: String): Boolean {
|
||||
throw UnsupportedOperationException()
|
||||
}
|
||||
|
||||
override fun addAll(c: Collection<String>): Boolean {
|
||||
throw UnsupportedOperationException()
|
||||
}
|
||||
|
||||
override fun addAll(index: Int, c: Collection<String>): Boolean {
|
||||
throw UnsupportedOperationException()
|
||||
}
|
||||
|
||||
override fun removeAll(c: Collection<String>): Boolean {
|
||||
throw UnsupportedOperationException()
|
||||
}
|
||||
|
||||
override fun retainAll(c: Collection<String>): Boolean {
|
||||
throw UnsupportedOperationException()
|
||||
}
|
||||
|
||||
override fun clear() {
|
||||
throw UnsupportedOperationException()
|
||||
}
|
||||
|
||||
override fun set(index: Int, element: String): String {
|
||||
throw UnsupportedOperationException()
|
||||
}
|
||||
|
||||
override fun add(index: Int, element: String) {
|
||||
throw UnsupportedOperationException()
|
||||
}
|
||||
|
||||
override fun removeAt(index: Int): String {
|
||||
throw UnsupportedOperationException()
|
||||
}
|
||||
|
||||
override fun listIterator(): MutableListIterator<String> {
|
||||
throw UnsupportedOperationException()
|
||||
}
|
||||
|
||||
override fun listIterator(index: Int): MutableListIterator<String> {
|
||||
throw UnsupportedOperationException()
|
||||
}
|
||||
|
||||
override fun subList(fromIndex: Int, toIndex: Int): MutableList<String> {
|
||||
throw UnsupportedOperationException()
|
||||
}
|
||||
|
||||
}
|
||||
fun box() = J.foo()
|
||||
@@ -0,0 +1,17 @@
|
||||
// FILE: JavaClass.java
|
||||
|
||||
public class JavaClass {
|
||||
public String getO() {
|
||||
return "O";
|
||||
}
|
||||
}
|
||||
|
||||
// FILE: main.kt
|
||||
|
||||
// KT-9522 Allow invoke convention for synthetic property
|
||||
|
||||
operator fun String.invoke() = this + "K"
|
||||
|
||||
fun box(): String {
|
||||
return JavaClass().o();
|
||||
}
|
||||
@@ -0,0 +1,26 @@
|
||||
// TARGET_BACKEND: JVM
|
||||
// FILE: JavaClass.java
|
||||
|
||||
public abstract class JavaClass {
|
||||
public static String test() {
|
||||
return Test.INSTANCE.foo(new Outer<String>("OK").new Inner<Integer>(1));
|
||||
}
|
||||
}
|
||||
|
||||
// FILE: Kotlin.kt
|
||||
|
||||
class Outer<E>(val x: E) {
|
||||
inner class Inner<F>(val y: F) {
|
||||
fun foo() = x.toString() + y.toString()
|
||||
}
|
||||
}
|
||||
|
||||
object Test {
|
||||
fun foo(x: Outer<String>.Inner<Integer>) = x.foo()
|
||||
}
|
||||
|
||||
fun box(): String {
|
||||
val result = JavaClass.test()
|
||||
if (result != "OK1") return "Fail: $result"
|
||||
return "OK"
|
||||
}
|
||||
@@ -0,0 +1,22 @@
|
||||
// TARGET_BACKEND: JVM
|
||||
// FILE: JavaClass.java
|
||||
|
||||
public abstract class JavaClass {
|
||||
public abstract InnerClass onCreateInner();
|
||||
|
||||
public class InnerClass {
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
// FILE: Kotlin.kt
|
||||
|
||||
public class MyWallpaperService : JavaClass() {
|
||||
override fun onCreateInner(): JavaClass.InnerClass = MyEngine()
|
||||
|
||||
private inner class MyEngine : JavaClass.InnerClass()
|
||||
}
|
||||
|
||||
fun box(): String {
|
||||
return if (MyWallpaperService().onCreateInner() != null) return "OK" else "fail"
|
||||
}
|
||||
@@ -0,0 +1,48 @@
|
||||
// WITH_RUNTIME
|
||||
// FILE: JavaClass.java
|
||||
|
||||
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";
|
||||
}
|
||||
}
|
||||
|
||||
// FILE: main.kt
|
||||
|
||||
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();
|
||||
}
|
||||
compiler/testData/codegen/box/javaInterop/generics/covariantOverrideWithDeclarationSiteProjection.kt
Vendored
+47
@@ -0,0 +1,47 @@
|
||||
// WITH_RUNTIME
|
||||
// FILE: JavaClass.java
|
||||
|
||||
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";
|
||||
}
|
||||
}
|
||||
|
||||
// FILE: main.kt
|
||||
|
||||
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();
|
||||
}
|
||||
+21
@@ -0,0 +1,21 @@
|
||||
// FILE: JavaClass.java
|
||||
|
||||
public class JavaClass {
|
||||
public static String test() {
|
||||
return MainKt.bar(MainKt.foo());
|
||||
}
|
||||
}
|
||||
|
||||
// FILE: main.kt
|
||||
|
||||
class Pair<out X, out Y>(val x: X, val y: Y)
|
||||
|
||||
class Inv<T>(val x: T)
|
||||
|
||||
fun foo(): Inv<Pair<CharSequence, CharSequence>> = Inv(Pair("O", "K"))
|
||||
|
||||
fun bar(inv: Inv<Pair<CharSequence, CharSequence>>) = inv.x.x.toString() + inv.x.y
|
||||
|
||||
fun box(): String {
|
||||
return JavaClass.test();
|
||||
}
|
||||
+29
@@ -0,0 +1,29 @@
|
||||
// FILE: Test.java
|
||||
|
||||
public class Test {
|
||||
public static String invokeFoo() {
|
||||
try {
|
||||
ExtensionKt.foo(null);
|
||||
}
|
||||
catch (IllegalArgumentException e) {
|
||||
try {
|
||||
ExtensionKt.getBar(null);
|
||||
}
|
||||
catch (IllegalArgumentException f) {
|
||||
return "OK";
|
||||
}
|
||||
}
|
||||
|
||||
return "Fail: assertion must have been fired";
|
||||
}
|
||||
}
|
||||
|
||||
// FILE: extension.kt
|
||||
|
||||
fun Any.foo() { }
|
||||
|
||||
val Any.bar: String get() = ""
|
||||
|
||||
fun box(): String {
|
||||
return Test.invokeFoo()
|
||||
}
|
||||
@@ -0,0 +1,19 @@
|
||||
// WITH_RUNTIME
|
||||
// FILE: Test.java
|
||||
|
||||
public class Test {
|
||||
public static String invokeMethodWithPublicField() {
|
||||
C c = new C("OK");
|
||||
return c.foo;
|
||||
}
|
||||
}
|
||||
|
||||
// FILE: simple.kt
|
||||
|
||||
class C(@JvmField val foo: String) {
|
||||
|
||||
}
|
||||
|
||||
fun box(): String {
|
||||
return Test.invokeMethodWithPublicField()
|
||||
}
|
||||
@@ -0,0 +1,19 @@
|
||||
// WITH_RUNTIME
|
||||
// FILE: Test.java
|
||||
|
||||
public class Test {
|
||||
public static String invokeMethodWithPublicField() {
|
||||
C c = new C();
|
||||
return c.foo;
|
||||
}
|
||||
}
|
||||
|
||||
// FILE: simple.kt
|
||||
|
||||
class C {
|
||||
@JvmField public val foo: String = "OK"
|
||||
}
|
||||
|
||||
fun box(): String {
|
||||
return Test.invokeMethodWithPublicField()
|
||||
}
|
||||
@@ -0,0 +1,23 @@
|
||||
// FILE: FakePlatformName.java
|
||||
|
||||
import kotlin.jvm.JvmName;
|
||||
|
||||
public class FakePlatformName {
|
||||
@JvmName(name = "fake")
|
||||
public String foo() {
|
||||
return "foo";
|
||||
}
|
||||
|
||||
public String fake() {
|
||||
return "fake";
|
||||
}
|
||||
}
|
||||
|
||||
// FILE: FakePlatformName.kt
|
||||
|
||||
fun box(): String {
|
||||
val test1 = FakePlatformName().foo()
|
||||
if (test1 != "foo") return "Failed: FakePlatformName().foo()==$test1"
|
||||
|
||||
return "OK"
|
||||
}
|
||||
@@ -0,0 +1,22 @@
|
||||
// WITH_RUNTIME
|
||||
// FILE: Baz.java
|
||||
|
||||
public class Baz {
|
||||
public static String baz() {
|
||||
return Foo.foo() + Bar.bar();
|
||||
}
|
||||
}
|
||||
|
||||
// FILE: bar.kt
|
||||
|
||||
@file:JvmName("Bar")
|
||||
public fun bar(): String = "K"
|
||||
|
||||
// FILE: foo.kt
|
||||
|
||||
@file:JvmName("Foo")
|
||||
public fun foo(): String = "O"
|
||||
|
||||
// FILE: test.kt
|
||||
|
||||
fun box(): String = Baz.baz()
|
||||
+20
@@ -0,0 +1,20 @@
|
||||
// WITH_RUNTIME
|
||||
// FILE: StringHolder.java
|
||||
|
||||
import java.lang.annotation.ElementType;
|
||||
import java.lang.annotation.Retention;
|
||||
import java.lang.annotation.RetentionPolicy;
|
||||
import java.lang.annotation.Target;
|
||||
|
||||
@Target(ElementType.TYPE)
|
||||
@Retention(RetentionPolicy.RUNTIME)
|
||||
public @interface StringHolder {
|
||||
public String value();
|
||||
}
|
||||
|
||||
// FILE: fileFacade.kt
|
||||
|
||||
@file:StringHolder("OK")
|
||||
|
||||
fun box(): String =
|
||||
Class.forName("FileFacadeKt").getAnnotation(StringHolder::class.java)?.value ?: "null"
|
||||
@@ -0,0 +1,17 @@
|
||||
// WITH_RUNTIME
|
||||
// FILE: Bar.java
|
||||
|
||||
public class Bar {
|
||||
public static String bar() {
|
||||
return Foo.foo();
|
||||
}
|
||||
}
|
||||
|
||||
// FILE: foo.kt
|
||||
|
||||
@file:JvmName("Foo")
|
||||
public fun foo(): String = "OK"
|
||||
|
||||
// FILE: simple.kt
|
||||
|
||||
fun box(): String = Bar.bar()
|
||||
@@ -0,0 +1,19 @@
|
||||
// WITH_RUNTIME
|
||||
// FILE: Test.java
|
||||
|
||||
public class Test {
|
||||
public static String invokeMethodWithOverloads() {
|
||||
C<String> c = new C<String>();
|
||||
return c.foo("O");
|
||||
}
|
||||
}
|
||||
|
||||
// FILE: generics.kt
|
||||
|
||||
class C<T> {
|
||||
@kotlin.jvm.JvmOverloads public fun foo(o: T, k: String = "K"): String = o.toString() + k
|
||||
}
|
||||
|
||||
fun box(): String {
|
||||
return Test.invokeMethodWithOverloads()
|
||||
}
|
||||
@@ -0,0 +1,19 @@
|
||||
// WITH_RUNTIME
|
||||
// FILE: Test.java
|
||||
|
||||
public class Test {
|
||||
public static String invokeMethodWithOverloads() {
|
||||
C c = new C();
|
||||
return c.foo();
|
||||
}
|
||||
}
|
||||
|
||||
// FILE: simple.kt
|
||||
|
||||
class C {
|
||||
@kotlin.jvm.JvmOverloads public fun foo(o: String = "O", k: String = "K"): String = o + k
|
||||
}
|
||||
|
||||
fun box(): String {
|
||||
return Test.invokeMethodWithOverloads()
|
||||
}
|
||||
@@ -0,0 +1,58 @@
|
||||
// WITH_RUNTIME
|
||||
// FILE: Test.java
|
||||
|
||||
import java.lang.annotation.Annotation;
|
||||
|
||||
class Test {
|
||||
|
||||
public static String test1() throws NoSuchMethodException {
|
||||
Annotation[] test1s = A.class.getMethod("test1").getAnnotations();
|
||||
for (Annotation test : test1s) {
|
||||
String name = test.toString();
|
||||
if (name.contains("testAnnotation")) {
|
||||
return "OK";
|
||||
}
|
||||
}
|
||||
return "fail";
|
||||
}
|
||||
|
||||
public static String test2() throws NoSuchMethodException {
|
||||
Annotation[] test2s = B.class.getMethod("test1").getAnnotations();
|
||||
for (Annotation test : test2s) {
|
||||
String name = test.toString();
|
||||
if (name.contains("testAnnotation")) {
|
||||
return "OK";
|
||||
}
|
||||
}
|
||||
return "fail";
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
// FILE: test.kt
|
||||
|
||||
@Retention(AnnotationRetention.RUNTIME)
|
||||
annotation class testAnnotation
|
||||
|
||||
class A {
|
||||
|
||||
companion object {
|
||||
val b: String = "OK"
|
||||
|
||||
@JvmStatic @testAnnotation fun test1() = b
|
||||
}
|
||||
}
|
||||
|
||||
object B {
|
||||
val b: String = "OK"
|
||||
|
||||
@JvmStatic @testAnnotation fun test1() = b
|
||||
}
|
||||
|
||||
fun box(): String {
|
||||
if (Test.test1() != "OK") return "fail 1"
|
||||
|
||||
if (Test.test2() != "OK") return "fail 2"
|
||||
|
||||
return "OK"
|
||||
}
|
||||
@@ -0,0 +1,51 @@
|
||||
// WITH_RUNTIME
|
||||
// FILE: Test.java
|
||||
|
||||
class Test {
|
||||
|
||||
public static String test1() {
|
||||
return A.test1();
|
||||
}
|
||||
|
||||
public static String test2() {
|
||||
return A.test2();
|
||||
}
|
||||
|
||||
public static String test3() {
|
||||
return A.test3("JAVA");
|
||||
}
|
||||
|
||||
public static String test4() {
|
||||
return A.getC();
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
// FILE: simpleCompanionObject.kt
|
||||
|
||||
class A {
|
||||
|
||||
companion object {
|
||||
val b: String = "OK"
|
||||
|
||||
@JvmStatic val c: String = "OK"
|
||||
|
||||
@JvmStatic fun test1() = b
|
||||
|
||||
@JvmStatic fun test2() = b
|
||||
|
||||
@JvmStatic fun String.test3() = this + b
|
||||
}
|
||||
}
|
||||
|
||||
fun box(): String {
|
||||
if (Test.test1() != "OK") return "fail 1"
|
||||
|
||||
if (Test.test2() != "OK") return "fail 2"
|
||||
|
||||
if (Test.test3() != "JAVAOK") return "fail 3"
|
||||
|
||||
if (Test.test4() != "OK") return "fail 4"
|
||||
|
||||
return "OK"
|
||||
}
|
||||
@@ -0,0 +1,43 @@
|
||||
// WITH_RUNTIME
|
||||
// FILE: Test.java
|
||||
|
||||
class Test {
|
||||
public static String foo() {
|
||||
return A.foo;
|
||||
}
|
||||
|
||||
public static String constBar() {
|
||||
return A.constBar;
|
||||
}
|
||||
|
||||
public static String getBar() {
|
||||
return A.getBar();
|
||||
}
|
||||
|
||||
public static String baz() {
|
||||
return A.baz();
|
||||
}
|
||||
}
|
||||
|
||||
// FILE: enumCompanionObject.kt
|
||||
|
||||
enum class A {
|
||||
;
|
||||
companion object {
|
||||
@JvmField val foo: String = "OK"
|
||||
|
||||
const val constBar: String = "OK"
|
||||
|
||||
@JvmStatic val bar: String = "OK"
|
||||
|
||||
@JvmStatic fun baz() = foo
|
||||
}
|
||||
}
|
||||
|
||||
fun box(): String {
|
||||
if (Test.foo() != "OK") return "Fail foo"
|
||||
if (Test.constBar() != "OK") return "Fail bar"
|
||||
if (Test.getBar() != "OK") return "Fail getBar"
|
||||
if (Test.baz() != "OK") return "Fail baz"
|
||||
return "OK"
|
||||
}
|
||||
@@ -0,0 +1,49 @@
|
||||
// WITH_RUNTIME
|
||||
// FILE: Test.java
|
||||
|
||||
class Test {
|
||||
|
||||
public static String test1() {
|
||||
return A.test1();
|
||||
}
|
||||
|
||||
public static String test2() {
|
||||
return A.test2();
|
||||
}
|
||||
|
||||
public static String test3() {
|
||||
return A.test3("JAVA");
|
||||
}
|
||||
|
||||
public static String test4() {
|
||||
return A.getC();
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
// FILE: simpleObject.kt
|
||||
|
||||
object A {
|
||||
|
||||
val b: String = "OK"
|
||||
|
||||
@JvmStatic val c: String = "OK"
|
||||
|
||||
@JvmStatic fun test1() = b
|
||||
|
||||
@JvmStatic fun test2() = b
|
||||
|
||||
@JvmStatic fun String.test3() = this + b
|
||||
}
|
||||
|
||||
fun box(): String {
|
||||
if (Test.test1() != "OK") return "fail 1"
|
||||
|
||||
if (Test.test2() != "OK") return "fail 2"
|
||||
|
||||
if (Test.test3() != "JAVAOK") return "fail 3"
|
||||
|
||||
if (Test.test4() != "OK") return "fail 4"
|
||||
|
||||
return "OK"
|
||||
}
|
||||
@@ -0,0 +1,21 @@
|
||||
// FILE: JavaClass.java
|
||||
|
||||
public class JavaClass extends A {
|
||||
public String test() {
|
||||
return "Java";
|
||||
}
|
||||
}
|
||||
|
||||
// FILE: test.kt
|
||||
|
||||
open class A {
|
||||
internal open fun test(): String = "Kotlin"
|
||||
}
|
||||
|
||||
fun box(): String {
|
||||
if (A().test() != "Kotlin") return "fail 1: ${A().test()}"
|
||||
|
||||
if (JavaClass().test() != "Java") return "fail 2: ${JavaClass().test()}"
|
||||
|
||||
return "OK"
|
||||
}
|
||||
@@ -0,0 +1,23 @@
|
||||
// WITH_RUNTIME
|
||||
// FILE: Baz.java
|
||||
|
||||
public class Baz {
|
||||
public static String baz() {
|
||||
return Util.foo() + Util.bar();
|
||||
}
|
||||
}
|
||||
|
||||
// FILE: bar.kt
|
||||
|
||||
@file:JvmName("Util")
|
||||
@file:JvmMultifileClass
|
||||
public fun bar(): String = "K"
|
||||
|
||||
// FILE: foo.kt
|
||||
|
||||
@file:[JvmName("Util") JvmMultifileClass]
|
||||
public fun foo(): String = "O"
|
||||
|
||||
// FILE: test.kt
|
||||
|
||||
fun box(): String = Baz.baz()
|
||||
+28
@@ -0,0 +1,28 @@
|
||||
// WITH_RUNTIME
|
||||
// FILE: Baz.java
|
||||
|
||||
public class Baz {
|
||||
public static String baz() {
|
||||
return Util.foo() + Util.bar();
|
||||
}
|
||||
}
|
||||
|
||||
// FILE: bar.kt
|
||||
|
||||
@file:JvmName("Util")
|
||||
@file:JvmMultifileClass
|
||||
public fun bar(): String = barx()
|
||||
|
||||
public fun foox(): String = "O"
|
||||
|
||||
// FILE: foo.kt
|
||||
|
||||
@file:JvmName("Util")
|
||||
@file:JvmMultifileClass
|
||||
public fun foo(): String = foox()
|
||||
|
||||
public fun barx(): String = "K"
|
||||
|
||||
// FILE: test.kt
|
||||
|
||||
fun box(): String = Baz.baz()
|
||||
@@ -0,0 +1,28 @@
|
||||
// WITH_RUNTIME
|
||||
// FILE: Baz.java
|
||||
|
||||
public class Baz {
|
||||
public static String baz() {
|
||||
return Util.foo() + Util.bar();
|
||||
}
|
||||
}
|
||||
|
||||
// FILE: bar.kt
|
||||
|
||||
@file:JvmName("Util")
|
||||
@file:JvmMultifileClass
|
||||
public fun bar(): String = barx()
|
||||
|
||||
private fun barx(): String = "K"
|
||||
|
||||
// FILE: foo.kt
|
||||
|
||||
@file:JvmName("Util")
|
||||
@file:JvmMultifileClass
|
||||
public fun foo(): String = foox()
|
||||
|
||||
private fun foox(): String = "O"
|
||||
|
||||
// FILE: test.kt
|
||||
|
||||
fun box(): String = Baz.baz()
|
||||
@@ -0,0 +1,33 @@
|
||||
// FILE: FortyTwoExtractor.java
|
||||
|
||||
public class FortyTwoExtractor {
|
||||
private Number fortyTwo = new FortyTwo();
|
||||
|
||||
public int intValue() {
|
||||
return fortyTwo.intValue();
|
||||
}
|
||||
}
|
||||
|
||||
// FILE: FortyTwoExtractor.kt
|
||||
|
||||
class FortyTwo : Number() {
|
||||
override fun toByte() = 42.toByte()
|
||||
|
||||
override fun toShort() = 42.toShort()
|
||||
|
||||
override fun toInt() = 42
|
||||
|
||||
override fun toLong() = 42L
|
||||
|
||||
override fun toFloat() = 42.0f
|
||||
|
||||
override fun toDouble() = 42.0
|
||||
|
||||
override fun toChar() = 42.toChar()
|
||||
}
|
||||
|
||||
fun box(): String {
|
||||
val extractor = FortyTwoExtractor()
|
||||
if (extractor.intValue() != 42) return "FAIL"
|
||||
return "OK"
|
||||
}
|
||||
@@ -0,0 +1,21 @@
|
||||
// FILE: Test.java
|
||||
|
||||
public class Test extends java.util.ArrayList<String> {
|
||||
public final int size() {
|
||||
return 56;
|
||||
}
|
||||
}
|
||||
|
||||
// FILE: test.kt
|
||||
|
||||
class OurTest : Test()
|
||||
|
||||
fun box(): String {
|
||||
val t = OurTest()
|
||||
val x: MutableCollection<String> = t
|
||||
|
||||
if (t.size != 56) return "fail 1: ${t.size}"
|
||||
if (x.size != 56) return "fail 1: ${x.size}"
|
||||
|
||||
return "OK"
|
||||
}
|
||||
@@ -0,0 +1,109 @@
|
||||
// FILE: J.java
|
||||
|
||||
public class J extends A {
|
||||
|
||||
public boolean okField = false;
|
||||
|
||||
public int getValProp() {
|
||||
return 123;
|
||||
}
|
||||
|
||||
public int getVarProp() {
|
||||
return 456;
|
||||
}
|
||||
|
||||
public void setVarProp(int x) {
|
||||
okField = true;
|
||||
}
|
||||
|
||||
public int isProp() {
|
||||
return 789;
|
||||
}
|
||||
|
||||
public void setProp(int x) {
|
||||
okField = true;
|
||||
}
|
||||
}
|
||||
|
||||
// FILE: test.kt
|
||||
|
||||
open class A {
|
||||
open val valProp: Int = -1
|
||||
open var varProp: Int = -1
|
||||
open var isProp: Int = -1
|
||||
}
|
||||
|
||||
class B : J() {
|
||||
override val valProp: Int = super.valProp + 1
|
||||
override var varProp: Int
|
||||
set(value) {
|
||||
super.varProp = value
|
||||
}
|
||||
get() = super.varProp + 1
|
||||
|
||||
override var isProp: Int
|
||||
set(value) {
|
||||
super.isProp = value
|
||||
}
|
||||
get() = super.isProp + 1
|
||||
}
|
||||
|
||||
fun box(): String {
|
||||
val j = J()
|
||||
var a: A = j
|
||||
|
||||
if (j.valProp != 123) return "fail 1"
|
||||
if (a.valProp != 123) return "fail 2"
|
||||
|
||||
j.varProp = -1
|
||||
if (!j.okField) return "fail 3"
|
||||
j.okField = false
|
||||
|
||||
a.varProp = -1
|
||||
if (!j.okField) return "fail 4"
|
||||
j.okField = false
|
||||
|
||||
if (j.varProp != 456) return "fail 5"
|
||||
if (a.varProp != 456) return "fail 6"
|
||||
|
||||
j.isProp = -1
|
||||
if (!j.okField) return "fail 7"
|
||||
j.okField = false
|
||||
|
||||
a.isProp = -1
|
||||
if (!j.okField) return "fail 8"
|
||||
j.okField = false
|
||||
|
||||
if (j.isProp != 789) return "fail 9"
|
||||
if (a.isProp != 789) return "fail 10"
|
||||
|
||||
val b = B()
|
||||
a = b
|
||||
|
||||
if (b.valProp != 124) return "fail 11"
|
||||
if (a.valProp != 124) return "fail 12"
|
||||
|
||||
b.varProp = -1
|
||||
if (!b.okField) return "fail 13"
|
||||
b.okField = false
|
||||
|
||||
a.varProp = -1
|
||||
if (!b.okField) return "fail 14"
|
||||
b.okField = false
|
||||
|
||||
if (b.varProp != 457) return "fail 15"
|
||||
if (a.varProp != 457) return "fail 16"
|
||||
|
||||
b.isProp = -1
|
||||
if (!b.okField) return "fail 17"
|
||||
b.okField = false
|
||||
|
||||
a.isProp = -1
|
||||
if (!b.okField) return "fail 18"
|
||||
b.okField = false
|
||||
|
||||
if (b.isProp != 790) return "fail 19"
|
||||
if (a.isProp != 790) return "fail 20"
|
||||
|
||||
return "OK"
|
||||
}
|
||||
@@ -0,0 +1,27 @@
|
||||
// FILE: J.java
|
||||
|
||||
public class J {
|
||||
public static int f() {
|
||||
return A.Companion.getI1() + A.Companion.getI2() + B.Named.getI1() + B.Named.getI2();
|
||||
}
|
||||
}
|
||||
|
||||
// FILE: test.kt
|
||||
|
||||
class A {
|
||||
companion object {
|
||||
val i1 = 1
|
||||
val i2 = 2
|
||||
}
|
||||
}
|
||||
|
||||
class B {
|
||||
companion object Named {
|
||||
val i1 = 3
|
||||
val i2 = 4
|
||||
}
|
||||
}
|
||||
|
||||
fun box(): String {
|
||||
return if (J.f() == A.i1 + A.i2 + B.i1 + B.i2) "OK" else "Fail: ${J.f()}"
|
||||
}
|
||||
+50
@@ -0,0 +1,50 @@
|
||||
// WITH_RUNTIME
|
||||
// FILE: Test.java
|
||||
|
||||
class Test {
|
||||
String test() {
|
||||
String s;
|
||||
|
||||
s = Klass.NAME;
|
||||
if (!s.equals("Klass")) throw new AssertionError("Fail class: " + s);
|
||||
|
||||
s = Klass.JVM_NAME;
|
||||
if (!s.equals("JvmKlass")) throw new AssertionError("Fail jvm class: " + s);
|
||||
|
||||
s = Trait.NAME;
|
||||
if (!s.equals("Trait")) throw new AssertionError("Fail interface: " + s);
|
||||
|
||||
s = Enoom.NAME;
|
||||
if (!s.equals("Enum")) throw new AssertionError("Fail enum: " + s);
|
||||
|
||||
s = Enoom.JVM_NAME;
|
||||
if (!s.equals("JvmEnum")) throw new AssertionError("Fail jvm enum: " + s);
|
||||
|
||||
return "OK";
|
||||
}
|
||||
}
|
||||
|
||||
// FILE: test.kt
|
||||
|
||||
class Klass {
|
||||
companion object {
|
||||
const val NAME = "Klass"
|
||||
@JvmField val JVM_NAME = "JvmKlass"
|
||||
}
|
||||
}
|
||||
|
||||
interface Trait {
|
||||
companion object {
|
||||
const val NAME = "Trait"
|
||||
}
|
||||
}
|
||||
|
||||
enum class Enoom {
|
||||
;
|
||||
companion object {
|
||||
const val NAME = "Enum"
|
||||
@JvmField val JVM_NAME = "JvmEnum"
|
||||
}
|
||||
}
|
||||
|
||||
fun box() = Test().test()
|
||||
@@ -0,0 +1,30 @@
|
||||
// FILE: JavaClass.java
|
||||
|
||||
public class JavaClass {
|
||||
|
||||
private Boolean value;
|
||||
|
||||
public Boolean isValue() {
|
||||
return value;
|
||||
}
|
||||
|
||||
public void setValue(boolean value) {
|
||||
this.value = value;
|
||||
}
|
||||
}
|
||||
|
||||
// FILE: kotlin.kt
|
||||
|
||||
fun box(): String {
|
||||
val javaClass = JavaClass()
|
||||
|
||||
if (javaClass.isValue != null) return "fail 1"
|
||||
|
||||
javaClass.isValue = false
|
||||
if (javaClass.isValue != false) return "fail 2"
|
||||
|
||||
javaClass.isValue = true
|
||||
if (javaClass.isValue != true) return "fail 3"
|
||||
|
||||
return "OK"
|
||||
}
|
||||
@@ -0,0 +1,28 @@
|
||||
// FILE: JavaClass.java
|
||||
|
||||
public class JavaClass {
|
||||
|
||||
private boolean value;
|
||||
|
||||
public boolean isValue() {
|
||||
return value;
|
||||
}
|
||||
|
||||
public void setValue(Boolean value) {
|
||||
this.value = value;
|
||||
}
|
||||
}
|
||||
|
||||
// FILE: kotlin.kt
|
||||
|
||||
fun box(): String {
|
||||
val javaClass = JavaClass()
|
||||
|
||||
if (javaClass.isValue != false) return "fail 1"
|
||||
|
||||
javaClass.isValue = true
|
||||
|
||||
if (javaClass.isValue != true) return "fail 2"
|
||||
|
||||
return "OK"
|
||||
}
|
||||
@@ -0,0 +1,19 @@
|
||||
// FILE: JavaClass.java
|
||||
|
||||
public class JavaClass {
|
||||
|
||||
protected String FIELD = "OK";
|
||||
|
||||
}
|
||||
|
||||
// FILE: Kotlin.kt
|
||||
|
||||
package test
|
||||
|
||||
import JavaClass
|
||||
|
||||
class B : JavaClass() {
|
||||
inline fun bar() = FIELD
|
||||
}
|
||||
|
||||
fun box() = B().bar()
|
||||
@@ -0,0 +1,37 @@
|
||||
// WITH_RUNTIME
|
||||
// FILE: JavaBaseClass.java
|
||||
|
||||
public class JavaBaseClass {
|
||||
|
||||
private String field = "fail";
|
||||
|
||||
protected String getFoo() {
|
||||
return field;
|
||||
}
|
||||
|
||||
protected void setFoo(String foo) {
|
||||
field = foo;
|
||||
}
|
||||
}
|
||||
|
||||
// FILE: kotlin.kt
|
||||
|
||||
package z
|
||||
|
||||
import JavaBaseClass
|
||||
|
||||
object KotlinExtender : JavaBaseClass() {
|
||||
@JvmStatic fun test(): String {
|
||||
return runSlowly {
|
||||
foo = "OK"
|
||||
foo
|
||||
}
|
||||
}
|
||||
}
|
||||
fun runSlowly(f: () -> String): String {
|
||||
return f()
|
||||
}
|
||||
|
||||
fun box(): String {
|
||||
return KotlinExtender.test()
|
||||
}
|
||||
@@ -0,0 +1,45 @@
|
||||
// WITH_RUNTIME
|
||||
// FILE: JavaBaseClass.java
|
||||
|
||||
public class JavaBaseClass {
|
||||
|
||||
private String field = "fail";
|
||||
|
||||
protected String getFoo() {
|
||||
return field;
|
||||
}
|
||||
|
||||
protected void setFoo(String foo) {
|
||||
field = foo;
|
||||
}
|
||||
}
|
||||
|
||||
// FILE: kotlin.kt
|
||||
|
||||
package z
|
||||
|
||||
import JavaBaseClass
|
||||
|
||||
class A {
|
||||
@JvmField var foo = "fail"
|
||||
|
||||
companion object : JavaBaseClass() {
|
||||
@JvmStatic fun test(): String {
|
||||
return runSlowly {
|
||||
foo = "OK"
|
||||
foo
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
fun runSlowly(f: () -> String): String {
|
||||
return f()
|
||||
}
|
||||
|
||||
fun box(): String {
|
||||
val a = A()
|
||||
a.foo = "Kotlin"
|
||||
if (a.foo != "Kotlin") return "fail"
|
||||
|
||||
return A.test()
|
||||
}
|
||||
@@ -0,0 +1,15 @@
|
||||
// FILE: Test.java
|
||||
|
||||
public abstract class Test<F> {
|
||||
protected final F value = null;
|
||||
}
|
||||
|
||||
// FILE: test.kt
|
||||
|
||||
class A : Test<String>() {
|
||||
fun foo(): String? = value
|
||||
}
|
||||
|
||||
fun box(): String {
|
||||
return if (A().foo() == null) "OK" else "Fail"
|
||||
}
|
||||
+29
@@ -0,0 +1,29 @@
|
||||
// WITH_REFLECT
|
||||
// FILE: J.java
|
||||
|
||||
@Anno("J")
|
||||
public class J {
|
||||
@Anno("foo")
|
||||
public static int foo = 42;
|
||||
|
||||
@Anno("bar")
|
||||
public static void bar() {}
|
||||
|
||||
@Anno("constructor")
|
||||
public J() {}
|
||||
}
|
||||
|
||||
// FILE: K.kt
|
||||
|
||||
import kotlin.test.assertEquals
|
||||
|
||||
annotation class Anno(val value: String)
|
||||
|
||||
fun box(): String {
|
||||
assertEquals("[@Anno(value=J)]", J::class.annotations.toString())
|
||||
assertEquals("[@Anno(value=foo)]", J::foo.annotations.toString())
|
||||
assertEquals("[@Anno(value=bar)]", J::bar.annotations.toString())
|
||||
assertEquals("[@Anno(value=constructor)]", ::J.annotations.toString())
|
||||
|
||||
return "OK"
|
||||
}
|
||||
@@ -0,0 +1,32 @@
|
||||
// WITH_REFLECT
|
||||
// FILE: J.java
|
||||
|
||||
public class J {
|
||||
private final int param;
|
||||
|
||||
public J(int param) {
|
||||
this.param = param;
|
||||
}
|
||||
|
||||
public String foo(int[] arr, Object[] arr2, Integer y) {
|
||||
return "" + param + arr[0] + arr2[0] + y;
|
||||
}
|
||||
}
|
||||
|
||||
// FILE: K.kt
|
||||
|
||||
import kotlin.reflect.jvm.*
|
||||
import kotlin.test.assertEquals
|
||||
|
||||
fun box(): String {
|
||||
val f = J::foo
|
||||
assertEquals(
|
||||
listOf(J::class.java, IntArray::class.java, Array<Any>::class.java, Integer::class.java),
|
||||
f.parameters.map { it.type.javaType }
|
||||
)
|
||||
assertEquals(String::class.java, f.returnType.javaType)
|
||||
|
||||
assertEquals("01A2", f.call(J(0), intArrayOf(1), arrayOf("A"), 2))
|
||||
|
||||
return "OK"
|
||||
}
|
||||
@@ -0,0 +1,37 @@
|
||||
// WITH_REFLECT
|
||||
// FILE: J.java
|
||||
|
||||
public class J {
|
||||
private final String result;
|
||||
|
||||
private J(String result) {
|
||||
this.result = result;
|
||||
}
|
||||
|
||||
private String getResult() {
|
||||
return result;
|
||||
}
|
||||
}
|
||||
|
||||
// FILE: K.kt
|
||||
|
||||
import kotlin.reflect.*
|
||||
import kotlin.reflect.jvm.*
|
||||
import kotlin.test.*
|
||||
|
||||
fun box(): String {
|
||||
val c = J::class.constructors.single()
|
||||
assertFalse(c.isAccessible)
|
||||
assertFailsWith(IllegalCallableAccessException::class) { c.call("") }
|
||||
|
||||
c.isAccessible = true
|
||||
assertTrue(c.isAccessible)
|
||||
val j = c.call("OK")
|
||||
|
||||
val m = J::class.members.single { it.name == "getResult" }
|
||||
assertFalse(m.isAccessible)
|
||||
assertFailsWith(IllegalCallableAccessException::class) { m.call(j)!! }
|
||||
|
||||
m.isAccessible = true
|
||||
return m.call(j) as String
|
||||
}
|
||||
@@ -0,0 +1,23 @@
|
||||
// WITH_REFLECT
|
||||
// FILE: J.java
|
||||
|
||||
public class J {
|
||||
public static String foo(int x, int[] arr, Object[] arr2) {
|
||||
return "" + x + arr[0] + arr2[0];
|
||||
}
|
||||
}
|
||||
|
||||
// FILE: K.kt
|
||||
|
||||
import kotlin.reflect.jvm.*
|
||||
import kotlin.test.assertEquals
|
||||
|
||||
fun box(): String {
|
||||
val f = J::foo
|
||||
assertEquals(listOf(Integer.TYPE, IntArray::class.java, Array<Any>::class.java), f.parameters.map { it.type.javaType })
|
||||
assertEquals(String::class.java, f.returnType.javaType)
|
||||
|
||||
assertEquals("01A", f.call(0, intArrayOf(1), arrayOf("A")))
|
||||
|
||||
return "OK"
|
||||
}
|
||||
@@ -0,0 +1,23 @@
|
||||
// WITH_REFLECT
|
||||
// FILE: J.java
|
||||
|
||||
public class J {
|
||||
public class Inner {}
|
||||
|
||||
public static class Nested {}
|
||||
|
||||
private static class PrivateNested {}
|
||||
|
||||
// This anonymous class should not appear in 'nestedClasses'
|
||||
private final Object o = new Object() {};
|
||||
}
|
||||
|
||||
// FILE: K.kt
|
||||
|
||||
import kotlin.test.assertEquals
|
||||
|
||||
fun box(): String {
|
||||
assertEquals(listOf("Inner", "Nested", "PrivateNested"), J::class.nestedClasses.map { it.simpleName!! }.sorted())
|
||||
|
||||
return "OK"
|
||||
}
|
||||
+77
@@ -0,0 +1,77 @@
|
||||
// WITH_REFLECT
|
||||
// FILE: J.java
|
||||
|
||||
public class J {
|
||||
public void publicMemberJ() {}
|
||||
private void privateMemberJ() {}
|
||||
public static void publicStaticJ() {}
|
||||
private static void privateStaticJ() {}
|
||||
}
|
||||
|
||||
// FILE: K.kt
|
||||
|
||||
import kotlin.reflect.*
|
||||
import kotlin.test.assertEquals
|
||||
|
||||
open class K : J() {
|
||||
public fun publicMemberK() {}
|
||||
private fun privateMemberK() {}
|
||||
public fun Any.publicMemberExtensionK() {}
|
||||
private fun Any.privateMemberExtensionK() {}
|
||||
}
|
||||
|
||||
class L : K()
|
||||
|
||||
fun Collection<KFunction<*>>.names(): Set<String> =
|
||||
this.map { it.name }.toSet()
|
||||
|
||||
fun check(c: Collection<KFunction<*>>, names: Set<String>) {
|
||||
assertEquals(names, c.names())
|
||||
}
|
||||
|
||||
fun box(): String {
|
||||
val any = setOf("equals", "hashCode", "toString")
|
||||
|
||||
val j = J::class
|
||||
|
||||
check(j.staticFunctions,
|
||||
setOf("publicStaticJ", "privateStaticJ"))
|
||||
check(j.declaredFunctions,
|
||||
setOf("publicMemberJ", "privateMemberJ", "publicStaticJ", "privateStaticJ"))
|
||||
check(j.declaredMemberFunctions,
|
||||
setOf("publicMemberJ", "privateMemberJ"))
|
||||
check(j.declaredMemberExtensionFunctions,
|
||||
emptySet())
|
||||
|
||||
check(j.functions, any + j.declaredFunctions.names())
|
||||
check(j.memberFunctions, any + j.declaredMemberFunctions.names())
|
||||
check(j.memberExtensionFunctions, emptySet())
|
||||
|
||||
val k = K::class
|
||||
|
||||
check(k.staticFunctions,
|
||||
emptySet())
|
||||
check(k.declaredFunctions,
|
||||
setOf("publicMemberK", "privateMemberK", "publicMemberExtensionK", "privateMemberExtensionK"))
|
||||
check(k.declaredMemberFunctions,
|
||||
setOf("publicMemberK", "privateMemberK"))
|
||||
check(k.declaredMemberExtensionFunctions,
|
||||
setOf("publicMemberExtensionK", "privateMemberExtensionK"))
|
||||
|
||||
check(k.memberFunctions, any + setOf("publicMemberJ") + k.declaredMemberFunctions.names())
|
||||
check(k.memberExtensionFunctions, k.declaredMemberExtensionFunctions.names())
|
||||
check(k.functions, any + (k.memberFunctions + k.memberExtensionFunctions).names())
|
||||
|
||||
|
||||
val l = L::class
|
||||
|
||||
check(l.staticFunctions, emptySet())
|
||||
check(l.declaredFunctions, emptySet())
|
||||
check(l.declaredMemberFunctions, emptySet())
|
||||
check(l.declaredMemberExtensionFunctions, emptySet())
|
||||
check(l.memberFunctions, any + setOf("publicMemberJ", "publicMemberK"))
|
||||
check(l.memberExtensionFunctions, setOf("publicMemberExtensionK"))
|
||||
check(l.functions, any + (l.memberFunctions + l.memberExtensionFunctions).names())
|
||||
|
||||
return "OK"
|
||||
}
|
||||
+29
@@ -0,0 +1,29 @@
|
||||
// WITH_REFLECT
|
||||
// FILE: J.java
|
||||
|
||||
import kotlin.jvm.functions.Function2;
|
||||
import kotlin.reflect.KFunction;
|
||||
|
||||
public class J {
|
||||
public static String go() {
|
||||
KFunction<String> fun = K.Companion.getRef();
|
||||
Object result = ((Function2) fun).invoke(new K(), "KO");
|
||||
return (String) result;
|
||||
}
|
||||
}
|
||||
|
||||
// FILE: K.kt
|
||||
|
||||
class K {
|
||||
fun reverse(s: String): String {
|
||||
return s.reversed()
|
||||
}
|
||||
|
||||
companion object {
|
||||
fun getRef() = K::reverse
|
||||
}
|
||||
}
|
||||
|
||||
fun box(): String {
|
||||
return J.go()
|
||||
}
|
||||
@@ -0,0 +1,28 @@
|
||||
// WITH_REFLECT
|
||||
// FILE: J.java
|
||||
|
||||
public class J {
|
||||
public J() {
|
||||
}
|
||||
|
||||
public void member(String s) {
|
||||
}
|
||||
|
||||
public static void staticMethod(int x) {
|
||||
}
|
||||
}
|
||||
|
||||
// FILE: K.kt
|
||||
|
||||
import kotlin.reflect.*
|
||||
import kotlin.test.assertEquals
|
||||
|
||||
fun box(): String {
|
||||
assertEquals(listOf("equals", "hashCode", "member", "staticMethod", "toString"), J::class.members.map { it.name }.sorted())
|
||||
assertEquals(listOf("equals", "hashCode", "member", "staticMethod", "toString"), J::class.functions.map { it.name }.sorted())
|
||||
assertEquals(listOf("member", "staticMethod"), J::class.declaredFunctions.map { it.name }.sorted())
|
||||
|
||||
assertEquals(1, J::class.constructors.size)
|
||||
|
||||
return "OK"
|
||||
}
|
||||
@@ -0,0 +1,48 @@
|
||||
// WITH_REFLECT
|
||||
// FILE: J.java
|
||||
|
||||
import java.util.List;
|
||||
|
||||
public class J {
|
||||
void simple() {}
|
||||
|
||||
void objectTypes(
|
||||
Object o, String s, Object[] oo, String[] ss
|
||||
) {}
|
||||
|
||||
void primitives(
|
||||
boolean z, char c, byte b, short s, int i, float f, long j, double d
|
||||
) {}
|
||||
|
||||
void primitiveArrays(
|
||||
boolean[] z, char[] c, byte[] b, short[] s, int[] i, float[] f, long[] j, double[] d
|
||||
) {}
|
||||
|
||||
void multiDimensionalArrays(
|
||||
int[][][] i, Cloneable[][][][] c
|
||||
) {}
|
||||
|
||||
void wildcards(
|
||||
List<? extends Number> l, List<? super Cloneable> m
|
||||
) {}
|
||||
}
|
||||
|
||||
// FILE: K.kt
|
||||
|
||||
import kotlin.reflect.KFunction
|
||||
|
||||
// Initiate descriptor computation in reflection to ensure that nothing fails
|
||||
fun test(f: KFunction<*>) {
|
||||
f.parameters
|
||||
}
|
||||
|
||||
fun box(): String {
|
||||
test(J::simple)
|
||||
test(J::objectTypes)
|
||||
test(J::primitives)
|
||||
test(J::primitiveArrays)
|
||||
test(J::multiDimensionalArrays)
|
||||
test(J::wildcards)
|
||||
|
||||
return "OK"
|
||||
}
|
||||
@@ -0,0 +1,23 @@
|
||||
// WITH_RUNTIME
|
||||
// FILE: Test.java
|
||||
|
||||
class O {}
|
||||
class K {}
|
||||
|
||||
@Ann(args={O.class, K.class})
|
||||
class Test {
|
||||
}
|
||||
|
||||
// FILE: array.kt
|
||||
|
||||
import kotlin.reflect.KClass
|
||||
|
||||
@Retention(AnnotationRetention.RUNTIME)
|
||||
annotation class Ann(val args: Array<KClass<*>>)
|
||||
|
||||
fun box(): String {
|
||||
val args = Test::class.java.getAnnotation(Ann::class.java).args
|
||||
val argName1 = args[0].java.simpleName ?: "fail 1"
|
||||
val argName2 = args[1].java.simpleName ?: "fail 2"
|
||||
return argName1 + argName2
|
||||
}
|
||||
@@ -0,0 +1,20 @@
|
||||
// WITH_RUNTIME
|
||||
// FILE: Test.java
|
||||
|
||||
class OK {}
|
||||
|
||||
@Ann(arg=OK.class)
|
||||
class Test {
|
||||
}
|
||||
|
||||
// FILE: basic.kt
|
||||
|
||||
import kotlin.reflect.KClass
|
||||
|
||||
@Retention(AnnotationRetention.RUNTIME)
|
||||
annotation class Ann(val arg: KClass<*>)
|
||||
|
||||
fun box(): String {
|
||||
val argName = Test::class.java.getAnnotation(Ann::class.java).arg.java.simpleName ?: "fail 1"
|
||||
return argName
|
||||
}
|
||||
@@ -0,0 +1,23 @@
|
||||
// WITH_RUNTIME
|
||||
// FILE: Test.java
|
||||
|
||||
class O {}
|
||||
class K {}
|
||||
|
||||
@Ann(args={O.class, K.class})
|
||||
class Test {
|
||||
}
|
||||
|
||||
// FILE: vararg.kt
|
||||
|
||||
import kotlin.reflect.KClass
|
||||
|
||||
@Retention(AnnotationRetention.RUNTIME)
|
||||
annotation class Ann(vararg val args: KClass<*>)
|
||||
|
||||
fun box(): String {
|
||||
val args = Test::class.java.getAnnotation(Ann::class.java).args
|
||||
val argName1 = args[0].java.simpleName ?: "fail 1"
|
||||
val argName2 = args[1].java.simpleName ?: "fail 2"
|
||||
return argName1 + argName2
|
||||
}
|
||||
+19
@@ -0,0 +1,19 @@
|
||||
// WITH_REFLECT
|
||||
// FILE: J.java
|
||||
|
||||
public class J {
|
||||
void foo(String s, int i) {}
|
||||
|
||||
static void bar(J j) {}
|
||||
}
|
||||
|
||||
// FILE: K.kt
|
||||
|
||||
import kotlin.test.assertEquals
|
||||
|
||||
fun box(): String {
|
||||
assertEquals(listOf(null, null, null), J::foo.parameters.map { it.name })
|
||||
assertEquals(listOf(null), J::bar.parameters.map { it.name })
|
||||
|
||||
return "OK"
|
||||
}
|
||||
+67
@@ -0,0 +1,67 @@
|
||||
// WITH_REFLECT
|
||||
// FILE: J.java
|
||||
|
||||
public class J {
|
||||
public String publicMemberJ;
|
||||
private String privateMemberJ;
|
||||
public static String publicStaticJ;
|
||||
private static String privateStaticJ;
|
||||
}
|
||||
|
||||
// FILE: K.kt
|
||||
|
||||
import kotlin.reflect.*
|
||||
import kotlin.test.assertEquals
|
||||
|
||||
open class K : J() {
|
||||
public val publicMemberK: String = ""
|
||||
private val privateMemberK: String = ""
|
||||
public val Any.publicMemberExtensionK: String get() = ""
|
||||
private val Any.privateMemberExtensionK: String get() = ""
|
||||
}
|
||||
|
||||
class L : K()
|
||||
|
||||
fun Collection<KProperty<*>>.names(): Set<String> =
|
||||
this.map { it.name }.toSet()
|
||||
|
||||
fun check(c: Collection<KProperty<*>>, names: Set<String>) {
|
||||
assertEquals(names, c.names())
|
||||
}
|
||||
|
||||
fun box(): String {
|
||||
val j = J::class
|
||||
|
||||
check(j.staticProperties,
|
||||
setOf("publicStaticJ", "privateStaticJ"))
|
||||
check(j.declaredMemberProperties,
|
||||
setOf("publicMemberJ", "privateMemberJ"))
|
||||
check(j.declaredMemberExtensionProperties,
|
||||
emptySet())
|
||||
|
||||
check(j.memberProperties, j.declaredMemberProperties.names())
|
||||
check(j.memberExtensionProperties, emptySet())
|
||||
|
||||
val k = K::class
|
||||
|
||||
check(k.staticProperties,
|
||||
emptySet())
|
||||
check(k.declaredMemberProperties,
|
||||
setOf("publicMemberK", "privateMemberK"))
|
||||
check(k.declaredMemberExtensionProperties,
|
||||
setOf("publicMemberExtensionK", "privateMemberExtensionK"))
|
||||
|
||||
check(k.memberProperties, setOf("publicMemberJ") + k.declaredMemberProperties.names())
|
||||
check(k.memberExtensionProperties, k.declaredMemberExtensionProperties.names())
|
||||
|
||||
|
||||
val l = L::class
|
||||
|
||||
check(l.staticProperties, emptySet())
|
||||
check(l.declaredMemberProperties, emptySet())
|
||||
check(l.declaredMemberExtensionProperties, emptySet())
|
||||
check(l.memberProperties, setOf("publicMemberJ", "publicMemberK"))
|
||||
check(l.memberExtensionProperties, setOf("publicMemberExtensionK"))
|
||||
|
||||
return "OK"
|
||||
}
|
||||
+17
@@ -0,0 +1,17 @@
|
||||
// FILE: J.java
|
||||
|
||||
public class J {
|
||||
public String result = null;
|
||||
}
|
||||
|
||||
// FILE: K.kt
|
||||
|
||||
class K : J()
|
||||
|
||||
fun box(): String {
|
||||
val k = K()
|
||||
val p = K::result
|
||||
if (p.get(k) != null) return "Fail"
|
||||
p.set(k, "OK")
|
||||
return p.get(k)
|
||||
}
|
||||
@@ -0,0 +1,23 @@
|
||||
// WITH_REFLECT
|
||||
// FILE: J.java
|
||||
|
||||
public class J {
|
||||
static String x;
|
||||
}
|
||||
|
||||
// FILE: K.kt
|
||||
|
||||
import kotlin.test.assertEquals
|
||||
|
||||
fun box(): String {
|
||||
val f = J::x
|
||||
assertEquals("x", f.name)
|
||||
|
||||
assertEquals(f, J::class.members.single { it.name == "x" })
|
||||
|
||||
f.set("OK")
|
||||
assertEquals("OK", J.x)
|
||||
assertEquals("OK", f.getter())
|
||||
|
||||
return f.get()
|
||||
}
|
||||
+49
@@ -0,0 +1,49 @@
|
||||
// WITH_REFLECT
|
||||
// FILE: J.java
|
||||
|
||||
public class J extends K {
|
||||
}
|
||||
|
||||
// FILE: K.kt
|
||||
|
||||
import kotlin.reflect.*
|
||||
import kotlin.reflect.jvm.*
|
||||
|
||||
public open class K {
|
||||
var prop: String = ":("
|
||||
|
||||
val Int.ext: Int get() = this
|
||||
}
|
||||
|
||||
fun box(): String {
|
||||
val j = J()
|
||||
|
||||
val prop = J::prop
|
||||
if (prop !is KMutableProperty1<*, *>) return "Fail instanceof"
|
||||
if (prop.name != "prop") return "Fail name: ${prop.name}"
|
||||
if (prop.get(j) != ":(") return "Fail get before: ${prop.get(j)}"
|
||||
prop.set(j, ":)")
|
||||
if (prop.get(j) != ":)") return "Fail get after: ${prop.get(j)}"
|
||||
|
||||
|
||||
if (prop == K::prop) return "Fail J::prop == K::prop (these are different properties)"
|
||||
|
||||
|
||||
val klass = J::class.java.kotlin
|
||||
if (klass.declaredMemberProperties.isNotEmpty()) return "Fail: declaredMemberProperties should be empty"
|
||||
if (klass.declaredMemberExtensionProperties.isNotEmpty()) return "Fail: declaredMemberExtensionProperties should be empty"
|
||||
|
||||
val prop2 = klass.memberProperties.firstOrNull { it.name == "prop" } ?: "Fail: no 'prop' property in memberProperties"
|
||||
if (prop != prop2) return "Fail: property references from :: and from properties differ: $prop != $prop2"
|
||||
if (prop2 !is KMutableProperty1<*, *>) return "Fail instanceof 2"
|
||||
(prop2 as KMutableProperty1<J, String>).set(j, "::)")
|
||||
if (prop.get(j) != "::)") return "Fail get after 2: ${prop.get(j)}"
|
||||
|
||||
|
||||
val ext = klass.memberExtensionProperties.firstOrNull { it.name == "ext" } ?: "Fail: no 'ext' property in memberExtensionProperties"
|
||||
ext as KProperty2<J, Int, Int>
|
||||
val fortyTwo = ext.get(j, 42)
|
||||
if (fortyTwo != 42) return "Fail ext get: $fortyTwo"
|
||||
|
||||
return "OK"
|
||||
}
|
||||
+19
@@ -0,0 +1,19 @@
|
||||
// WITH_REFLECT
|
||||
// FILE: J.java
|
||||
|
||||
public class J {
|
||||
private String result = "Fail";
|
||||
}
|
||||
|
||||
// FILE: K.kt
|
||||
|
||||
import kotlin.reflect.*
|
||||
import kotlin.reflect.jvm.*
|
||||
|
||||
fun box(): String {
|
||||
val a = J()
|
||||
val p = J::class.members.single { it.name == "result" } as KMutableProperty1<J, String>
|
||||
p.isAccessible = true
|
||||
p.set(a, "OK")
|
||||
return p.get(a)
|
||||
}
|
||||
+19
@@ -0,0 +1,19 @@
|
||||
// WITH_REFLECT
|
||||
// FILE: J.java
|
||||
|
||||
public class J {
|
||||
private static String result = "Fail";
|
||||
}
|
||||
|
||||
// FILE: K.kt
|
||||
|
||||
import kotlin.reflect.*
|
||||
import kotlin.reflect.jvm.*
|
||||
|
||||
fun box(): String {
|
||||
val a = J()
|
||||
val p = J::class.members.single { it.name == "result" } as KMutableProperty0<String>
|
||||
p.isAccessible = true
|
||||
p.set("OK")
|
||||
return p.get()
|
||||
}
|
||||
Vendored
+32
@@ -0,0 +1,32 @@
|
||||
// WITH_REFLECT
|
||||
// FILE: J.java
|
||||
|
||||
public class J {
|
||||
public String foo = "";
|
||||
}
|
||||
|
||||
// FILE: K.kt
|
||||
|
||||
import kotlin.test.*
|
||||
|
||||
class K : J() {
|
||||
fun getFoo(): String = "K"
|
||||
}
|
||||
|
||||
fun box(): String {
|
||||
val j = J()
|
||||
val x = J::foo
|
||||
x.set(j, "J")
|
||||
assertEquals("J", x.get(j))
|
||||
|
||||
val k = K()
|
||||
val y = K::foo
|
||||
y.set(k, "K")
|
||||
assertEquals("K", y.get(k))
|
||||
assertEquals("K", x.get(k))
|
||||
|
||||
val z = K::getFoo
|
||||
assertEquals("K", z.invoke(k))
|
||||
|
||||
return "OK"
|
||||
}
|
||||
+39
@@ -0,0 +1,39 @@
|
||||
// WITH_REFLECT
|
||||
// FILE: J.java
|
||||
|
||||
public class J implements K {
|
||||
private String foo;
|
||||
|
||||
@Override
|
||||
public String getFoo() {
|
||||
return foo;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void setFoo(String s) {
|
||||
foo = s;
|
||||
}
|
||||
}
|
||||
|
||||
// FILE: K.kt
|
||||
|
||||
import kotlin.test.assertEquals
|
||||
import kotlin.reflect.KParameter
|
||||
|
||||
interface K {
|
||||
var foo: String
|
||||
}
|
||||
|
||||
fun box(): String {
|
||||
val p = J::foo
|
||||
assertEquals("foo", p.name)
|
||||
|
||||
if (p.parameters.size != 1) return "Should have only 1 parameter"
|
||||
if (p.parameters.single().kind != KParameter.Kind.INSTANCE) return "Should have an instance parameter"
|
||||
|
||||
if (J::class.members.none { it == p }) return "No foo in members"
|
||||
|
||||
val j = J()
|
||||
p.setter.call(j, "OK")
|
||||
return p.getter.call(j)
|
||||
}
|
||||
Vendored
+15
@@ -0,0 +1,15 @@
|
||||
// FILE: J.java
|
||||
|
||||
public class J extends K {
|
||||
public final int value = 42;
|
||||
}
|
||||
|
||||
// FILE: K.kt
|
||||
|
||||
open class K
|
||||
|
||||
fun box(): String {
|
||||
val f = J::value
|
||||
val a = J()
|
||||
return if (f.get(a) == 42) "OK" else "Fail: ${f.get(a)}"
|
||||
}
|
||||
+22
@@ -0,0 +1,22 @@
|
||||
// WITH_REFLECT
|
||||
// FILE: J.java
|
||||
|
||||
public class J {
|
||||
public static String foo() {
|
||||
return "";
|
||||
}
|
||||
}
|
||||
|
||||
// FILE: K.kt
|
||||
|
||||
import kotlin.test.assertNotEquals
|
||||
|
||||
fun nonNullString(): String = ""
|
||||
fun nullableString(): String? = ""
|
||||
|
||||
fun box(): String {
|
||||
assertNotEquals(J::foo.returnType, ::nonNullString.returnType)
|
||||
assertNotEquals(J::foo.returnType, ::nullableString.returnType)
|
||||
|
||||
return "OK"
|
||||
}
|
||||
@@ -0,0 +1,25 @@
|
||||
// WITH_REFLECT
|
||||
// FILE: J.java
|
||||
|
||||
import java.util.List;
|
||||
|
||||
public class J {
|
||||
public static String string() {
|
||||
return "";
|
||||
}
|
||||
|
||||
public static List<Object> list() {
|
||||
return null;
|
||||
}
|
||||
}
|
||||
|
||||
// FILE: K.kt
|
||||
|
||||
import kotlin.test.assertEquals
|
||||
|
||||
fun box(): String {
|
||||
assertEquals("kotlin.String!", J::string.returnType.toString())
|
||||
assertEquals("kotlin.collections.(Mutable)List<kotlin.Any!>!", J::list.returnType.toString())
|
||||
|
||||
return "OK"
|
||||
}
|
||||
@@ -0,0 +1,32 @@
|
||||
// FILE: JavaClass.java
|
||||
|
||||
public class JavaClass {
|
||||
|
||||
public static String nullString() {
|
||||
return null;
|
||||
}
|
||||
|
||||
public static String nonnullString() {
|
||||
return "OK";
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
// FILE: kotlin.kt
|
||||
|
||||
fun box(): String {
|
||||
val nullStr = JavaClass.nullString()
|
||||
val nonnullStr = JavaClass.nonnullString()
|
||||
|
||||
if (nullStr.foo() != null) return "fail 1"
|
||||
if (nonnullStr.foo() != nonnullStr) return "fail 2"
|
||||
|
||||
if (nullStr.fooN() != null) return "fail 3"
|
||||
if (nonnullStr.fooN() != nonnullStr) return "fail 4"
|
||||
|
||||
return "OK"
|
||||
}
|
||||
|
||||
inline fun <reified T> T.foo(): T = this as T
|
||||
|
||||
inline fun <reified T> T.fooN(): T? = this as T?
|
||||
@@ -0,0 +1,32 @@
|
||||
// FILE: JavaClass.java
|
||||
|
||||
public class JavaClass {
|
||||
|
||||
public static String nullString() {
|
||||
return null;
|
||||
}
|
||||
|
||||
public static String nonnullString() {
|
||||
return "OK";
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
// FILE: kotlin.kt
|
||||
|
||||
fun box(): String {
|
||||
val nullStr = JavaClass.nullString()
|
||||
val nonnullStr = JavaClass.nonnullString()
|
||||
|
||||
if (nullStr.foo() != true) return "fail 1"
|
||||
if (nonnullStr.foo() != true) return "fail 2"
|
||||
|
||||
if (nullStr.fooN() != true) return "fail 3"
|
||||
if (nonnullStr.fooN() != true) return "fail 4"
|
||||
|
||||
return "OK"
|
||||
}
|
||||
|
||||
inline fun <reified T> T.foo(): Boolean = this is T
|
||||
|
||||
inline fun <reified T> T.fooN(): Boolean = this is T?
|
||||
@@ -0,0 +1,37 @@
|
||||
// TARGET_BACKEND: JVM
|
||||
// FILE: WithGenerics.java
|
||||
|
||||
class WithGenerics {
|
||||
public static String foo1() {
|
||||
A<Double> x = new A<Double>("OK");
|
||||
return x.toString();
|
||||
}
|
||||
|
||||
public static String foo2() {
|
||||
A<Integer> x = new A<Integer>(123);
|
||||
return x.toString();
|
||||
}
|
||||
}
|
||||
|
||||
// FILE: WithGenerics.kt
|
||||
|
||||
open class A<T> {
|
||||
val prop: String
|
||||
constructor(x: String) {
|
||||
prop = x
|
||||
}
|
||||
constructor(x: T) {
|
||||
prop = x.toString()
|
||||
}
|
||||
|
||||
override fun toString() = prop
|
||||
}
|
||||
|
||||
fun box(): String {
|
||||
val a1 = WithGenerics.foo1()
|
||||
if (a1 != "OK") return "fail1: $a1"
|
||||
val a2 = WithGenerics.foo2()
|
||||
if (a2 != "123") return "fail2: $a2"
|
||||
|
||||
return "OK"
|
||||
}
|
||||
@@ -0,0 +1,41 @@
|
||||
// TARGET_BACKEND: JVM
|
||||
// FILE: WithPrimary.java
|
||||
|
||||
class WithPrimary {
|
||||
public static A test1() {
|
||||
return new A("123", "abc");
|
||||
}
|
||||
public static A test2() {
|
||||
return new A();
|
||||
}
|
||||
public static A test3() {
|
||||
return new A("123", 456);
|
||||
}
|
||||
public static A test4() {
|
||||
return new A(1.0);
|
||||
}
|
||||
}
|
||||
|
||||
// FILE: WithPrimary.kt
|
||||
|
||||
class A(val x: String = "def_x", val y: String = "1") {
|
||||
constructor(x: String, y: Int): this(x, y.toString()) {}
|
||||
constructor(x: Double): this(x.toString(), "def_y") {}
|
||||
override fun toString() = "$x#$y"
|
||||
}
|
||||
|
||||
fun box(): String {
|
||||
val test1 = WithPrimary.test1().toString()
|
||||
if (test1 != "123#abc") return "fail1: $test1"
|
||||
|
||||
val test2 = WithPrimary.test2().toString()
|
||||
if (test2 != "def_x#1") return "fail2: $test2"
|
||||
|
||||
val test3 = WithPrimary.test3().toString()
|
||||
if (test3 != "123#456") return "fail3: $test3"
|
||||
|
||||
val test4 = WithPrimary.test4().toString()
|
||||
if (test4 != "1.0#def_y") return "fail4: $test4"
|
||||
|
||||
return "OK"
|
||||
}
|
||||
@@ -0,0 +1,34 @@
|
||||
// TARGET_BACKEND: JVM
|
||||
// FILE: WithVarargs.java
|
||||
|
||||
public class WithVarargs {
|
||||
public static String foo() {
|
||||
return new A("1", "2", "3").getProp();
|
||||
}
|
||||
}
|
||||
|
||||
// FILE: withVarargs.kt
|
||||
|
||||
fun join(x: Array<out String>): String {
|
||||
var result = ""
|
||||
for (i in x) {
|
||||
result += i
|
||||
result += "#"
|
||||
}
|
||||
|
||||
return result
|
||||
}
|
||||
|
||||
class A {
|
||||
val prop: String
|
||||
constructor(vararg x: String) {
|
||||
prop = join(x)
|
||||
}
|
||||
}
|
||||
|
||||
fun box(): String {
|
||||
val a1 = WithVarargs.foo()
|
||||
if (a1 != "1#2#3#") return "fail1: ${a1}"
|
||||
|
||||
return "OK"
|
||||
}
|
||||
@@ -0,0 +1,41 @@
|
||||
// TARGET_BACKEND: JVM
|
||||
// FILE: WithoutPrimary.java
|
||||
|
||||
class WithoutPrimary {
|
||||
public static A test1() {
|
||||
return new A("123", "abc");
|
||||
}
|
||||
public static A test3() {
|
||||
return new A("123", 456);
|
||||
}
|
||||
public static A test4() {
|
||||
return new A(1.0);
|
||||
}
|
||||
}
|
||||
|
||||
// FILE: WithoutPrimary.kt
|
||||
|
||||
class A {
|
||||
val x: String
|
||||
val y: String
|
||||
constructor(x: String, y: String) {
|
||||
this.x = x
|
||||
this.y = y
|
||||
}
|
||||
constructor(x: String = "def_x", y: Int = 1): this(x, y.toString()) {}
|
||||
constructor(x: Double): this(x.toString(), "def_y") {}
|
||||
override fun toString() = "$x#$y"
|
||||
}
|
||||
|
||||
fun box(): String {
|
||||
val test1 = WithoutPrimary.test1().toString()
|
||||
if (test1 != "123#abc") return "fail1: $test1"
|
||||
|
||||
val test3 = WithoutPrimary.test3().toString()
|
||||
if (test3 != "123#456") return "fail3: $test3"
|
||||
|
||||
val test4 = WithoutPrimary.test4().toString()
|
||||
if (test4 != "1.0#def_y") return "fail4: $test4"
|
||||
|
||||
return "OK"
|
||||
}
|
||||
+25
@@ -0,0 +1,25 @@
|
||||
// FILE: Child.java
|
||||
|
||||
class Child extends Parent {
|
||||
public static int b = 3;
|
||||
public static int c = 4;
|
||||
}
|
||||
|
||||
// FILE: Parent.java
|
||||
|
||||
class Parent {
|
||||
public static int a = 1;
|
||||
public static int b = 2;
|
||||
}
|
||||
|
||||
// FILE: test.kt
|
||||
|
||||
fun box(): String {
|
||||
if (Parent.a != 1) return "expected Parent.a == 1"
|
||||
if (Parent.b != 2) return "expected Parent.b == 2"
|
||||
if (Child.a != 1) return "expected Child.a == 1"
|
||||
if (Child.b != 3) return "expected Child.b == 3"
|
||||
if (Child.c != 4) return "expected Child.c == 4"
|
||||
|
||||
return "OK"
|
||||
}
|
||||
@@ -0,0 +1,33 @@
|
||||
// FILE: Child.java
|
||||
|
||||
class Child extends Parent {
|
||||
public static String bar() {
|
||||
return "Child.bar";
|
||||
}
|
||||
public static String baz() {
|
||||
return "Child.baz";
|
||||
}
|
||||
}
|
||||
|
||||
// FILE: Parent.java
|
||||
|
||||
class Parent {
|
||||
public static String foo() {
|
||||
return "Parent.foo";
|
||||
}
|
||||
public static String baz() {
|
||||
return "Parent.baz";
|
||||
}
|
||||
}
|
||||
|
||||
// FILE: test.kt
|
||||
|
||||
fun box(): String {
|
||||
if (Parent.foo() != "Parent.foo") return "expected: Parent.foo"
|
||||
if (Parent.baz() != "Parent.baz") return "expected: Parent.baz"
|
||||
if (Child.foo() != "Parent.foo") return "expected: Child.foo() != Parent.foo"
|
||||
if (Child.baz() != "Child.baz") return "expected: Child.baz"
|
||||
if (Child.bar() != "Child.bar") return "expected: Child.bar"
|
||||
|
||||
return "OK"
|
||||
}
|
||||
@@ -0,0 +1,30 @@
|
||||
// FILE: Child.java
|
||||
|
||||
class Child extends Parent {
|
||||
public static String a = "2";
|
||||
public static String foo() {
|
||||
return "Child.foo()";
|
||||
}
|
||||
public static String foo(int i) {
|
||||
return "Child.foo(int)";
|
||||
}
|
||||
}
|
||||
|
||||
// FILE: Parent.java
|
||||
|
||||
class Parent {
|
||||
private static int a = 1;
|
||||
private static String foo() {
|
||||
return "Parent.foo";
|
||||
}
|
||||
}
|
||||
|
||||
// FILE: test.kt
|
||||
|
||||
fun box(): String {
|
||||
if (Child.a != "2") return "Fail #1"
|
||||
if (Child.foo() != "Child.foo()") return "Fail #2"
|
||||
if (Child.foo(1) != "Child.foo(int)") return "Fail #3"
|
||||
|
||||
return "OK"
|
||||
}
|
||||
@@ -0,0 +1,27 @@
|
||||
// FILE: Test.java
|
||||
|
||||
public class Test {
|
||||
|
||||
protected String data = "O";
|
||||
|
||||
protected Test() {
|
||||
|
||||
}
|
||||
|
||||
protected static String testStatic() {
|
||||
return "K";
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
// FILE: test.kt
|
||||
|
||||
public inline fun test(): String {
|
||||
val p = object : Test() {}
|
||||
return p.data + Test.testStatic();
|
||||
}
|
||||
|
||||
|
||||
fun box(): String {
|
||||
return test()
|
||||
}
|
||||
Some files were not shown because too many files have changed in this diff Show More
Reference in New Issue
Block a user