Introduce JavaAgainstKotlinBinariesTest
This commit is contained in:
+10
@@ -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);
|
||||
}
|
||||
}
|
||||
+2
@@ -0,0 +1,2 @@
|
||||
class KotlinClass
|
||||
interface KotlinTrait
|
||||
+23
@@ -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();
|
||||
}
|
||||
}
|
||||
+11
@@ -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) {}
|
||||
|
||||
}
|
||||
}
|
||||
+8
@@ -0,0 +1,8 @@
|
||||
package test;
|
||||
|
||||
class EnumAutoGeneratedMethods {
|
||||
void foo() {
|
||||
TestEnum.values();
|
||||
assert TestEnum.valueOf("first") == TestEnum.first;
|
||||
}
|
||||
}
|
||||
+5
@@ -0,0 +1,5 @@
|
||||
package test
|
||||
|
||||
enum class TestEnum {
|
||||
first second third
|
||||
}
|
||||
+16
@@ -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
|
||||
}
|
||||
+9
@@ -0,0 +1,9 @@
|
||||
package test;
|
||||
|
||||
import static test.kotlin.KotlinEnum.ENTRY;
|
||||
|
||||
public class EnumStaticImportInJava {
|
||||
void other() {
|
||||
ENTRY.foo();
|
||||
}
|
||||
}
|
||||
+7
@@ -0,0 +1,7 @@
|
||||
package test.kotlin
|
||||
|
||||
public enum class KotlinEnum {
|
||||
ENTRY;
|
||||
|
||||
public fun foo(): String = "foo"
|
||||
}
|
||||
+1
@@ -0,0 +1 @@
|
||||
// TOOL: DataFlowInspection
|
||||
+6
@@ -0,0 +1,6 @@
|
||||
class C {
|
||||
public C(B b, A a) {
|
||||
a.foo();
|
||||
b.foo();
|
||||
}
|
||||
}
|
||||
+6
@@ -0,0 +1,6 @@
|
||||
public interface A {
|
||||
public fun foo() {}
|
||||
}
|
||||
|
||||
public class B: A {
|
||||
}
|
||||
+13
@@ -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()
|
||||
}
|
||||
+1
@@ -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)
|
||||
Vendored
+11
@@ -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);
|
||||
}
|
||||
}
|
||||
|
||||
Vendored
+3
@@ -0,0 +1,3 @@
|
||||
package test.kotlin
|
||||
|
||||
fun foo(a: Any): Any = a
|
||||
Vendored
+1
@@ -0,0 +1 @@
|
||||
// TOOL: DataFlowInspection
|
||||
+6
@@ -0,0 +1,6 @@
|
||||
class UseKotlinSubclassesOfMappedTypes {
|
||||
void test() {
|
||||
Iterable<String> iterable = new KotlinIterableTraitTest();
|
||||
Comparable<Integer> comparable = new KotlinComparableTest();
|
||||
}
|
||||
}
|
||||
+11
@@ -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()
|
||||
}
|
||||
}
|
||||
+10
@@ -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();
|
||||
}
|
||||
}
|
||||
+4
@@ -0,0 +1,4 @@
|
||||
package test
|
||||
|
||||
fun foo() {}
|
||||
var bar = 12
|
||||
Reference in New Issue
Block a user