FIR: include properties from primary constructors in tree
This commit is contained in:
@@ -74,12 +74,10 @@ class RawFirBuilder(val session: FirSession) {
|
||||
}
|
||||
|
||||
private inner class Visitor : KtVisitor<FirElement, Unit>() {
|
||||
@Suppress("UNCHECKED_CAST")
|
||||
private fun <R : FirElement> KtElement?.convertSafe(): R? =
|
||||
private inline fun <reified R : FirElement> KtElement?.convertSafe(): R? =
|
||||
this?.accept(this@Visitor, Unit) as? R
|
||||
|
||||
@Suppress("UNCHECKED_CAST")
|
||||
private fun <R : FirElement> KtElement.convert(): R =
|
||||
private inline fun <reified R : FirElement> KtElement.convert(): R =
|
||||
this.accept(this@Visitor, Unit) as R
|
||||
|
||||
private fun KtTypeReference?.toFirOrImplicitType(): FirType =
|
||||
@@ -126,7 +124,6 @@ class RawFirBuilder(val session: FirSession) {
|
||||
val firValueParameter = FirValueParameterImpl(
|
||||
session,
|
||||
this,
|
||||
hasValOrVar(),
|
||||
nameAsSafeName,
|
||||
when {
|
||||
typeReference != null -> typeReference.toFirOrErrorType()
|
||||
@@ -142,6 +139,31 @@ class RawFirBuilder(val session: FirSession) {
|
||||
return firValueParameter
|
||||
}
|
||||
|
||||
private fun KtParameter.toFirProperty(): FirProperty {
|
||||
require(hasValOrVar())
|
||||
val type = typeReference.toFirOrErrorType()
|
||||
val firProperty = FirMemberPropertyImpl(
|
||||
session,
|
||||
this,
|
||||
nameAsSafeName,
|
||||
visibility,
|
||||
modality,
|
||||
platformStatus,
|
||||
isOverride = hasModifier(KtTokens.OVERRIDE_KEYWORD),
|
||||
isConst = false,
|
||||
isLateInit = false,
|
||||
receiverType = null,
|
||||
returnType = type,
|
||||
isVar = valOrVarKeyword?.node?.elementType == KtTokens.VAR_KEYWORD,
|
||||
initializer = null,
|
||||
getter = FirDefaultPropertyGetter(session, this, type),
|
||||
setter = FirDefaultPropertySetter(session, this, type),
|
||||
delegate = null
|
||||
)
|
||||
extractAnnotationsTo(firProperty)
|
||||
return firProperty
|
||||
}
|
||||
|
||||
private fun KtModifierListOwner.extractAnnotationsTo(container: FirAbstractAnnotatedDeclaration) {
|
||||
for (annotationEntry in annotationEntries) {
|
||||
container.annotations += annotationEntry.convert<FirAnnotationCall>()
|
||||
@@ -297,6 +319,12 @@ class RawFirBuilder(val session: FirSession) {
|
||||
classOrObject.extractAnnotationsTo(firClass)
|
||||
classOrObject.extractTypeParametersTo(firClass)
|
||||
classOrObject.extractSuperTypeListEntriesTo(firClass)
|
||||
classOrObject.primaryConstructor?.valueParameters?.forEach {
|
||||
if (it.hasValOrVar()) {
|
||||
firClass.declarations += it.toFirProperty()
|
||||
}
|
||||
}
|
||||
|
||||
for (declaration in classOrObject.declarations) {
|
||||
firClass.declarations += declaration.convert<FirDeclaration>()
|
||||
}
|
||||
|
||||
-1
@@ -18,7 +18,6 @@ import org.jetbrains.kotlin.fir.visitors.FirTransformer
|
||||
class FirValueParameterImpl(
|
||||
session: FirSession,
|
||||
psi: PsiElement?,
|
||||
val isProperty: Boolean,
|
||||
name: Name,
|
||||
override var returnType: FirType,
|
||||
override val defaultValue: FirExpression?,
|
||||
|
||||
@@ -2,6 +2,9 @@ FILE: derivedClass.kt
|
||||
<T> public? open class Base {
|
||||
public? constructor(x: T)
|
||||
|
||||
public? final? property x(val): T
|
||||
public? get(): T
|
||||
|
||||
}
|
||||
<T : Any> public? final class Derived : Base<T> {
|
||||
public? constructor(x: T): super(STUB)
|
||||
|
||||
@@ -13,6 +13,12 @@ FILE: enums.kt
|
||||
public? final enum class Planet {
|
||||
public? constructor(m: Double, r: Double)
|
||||
|
||||
public? final? property m(val): Double
|
||||
public? get(): Double
|
||||
|
||||
internal final? property r(val): Double
|
||||
public? get(): Double
|
||||
|
||||
public? final enum entry MERCURY : Planet {
|
||||
public? open? override function sayHello(): <implicit> {
|
||||
}
|
||||
|
||||
@@ -8,6 +8,9 @@ FILE: enums2.kt
|
||||
public? final enum class SomeEnum {
|
||||
public? constructor(x: Some)
|
||||
|
||||
public? final? property x(val): Some
|
||||
public? get(): Some
|
||||
|
||||
public? final enum entry FIRST : SomeEnum {
|
||||
public? open? override function check(y: Some): Boolean {
|
||||
STUB
|
||||
|
||||
@@ -2,6 +2,9 @@ FILE: nestedClass.kt
|
||||
public? abstract class Base {
|
||||
public? constructor(s: String)
|
||||
|
||||
public? final? property s(val): String
|
||||
public? get(): String
|
||||
|
||||
}
|
||||
public? final class Outer {
|
||||
public? final class Derived : Base {
|
||||
|
||||
@@ -2,6 +2,9 @@ FILE: derivedClass.kt
|
||||
<T> public? open class Base {
|
||||
public? constructor(x: R|T|)
|
||||
|
||||
public? final? property x(val): R|T|
|
||||
public? get(): R|T|
|
||||
|
||||
}
|
||||
<T : R|kotlin/Any|> public? final class Derived : R|Base<T>| {
|
||||
public? constructor(x: R|T|): super(STUB)
|
||||
|
||||
+3
@@ -8,6 +8,9 @@ FILE: enum.kt
|
||||
public? final enum class SomeEnum {
|
||||
public? constructor(x: R|Some|)
|
||||
|
||||
public? final? property x(val): R|Some|
|
||||
public? get(): R|Some|
|
||||
|
||||
public? final enum entry FIRST : R|SomeEnum| {
|
||||
public? open? override function check(y: R|Some|): R|kotlin/Boolean| {
|
||||
STUB
|
||||
|
||||
@@ -10,6 +10,9 @@ FILE: Annotations.kt
|
||||
@R|annotations/WithString|(STUB) public? final class Second : @R|annotations/WithInt|(STUB) R|test/First| {
|
||||
public? constructor(y: R|kotlin/Char|): super()
|
||||
|
||||
public? final? property y(val): R|kotlin/Char|
|
||||
public? get(): R|kotlin/Char|
|
||||
|
||||
public? open? override function foo(arg: R|kotlin/Double|): R|error: Not supported: FirImplicitTypeImpl| {
|
||||
}
|
||||
|
||||
|
||||
@@ -2,6 +2,9 @@ FILE: nestedClass.kt
|
||||
public? abstract class Base {
|
||||
public? constructor(s: R|kotlin/String|)
|
||||
|
||||
public? final? property s(val): R|kotlin/String|
|
||||
public? get(): R|kotlin/String|
|
||||
|
||||
}
|
||||
public? final class Outer {
|
||||
public? final class Derived : R|Base| {
|
||||
|
||||
Reference in New Issue
Block a user