Introduce FirResolvedTypeRef.delegatedTypeRef to see children types in IDE

This is needed to have access to resolved children types (e.g. type arguments) from IDE
This commit is contained in:
Mikhail Glukhikh
2019-07-31 15:46:06 +03:00
parent 38c1a50c1d
commit 8808c775a4
14 changed files with 41 additions and 5 deletions
@@ -46,6 +46,7 @@ class FirSpecificTypeResolverTransformer(
resolvedType resolvedType
).apply { ).apply {
annotations += typeRef.annotations annotations += typeRef.annotations
delegatedTypeRef = typeRef
}.compose() }.compose()
} }
@@ -1,7 +1,7 @@
import incorrect.directory.My import incorrect.directory.My
class My : My() class My : <!OTHER_ERROR!>My<!>()
class Your : His() class Your : His()
class His : Your() class His : <!OTHER_ERROR!>Your<!>()
@@ -2,4 +2,4 @@ import incorrect.directory.Your
typealias My = incorrect.directory.My typealias My = incorrect.directory.My
typealias Your = Your typealias Your = <!OTHER_ERROR!>Your<!>
@@ -16,4 +16,4 @@ abstract class My<T : Some> {
class Some : T() class Some : T()
} }
abstract class Your<T : Some> : T abstract class Your<T : Some> : <!OTHER_ERROR!>T<!>
@@ -20,6 +20,7 @@ abstract class FirErrorTypeRef : FirResolvedTypeRef(), FirDiagnosticHolder {
abstract override val source: FirSourceElement? abstract override val source: FirSourceElement?
abstract override val annotations: List<FirAnnotationCall> abstract override val annotations: List<FirAnnotationCall>
abstract override val type: ConeKotlinType abstract override val type: ConeKotlinType
abstract override val delegatedTypeRef: FirTypeRef?
abstract override val diagnostic: FirDiagnostic abstract override val diagnostic: FirDiagnostic
override fun <R, D> accept(visitor: FirVisitor<R, D>, data: D): R = visitor.visitErrorTypeRef(this, data) override fun <R, D> accept(visitor: FirVisitor<R, D>, data: D): R = visitor.visitErrorTypeRef(this, data)
@@ -19,6 +19,7 @@ abstract class FirResolvedFunctionTypeRef : FirResolvedTypeRef(), FirFunctionTyp
abstract override val source: FirSourceElement? abstract override val source: FirSourceElement?
abstract override val annotations: List<FirAnnotationCall> abstract override val annotations: List<FirAnnotationCall>
abstract override val type: ConeKotlinType abstract override val type: ConeKotlinType
abstract override val delegatedTypeRef: FirTypeRef?
abstract override val isMarkedNullable: Boolean abstract override val isMarkedNullable: Boolean
abstract override val receiverTypeRef: FirTypeRef? abstract override val receiverTypeRef: FirTypeRef?
abstract override val valueParameters: List<FirValueParameter> abstract override val valueParameters: List<FirValueParameter>
@@ -19,6 +19,7 @@ abstract class FirResolvedTypeRef : FirPureAbstractElement(), FirTypeRef {
abstract override val source: FirSourceElement? abstract override val source: FirSourceElement?
abstract override val annotations: List<FirAnnotationCall> abstract override val annotations: List<FirAnnotationCall>
abstract val type: ConeKotlinType abstract val type: ConeKotlinType
abstract val delegatedTypeRef: FirTypeRef?
override fun <R, D> accept(visitor: FirVisitor<R, D>, data: D): R = visitor.visitResolvedTypeRef(this, data) override fun <R, D> accept(visitor: FirVisitor<R, D>, data: D): R = visitor.visitResolvedTypeRef(this, data)
} }
@@ -12,6 +12,7 @@ import org.jetbrains.kotlin.fir.impl.FirAbstractAnnotatedElement
import org.jetbrains.kotlin.fir.types.ConeClassErrorType import org.jetbrains.kotlin.fir.types.ConeClassErrorType
import org.jetbrains.kotlin.fir.types.ConeKotlinType import org.jetbrains.kotlin.fir.types.ConeKotlinType
import org.jetbrains.kotlin.fir.types.FirErrorTypeRef import org.jetbrains.kotlin.fir.types.FirErrorTypeRef
import org.jetbrains.kotlin.fir.types.FirTypeRef
import org.jetbrains.kotlin.fir.visitors.* import org.jetbrains.kotlin.fir.visitors.*
/* /*
@@ -25,6 +26,7 @@ class FirErrorTypeRefImpl(
) : FirErrorTypeRef(), FirAbstractAnnotatedElement { ) : FirErrorTypeRef(), FirAbstractAnnotatedElement {
override val annotations: MutableList<FirAnnotationCall> = mutableListOf() override val annotations: MutableList<FirAnnotationCall> = mutableListOf()
override val type: ConeKotlinType = ConeClassErrorType(diagnostic.reason) override val type: ConeKotlinType = ConeClassErrorType(diagnostic.reason)
override val delegatedTypeRef: FirTypeRef? get() = null
override fun <R, D> acceptChildren(visitor: FirVisitor<R, D>, data: D) { override fun <R, D> acceptChildren(visitor: FirVisitor<R, D>, data: D) {
annotations.forEach { it.accept(visitor, data) } annotations.forEach { it.accept(visitor, data) }
@@ -27,6 +27,7 @@ class FirResolvedFunctionTypeRefImpl(
override var returnTypeRef: FirTypeRef override var returnTypeRef: FirTypeRef
) : FirResolvedFunctionTypeRef(), FirAbstractAnnotatedElement { ) : FirResolvedFunctionTypeRef(), FirAbstractAnnotatedElement {
override val annotations: MutableList<FirAnnotationCall> = mutableListOf() override val annotations: MutableList<FirAnnotationCall> = mutableListOf()
override val delegatedTypeRef: FirTypeRef? get() = null
override val valueParameters: MutableList<FirValueParameter> = mutableListOf() override val valueParameters: MutableList<FirValueParameter> = mutableListOf()
override fun <R, D> acceptChildren(visitor: FirVisitor<R, D>, data: D) { override fun <R, D> acceptChildren(visitor: FirVisitor<R, D>, data: D) {
@@ -10,6 +10,7 @@ import org.jetbrains.kotlin.fir.expressions.FirAnnotationCall
import org.jetbrains.kotlin.fir.impl.FirAbstractAnnotatedElement import org.jetbrains.kotlin.fir.impl.FirAbstractAnnotatedElement
import org.jetbrains.kotlin.fir.types.ConeKotlinType import org.jetbrains.kotlin.fir.types.ConeKotlinType
import org.jetbrains.kotlin.fir.types.FirResolvedTypeRef import org.jetbrains.kotlin.fir.types.FirResolvedTypeRef
import org.jetbrains.kotlin.fir.types.FirTypeRef
import org.jetbrains.kotlin.fir.visitors.* import org.jetbrains.kotlin.fir.visitors.*
/* /*
@@ -22,13 +23,16 @@ class FirResolvedTypeRefImpl(
override val type: ConeKotlinType override val type: ConeKotlinType
) : FirResolvedTypeRef(), FirAbstractAnnotatedElement { ) : FirResolvedTypeRef(), FirAbstractAnnotatedElement {
override val annotations: MutableList<FirAnnotationCall> = mutableListOf() override val annotations: MutableList<FirAnnotationCall> = mutableListOf()
override var delegatedTypeRef: FirTypeRef? = null
override fun <R, D> acceptChildren(visitor: FirVisitor<R, D>, data: D) { override fun <R, D> acceptChildren(visitor: FirVisitor<R, D>, data: D) {
annotations.forEach { it.accept(visitor, data) } annotations.forEach { it.accept(visitor, data) }
delegatedTypeRef?.accept(visitor, data)
} }
override fun <D> transformChildren(transformer: FirTransformer<D>, data: D): FirResolvedTypeRefImpl { override fun <D> transformChildren(transformer: FirTransformer<D>, data: D): FirResolvedTypeRefImpl {
annotations.transformInplace(transformer, data) annotations.transformInplace(transformer, data)
delegatedTypeRef = delegatedTypeRef?.transformSingle(transformer, data)
return this return this
} }
} }
@@ -13,6 +13,7 @@ import org.jetbrains.kotlin.fir.symbols.impl.ConeClassLikeLookupTagImpl
import org.jetbrains.kotlin.fir.types.ConeClassLikeType import org.jetbrains.kotlin.fir.types.ConeClassLikeType
import org.jetbrains.kotlin.fir.types.ConeKotlinTypeProjection import org.jetbrains.kotlin.fir.types.ConeKotlinTypeProjection
import org.jetbrains.kotlin.fir.types.FirResolvedTypeRef import org.jetbrains.kotlin.fir.types.FirResolvedTypeRef
import org.jetbrains.kotlin.fir.types.FirTypeRef
import org.jetbrains.kotlin.fir.visitors.FirTransformer import org.jetbrains.kotlin.fir.visitors.FirTransformer
import org.jetbrains.kotlin.fir.visitors.FirVisitor import org.jetbrains.kotlin.fir.visitors.FirVisitor
import org.jetbrains.kotlin.name.ClassId import org.jetbrains.kotlin.name.ClassId
@@ -28,6 +29,9 @@ sealed class FirImplicitBuiltinTypeRef(
override val type: ConeClassLikeType = ConeClassLikeTypeImpl(ConeClassLikeLookupTagImpl(id), typeArguments, isNullable) override val type: ConeClassLikeType = ConeClassLikeTypeImpl(ConeClassLikeLookupTagImpl(id), typeArguments, isNullable)
override val delegatedTypeRef: FirTypeRef?
get() = null
override fun <R, D> acceptChildren(visitor: FirVisitor<R, D>, data: D) {} override fun <R, D> acceptChildren(visitor: FirVisitor<R, D>, data: D) {}
override fun <D> transformChildren(transformer: FirTransformer<D>, data: D): FirElement { override fun <D> transformChildren(transformer: FirTransformer<D>, data: D): FirElement {
@@ -486,13 +486,28 @@ object ImplementationConfigurator : AbstractFirTreeImplementationConfigurator()
noSource() noSource()
} }
impl(resolvedTypeRef) impl(resolvedTypeRef) {
default("delegatedTypeRef") {
value = "null"
}
}
val errorTypeRefImpl = impl(errorTypeRef) { val errorTypeRefImpl = impl(errorTypeRef) {
default("type", "ConeClassErrorType(diagnostic.reason)") default("type", "ConeClassErrorType(diagnostic.reason)")
default("delegatedTypeRef") {
value = "null"
withGetter = true
}
useTypes(coneClassErrorTypeType) useTypes(coneClassErrorTypeType)
} }
impl(resolvedFunctionTypeRef) {
default("delegatedTypeRef") {
value = "null"
withGetter = true
}
}
impl(errorFunction) { impl(errorFunction) {
defaultNull("receiverTypeRef", "body", withGetter = true) defaultNull("receiverTypeRef", "body", withGetter = true)
default("returnTypeRef", "FirErrorTypeRefImpl(null, diagnostic)") default("returnTypeRef", "FirErrorTypeRefImpl(null, diagnostic)")
@@ -490,6 +490,7 @@ object NodeConfigurator : AbstractFieldConfigurator() {
resolvedTypeRef.configure { resolvedTypeRef.configure {
+field("type", coneKotlinTypeType) +field("type", coneKotlinTypeType)
+field("delegatedTypeRef", typeRef, nullable = true)
} }
delegatedTypeRef.configure { delegatedTypeRef.configure {
@@ -20,6 +20,7 @@ import org.jetbrains.kotlin.fir.scopes.impl.selfImportingScope
import org.jetbrains.kotlin.fir.symbols.CallableId import org.jetbrains.kotlin.fir.symbols.CallableId
import org.jetbrains.kotlin.fir.symbols.impl.FirCallableSymbol import org.jetbrains.kotlin.fir.symbols.impl.FirCallableSymbol
import org.jetbrains.kotlin.fir.types.FirErrorTypeRef import org.jetbrains.kotlin.fir.types.FirErrorTypeRef
import org.jetbrains.kotlin.fir.types.FirUserTypeRef
import org.jetbrains.kotlin.fir.visitors.FirVisitorVoid import org.jetbrains.kotlin.fir.visitors.FirVisitorVoid
import org.jetbrains.kotlin.name.ClassId import org.jetbrains.kotlin.name.ClassId
import org.jetbrains.kotlin.name.FqName import org.jetbrains.kotlin.name.FqName
@@ -190,6 +191,10 @@ fun KtElement.getOrBuildFir(
override fun visitThisReference(thisReference: FirThisReference) {} override fun visitThisReference(thisReference: FirThisReference) {}
override fun visitErrorTypeRef(errorTypeRef: FirErrorTypeRef) {} override fun visitErrorTypeRef(errorTypeRef: FirErrorTypeRef) {}
override fun visitUserTypeRef(userTypeRef: FirUserTypeRef) {
userTypeRef.acceptChildren(this)
}
}) })
var current: PsiElement? = psi var current: PsiElement? = psi
while (current is KtElement) { while (current is KtElement) {