[kotlin] J2K: unignore K2 tests with K2-specific testdata

KTIJ-30693
KTIJ-30760

GitOrigin-RevId: 80dacdc6dcd7667d5b19771eb3ff192c577bd7d9
This commit is contained in:
Alexey Belkov
2024-07-30 20:12:37 +04:00
committed by intellij-monorepo-bot
parent 3f9fd4a187
commit 0aba5a4e72
186 changed files with 1347 additions and 115 deletions

View File

@@ -1,5 +1,3 @@
// IGNORE_K2
import java.util.Arrays;
import java.util.List;

View File

@@ -0,0 +1,10 @@
import java.util.Arrays
import java.util.List
class Collections {
fun test() {
val x = List.of<String?>(null)
val y = List.of<String?>("C", null)
val z = Arrays.asList<String?>(null)
}
}

View File

@@ -1,4 +1,3 @@
// IGNORE_K2
// !ADD_JAVA_API
import javaApi.Anon5;
import javaApi.TypeUseAnon1;

View File

@@ -0,0 +1,113 @@
// ERROR: This annotation is not applicable to target 'type parameter'.
// ERROR: This annotation is not applicable to target 'type parameter'.
import javaApi.Anon5
import javaApi.TypeUseAnon1
import javaApi.TypeUseAnon2
import javaApi.TypeUseAnon3
import java.io.File
class TEST1 {
@Anon5(1)
fun foo(@Anon5(2) o: @TypeUseAnon1 Any?): @TypeUseAnon1 String {
@Anon5(3) val baz: @TypeUseAnon1 String = ""
return ""
}
@Anon5(4)
var bar: @TypeUseAnon1 String? = null
}
class TEST2 {
@Anon5(1)
fun foo(@Anon5(2) o: @TypeUseAnon2 Any?): @TypeUseAnon2 String {
@Anon5(3) val baz: @TypeUseAnon2 String = ""
return ""
}
@Anon5(4)
var bar: @TypeUseAnon2 String? = null
}
class TEST3 {
@Anon5(1)
fun foo(@Anon5(2) o: @TypeUseAnon3 Any?): @TypeUseAnon3 String {
@Anon5(3) val baz: @TypeUseAnon3 String = ""
return ""
}
@Anon5(4)
var bar: @TypeUseAnon3 String? = null
}
class TestInstanceOf {
fun test(s: String?) {
println(s is @TypeUseAnon3 String)
}
}
class TestTypeCast {
fun test(foo: Any?) {
val s = foo as @TypeUseAnon3 String?
}
}
class TestInheritance1 : @TypeUseAnon1 C()
class TestInheritance2 : @TypeUseAnon1 I1
class TestInheritance3 : @TypeUseAnon1 C(), @TypeUseAnon2 I1, @TypeUseAnon2 @TypeUseAnon3 I2
open class C
interface I1
interface I2
class TestCatch {
fun foo() {
try {
} catch (e: @TypeUseAnon1 Exception) {
}
}
}
class TestForLoopParameter {
fun foo(arr: IntArray) {
for (test: @TypeUseAnon1 Int in arr) {
println(test)
}
for (i: @TypeUseAnon1 Int in arr.indices) {
println(i)
}
}
}
class TestPrimaryConstructorProperty(private var foo: @TypeUseAnon1 @TypeUseAnon2 String?)
class TestStandardMethods : Cloneable {
override fun toString(): @TypeUseAnon1 String {
return ""
}
@Throws(CloneNotSupportedException::class)
public override fun clone(): @TypeUseAnon1 Any {
return super.clone()
}
}
annotation class TestAnnotationMethod(
val value: @TypeUseAnon1 String,
val value2: @TypeUseAnon1 @TypeUseAnon2 String = "test"
)
/**
* TYPE_USE annotation is allowed on a type parameter only in Java,
* in Kotlin an error is expected.
*/
interface TestTypeParameter<@TypeUseAnon1 F : @TypeUseAnon1 File?> {
fun <@TypeUseAnon1 T : @TypeUseAnon1 File?> foo()
}
class TestTypeArgument {
fun f1() {
this.f2<@TypeUseAnon1 String?>("")
}
fun <T> f2(t: T?) {
}
}

View File

