FIR: add pointer from primary constructor param to correspondng property

This commit is contained in:
Tianyu Geng
2021-10-19 11:18:39 -07:00
committed by Roman Golyshev
parent 112f365414
commit 9b3add0130
18 changed files with 31 additions and 19 deletions
@@ -10,7 +10,9 @@ import org.jetbrains.kotlin.fir.*
import org.jetbrains.kotlin.fir.builder.Context
import org.jetbrains.kotlin.fir.builder.filterUseSiteTarget
import org.jetbrains.kotlin.fir.builder.initContainingClassAttr
import org.jetbrains.kotlin.fir.declarations.*
import org.jetbrains.kotlin.fir.declarations.FirDeclarationOrigin
import org.jetbrains.kotlin.fir.declarations.FirProperty
import org.jetbrains.kotlin.fir.declarations.FirValueParameter
import org.jetbrains.kotlin.fir.declarations.builder.buildProperty
import org.jetbrains.kotlin.fir.declarations.impl.FirDeclarationStatusImpl
import org.jetbrains.kotlin.fir.declarations.impl.FirDefaultPropertyGetter
@@ -112,6 +114,7 @@ class ValueParameter(
if (firValueParameter.isVararg) {
this.isFromVararg = true
}
firValueParameter.correspondingProperty = this
this.fromPrimaryConstructor = true
}
}
@@ -625,6 +625,7 @@ open class RawFirBuilder(
if (firParameter.isVararg) {
isFromVararg = true
}
firParameter.correspondingProperty = this
fromPrimaryConstructor = true
}
}
@@ -12,7 +12,7 @@ FILE: annotation.kt
}
@base() public? final? class correct : R|kotlin/Any| {
public? [ContainingClassKey=correct] constructor(@base() x: Int): R|correct| {
public? [ContainingClassKey=correct] constructor([CorrespondingProperty=/correct.x] @base() x: Int): R|correct| {
super<R|kotlin/Any|>()
}
@@ -1,6 +1,6 @@
FILE: derivedClass.kt
public? open class Base<T> : R|kotlin/Any| {
public? [ContainingClassKey=Base] constructor<T>(x: T): R|Base<T>| {
public? [ContainingClassKey=Base] constructor<T>([CorrespondingProperty=/Base.x] x: T): R|Base<T>| {
super<R|kotlin/Any|>()
}
@@ -15,7 +15,7 @@ FILE: enums.kt
}
public? final? enum class Planet : R|kotlin/Enum<Planet>| {
private [ContainingClassKey=Planet] constructor(m: Double, r: Double): R|Planet| {
private [ContainingClassKey=Planet] constructor([CorrespondingProperty=/Planet.m] m: Double, [CorrespondingProperty=/Planet.r] r: Double): R|Planet| {
super<R|kotlin/Enum<Planet>|>()
}
@@ -81,7 +81,7 @@ FILE: enums.kt
}
public? final? enum class PseudoInsn : R|kotlin/Enum<PseudoInsn>| {
private [ContainingClassKey=PseudoInsn] constructor(signature: String = String(()V)): R|PseudoInsn| {
private [ContainingClassKey=PseudoInsn] constructor([CorrespondingProperty=/PseudoInsn.signature] signature: String = String(()V)): R|PseudoInsn| {
super<R|kotlin/Enum<PseudoInsn>|>()
}
@@ -14,7 +14,7 @@ FILE: enums2.kt
}
public? final? enum class SomeEnum : R|kotlin/Enum<SomeEnum>| {
private [ContainingClassKey=SomeEnum] constructor(x: Some): R|SomeEnum| {
private [ContainingClassKey=SomeEnum] constructor([CorrespondingProperty=/SomeEnum.x] x: Some): R|SomeEnum| {
super<R|kotlin/Enum<SomeEnum>|>()
}
@@ -1,6 +1,6 @@
FILE: nestedClass.kt
public? abstract class Base : R|kotlin/Any| {
public? [ContainingClassKey=Base] constructor(s: String): R|Base| {
public? [ContainingClassKey=Base] constructor([CorrespondingProperty=/Base.s] s: String): R|Base| {
super<R|kotlin/Any|>()
}
@@ -21,7 +21,7 @@ FILE: annotated.kt
^foo IntegerLiteral(42)
}
public? final? data class Two : R|kotlin/Any| {
public? [ContainingClassKey=Two] constructor(x: Int, y: Int): R|Two| {
public? [ContainingClassKey=Two] constructor([CorrespondingProperty=/Two.x] x: Int, [CorrespondingProperty=/Two.y] y: Int): R|Two| {
super<R|kotlin/Any|>()
}
@@ -5,7 +5,7 @@ FILE: arrayAccess.kt
^foo IntegerLiteral(1)
}
public? final? class Wrapper : R|kotlin/Any| {
public? [ContainingClassKey=Wrapper] constructor(v: IntArray): R|Wrapper| {
public? [ContainingClassKey=Wrapper] constructor([CorrespondingProperty=/Wrapper.v] v: IntArray): R|Wrapper| {
super<R|kotlin/Any|>()
}
@@ -9,7 +9,7 @@ FILE: calls.kt
^testRegular IntegerLiteral(3).distance#(IntegerLiteral(4))
}
public? final? class My : R|kotlin/Any| {
public? [ContainingClassKey=My] constructor(x: Int): R|My| {
public? [ContainingClassKey=My] constructor([CorrespondingProperty=/My.x] x: Int): R|My| {
super<R|kotlin/Any|>()
}
@@ -1,6 +1,6 @@
FILE: collectionLiterals.kt
public? final? annotation class Ann1 : R|kotlin/Annotation| {
public? [ContainingClassKey=Ann1] constructor(arr: IntArray): R|Ann1| {
public? [ContainingClassKey=Ann1] constructor([CorrespondingProperty=/Ann1.arr] arr: IntArray): R|Ann1| {
super<R|kotlin/Any|>()
}
@@ -9,7 +9,7 @@ FILE: collectionLiterals.kt
}
public? final? annotation class Ann2 : R|kotlin/Annotation| {
public? [ContainingClassKey=Ann2] constructor(arr: DoubleArray): R|Ann2| {
public? [ContainingClassKey=Ann2] constructor([CorrespondingProperty=/Ann2.arr] arr: DoubleArray): R|Ann2| {
super<R|kotlin/Any|>()
}
@@ -18,7 +18,7 @@ FILE: collectionLiterals.kt
}
public? final? annotation class Ann3 : R|kotlin/Annotation| {
public? [ContainingClassKey=Ann3] constructor(arr: Array<String>): R|Ann3| {
public? [ContainingClassKey=Ann3] constructor([CorrespondingProperty=/Ann3.arr] arr: Array<String>): R|Ann3| {
super<R|kotlin/Any|>()
}
@@ -1,6 +1,6 @@
FILE: destructuring.kt
public? final? data class Some : R|kotlin/Any| {
public? [ContainingClassKey=Some] constructor(first: Int, second: Double, third: String): R|Some| {
public? [ContainingClassKey=Some] constructor([CorrespondingProperty=/Some.first] first: Int, [CorrespondingProperty=/Some.second] second: Double, [CorrespondingProperty=/Some.third] third: String): R|Some| {
super<R|kotlin/Any|>()
}
@@ -50,7 +50,7 @@ FILE: for.kt
}
public? final? data class Some : R|kotlin/Any| {
public? [ContainingClassKey=Some] constructor(x: Int, y: Int): R|Some| {
public? [ContainingClassKey=Some] constructor([CorrespondingProperty=/Some.x] x: Int, [CorrespondingProperty=/Some.y] y: Int): R|Some| {
super<R|kotlin/Any|>()
}
@@ -1,6 +1,6 @@
FILE: lambda.kt
public? final? data class Tuple : R|kotlin/Any| {
public? [ContainingClassKey=Tuple] constructor(x: Int, y: Int): R|Tuple| {
public? [ContainingClassKey=Tuple] constructor([CorrespondingProperty=/Tuple.x] x: Int, [CorrespondingProperty=/Tuple.y] y: Int): R|Tuple| {
super<R|kotlin/Any|>()
}
@@ -1,7 +1,7 @@
FILE: locals.kt
public? final? fun withLocals(p: Int): Int {
local final? class Local : R|kotlin/Any| {
public? [ContainingClassKey=Local] constructor(pp: Int): R|Local| {
public? [ContainingClassKey=Local] constructor([CorrespondingProperty=<local>/pp] pp: Int): R|Local| {
super<R|kotlin/Any|>()
}
@@ -31,7 +31,7 @@ FILE: unary.kt
}
public? final? class X : R|kotlin/Any| {
public? [ContainingClassKey=X] constructor(i: Int): R|X| {
public? [ContainingClassKey=X] constructor([CorrespondingProperty=/X.i] i: Int): R|X| {
super<R|kotlin/Any|>()
}
@@ -74,7 +74,7 @@ FILE: unary.kt
}
public? final? class Y : R|kotlin/Any| {
public? [ContainingClassKey=Y] constructor(arr: Array<Int>): R|Y| {
public? [ContainingClassKey=Y] constructor([CorrespondingProperty=/Y.arr] arr: Array<Int>): R|Y| {
super<R|kotlin/Any|>()
}
@@ -123,3 +123,10 @@ private object MatchingParameterFunctionTypeKey : FirDeclarationDataKey()
*/
var <D : FirAnonymousFunction>
D.matchingParameterFunctionType: ConeKotlinType? by FirDeclarationDataRegistry.data(MatchingParameterFunctionTypeKey)
private object CorrespondingProperty : FirDeclarationDataKey()
/**
* The corresponding [FirProperty] if the current value parameter is a `val` or `var` declared inside the primary constructor.
*/
var FirValueParameter.correspondingProperty: FirProperty? by FirDeclarationDataRegistry.data(CorrespondingProperty)
@@ -437,6 +437,7 @@ open class FirRenderer(builder: StringBuilder, protected val mode: RenderMode =
private fun Any.renderAsDeclarationAttributeValue() = when (this) {
is FirCallableSymbol<*> -> callableId.toString()
is FirClassLikeSymbol<*> -> classId.asString()
is FirProperty -> symbol.callableId.toString()
else -> toString()
}