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>() {
|
private inner class Visitor : KtVisitor<FirElement, Unit>() {
|
||||||
@Suppress("UNCHECKED_CAST")
|
private inline fun <reified R : FirElement> KtElement?.convertSafe(): R? =
|
||||||
private fun <R : FirElement> KtElement?.convertSafe(): R? =
|
|
||||||
this?.accept(this@Visitor, Unit) as? R
|
this?.accept(this@Visitor, Unit) as? R
|
||||||
|
|
||||||
@Suppress("UNCHECKED_CAST")
|
private inline fun <reified R : FirElement> KtElement.convert(): R =
|
||||||
private fun <R : FirElement> KtElement.convert(): R =
|
|
||||||
this.accept(this@Visitor, Unit) as R
|
this.accept(this@Visitor, Unit) as R
|
||||||
|
|
||||||
private fun KtTypeReference?.toFirOrImplicitType(): FirType =
|
private fun KtTypeReference?.toFirOrImplicitType(): FirType =
|
||||||
@@ -126,7 +124,6 @@ class RawFirBuilder(val session: FirSession) {
|
|||||||
val firValueParameter = FirValueParameterImpl(
|
val firValueParameter = FirValueParameterImpl(
|
||||||
session,
|
session,
|
||||||
this,
|
this,
|
||||||
hasValOrVar(),
|
|
||||||
nameAsSafeName,
|
nameAsSafeName,
|
||||||
when {
|
when {
|
||||||
typeReference != null -> typeReference.toFirOrErrorType()
|
typeReference != null -> typeReference.toFirOrErrorType()
|
||||||
@@ -142,6 +139,31 @@ class RawFirBuilder(val session: FirSession) {
|
|||||||
return firValueParameter
|
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) {
|
private fun KtModifierListOwner.extractAnnotationsTo(container: FirAbstractAnnotatedDeclaration) {
|
||||||
for (annotationEntry in annotationEntries) {
|
for (annotationEntry in annotationEntries) {
|
||||||
container.annotations += annotationEntry.convert<FirAnnotationCall>()
|
container.annotations += annotationEntry.convert<FirAnnotationCall>()
|
||||||
@@ -297,6 +319,12 @@ class RawFirBuilder(val session: FirSession) {
|
|||||||
classOrObject.extractAnnotationsTo(firClass)
|
classOrObject.extractAnnotationsTo(firClass)
|
||||||
classOrObject.extractTypeParametersTo(firClass)
|
classOrObject.extractTypeParametersTo(firClass)
|
||||||
classOrObject.extractSuperTypeListEntriesTo(firClass)
|
classOrObject.extractSuperTypeListEntriesTo(firClass)
|
||||||
|
classOrObject.primaryConstructor?.valueParameters?.forEach {
|
||||||
|
if (it.hasValOrVar()) {
|
||||||
|
firClass.declarations += it.toFirProperty()
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
for (declaration in classOrObject.declarations) {
|
for (declaration in classOrObject.declarations) {
|
||||||
firClass.declarations += declaration.convert<FirDeclaration>()
|
firClass.declarations += declaration.convert<FirDeclaration>()
|
||||||
}
|
}
|
||||||
|
|||||||
-1
@@ -18,7 +18,6 @@ import org.jetbrains.kotlin.fir.visitors.FirTransformer
|
|||||||
class FirValueParameterImpl(
|
class FirValueParameterImpl(
|
||||||
session: FirSession,
|
session: FirSession,
|
||||||
psi: PsiElement?,
|
psi: PsiElement?,
|
||||||
val isProperty: Boolean,
|
|
||||||
name: Name,
|
name: Name,
|
||||||
override var returnType: FirType,
|
override var returnType: FirType,
|
||||||
override val defaultValue: FirExpression?,
|
override val defaultValue: FirExpression?,
|
||||||
|
|||||||
@@ -2,6 +2,9 @@ FILE: derivedClass.kt
|
|||||||
<T> public? open class Base {
|
<T> public? open class Base {
|
||||||
public? constructor(x: T)
|
public? constructor(x: T)
|
||||||
|
|
||||||
|
public? final? property x(val): T
|
||||||
|
public? get(): T
|
||||||
|
|
||||||
}
|
}
|
||||||
<T : Any> public? final class Derived : Base<T> {
|
<T : Any> public? final class Derived : Base<T> {
|
||||||
public? constructor(x: T): super(STUB)
|
public? constructor(x: T): super(STUB)
|
||||||
|
|||||||
@@ -13,6 +13,12 @@ FILE: enums.kt
|
|||||||
public? final enum class Planet {
|
public? final enum class Planet {
|
||||||
public? constructor(m: Double, r: Double)
|
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? final enum entry MERCURY : Planet {
|
||||||
public? open? override function sayHello(): <implicit> {
|
public? open? override function sayHello(): <implicit> {
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -8,6 +8,9 @@ FILE: enums2.kt
|
|||||||
public? final enum class SomeEnum {
|
public? final enum class SomeEnum {
|
||||||
public? constructor(x: Some)
|
public? constructor(x: Some)
|
||||||
|
|
||||||
|
public? final? property x(val): Some
|
||||||
|
public? get(): Some
|
||||||
|
|
||||||
public? final enum entry FIRST : SomeEnum {
|
public? final enum entry FIRST : SomeEnum {
|
||||||
public? open? override function check(y: Some): Boolean {
|
public? open? override function check(y: Some): Boolean {
|
||||||
STUB
|
STUB
|
||||||
|
|||||||
@@ -2,6 +2,9 @@ FILE: nestedClass.kt
|
|||||||
public? abstract class Base {
|
public? abstract class Base {
|
||||||
public? constructor(s: String)
|
public? constructor(s: String)
|
||||||
|
|
||||||
|
public? final? property s(val): String
|
||||||
|
public? get(): String
|
||||||
|
|
||||||
}
|
}
|
||||||
public? final class Outer {
|
public? final class Outer {
|
||||||
public? final class Derived : Base {
|
public? final class Derived : Base {
|
||||||
|
|||||||
@@ -2,6 +2,9 @@ FILE: derivedClass.kt
|
|||||||
<T> public? open class Base {
|
<T> public? open class Base {
|
||||||
public? constructor(x: R|T|)
|
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>| {
|
<T : R|kotlin/Any|> public? final class Derived : R|Base<T>| {
|
||||||
public? constructor(x: R|T|): super(STUB)
|
public? constructor(x: R|T|): super(STUB)
|
||||||
|
|||||||
+3
@@ -8,6 +8,9 @@ FILE: enum.kt
|
|||||||
public? final enum class SomeEnum {
|
public? final enum class SomeEnum {
|
||||||
public? constructor(x: R|Some|)
|
public? constructor(x: R|Some|)
|
||||||
|
|
||||||
|
public? final? property x(val): R|Some|
|
||||||
|
public? get(): R|Some|
|
||||||
|
|
||||||
public? final enum entry FIRST : R|SomeEnum| {
|
public? final enum entry FIRST : R|SomeEnum| {
|
||||||
public? open? override function check(y: R|Some|): R|kotlin/Boolean| {
|
public? open? override function check(y: R|Some|): R|kotlin/Boolean| {
|
||||||
STUB
|
STUB
|
||||||
|
|||||||
@@ -10,6 +10,9 @@ FILE: Annotations.kt
|
|||||||
@R|annotations/WithString|(STUB) public? final class Second : @R|annotations/WithInt|(STUB) R|test/First| {
|
@R|annotations/WithString|(STUB) public? final class Second : @R|annotations/WithInt|(STUB) R|test/First| {
|
||||||
public? constructor(y: R|kotlin/Char|): super()
|
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| {
|
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? abstract class Base {
|
||||||
public? constructor(s: R|kotlin/String|)
|
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 Outer {
|
||||||
public? final class Derived : R|Base| {
|
public? final class Derived : R|Base| {
|
||||||
|
|||||||
Reference in New Issue
Block a user