@@ -0,0 +1,11 @@
internal class C {
var abc: Int
init {
abc = 2
}
init {
abc = 0
}
}

View File

@@ -1,4 +1,3 @@
// IGNORE_K2
public final class Foo {
private Foo() {
}

View File

@@ -0,0 +1,7 @@
object Foo {
val isLinux: Boolean
init {
isLinux = true
}
}

View File

@@ -1,4 +1,3 @@
// IGNORE_K2
import java.util.ArrayList;
import java.util.List;

View File

@@ -0,0 +1,15 @@
class Temp1 {
private val listField: MutableList<Int?>
init {
listField = ArrayList<Int?>()
}
fun m() {
listField.add(2)
listField.add(1)
for (i in listField) {
println(i)
}
}
}

View File

@@ -1,4 +1,3 @@
// IGNORE_K2
class Test {
String str;
{

View File

@@ -0,0 +1,3 @@
internal class Test {
var str: String? = "Ola"
}

View File

@@ -1,4 +1,3 @@
// IGNORE_K2
class Test {
static String str;
static {

View File

@@ -0,0 +1,7 @@
internal object Test {
var str: String?
init {
str = "Ola"
}
}

View File

@@ -0,0 +1,11 @@
internal object C {
var abc: Int
init {
abc = 2
}
init {
abc = 0
}
}

View File

@@ -1,4 +1,3 @@
// IGNORE_K2
abstract class C {
String mMemberVariable;

View File

@@ -0,0 +1,23 @@
internal abstract class C {
var mMemberVariable: String? = null
fun foo() {
val s1 = checkNotNull(f())
val s2 = checkNotNull(g()) { "g should not return null" }
val doNotMergeDueToPossibleSideEffects = g()
assert(s2.hashCode() == 42)
val h = s2.hashCode()
val s3 = "sss"
checkNotNull(s3.hashCode())
checkNotNull(doNotMergeDueToPossibleSideEffects)
checkNotNull(mMemberVariable)
val doNotTouchDifferentAssert = f()
assert(doNotTouchDifferentAssert == null)
}
abstract fun f(): String
abstract fun g(): String
}

View File

@@ -1,4 +1,3 @@
// IGNORE_K2
class Foo {
private static String s;
private static Integer i;

View File

@@ -0,0 +1,49 @@
internal object Foo {
private val s: String? = null
private val i: Int? = null
private val c: Char? = null
@JvmStatic
fun main(args: Array<String>) {
println("5" + 1)
println(1.toString() + "5")
println((1 + 3).toString() + "5")
println((1 + 3).toString() + "5")
println("5" + "5" + (1 + 3))
println("5" + "5" + 1 + 3)
println("5" + "5" + 1)
println("5" + ("5" + 1) + 3)
println("5" + ("5" + 1) + 3 + 4)
println(1.toString() + "3" + 4 + "5")
println((1 + 3 + 4).toString() + "5")
println("5" + 1 + 3 + 4)
println('c'.toString() + "5")
println(('c'.code + 'd'.code).toString() + "5")
println("5" + 'c')
println("5" + 'c' + 'd')
println(c.toString() + "s")
println(c.toString() + "s" + c)
println("s" + c + c)
println(s + 'c')
println(s + 'c' + 'd')
println('c'.toString() + s)
println(s + null)
println(null.toString() + s)
println(i.toString() + "s")
println(i.toString() + "s" + i)
println("s" + i + i)
println(null.toString() + "s")
println("s" + null)
println("s" + null + null)
val o = Any()
println(o.toString() + "")
println("" + o)
println(o.hashCode().toString() + "")
println("" + o.hashCode())
val bar = arrayOf<String?>("hi")
println(1.toString() + bar[0])
println((1 + 2).toString() + bar[0])
println(bar[0] + 1)
println(bar[0] + 1 + 2)
}
}

View File

@@ -1,4 +1,3 @@
// IGNORE_K2
class A {
private int v;

View File

@@ -0,0 +1,30 @@
internal class A // this is a primary constructor
// this is a secondary constructor 1
// end of primary constructor body
@JvmOverloads constructor(p: Int = 1) {
private val v = 1
// end of secondary constructor 1 body
// this is a secondary constructor 2
constructor(s: String) : this(s.length) // end of secondary constructor 2 body
}
internal class B // this constructor will disappear
// end of constructor body
(private var x: Int) {
fun foo() {}
}
/*
* The magic of comments
*/
// single line magic comments
internal class CtorComment {
var myA: String? = "a"
}
internal class CtorComment2 /*
* The magic of comments
*/
// single line magic comments

View File

@@ -1,4 +1,3 @@
// IGNORE_K2
package org.test.customer
class Customer {

View File

@@ -0,0 +1,46 @@
package org.test.customer
internal class Customer(first: String?, last: String?) {
val firstName: String?
val lastName: String?
init {
doSmthBefore()
this.firstName = first
this.lastName = last
doSmthAfter()
}
private fun doSmthBefore() {}
private fun doSmthAfter() {}
}
internal class CustomerBuilder {
var _firstName: String? = "Homer"
var _lastName: String? = "Simpson"
fun WithFirstName(firstName: String?): CustomerBuilder {
_firstName = firstName
return this
}
fun WithLastName(lastName: String?): CustomerBuilder {
_lastName = lastName
return this
}
fun Build(): Customer {
return Customer(_firstName, _lastName)
}
}
object User {
fun main() {
val customer = CustomerBuilder()
.WithFirstName("Homer")
.WithLastName("Simpson")
.Build()
println(customer.firstName)
println(customer.lastName)
}
}

View File

@@ -1,4 +1,3 @@
// IGNORE_K2
class C {
public String x;

View File

@@ -0,0 +1 @@
internal class C(var x: String)

View File

@@ -1 +1 @@
internal class C(var x: String)
internal class C(var x: String?)

View File

@@ -1,4 +1,3 @@
// IGNORE_K2
class C {
public Object x;

View File

@@ -0,0 +1,7 @@
internal class C(x: String?) {
var x: Any?
init {
this.x = x
}
}

View File

@@ -1,4 +1,3 @@
// IGNORE_K2
class C {
private final String string;

View File

@@ -0,0 +1 @@
internal class C @JvmOverloads constructor(private val string: String?, a: Int = string!!.length)

View File

@@ -1,4 +1,3 @@
// IGNORE_K2
import java.lang.SuppressWarnings;
class C {

View File

@@ -0,0 +1,8 @@
// ERROR: This annotation is not applicable to target 'value parameter' and use site target '@field'
// ERROR: This annotation is not applicable to target 'value parameter' and use site target '@param'
// ERROR: This annotation is not applicable to target 'value parameter' and use site target '@param'
internal class C(
@field:Deprecated("") private val p1: Int, @param:Deprecated("") private val myP2: Int, @param:Deprecated(
""
) var p3: Int
)

View File

@@ -1,6 +1,6 @@
// ERROR: This annotation is not applicable to target 'value parameter' and use site target '@field'
// ERROR: This annotation is not applicable to target 'value parameter' and use site target '@param'
// ERROR: This annotation is not applicable to target 'value parameter' and use site target '@param'
// ERROR: This annotation is not applicable to target 'value parameter' and use-site target '@param'.
// ERROR: This annotation is not applicable to target 'value parameter' and use-site target '@param'.
// ERROR: This annotation is not applicable to target 'backing field' and use-site target '@field'.
internal class C(
@field:Deprecated("") private val p1: Int, @param:Deprecated("") private val myP2: Int, @param:Deprecated(
""

View File

@@ -1,4 +1,3 @@
// IGNORE_K2
public class Identifier<T> {
private final T myName;
private boolean myHasDollar;

View File

@@ -0,0 +1,28 @@
class Identifier<T> {
val name: T?
private var myHasDollar = false
private var myNullable = true
constructor(name: T?) {
this.name = name
}
constructor(name: T?, isNullable: Boolean) {
this.name = name
myNullable = isNullable
}
constructor(name: T?, hasDollar: Boolean, isNullable: Boolean) {
this.name = name
myHasDollar = hasDollar
myNullable = isNullable
}
}
object User {
fun main() {
val i1: Identifier<*> = Identifier<String?>("name", false, true)
val i2: Identifier<*> = Identifier<String?>("name", false)
val i3: Identifier<*> = Identifier<String?>("name")
}
}

View File

@@ -1,4 +1,3 @@
// IGNORE_K2
public class Identifier {
private final String myName;
private boolean myHasDollar;

View File

@@ -0,0 +1,28 @@
class Identifier {
val name: String
private var myHasDollar = false
private var myNullable = true
constructor(name: String) {
this.name = name
}
constructor(name: String, isNullable: Boolean) {
this.name = name
myNullable = isNullable
}
constructor(name: String, hasDollar: Boolean, isNullable: Boolean) {
this.name = name
myHasDollar = hasDollar
myNullable = isNullable
}
}
object User {
fun main() {
val i1 = Identifier("name", false, true)
val i2 = Identifier("name", false)
val i3 = Identifier("name")
}
}

View File

@@ -1,18 +1,18 @@
class Identifier {
val name: String
val name: String?
private var myHasDollar = false
private var myNullable = true
constructor(name: String) {
constructor(name: String?) {
this.name = name
}
constructor(name: String, isNullable: Boolean) {
constructor(name: String?, isNullable: Boolean) {
this.name = name
myNullable = isNullable
}
constructor(name: String, hasDollar: Boolean, isNullable: Boolean) {
constructor(name: String?, hasDollar: Boolean, isNullable: Boolean) {
this.name = name
myHasDollar = hasDollar
myNullable = isNullable

View File

@@ -1,4 +1,3 @@
// IGNORE_K2
class C1 {
C1(int arg1,
int arg2,

View File

@@ -0,0 +1,16 @@
internal class C1(
arg1: Int,
arg2: Int,
arg3: Int
) {
constructor(
x: Int,
y: Int
) : this(x, x + y, 0)
}
internal class C2(
private var arg1: Int,
private var arg2: Int,
arg3: Int
)

View File

@@ -1,4 +1,3 @@
// IGNORE_K2
public class J {
private String s1;
private String s2;

View File

@@ -0,0 +1,7 @@
class J(private var s1: String?) {
private var s2: String? = null
constructor(s1: String?, s2: String?) : this(s1) {
this.s2 = s2
}
}

View File

@@ -1,4 +1,3 @@
// IGNORE_K2
public class J {
private String s1;
private String s2;

View File

@@ -0,0 +1,12 @@
class J(private var s1: String?) {
private var s2: String? = null
private var s3: String? = null
constructor(s1: String?, s2: String?) : this(s1) {
this.s2 = s2
}
constructor(s1: String?, s2: String?, s3: String?) : this(s1, s2) {
this.s3 = s3
}
}

View File

@@ -1,4 +1,3 @@
// IGNORE_K2
public class J {
private String s1;
private String s2;

View File

@@ -0,0 +1,17 @@
class J(private var s1: String?) {
private var s2: String? = null
private var s3: String? = null
private var s4: String? = null
constructor(s1: String?, s2: String?) : this(s1) {
this.s2 = s2
}
constructor(s1: String?, s2: String?, s3: String?) : this(s1, s2) {
this.s3 = s3
}
constructor(s1: String?, s2: String?, s3: String?, s4: String?) : this(s1, s2, s3) {
this.s4 = s4
}
}

View File

@@ -1,4 +1,3 @@
// IGNORE_K2
class C {
private static int staticField1 = 0;
private static int staticField2 = 0;

View File

@@ -0,0 +1,10 @@
internal class C() {
constructor(p: Int) : this() {
println(staticField1 + staticField2)
}
companion object {
private val staticField1 = 0
private val staticField2 = 0
}
}

View File

@@ -1,4 +1,3 @@
// IGNORE_K2
public class X {
void foo() {
Runnable runnable = new Runnable() {

View File

@@ -0,0 +1,11 @@
class X {
fun foo() {
val runnable: Runnable = object : Runnable {
var value: Int = 10
override fun run() {
println(this.value)
}
}
}
}

View File

@@ -1,4 +1,3 @@
// IGNORE_K2
class AccessorsArePreserved {
private Integer someInt = 1;

View File

@@ -0,0 +1,27 @@
internal class AccessorsArePreserved {
var someInt: Int = 1
// get header
get() {
// get body 1
println("Some text")
// get body 2
return field
} // get footer
// set header
set(state) {
// set body 1
field = state
// set body 2
println("Some text")
} // set footer
}
internal class AccessorsAreRemoved {
// set body
// set footer
// set header
// get body
// get footer
// get header
var someInt: Int = 1
}

View File

@@ -1,5 +1,5 @@
internal class AccessorsArePreserved {
var someInt: Int = 1
var someInt: Int? = 1
// get header
get() {
// get body 1
@@ -23,5 +23,5 @@ internal class AccessorsAreRemoved {
// get body
// get footer
// get header
var someInt: Int = 1
var someInt: Int? = 1
}

View File

@@ -1,4 +1,3 @@
// IGNORE_K2
public class Test {
private String id;
private String name;

View File

@@ -0,0 +1,5 @@
class Test(var id: String?, var name: String?, var age: Int) {
init {
println(age)
}
}

View File

@@ -1,4 +1,3 @@
// IGNORE_K2
@interface TestAnnotationField {}
@interface TestAnnotationParam {}
@interface TestAnnotationGet {}

View File

@@ -0,0 +1,7 @@
internal annotation class TestAnnotationField
internal annotation class TestAnnotationParam
internal annotation class TestAnnotationGet
internal annotation class TestAnnotationSet
class Test(@field:TestAnnotationField @set:TestAnnotationSet @get:TestAnnotationGet @param:TestAnnotationParam var arg: String?)

View File

@@ -1,4 +1,3 @@
// IGNORE_K2
public class Test {
private int myCount;

View File

@@ -0,0 +1,5 @@
class Test(var count: Int) {
fun inc() {
this.count++
}
}

View File

@@ -1,4 +1,3 @@
// IGNORE_K2
public class AAA {
private int myX = 42;

View File

@@ -0,0 +1,10 @@
class AAA {
var x: Int = 42
private set
fun foo(other: AAA) {
println(this.x)
println(other.x)
this.x = 10
}
}

View File

@@ -1,4 +1,3 @@
// IGNORE_K2
public class AAA {
private int myX = 42;

View File

@@ -0,0 +1,4 @@
class AAA {
var x: Int = 42
private set
}

View File

@@ -1,4 +1,3 @@
// IGNORE_K2
public class AAA {
protected int myX = 42;

View File

@@ -0,0 +1,17 @@
open class AAA {
var x: Int = 42
protected set
fun foo(other: AAA) {
println(this.x)
println(other.x)
this.x = 10
}
}
internal class BBB : AAA() {
fun bar() {
println(this.x)
this.x = 10
}
}

View File

@@ -1,4 +1,3 @@
// IGNORE_K2
class C {
final int myArg1;
int myArg2;

View File

@@ -0,0 +1,14 @@
internal class C(val arg1: Int) {
var arg2: Int = 0
var arg3: Int = 0
constructor(arg1: Int, arg2: Int, arg3: Int) : this(arg1) {
this.arg2 = arg2
this.arg3 = arg3
}
constructor(arg1: Int, arg2: Int) : this(arg1) {
this.arg2 = arg2
this.arg3 = 0
}
}

View File

@@ -1,4 +1,3 @@
// IGNORE_K2
public class AAA {
private int x = 42;

View File

@@ -0,0 +1,17 @@
class AAA {
var x: Int = 42
fun foo() {
this.x = this.x + 1
}
fun bar(other: AAA) {
other.x = other.x + 1
}
}
internal class B {
fun foo(a: AAA) {
a.x = a.x + 1
}
}

View File

@@ -1,4 +1,3 @@
// IGNORE_K2
public class A {
private String foo;

View File

@@ -0,0 +1,40 @@
class A {
var foo: String? = null
fun g1(foo: String): Boolean {
return this.foo == foo
}
fun g2(foo: String): Boolean {
return this.foo == foo
}
fun g3(foo: String, other: A): Boolean {
return other.foo == foo
}
fun g4(foo: String?): Boolean {
return this.foo.equals(foo, ignoreCase = true)
}
fun g5(foo: String?): Boolean {
return this.foo.equals(foo, ignoreCase = true)
}
fun g6(foo: String?, other: A): Boolean {
return other.foo.equals(foo, ignoreCase = true)
}
fun s1(foo: String?) {
this.foo = foo
}
fun s2(foo: String?) {
this.foo = foo
}
fun s3() {
val foo = ""
this.foo = foo
}
}

View File

@@ -1,15 +1,15 @@
class A {
var foo: String? = null
fun g1(foo: String): Boolean {
fun g1(foo: String?): Boolean {
return this.foo == foo
}
fun g2(foo: String): Boolean {
fun g2(foo: String?): Boolean {
return this.foo == foo
}
fun g3(foo: String, other: A): Boolean {
fun g3(foo: String?, other: A): Boolean {
return other.foo == foo
}

View File

@@ -1,4 +1,3 @@
// IGNORE_K2
public class A {
private String mItem;

View File

@@ -0,0 +1,12 @@
class A {
var item: String? = null
fun f1(item: String?) {
this.item = this.item + item
}
fun f2() {
val item = this.item
this.item = item
}
}

View File

@@ -1,4 +1,3 @@
// IGNORE_K2
public class C {
private String myX = "";

View File

@@ -0,0 +1,16 @@
class C {
private var myX: String? = ""
var x: String?
get() {
println("getter invoked")
return myX
}
set(x) {
this.myX = x
}
fun foo() {
println("myX = " + myX)
}
}

View File

@@ -1,4 +1,3 @@
// IGNORE_K2
public class C {
private String x = "";

View File

@@ -0,0 +1,7 @@
class C {
var x: String = ""
get() {
println("getter invoked")
return field
}
}

View File

@@ -1,5 +1,5 @@
class C {
var x: String = ""
var x: String? = ""
get() {
println("getter invoked")
return field

View File

@@ -1,4 +1,3 @@
// IGNORE_K2
public class C {
private String x = "";

View File

@@ -0,0 +1,7 @@
class C {
var x: String = ""
get() {
println("getter invoked")
return field
}
}

View File

@@ -1,5 +1,5 @@
class C {
var x: String = ""
var x: String? = ""
get() {
println("getter invoked")
return field

View File

@@ -1,4 +1,3 @@
// IGNORE_K2
public class C {
private String x = "old";

View File

@@ -0,0 +1,19 @@
class C {
var x: String? = "old"
get() {
println("side effect")
return field
}
set(x) {
println("old value: " + field)
field = x
}
companion object {
@JvmStatic
fun main(args: Array<String>) {
val c = C()
c.x = "new"
}
}
}

View File

@@ -1,4 +1,3 @@
// IGNORE_K2
class C {
private int field = 0;

View File

@@ -0,0 +1,8 @@
internal class C {
var default: Int = 0
private set
fun foo() {
println(this.default)
}
}

View File

@@ -1,4 +1,3 @@
// IGNORE_K2
class C {
private int field = 0;

View File

@@ -0,0 +1,8 @@
internal class C {
var `this`: Int = 0
private set
fun foo() {
println(this.`this`)
}
}

View File

@@ -1,4 +1,3 @@
// IGNORE_K2
public class Test {
public String getA() {
return b;

View File

@@ -0,0 +1,8 @@
class Test {
fun getA(): String? {
return b
}
var a: String? = "t"
var b: String? = "s"
}

View File

@@ -1,4 +1,3 @@
// IGNORE_K2
class A {
private Object o;

View File

@@ -0,0 +1,11 @@
internal class A {
var value: Any? = null
private set
fun setValue(s: String?) {
takesString(s)
this.value = s
}
private fun takesString(s: String?) {}
}

View File

@@ -1,4 +1,3 @@
// IGNORE_K2
public class C {
private String myX = "";

View File

@@ -0,0 +1,14 @@
class C {
private var myX = ""
var x: String
get() = myX
set(x) {
println("setter invoked")
this.myX = x
}
fun foo() {
myX = "a"
}
}

View File

@@ -1,7 +1,7 @@
class C {
private var myX = ""
private var myX: String? = ""
var x: String
var x: String?
get() = myX
set(x) {
println("setter invoked")

View File

@@ -1,4 +1,3 @@
// IGNORE_K2
public class C {
private String x = "";

View File

@@ -0,0 +1,7 @@
class C {
var x: String = ""
set(value) {
println("setter invoked")
field = value
}
}

View File

@@ -1,5 +1,5 @@
class C {
var x: String = ""
var x: String? = ""
set(value) {
println("setter invoked")
field = value

View File

@@ -1,4 +1,3 @@
// IGNORE_K2
public class C {
private String x = "";

Some files were not shown because too many files have changed in this diff Show More