Introduce JavaAgainstKotlinBinariesTest

This commit is contained in:
Pavel V. Talanov
2015-10-29 13:37:41 +03:00
parent 506b5509f3
commit be668fc4f5
36 changed files with 281 additions and 90 deletions
@@ -0,0 +1,10 @@
// KT-4355 IDEA complains when assigning Kotlin objects where java.lang.Object is expected
class AssignKotlinClassToObjectInJava {
void test(KotlinTrait trait) {
Object kotlinClass = new KotlinClass();
Object kotlinTrait = trait;
KotlinClass foo = null;
foo.equals(foo);
}
}
@@ -0,0 +1,2 @@
class KotlinClass
interface KotlinTrait
@@ -0,0 +1,23 @@
import java.util.ArrayList;
import java.util.Collection;
import java.util.List;
import test.*;
class AssignMappedKotlinType {
void test() {
int i1 = AssignMappedKotlinTypeKt.getInt();
Integer i2 = AssignMappedKotlinTypeKt.getInt();
Number number = AssignMappedKotlinTypeKt.getNumber();
String str = AssignMappedKotlinTypeKt.getString();
Collection<Integer> intCollection = AssignMappedKotlinTypeKt.getList();
List<Integer> intList = AssignMappedKotlinTypeKt.getList();
Collection<Integer> intMutableCollection = AssignMappedKotlinTypeKt.getMutableList();
List<Integer> intMutableList = AssignMappedKotlinTypeKt.getMutableList();
Collection<String> stringsCollection = AssignMappedKotlinTypeKt.getArrayList();
ArrayList<String> arrayListCollection = AssignMappedKotlinTypeKt.getArrayList();
}
}
@@ -0,0 +1,11 @@
package test
import java.util.ArrayList
fun getInt(): Int = 12
fun getString(): String = "Test"
fun getNumber(): Number? = null
fun getList(): List<Int> = listOf(1, 2, 3)
fun getMutableList(): MutableList<Int> = ArrayList<Int>()
fun getArrayList(): ArrayList<String> = ArrayList<String>()
@@ -0,0 +1,12 @@
class ClassObject {
void foo() {
WithClassObject.Companion.getValue();
WithClassObject.Companion.getValue();
WithClassObject.Companion.foo();
WithClassObject.Companion.getValueWithGetter();
WithClassObject.Companion.getVariable();
WithClassObject.Companion.setVariable(0);
WithClassObject.Companion.getVariableWithAccessors();
WithClassObject.Companion.setVariableWithAccessors(0);
}
}
@@ -0,0 +1,15 @@
class WithClassObject {
companion object {
fun foo() {}
val value: Int = 0
val valueWithGetter: Int
get() = 1
var variable: Int = 0
var variableWithAccessors: Int
get() = 0
set(v) {}
}
}
@@ -0,0 +1,8 @@
package test;
class EnumAutoGeneratedMethods {
void foo() {
TestEnum.values();
assert TestEnum.valueOf("first") == TestEnum.first;
}
}
@@ -0,0 +1,5 @@
package test
enum class TestEnum {
first second third
}
@@ -0,0 +1,16 @@
package test;
class EnumEntriesInSwitch {
void foo() {
ZZZ a = ZZZ.A1;
switch (a) {
case A1: break;
case B1: break;
}
switch (ZZZ.B1) {
case A1: break;
case B1: break;
}
}
}
@@ -0,0 +1,6 @@
package test
enum class ZZZ {
A1,
B1
}
@@ -0,0 +1,9 @@
package test;
import static test.kotlin.KotlinEnum.ENTRY;
public class EnumStaticImportInJava {
void other() {
ENTRY.foo();
}
}
@@ -0,0 +1,7 @@
package test.kotlin
public enum class KotlinEnum {
ENTRY;
public fun foo(): String = "foo"
}
@@ -0,0 +1 @@
// TOOL: DataFlowInspection
@@ -0,0 +1,6 @@
class C {
public C(B b, A a) {
a.foo();
b.foo();
}
}
@@ -0,0 +1,6 @@
public interface A {
public fun foo() {}
}
public class B: A {
}
@@ -0,0 +1,13 @@
import test.kotlin.A;
import static test.kotlin.JvmOverloadsFunctionsKt.foo;
class JvmOverloadsFunctions {
public static void main(String[] args) {
A a = new A() { };
foo(a.getClass(), a, true, "Some");
foo(a.getClass(), a, true);
foo(a.getClass(), a);
}
}
@@ -0,0 +1,9 @@
package test.kotlin
interface A
@kotlin.jvm.JvmOverloads
public fun foo<T : A>(k: Class<T>, a: A, b: Boolean = false, s: String="hello"): List<T> {
println("$b $s")
return listOf()
}
@@ -0,0 +1 @@
// WITH_RUNTIME
@@ -0,0 +1,27 @@
class KotlinAnnotations {
@<error descr="'d' missing though required">k.Anno1</error>()
@<error descr="'c', 'g' missing though required">k.Anno2</error>()
public static void m1() {
}
@<error descr="'d' missing though required">k.Anno1</error>(c = 3)
@<error descr="'g' missing though required">k.Anno2</error>(c = 3)
public static void m2() {
}
@k.Anno1(d = 5)
@<error descr="'c' missing though required">k.Anno2</error>(g = "asdas")
public static void m3() {
}
@k.Anno1(c = 1, d = 5)
@k.Anno2(c = {6, 5}, g = "asdas")
public static void m4() {
}
@k.Anno1(<error descr="Cannot resolve method 'x'">x</error> = 1)
@k.Anno2(<error descr="Cannot resolve method 'x'">x</error> = 2)
public static void m5() {
}
}
@@ -0,0 +1,4 @@
package k
annotation class Anno1(val d: Int, val c: Int = 2)
annotation class Anno2(val c: IntArray, val g: String)
@@ -0,0 +1,11 @@
package test;
import org.jetbrains.annotations.NotNull;
import test.kotlin.*;
public class TopLevelFunctionInDataFlowInspection {
void other(@NotNull Object some) {
Object foo = TopLevelFunctionInDataFlowInspectionKt.foo(some);
}
}
@@ -0,0 +1,3 @@
package test.kotlin
fun foo(a: Any): Any = a
@@ -0,0 +1 @@
// TOOL: DataFlowInspection
@@ -0,0 +1,6 @@
class UseKotlinSubclassesOfMappedTypes {
void test() {
Iterable<String> iterable = new KotlinIterableTraitTest();
Comparable<Integer> comparable = new KotlinComparableTest();
}
}
@@ -0,0 +1,11 @@
class KotlinComparableTest : Comparable<Int> {
override fun compareTo(other: Int): Int {
throw UnsupportedOperationException()
}
}
class KotlinIterableTraitTest : Iterable<String> {
override fun iterator(): Iterator<String> {
throw UnsupportedOperationException()
}
}
@@ -0,0 +1,10 @@
package test;
// Check absence of 'Static method reference via subclass warning' for kotlin usages
public class UsingKotlinPackageDeclarations {
public static int test() {
UsingKotlinPackageDeclarationsKt.foo();
UsingKotlinPackageDeclarationsKt.setBar(15);
return UsingKotlinPackageDeclarationsKt.getBar();
}
}
@@ -0,0 +1,4 @@
package test
fun foo() {}
var bar = 12