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