[FIR IDE] Add base support for FIR incomplete types resolve
This commit is contained in:
+2
@@ -86,6 +86,8 @@ class FirSpecificTypeResolverTransformer(
|
|||||||
typeRef.source
|
typeRef.source
|
||||||
}
|
}
|
||||||
|
|
||||||
|
delegatedTypeRef = typeRef
|
||||||
|
|
||||||
diagnostic = resolvedType.diagnostic
|
diagnostic = resolvedType.diagnostic
|
||||||
}
|
}
|
||||||
}.compose()
|
}.compose()
|
||||||
|
|||||||
+1
-1
@@ -39,7 +39,7 @@ internal class FirErrorFunctionImpl(
|
|||||||
override val symbol: FirErrorFunctionSymbol,
|
override val symbol: FirErrorFunctionSymbol,
|
||||||
override val typeParameters: MutableList<FirTypeParameter>,
|
override val typeParameters: MutableList<FirTypeParameter>,
|
||||||
) : FirErrorFunction() {
|
) : FirErrorFunction() {
|
||||||
override var returnTypeRef: FirTypeRef = FirErrorTypeRefImpl(null, diagnostic)
|
override var returnTypeRef: FirTypeRef = FirErrorTypeRefImpl(null, null, diagnostic)
|
||||||
override val receiverTypeRef: FirTypeRef? get() = null
|
override val receiverTypeRef: FirTypeRef? get() = null
|
||||||
override var controlFlowGraphReference: FirControlFlowGraphReference? = null
|
override var controlFlowGraphReference: FirControlFlowGraphReference? = null
|
||||||
override val body: FirBlock? get() = null
|
override val body: FirBlock? get() = null
|
||||||
|
|||||||
+1
-1
@@ -40,7 +40,7 @@ internal class FirErrorPropertyImpl(
|
|||||||
override val typeParameters: MutableList<FirTypeParameter>,
|
override val typeParameters: MutableList<FirTypeParameter>,
|
||||||
override val symbol: FirErrorPropertySymbol,
|
override val symbol: FirErrorPropertySymbol,
|
||||||
) : FirErrorProperty() {
|
) : FirErrorProperty() {
|
||||||
override var returnTypeRef: FirTypeRef = FirErrorTypeRefImpl(null, diagnostic)
|
override var returnTypeRef: FirTypeRef = FirErrorTypeRefImpl(null, null, diagnostic)
|
||||||
override val receiverTypeRef: FirTypeRef? get() = null
|
override val receiverTypeRef: FirTypeRef? get() = null
|
||||||
override val initializer: FirExpression? get() = null
|
override val initializer: FirExpression? get() = null
|
||||||
override val delegate: FirExpression? get() = null
|
override val delegate: FirExpression? get() = null
|
||||||
|
|||||||
+1
-1
@@ -23,7 +23,7 @@ internal class FirErrorExpressionImpl(
|
|||||||
override val source: FirSourceElement?,
|
override val source: FirSourceElement?,
|
||||||
override val diagnostic: ConeDiagnostic,
|
override val diagnostic: ConeDiagnostic,
|
||||||
) : FirErrorExpression() {
|
) : FirErrorExpression() {
|
||||||
override var typeRef: FirTypeRef = FirErrorTypeRefImpl(source, ConeStubDiagnostic(diagnostic))
|
override var typeRef: FirTypeRef = FirErrorTypeRefImpl(source, null, ConeStubDiagnostic(diagnostic))
|
||||||
override val annotations: List<FirAnnotationCall> get() = emptyList()
|
override val annotations: List<FirAnnotationCall> get() = emptyList()
|
||||||
|
|
||||||
override fun <R, D> acceptChildren(visitor: FirVisitor<R, D>, data: D) {
|
override fun <R, D> acceptChildren(visitor: FirVisitor<R, D>, data: D) {
|
||||||
|
|||||||
@@ -26,11 +26,13 @@ import org.jetbrains.kotlin.fir.visitors.*
|
|||||||
@FirBuilderDsl
|
@FirBuilderDsl
|
||||||
class FirErrorTypeRefBuilder : FirAnnotationContainerBuilder {
|
class FirErrorTypeRefBuilder : FirAnnotationContainerBuilder {
|
||||||
override var source: FirSourceElement? = null
|
override var source: FirSourceElement? = null
|
||||||
|
var delegatedTypeRef: FirTypeRef? = null
|
||||||
lateinit var diagnostic: ConeDiagnostic
|
lateinit var diagnostic: ConeDiagnostic
|
||||||
|
|
||||||
override fun build(): FirErrorTypeRef {
|
override fun build(): FirErrorTypeRef {
|
||||||
return FirErrorTypeRefImpl(
|
return FirErrorTypeRefImpl(
|
||||||
source,
|
source,
|
||||||
|
delegatedTypeRef,
|
||||||
diagnostic,
|
diagnostic,
|
||||||
)
|
)
|
||||||
}
|
}
|
||||||
@@ -55,6 +57,7 @@ inline fun buildErrorTypeRefCopy(original: FirErrorTypeRef, init: FirErrorTypeRe
|
|||||||
}
|
}
|
||||||
val copyBuilder = FirErrorTypeRefBuilder()
|
val copyBuilder = FirErrorTypeRefBuilder()
|
||||||
copyBuilder.source = original.source
|
copyBuilder.source = original.source
|
||||||
|
copyBuilder.delegatedTypeRef = original.delegatedTypeRef
|
||||||
copyBuilder.diagnostic = original.diagnostic
|
copyBuilder.diagnostic = original.diagnostic
|
||||||
return copyBuilder.apply(init).build()
|
return copyBuilder.apply(init).build()
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -21,18 +21,20 @@ import org.jetbrains.kotlin.fir.visitors.*
|
|||||||
|
|
||||||
internal class FirErrorTypeRefImpl(
|
internal class FirErrorTypeRefImpl(
|
||||||
override val source: FirSourceElement?,
|
override val source: FirSourceElement?,
|
||||||
|
override var delegatedTypeRef: FirTypeRef?,
|
||||||
override val diagnostic: ConeDiagnostic,
|
override val diagnostic: ConeDiagnostic,
|
||||||
) : FirErrorTypeRef() {
|
) : FirErrorTypeRef() {
|
||||||
override val annotations: MutableList<FirAnnotationCall> = mutableListOf()
|
override val annotations: MutableList<FirAnnotationCall> = mutableListOf()
|
||||||
override val type: ConeKotlinType = ConeClassErrorType(diagnostic)
|
override val type: ConeKotlinType = ConeClassErrorType(diagnostic)
|
||||||
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) }
|
||||||
|
delegatedTypeRef?.accept(visitor, data)
|
||||||
}
|
}
|
||||||
|
|
||||||
override fun <D> transformChildren(transformer: FirTransformer<D>, data: D): FirErrorTypeRefImpl {
|
override fun <D> transformChildren(transformer: FirTransformer<D>, data: D): FirErrorTypeRefImpl {
|
||||||
transformAnnotations(transformer, data)
|
transformAnnotations(transformer, data)
|
||||||
|
delegatedTypeRef = delegatedTypeRef?.transformSingle(transformer, data)
|
||||||
return this
|
return this
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
+3
-7
@@ -170,10 +170,6 @@ object ImplementationConfigurator : AbstractFirTreeImplementationConfigurator()
|
|||||||
|
|
||||||
val errorTypeRefImpl = impl(errorTypeRef) {
|
val errorTypeRefImpl = impl(errorTypeRef) {
|
||||||
default("type", "ConeClassErrorType(diagnostic)")
|
default("type", "ConeClassErrorType(diagnostic)")
|
||||||
default("delegatedTypeRef") {
|
|
||||||
value = "null"
|
|
||||||
withGetter = true
|
|
||||||
}
|
|
||||||
default("annotations", "mutableListOf()")
|
default("annotations", "mutableListOf()")
|
||||||
useTypes(coneClassErrorTypeType)
|
useTypes(coneClassErrorTypeType)
|
||||||
}
|
}
|
||||||
@@ -201,7 +197,7 @@ object ImplementationConfigurator : AbstractFirTreeImplementationConfigurator()
|
|||||||
"getter", "setter",
|
"getter", "setter",
|
||||||
withGetter = true
|
withGetter = true
|
||||||
)
|
)
|
||||||
default("returnTypeRef", "FirErrorTypeRefImpl(null, diagnostic)")
|
default("returnTypeRef", "FirErrorTypeRefImpl(null, null, diagnostic)")
|
||||||
useTypes(errorTypeRefImpl)
|
useTypes(errorTypeRefImpl)
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -396,13 +392,13 @@ object ImplementationConfigurator : AbstractFirTreeImplementationConfigurator()
|
|||||||
|
|
||||||
impl(errorExpression) {
|
impl(errorExpression) {
|
||||||
defaultEmptyList("annotations")
|
defaultEmptyList("annotations")
|
||||||
default("typeRef", "FirErrorTypeRefImpl(source, ConeStubDiagnostic(diagnostic))")
|
default("typeRef", "FirErrorTypeRefImpl(source, null, ConeStubDiagnostic(diagnostic))")
|
||||||
useTypes(errorTypeRefImpl, coneStubDiagnosticType)
|
useTypes(errorTypeRefImpl, coneStubDiagnosticType)
|
||||||
}
|
}
|
||||||
|
|
||||||
impl(errorFunction) {
|
impl(errorFunction) {
|
||||||
defaultNull("receiverTypeRef", "body", withGetter = true)
|
defaultNull("receiverTypeRef", "body", withGetter = true)
|
||||||
default("returnTypeRef", "FirErrorTypeRefImpl(null, diagnostic)")
|
default("returnTypeRef", "FirErrorTypeRefImpl(null, null, diagnostic)")
|
||||||
useTypes(errorTypeRefImpl)
|
useTypes(errorTypeRefImpl)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
+11
-1
@@ -10,6 +10,7 @@ import org.jetbrains.kotlin.fir.declarations.FirDeclaration
|
|||||||
import org.jetbrains.kotlin.fir.realPsi
|
import org.jetbrains.kotlin.fir.realPsi
|
||||||
import org.jetbrains.kotlin.fir.references.*
|
import org.jetbrains.kotlin.fir.references.*
|
||||||
import org.jetbrains.kotlin.fir.types.FirErrorTypeRef
|
import org.jetbrains.kotlin.fir.types.FirErrorTypeRef
|
||||||
|
import org.jetbrains.kotlin.fir.types.FirResolvedTypeRef
|
||||||
import org.jetbrains.kotlin.fir.types.FirTypeRef
|
import org.jetbrains.kotlin.fir.types.FirTypeRef
|
||||||
import org.jetbrains.kotlin.fir.types.FirUserTypeRef
|
import org.jetbrains.kotlin.fir.types.FirUserTypeRef
|
||||||
import org.jetbrains.kotlin.fir.types.impl.FirResolvedTypeRefImpl
|
import org.jetbrains.kotlin.fir.types.impl.FirResolvedTypeRefImpl
|
||||||
@@ -68,9 +69,18 @@ internal open class FirElementsRecorder : FirVisitor<Unit, MutableMap<KtElement,
|
|||||||
override fun visitBackingFieldReference(backingFieldReference: FirBackingFieldReference, data: MutableMap<KtElement, FirElement>) {}
|
override fun visitBackingFieldReference(backingFieldReference: FirBackingFieldReference, data: MutableMap<KtElement, FirElement>) {}
|
||||||
override fun visitSuperReference(superReference: FirSuperReference, data: MutableMap<KtElement, FirElement>) {}
|
override fun visitSuperReference(superReference: FirSuperReference, data: MutableMap<KtElement, FirElement>) {}
|
||||||
override fun visitThisReference(thisReference: FirThisReference, data: MutableMap<KtElement, FirElement>) {}
|
override fun visitThisReference(thisReference: FirThisReference, data: MutableMap<KtElement, FirElement>) {}
|
||||||
override fun visitErrorTypeRef(errorTypeRef: FirErrorTypeRef, data: MutableMap<KtElement, FirElement>) {}
|
|
||||||
//@formatter:on
|
//@formatter:on
|
||||||
|
|
||||||
|
override fun visitErrorTypeRef(errorTypeRef: FirErrorTypeRef, data: MutableMap<KtElement, FirElement>) {
|
||||||
|
super.visitResolvedTypeRef(errorTypeRef, data)
|
||||||
|
errorTypeRef.delegatedTypeRef?.accept(this, data)
|
||||||
|
}
|
||||||
|
|
||||||
|
override fun visitResolvedTypeRef(resolvedTypeRef: FirResolvedTypeRef, data: MutableMap<KtElement, FirElement>) {
|
||||||
|
super.visitResolvedTypeRef(resolvedTypeRef, data)
|
||||||
|
resolvedTypeRef.delegatedTypeRef?.accept(this, data)
|
||||||
|
}
|
||||||
|
|
||||||
override fun visitUserTypeRef(userTypeRef: FirUserTypeRef, data: MutableMap<KtElement, FirElement>) {
|
override fun visitUserTypeRef(userTypeRef: FirUserTypeRef, data: MutableMap<KtElement, FirElement>) {
|
||||||
userTypeRef.acceptChildren(this, data)
|
userTypeRef.acceptChildren(this, data)
|
||||||
}
|
}
|
||||||
|
|||||||
+5
-2
@@ -388,8 +388,11 @@ internal object FirReferenceResolveHelper {
|
|||||||
): ClassId? {
|
): ClassId? {
|
||||||
val qualifierToResolve = qualifier.parent as KtUserType
|
val qualifierToResolve = qualifier.parent as KtUserType
|
||||||
// FIXME make it work with generics in functional types (like () -> AA.BB<CC, AA.DD>)
|
// FIXME make it work with generics in functional types (like () -> AA.BB<CC, AA.DD>)
|
||||||
val wholeType =
|
val wholeType = when (val psi = wholeTypeFir.psi) {
|
||||||
(wholeTypeFir.psi as KtTypeReference).typeElement?.unwrapNullable() as? KtUserType ?: return null
|
is KtUserType -> psi
|
||||||
|
is KtTypeReference -> psi.typeElement?.unwrapNullable() as? KtUserType
|
||||||
|
else -> null
|
||||||
|
} ?: return null
|
||||||
|
|
||||||
val qualifiersToDrop = countQualifiersToDrop(wholeType, qualifierToResolve)
|
val qualifiersToDrop = countQualifiersToDrop(wholeType, qualifierToResolve)
|
||||||
return wholeTypeFir.type.classId?.dropLastNestedClasses(qualifiersToDrop)
|
return wholeTypeFir.type.classId?.dropLastNestedClasses(qualifiersToDrop)
|
||||||
|
|||||||
@@ -1,4 +1,3 @@
|
|||||||
// IGNORE_FIR
|
|
||||||
val v: UnknownClass<<caret>String>
|
val v: UnknownClass<<caret>String>
|
||||||
|
|
||||||
// REF: (kotlin).String
|
// REF: (kotlin).String
|
||||||
|
|||||||
@@ -1,4 +1,3 @@
|
|||||||
// IGNORE_FIR
|
|
||||||
val v: UnknownClass<<caret>String>()
|
val v: UnknownClass<<caret>String>()
|
||||||
|
|
||||||
// REF: (kotlin).String
|
// REF: (kotlin).String
|
||||||
|
|||||||
@@ -1,4 +1,3 @@
|
|||||||
// IGNORE_FIR
|
|
||||||
class Foo<T, V>
|
class Foo<T, V>
|
||||||
|
|
||||||
class Bar: Foo<<caret>String
|
class Bar: Foo<<caret>String
|
||||||
|
|||||||
@@ -1,5 +1,3 @@
|
|||||||
// IGNORE_FIR
|
|
||||||
|
|
||||||
package foo
|
package foo
|
||||||
|
|
||||||
class A
|
class A
|
||||||
|
|||||||
@@ -1,5 +1,3 @@
|
|||||||
// IGNORE_FIR
|
|
||||||
|
|
||||||
package foo
|
package foo
|
||||||
|
|
||||||
class A
|
class A
|
||||||
|
|||||||
@@ -1,4 +1,3 @@
|
|||||||
// IGNORE_FIR
|
|
||||||
package foo
|
package foo
|
||||||
|
|
||||||
class A
|
class A
|
||||||
|
|||||||
Reference in New Issue
Block a user