mirror of
https://github.com/jlengrand/kotlin.git
synced 2026-05-16 00:21:32 +00:00
Migrate boxWithJava tests to multi-file framework
This commit is contained in:
@@ -1,3 +1,5 @@
|
||||
// FILE: JavaClass.java
|
||||
|
||||
public class JavaClass {
|
||||
|
||||
public static class C extends B {
|
||||
@@ -21,3 +23,25 @@ public class JavaClass {
|
||||
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();
|
||||
}
|
||||
@@ -1,19 +0,0 @@
|
||||
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();
|
||||
}
|
||||
@@ -1,4 +0,0 @@
|
||||
@file:StringHolder("OK")
|
||||
|
||||
fun box(): String =
|
||||
Class.forName("FileFacadeKt").getAnnotation(StringHolder::class.java)?.value ?: "null"
|
||||
@@ -1,3 +1,21 @@
|
||||
// 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
|
||||
|
||||
@@ -1,15 +0,0 @@
|
||||
import java.lang.Runnable;
|
||||
|
||||
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();
|
||||
}
|
||||
}
|
||||
@@ -1,3 +1,13 @@
|
||||
// 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
|
||||
|
||||
@@ -1,7 +0,0 @@
|
||||
import java.lang.Runnable;
|
||||
|
||||
class Test {
|
||||
public static Class<?> apply(Runnable x) {
|
||||
return x.getClass();
|
||||
}
|
||||
}
|
||||
@@ -1,3 +1,14 @@
|
||||
// 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)
|
||||
@@ -1,6 +0,0 @@
|
||||
class O {}
|
||||
class K {}
|
||||
|
||||
@Ann(args={O.class, K.class})
|
||||
class Test {
|
||||
}
|
||||
@@ -1,3 +1,13 @@
|
||||
// FILE: Test.java
|
||||
|
||||
class OK {}
|
||||
|
||||
@Ann(arg=OK.class)
|
||||
class Test {
|
||||
}
|
||||
|
||||
// FILE: basic.kt
|
||||
|
||||
import kotlin.reflect.KClass
|
||||
|
||||
@Retention(AnnotationRetention.RUNTIME)
|
||||
@@ -1,5 +0,0 @@
|
||||
class OK {}
|
||||
|
||||
@Ann(arg=OK.class)
|
||||
class Test {
|
||||
}
|
||||
@@ -1,3 +1,14 @@
|
||||
// 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)
|
||||
@@ -1,6 +0,0 @@
|
||||
class O {}
|
||||
class K {}
|
||||
|
||||
@Ann(args={O.class, K.class})
|
||||
class Test {
|
||||
}
|
||||
@@ -1,3 +1,5 @@
|
||||
// FILE: Test.java
|
||||
|
||||
import java.lang.*;
|
||||
import java.util.*;
|
||||
|
||||
@@ -8,3 +10,19 @@ public class Test {
|
||||
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"
|
||||
}
|
||||
@@ -1,13 +0,0 @@
|
||||
//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"
|
||||
}
|
||||
@@ -1,3 +1,16 @@
|
||||
// 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()
|
||||
@@ -1,8 +0,0 @@
|
||||
public class Test {
|
||||
public static void checkCallFromJava() {
|
||||
try {
|
||||
String x = SubstitutedIterableKt.foo().iterator().next();
|
||||
throw new AssertionError("E should have been thrown");
|
||||
} catch (E e) { }
|
||||
}
|
||||
}
|
||||
@@ -1,3 +1,20 @@
|
||||
// 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!!
|
||||
@@ -1,12 +0,0 @@
|
||||
class Test {
|
||||
interface A {
|
||||
boolean add(String s);
|
||||
}
|
||||
|
||||
static class D extends C {}
|
||||
|
||||
void test() {
|
||||
A a = new D();
|
||||
a.add("lol");
|
||||
}
|
||||
}
|
||||
16
compiler/testData/codegen/boxWithJava/casts/javaTypeIsFunK.kt
vendored
Normal file
16
compiler/testData/codegen/boxWithJava/casts/javaTypeIsFunK.kt
vendored
Normal file
@@ -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<*>"
|
||||
}
|
||||
@@ -1,5 +0,0 @@
|
||||
class JFun implements kotlin.jvm.functions.Function0<String> {
|
||||
public String invoke() {
|
||||
return "OK";
|
||||
}
|
||||
}
|
||||
@@ -1,6 +0,0 @@
|
||||
fun box(): String {
|
||||
val jfun = JFun()
|
||||
val jf = jfun as Any
|
||||
if (jf is Function0<*>) return jfun()
|
||||
else return "Failed: jf is Function0<*>"
|
||||
}
|
||||
@@ -1,3 +1,5 @@
|
||||
// FILE: Box.java
|
||||
|
||||
public class Box<T> {
|
||||
private final T value;
|
||||
|
||||
@@ -12,4 +14,11 @@ public class Box<T> {
|
||||
public T getValue() {
|
||||
return value;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// FILE: test.kt
|
||||
|
||||
fun box(): String {
|
||||
val sub = Box<Long>(-1)
|
||||
return if (sub.value == -1L) "OK" else "fail"
|
||||
}
|
||||
@@ -1,4 +0,0 @@
|
||||
fun box(): String {
|
||||
val sub = Box<Long>(-1)
|
||||
return if (sub.value == -1L) "OK" else "fail"
|
||||
}
|
||||
@@ -1,3 +1,15 @@
|
||||
// FILE: CompanionInitialization.java
|
||||
|
||||
public class CompanionInitialization {
|
||||
|
||||
public static Object getCompanion() {
|
||||
return ConcreteWithStatic.Companion;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
// FILE: CompanionInitialization.kt
|
||||
|
||||
interface IStatic
|
||||
|
||||
open class Static(x: IStatic) {
|
||||
@@ -17,4 +29,4 @@ fun box(): String {
|
||||
if (companion != ConcreteWithStatic) return "fail 2"
|
||||
|
||||
return "OK"
|
||||
}
|
||||
}
|
||||
@@ -1,7 +0,0 @@
|
||||
public class CompanionInitialization {
|
||||
|
||||
public static Object getCompanion() {
|
||||
return ConcreteWithStatic.Companion;
|
||||
}
|
||||
|
||||
}
|
||||
@@ -1,5 +0,0 @@
|
||||
public class J {
|
||||
public static int f() {
|
||||
return A.Companion.getI1() + A.Companion.getI2() + B.Named.getI1() + B.Named.getI2();
|
||||
}
|
||||
}
|
||||
@@ -1,3 +1,37 @@
|
||||
// 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
|
||||
|
||||
@@ -1,29 +0,0 @@
|
||||
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";
|
||||
}
|
||||
}
|
||||
@@ -1,3 +1,5 @@
|
||||
// FILE: J.java
|
||||
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
|
||||
import java.util.Collection;
|
||||
@@ -62,3 +64,32 @@ public class J extends MyList {
|
||||
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"
|
||||
}
|
||||
@@ -1,26 +0,0 @@
|
||||
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"
|
||||
}
|
||||
@@ -1,3 +1,5 @@
|
||||
// FILE: J.java
|
||||
|
||||
public class J {
|
||||
abstract static public class AImpl {
|
||||
public char charAt(int index) {
|
||||
@@ -13,3 +15,14 @@ public class J {
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// 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"
|
||||
}
|
||||
@@ -1,9 +0,0 @@
|
||||
|
||||
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"
|
||||
}
|
||||
@@ -1,3 +1,15 @@
|
||||
// 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'
|
||||
@@ -1,7 +0,0 @@
|
||||
public class J {
|
||||
public static class A extends AImpl implements CharSequence {
|
||||
public CharSequence subSequence(int start, int end) {
|
||||
return null;
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -1,3 +1,5 @@
|
||||
// FILE: J.java
|
||||
|
||||
import java.util.*;
|
||||
public class J {
|
||||
abstract static public class AImpl {
|
||||
@@ -97,3 +99,15 @@ public class J {
|
||||
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"
|
||||
}
|
||||
@@ -1,10 +0,0 @@
|
||||
|
||||
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"
|
||||
}
|
||||
@@ -1,3 +1,12 @@
|
||||
// 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()
|
||||
@@ -1,4 +0,0 @@
|
||||
public class A extends AImpl implements java.util.List<String> {
|
||||
public <T> T[] toArray(T[] a) {return null;}
|
||||
public Object[] toArray() {return null;}
|
||||
}
|
||||
@@ -1,3 +1,5 @@
|
||||
// FILE: J.java
|
||||
|
||||
import java.util.*;
|
||||
public class J {
|
||||
abstract static public class AImpl<E> {
|
||||
@@ -97,3 +99,15 @@ public class J {
|
||||
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"
|
||||
}
|
||||
@@ -1,10 +0,0 @@
|
||||
|
||||
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"
|
||||
}
|
||||
@@ -1,3 +1,13 @@
|
||||
// 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
|
||||
}
|
||||
@@ -1,5 +0,0 @@
|
||||
import java.util.*;
|
||||
|
||||
public class J implements Container {
|
||||
final public String removeAt(int index) { return "abc"; }
|
||||
}
|
||||
@@ -1,3 +1,13 @@
|
||||
// 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
|
||||
}
|
||||
@@ -1,5 +0,0 @@
|
||||
import java.util.*;
|
||||
|
||||
public class J implements Sized {
|
||||
final public int getSize() { return 123; }
|
||||
}
|
||||
@@ -1,3 +1,21 @@
|
||||
// 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()
|
||||
@@ -1,13 +0,0 @@
|
||||
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";
|
||||
}
|
||||
}
|
||||
@@ -1,3 +1,15 @@
|
||||
// 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()
|
||||
@@ -37,4 +49,4 @@ fun box(): String {
|
||||
null in anySet
|
||||
|
||||
return "OK"
|
||||
}
|
||||
}
|
||||
@@ -1,7 +0,0 @@
|
||||
import java.util.*;
|
||||
|
||||
public class J {
|
||||
public static String nullValue() {
|
||||
return null;
|
||||
}
|
||||
}
|
||||
@@ -1,3 +1,21 @@
|
||||
// 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()
|
||||
@@ -37,4 +55,4 @@ open class KList<E> : List<E> {
|
||||
}
|
||||
}
|
||||
|
||||
fun box() = J.foo()
|
||||
fun box() = J.foo()
|
||||
@@ -1,13 +0,0 @@
|
||||
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";
|
||||
}
|
||||
}
|
||||
@@ -1,3 +1,21 @@
|
||||
// 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()
|
||||
@@ -1,13 +0,0 @@
|
||||
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";
|
||||
}
|
||||
}
|
||||
@@ -1,3 +1,28 @@
|
||||
// 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()
|
||||
@@ -76,4 +101,4 @@ open class A : MutableList<Int> {
|
||||
}
|
||||
}
|
||||
|
||||
fun box() = J.foo()
|
||||
fun box() = J.foo()
|
||||
@@ -1,20 +0,0 @@
|
||||
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";
|
||||
}
|
||||
}
|
||||
@@ -1,3 +1,21 @@
|
||||
// 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()
|
||||
@@ -1,13 +0,0 @@
|
||||
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";
|
||||
}
|
||||
}
|
||||
@@ -1,3 +1,13 @@
|
||||
// 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
|
||||
@@ -1,3 +1,5 @@
|
||||
// FILE: JavaClass.java
|
||||
|
||||
public class JavaClass {
|
||||
|
||||
public static class C extends B {
|
||||
@@ -21,3 +23,24 @@ public class JavaClass {
|
||||
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();
|
||||
}
|
||||
@@ -1,18 +0,0 @@
|
||||
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();
|
||||
}
|
||||
@@ -1,4 +0,0 @@
|
||||
public class B {
|
||||
public static int a = A.INSTANCE.getC();
|
||||
public static int b = A.INSTANCE.foo();
|
||||
}
|
||||
@@ -1,10 +0,0 @@
|
||||
import B
|
||||
|
||||
object A {
|
||||
val c = 1
|
||||
fun foo() = 4
|
||||
}
|
||||
|
||||
fun box(): String {
|
||||
return if (B.a == 1 && B.b == 4) "OK" else "${B.a} ${B.b}"
|
||||
}
|
||||
@@ -1,3 +1,5 @@
|
||||
// FILE: J.java
|
||||
|
||||
public class J {
|
||||
// This test checks that although type '@org.jetbrains.annotations.NotNull Integer' is perceived as simple Int,
|
||||
// it's correctly mapped to 'Lj.l.Integer' by JVM backend
|
||||
@@ -5,3 +7,7 @@ public class J {
|
||||
return "OK";
|
||||
}
|
||||
}
|
||||
|
||||
// FILE: box.kt
|
||||
|
||||
fun box() = J.test(1)
|
||||
@@ -1 +0,0 @@
|
||||
fun box() = J.test(1)
|
||||
21
compiler/testData/codegen/boxWithJava/fileClasses/differentFiles.kt
vendored
Normal file
21
compiler/testData/codegen/boxWithJava/fileClasses/differentFiles.kt
vendored
Normal file
@@ -0,0 +1,21 @@
|
||||
// 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()
|
||||
@@ -1,5 +0,0 @@
|
||||
public class Baz {
|
||||
public static String baz() {
|
||||
return Foo.foo() + Bar.bar();
|
||||
}
|
||||
}
|
||||
@@ -1,2 +0,0 @@
|
||||
@file:JvmName("Bar")
|
||||
public fun bar(): String = "K"
|
||||
@@ -1 +0,0 @@
|
||||
fun box(): String = Baz.baz()
|
||||
@@ -1,2 +0,0 @@
|
||||
@file:JvmName("Foo")
|
||||
public fun foo(): String = "O"
|
||||
@@ -1,3 +1,5 @@
|
||||
// FILE: StringHolder.java
|
||||
|
||||
import java.lang.annotation.ElementType;
|
||||
import java.lang.annotation.Retention;
|
||||
import java.lang.annotation.RetentionPolicy;
|
||||
@@ -7,4 +9,11 @@ import java.lang.annotation.Target;
|
||||
@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"
|
||||
22
compiler/testData/codegen/boxWithJava/fileClasses/multifileClassWith2Files.kt
vendored
Normal file
22
compiler/testData/codegen/boxWithJava/fileClasses/multifileClassWith2Files.kt
vendored
Normal file
@@ -0,0 +1,22 @@
|
||||
// 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()
|
||||
@@ -1,5 +0,0 @@
|
||||
public class Baz {
|
||||
public static String baz() {
|
||||
return Util.foo() + Util.bar();
|
||||
}
|
||||
}
|
||||
@@ -1,3 +0,0 @@
|
||||
@file:JvmName("Util")
|
||||
@file:JvmMultifileClass
|
||||
public fun bar(): String = "K"
|
||||
@@ -1,2 +0,0 @@
|
||||
@file:[JvmName("Util") JvmMultifileClass]
|
||||
public fun foo(): String = "O"
|
||||
@@ -1 +0,0 @@
|
||||
fun box(): String = Baz.baz()
|
||||
27
compiler/testData/codegen/boxWithJava/fileClasses/multifileClassWithCrossCall.kt
vendored
Normal file
27
compiler/testData/codegen/boxWithJava/fileClasses/multifileClassWithCrossCall.kt
vendored
Normal file
@@ -0,0 +1,27 @@
|
||||
// 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()
|
||||
@@ -1,5 +0,0 @@
|
||||
public class Baz {
|
||||
public static String baz() {
|
||||
return Util.foo() + Util.bar();
|
||||
}
|
||||
}
|
||||
@@ -1,5 +0,0 @@
|
||||
@file:JvmName("Util")
|
||||
@file:JvmMultifileClass
|
||||
public fun bar(): String = barx()
|
||||
|
||||
public fun foox(): String = "O"
|
||||
@@ -1,5 +0,0 @@
|
||||
@file:JvmName("Util")
|
||||
@file:JvmMultifileClass
|
||||
public fun foo(): String = foox()
|
||||
|
||||
public fun barx(): String = "K"
|
||||
@@ -1 +0,0 @@
|
||||
fun box(): String = Baz.baz()
|
||||
27
compiler/testData/codegen/boxWithJava/fileClasses/multifileClassWithPrivate.kt
vendored
Normal file
27
compiler/testData/codegen/boxWithJava/fileClasses/multifileClassWithPrivate.kt
vendored
Normal file
@@ -0,0 +1,27 @@
|
||||
// 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()
|
||||
@@ -1,5 +0,0 @@
|
||||
public class Baz {
|
||||
public static String baz() {
|
||||
return Util.foo() + Util.bar();
|
||||
}
|
||||
}
|
||||
@@ -1,5 +0,0 @@
|
||||
@file:JvmName("Util")
|
||||
@file:JvmMultifileClass
|
||||
public fun bar(): String = barx()
|
||||
|
||||
private fun barx(): String = "K"
|
||||
@@ -1,5 +0,0 @@
|
||||
@file:JvmName("Util")
|
||||
@file:JvmMultifileClass
|
||||
public fun foo(): String = foox()
|
||||
|
||||
private fun foox(): String = "O"
|
||||
@@ -1 +0,0 @@
|
||||
fun box(): String = Baz.baz()
|
||||
16
compiler/testData/codegen/boxWithJava/fileClasses/simple.kt
vendored
Normal file
16
compiler/testData/codegen/boxWithJava/fileClasses/simple.kt
vendored
Normal file
@@ -0,0 +1,16 @@
|
||||
// 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()
|
||||
@@ -1,5 +0,0 @@
|
||||
public class Bar {
|
||||
public static String bar() {
|
||||
return Foo.foo();
|
||||
}
|
||||
}
|
||||
@@ -1,2 +0,0 @@
|
||||
@file:JvmName("Foo")
|
||||
public fun foo(): String = "OK"
|
||||
@@ -1 +0,0 @@
|
||||
fun box(): String = Bar.bar()
|
||||
27
compiler/testData/codegen/boxWithJava/inline.kt
vendored
Normal file
27
compiler/testData/codegen/boxWithJava/inline.kt
vendored
Normal file
@@ -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()
|
||||
}
|
||||
@@ -1,13 +0,0 @@
|
||||
public class Test {
|
||||
|
||||
protected String data = "O";
|
||||
|
||||
protected Test() {
|
||||
|
||||
}
|
||||
|
||||
protected static String testStatic() {
|
||||
return "K";
|
||||
}
|
||||
|
||||
}
|
||||
@@ -1,10 +0,0 @@
|
||||
|
||||
public inline fun test(): String {
|
||||
val p = object : Test() {}
|
||||
return p.data + Test.testStatic();
|
||||
}
|
||||
|
||||
|
||||
fun box(): String {
|
||||
return test()
|
||||
}
|
||||
@@ -1,3 +1,15 @@
|
||||
// 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()
|
||||
|
||||
@@ -6,4 +18,4 @@ public class MyWallpaperService : JavaClass() {
|
||||
|
||||
fun box(): String {
|
||||
return if (MyWallpaperService().onCreateInner() != null) return "OK" else "fail"
|
||||
}
|
||||
}
|
||||
@@ -1,7 +0,0 @@
|
||||
public abstract class JavaClass {
|
||||
public abstract InnerClass onCreateInner();
|
||||
|
||||
public class InnerClass {
|
||||
|
||||
}
|
||||
}
|
||||
@@ -1,3 +1,13 @@
|
||||
// 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()
|
||||
@@ -1,5 +0,0 @@
|
||||
public abstract class JavaClass {
|
||||
public static String test() {
|
||||
return Test.INSTANCE.foo(new Outer<String>("OK").new Inner<Integer>(1));
|
||||
}
|
||||
}
|
||||
@@ -1,3 +1,15 @@
|
||||
// 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)
|
||||
}
|
||||
@@ -19,4 +31,4 @@ fun box(): String {
|
||||
if (companion != IStatic) return "fail 2"
|
||||
|
||||
return "OK"
|
||||
}
|
||||
}
|
||||
@@ -1,7 +0,0 @@
|
||||
public class CompanionInitialization {
|
||||
|
||||
public static Object getCompanion() {
|
||||
return IStatic.Companion;
|
||||
}
|
||||
|
||||
}
|
||||
@@ -1,3 +1,13 @@
|
||||
// FILE: B.java
|
||||
|
||||
class B {
|
||||
static String test(A x) {
|
||||
return A.DefaultImpls.foo(x);
|
||||
}
|
||||
}
|
||||
|
||||
// FILE: main.kt
|
||||
|
||||
interface A {
|
||||
fun foo() = "OK"
|
||||
}
|
||||
@@ -1,5 +0,0 @@
|
||||
class B {
|
||||
static String test(A x) {
|
||||
return A.DefaultImpls.foo(x);
|
||||
}
|
||||
}
|
||||
Some files were not shown because too many files have changed in this diff Show More
Reference in New Issue
Block a user