[FIR] Generate java declarations for record components of java records

^KT-53964 Fixed
This commit is contained in:
Dmitriy Novozhilov
2022-09-30 14:51:58 +03:00
parent 2ed6e9febf
commit c0ad67c4f9
35 changed files with 469 additions and 71 deletions
@@ -14,11 +14,11 @@ class MyRec(
)
fun foo(jr: JRecord) {
JRecord(<!TOO_MANY_ARGUMENTS!>1<!>, <!TOO_MANY_ARGUMENTS!>""<!>)
JRecord(1, "")
jr.<!UNRESOLVED_REFERENCE!>x<!>()
jr.<!UNRESOLVED_REFERENCE!>y<!>()
jr.x()
jr.y()
jr.<!UNRESOLVED_REFERENCE!>x<!>
jr.<!UNRESOLVED_REFERENCE!>y<!>
jr.x
jr.y
}
@@ -0,0 +1,22 @@
// FIR_IDENTICAL
// FIR_IDE_IGNORE
// API_VERSION: 1.5
// LANGUAGE: +JvmRecordSupport
// SCOPE_DUMP: MyRecord:x
// FILE: MyRecord.java
public record MyRecord(String x) {
public String x() {
System.out.println("hello");
return x;
}
}
// FILE: main.kt
fun takeString(s: String) {}
fun foo(mr: MyRecord) {
takeString(mr.x)
takeString(mr.x())
}
@@ -0,0 +1,3 @@
MyRecord:
[Enhancement]: public open fun x(): R|kotlin/String!| from Java enhancement scope for /MyRecord [id: 0]
@@ -0,0 +1,12 @@
package
public fun foo(/*0*/ mr: MyRecord): kotlin.Unit
public fun takeString(/*0*/ s: kotlin.String): kotlin.Unit
/*record*/ public final class MyRecord : java.lang.Record {
public constructor MyRecord(/*0*/ x: kotlin.String!)
public abstract override /*1*/ /*fake_override*/ fun equals(/*0*/ other: kotlin.Any?): kotlin.Boolean
public abstract override /*1*/ /*fake_override*/ fun hashCode(): kotlin.Int
public abstract override /*1*/ /*fake_override*/ fun toString(): kotlin.String
/*record component*/ public open fun x(): kotlin.String!
}
@@ -0,0 +1,31 @@
// FIR_IDENTICAL
// FIR_IDE_IGNORE
// FILE: MyInterface.java
public interface MyInterface<T> {
T x();
}
// FILE: MyRecord.java
public record MyRecord<T>(T x) implements MyInterface<T> {}
// FILE: main.kt
fun takeInt(x: Int) {}
fun takeString(s: String) {}
fun takeAny(a: Any) {}
fun test_1(mr: MyRecord<Int>) {
takeInt(mr.x)
takeInt(mr.x())
}
fun test_2(mr: MyRecord<String>) {
takeString(mr.x)
takeString(mr.x())
}
fun test_3(mr: MyRecord<*>) {
takeAny(mr.x)
takeAny(mr.x())
}
@@ -0,0 +1,24 @@
package
public fun takeAny(/*0*/ a: kotlin.Any): kotlin.Unit
public fun takeInt(/*0*/ x: kotlin.Int): kotlin.Unit
public fun takeString(/*0*/ s: kotlin.String): kotlin.Unit
public fun test_1(/*0*/ mr: MyRecord<kotlin.Int>): kotlin.Unit
public fun test_2(/*0*/ mr: MyRecord<kotlin.String>): kotlin.Unit
public fun test_3(/*0*/ mr: MyRecord<*>): kotlin.Unit
public interface MyInterface</*0*/ T : kotlin.Any!> {
public open override /*1*/ /*fake_override*/ fun equals(/*0*/ other: kotlin.Any?): kotlin.Boolean
public open override /*1*/ /*fake_override*/ fun hashCode(): kotlin.Int
public open override /*1*/ /*fake_override*/ fun toString(): kotlin.String
public abstract fun x(): T!
}
/*record*/ public final class MyRecord</*0*/ T : kotlin.Any!> : java.lang.Record, MyInterface<T!> {
public constructor MyRecord</*0*/ T : kotlin.Any!>(/*0*/ x: T!)
public abstract override /*2*/ /*fake_override*/ fun equals(/*0*/ other: kotlin.Any?): kotlin.Boolean
public abstract override /*2*/ /*fake_override*/ fun hashCode(): kotlin.Int
public abstract override /*2*/ /*fake_override*/ fun toString(): kotlin.String
/*record component*/ public open override /*1*/ fun x(): T!
}
@@ -1,19 +0,0 @@
// FIR_IDE_IGNORE
// !API_VERSION: 1.5
// !LANGUAGE: +JvmRecordSupport
// FILE: MyRecord.java
public record MyRecord(int x, CharSequence y) {
}
// FILE: main.kt
fun foo(mr: MyRecord) {
MyRecord(<!TOO_MANY_ARGUMENTS!>1<!>, <!TOO_MANY_ARGUMENTS!>""<!>)
mr.<!UNRESOLVED_REFERENCE!>x<!>()
mr.<!UNRESOLVED_REFERENCE!>y<!>()
mr.<!UNRESOLVED_REFERENCE!>x<!>
mr.<!UNRESOLVED_REFERENCE!>y<!>
}
@@ -1,19 +1,26 @@
// FIR_IDENTICAL
// FIR_IDE_IGNORE
// !API_VERSION: 1.5
// !LANGUAGE: +JvmRecordSupport
// FILE: MyRecord.java
public record MyRecord(int x, CharSequence y) {
// API_VERSION: 1.5
// LANGUAGE: +JvmRecordSupport
// SCOPE_DUMP: MyRecord:x;y;z
}
// FILE: MyRecord.java
public record MyRecord(CharSequence x, int y, String... z) {}
// FILE: main.kt
fun takeInt(x: Int) {}
fun takeCharSequence(s: CharSequence) {}
fun takeStringArray(a: Array<out String>) {}
fun foo(mr: MyRecord) {
MyRecord(1, "")
MyRecord("", 1, "a", "b")
mr.x()
mr.y()
takeCharSequence(mr.x())
takeInt(mr.y())
takeStringArray(mr.z())
mr.x
mr.y
takeCharSequence(mr.x)
takeInt(mr.y)
takeStringArray(mr.z)
}
@@ -0,0 +1,5 @@
MyRecord:
[Enhancement]: public final fun x(): R|kotlin/CharSequence!| from Java enhancement scope for /MyRecord [id: 0]
[Enhancement]: public final fun y(): R|kotlin/Int| from Java enhancement scope for /MyRecord [id: 0]
[Enhancement]: public final fun z(): R|ft<kotlin/Array<kotlin/String!>, kotlin/Array<out kotlin/String!>?>| from Java enhancement scope for /MyRecord [id: 0]
@@ -1,12 +1,17 @@
package
public fun foo(/*0*/ mr: MyRecord): kotlin.Unit
public fun takeCharSequence(/*0*/ s: kotlin.CharSequence): kotlin.Unit
public fun takeInt(/*0*/ x: kotlin.Int): kotlin.Unit
public fun takeStringArray(/*0*/ a: kotlin.Array<out kotlin.String>): kotlin.Unit
/*record*/ public final class MyRecord : java.lang.Record {
public constructor MyRecord(/*0*/ x: kotlin.Int, /*1*/ y: kotlin.CharSequence!)
public constructor MyRecord(/*0*/ x: kotlin.CharSequence!, /*1*/ y: kotlin.Int, /*2*/ vararg z: kotlin.String! /*kotlin.Array<(out) kotlin.String!>!*/)
public abstract override /*1*/ /*fake_override*/ fun equals(/*0*/ other: kotlin.Any?): kotlin.Boolean
public abstract override /*1*/ /*fake_override*/ fun hashCode(): kotlin.Int
public abstract override /*1*/ /*fake_override*/ fun toString(): kotlin.String
/*record component*/ public open fun x(): kotlin.Int
/*record component*/ public open fun y(): kotlin.CharSequence!
/*record component*/ public open fun x(): kotlin.CharSequence!
/*record component*/ public open fun y(): kotlin.Int
/*record component*/ public open fun z(): kotlin.Array<(out) kotlin.String!>!
}