Introduce FirFile.fileSession, get rid of most FirElement.session usages
This commit is contained in:
@@ -332,7 +332,7 @@ class RawFirBuilder(val session: FirSession, val stubMode: Boolean) {
|
||||
is KtDelegatedSuperTypeEntry -> {
|
||||
val type = superTypeListEntry.typeReference.toFirOrErrorType()
|
||||
container.superTypeRefs += FirDelegatedTypeRefImpl(
|
||||
type,
|
||||
session, type,
|
||||
{ superTypeListEntry.delegateExpression }.toFirExpression("Should have delegate")
|
||||
)
|
||||
}
|
||||
|
||||
+9
-5
@@ -7,6 +7,7 @@ package org.jetbrains.kotlin.fir.resolve.transformers
|
||||
|
||||
import org.jetbrains.kotlin.fir.FirNamedReference
|
||||
import org.jetbrains.kotlin.fir.FirResolvedCallableReference
|
||||
import org.jetbrains.kotlin.fir.FirSession
|
||||
import org.jetbrains.kotlin.fir.declarations.FirDeclaration
|
||||
import org.jetbrains.kotlin.fir.declarations.FirFile
|
||||
import org.jetbrains.kotlin.fir.declarations.FirRegularClass
|
||||
@@ -23,16 +24,19 @@ import org.jetbrains.kotlin.fir.visitors.compose
|
||||
|
||||
class FirAccessResolveTransformer : FirAbstractTreeTransformerWithSuperTypes(reversedScopePriority = true) {
|
||||
|
||||
private lateinit var session: FirSession
|
||||
|
||||
override fun transformFile(file: FirFile, data: Nothing?): CompositeTransformResult<FirFile> {
|
||||
session = file.fileSession
|
||||
return withScopeCleanup {
|
||||
towerScope.scopes += FirTopLevelDeclaredMemberScope(file, file.session)
|
||||
towerScope.scopes += FirTopLevelDeclaredMemberScope(file, session)
|
||||
super.transformFile(file, data)
|
||||
}
|
||||
}
|
||||
|
||||
override fun transformRegularClass(regularClass: FirRegularClass, data: Nothing?): CompositeTransformResult<FirDeclaration> {
|
||||
return withScopeCleanup {
|
||||
towerScope.scopes += regularClass.buildUseSiteScope(regularClass.session)
|
||||
towerScope.scopes += regularClass.buildUseSiteScope(session)
|
||||
super.transformRegularClass(regularClass, data)
|
||||
}
|
||||
}
|
||||
@@ -109,14 +113,14 @@ class FirAccessResolveTransformer : FirAbstractTreeTransformerWithSuperTypes(rev
|
||||
|
||||
return when (referents.size) {
|
||||
0 -> FirErrorNamedReference(
|
||||
namedReference.session, namedReference.psi, "Unresolved name: $name"
|
||||
session, namedReference.psi, "Unresolved name: $name"
|
||||
).compose()
|
||||
1 -> FirResolvedCallableReferenceImpl(
|
||||
namedReference.session, namedReference.psi,
|
||||
session, namedReference.psi,
|
||||
name, referents.single()
|
||||
).compose()
|
||||
else -> FirErrorNamedReference(
|
||||
namedReference.session, namedReference.psi, "Ambiguity: $name, ${referents.map { it.callableId }}"
|
||||
session, namedReference.psi, "Ambiguity: $name, ${referents.map { it.callableId }}"
|
||||
).compose()
|
||||
}
|
||||
|
||||
|
||||
+7
-3
@@ -24,13 +24,17 @@ class FirImportResolveTransformer() : FirAbstractTreeTransformer() {
|
||||
|
||||
private lateinit var symbolProvider: FirSymbolProvider
|
||||
|
||||
private lateinit var session: FirSession
|
||||
|
||||
constructor(session: FirSession) : this() {
|
||||
this.session = session
|
||||
// TODO: clarify this
|
||||
symbolProvider = FirSymbolProvider.getInstance(session)
|
||||
}
|
||||
|
||||
override fun transformFile(file: FirFile, data: Nothing?): CompositeTransformResult<FirFile> {
|
||||
symbolProvider = FirSymbolProvider.getInstance(file.session)
|
||||
session = file.fileSession
|
||||
symbolProvider = FirSymbolProvider.getInstance(file.fileSession)
|
||||
return file.also { it.transformChildren(this, null) }.compose()
|
||||
}
|
||||
|
||||
@@ -42,7 +46,7 @@ class FirImportResolveTransformer() : FirAbstractTreeTransformer() {
|
||||
var firstPart = fqName
|
||||
|
||||
if (import.isAllUnder && symbolProvider.getPackage(firstPart) != null) {
|
||||
return FirResolvedPackageStarImport(import, firstPart).compose()
|
||||
return FirResolvedPackageStarImport(session, import, firstPart).compose()
|
||||
}
|
||||
|
||||
while (!firstPart.isRoot) {
|
||||
@@ -56,7 +60,7 @@ class FirImportResolveTransformer() : FirAbstractTreeTransformer() {
|
||||
val foundSymbol = symbolProvider.getClassLikeSymbolByFqName(resolvedFqName)
|
||||
|
||||
if (foundSymbol != null) {
|
||||
return FirResolvedImportImpl(import, resolvedFqName).compose()
|
||||
return FirResolvedImportImpl(session, import, resolvedFqName).compose()
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
+3
-3
@@ -32,11 +32,11 @@ class FirSpecificTypeResolverTransformer(
|
||||
}
|
||||
|
||||
override fun transformFunctionTypeRef(functionTypeRef: FirFunctionTypeRef, data: Nothing?): CompositeTransformResult<FirTypeRef> {
|
||||
val typeResolver = FirTypeResolver.getInstance(functionTypeRef.session)
|
||||
val typeResolver = FirTypeResolver.getInstance(session)
|
||||
functionTypeRef.transformChildren(this, data)
|
||||
return FirResolvedFunctionTypeRefImpl(
|
||||
functionTypeRef.psi,
|
||||
functionTypeRef.session,
|
||||
session,
|
||||
functionTypeRef.isMarkedNullable,
|
||||
functionTypeRef.annotations as MutableList<FirAnnotationCall>,
|
||||
functionTypeRef.receiverTypeRef,
|
||||
@@ -48,7 +48,7 @@ class FirSpecificTypeResolverTransformer(
|
||||
|
||||
private fun transformType(typeRef: FirTypeRef, resolvedType: ConeKotlinType): CompositeTransformResult<FirTypeRef> {
|
||||
return FirResolvedTypeRefImpl(
|
||||
typeRef.session,
|
||||
session,
|
||||
typeRef.psi,
|
||||
resolvedType,
|
||||
false,
|
||||
|
||||
+2
-2
@@ -29,7 +29,7 @@ class FirSupertypeResolverTransformer : FirAbstractTreeTransformer() {
|
||||
private val fullyComputed: MutableSet<ClassId> = mutableSetOf()
|
||||
|
||||
override fun transformFile(file: FirFile, data: Nothing?): CompositeTransformResult<FirFile> {
|
||||
firSession = file.session
|
||||
firSession = file.fileSession
|
||||
return super.transformFile(file, data)
|
||||
}
|
||||
|
||||
@@ -176,7 +176,7 @@ class FirSupertypeResolverTransformer : FirAbstractTreeTransformer() {
|
||||
data: Nothing?
|
||||
): CompositeTransformResult<FirDeclaration> {
|
||||
return withScopeCleanup {
|
||||
val session = regularClass.session
|
||||
// ? Is it Ok to use original file session here ?
|
||||
val firProvider = FirProvider.getInstance(session)
|
||||
val classId = regularClass.symbol.classId
|
||||
lookupSuperTypes(regularClass, lookupInterfaces = false, deep = true, useSiteSession = session)
|
||||
|
||||
+2
-2
@@ -20,7 +20,7 @@ open class FirTypeResolveTransformer : FirAbstractTreeTransformerWithSuperTypes(
|
||||
private lateinit var session: FirSession
|
||||
|
||||
override fun transformFile(file: FirFile, data: Nothing?): CompositeTransformResult<FirFile> {
|
||||
session = file.session
|
||||
session = file.fileSession
|
||||
return withScopeCleanup {
|
||||
towerScope.addImportingScopes(file, session)
|
||||
super.transformFile(file, data)
|
||||
@@ -36,7 +36,7 @@ open class FirTypeResolveTransformer : FirAbstractTreeTransformerWithSuperTypes(
|
||||
}
|
||||
|
||||
return withScopeCleanup {
|
||||
val session = regularClass.session
|
||||
val session = session
|
||||
val firProvider = FirProvider.getInstance(session)
|
||||
val classId = regularClass.symbol.classId
|
||||
lookupSuperTypes(regularClass, lookupInterfaces = false, deep = true, useSiteSession = session)
|
||||
|
||||
+4
-4
@@ -120,15 +120,15 @@ class FirClassSubstitutionScope(
|
||||
psi,
|
||||
symbol,
|
||||
name,
|
||||
member.receiverTypeRef?.withReplacedConeType(newReceiverType),
|
||||
member.returnTypeRef.withReplacedConeType(newReturnType)
|
||||
member.receiverTypeRef?.withReplacedConeType(this@FirClassSubstitutionScope.session, newReceiverType),
|
||||
member.returnTypeRef.withReplacedConeType(this@FirClassSubstitutionScope.session, newReturnType)
|
||||
).apply {
|
||||
status = member.status as FirDeclarationStatusImpl
|
||||
valueParameters += member.valueParameters.zip(newParameterTypes) { valueParameter, newType ->
|
||||
with(valueParameter) {
|
||||
FirValueParameterImpl(
|
||||
this@FirClassSubstitutionScope.session, psi,
|
||||
name, this.returnTypeRef.withReplacedConeType(newType),
|
||||
name, this.returnTypeRef.withReplacedConeType(this@FirClassSubstitutionScope.session, newType),
|
||||
defaultValue, isCrossinline, isNoinline, isVararg
|
||||
)
|
||||
}
|
||||
@@ -140,7 +140,7 @@ class FirClassSubstitutionScope(
|
||||
}
|
||||
|
||||
|
||||
fun FirTypeRef.withReplacedConeType(newType: ConeKotlinType?): FirResolvedTypeRef {
|
||||
fun FirTypeRef.withReplacedConeType(session: FirSession, newType: ConeKotlinType?): FirResolvedTypeRef {
|
||||
require(this is FirResolvedTypeRef)
|
||||
if (newType == null) return this
|
||||
|
||||
|
||||
+1
@@ -18,6 +18,7 @@ class FirDefaultStarImportingScope(session: FirSession, lookupInFir: Boolean = f
|
||||
?.filter { it.isAllUnder }
|
||||
?.map {
|
||||
FirResolvedPackageStarImport(
|
||||
session,
|
||||
FirImportImpl(session, null, it.fqName, isAllUnder = true, aliasName = null),
|
||||
it.fqName
|
||||
)
|
||||
|
||||
@@ -48,9 +48,6 @@ interface FirDeclarationStatus : FirElement {
|
||||
|
||||
val isStatic: Boolean
|
||||
|
||||
override val psi: PsiElement?
|
||||
get() = null
|
||||
|
||||
override fun <R, D> accept(visitor: FirVisitor<R, D>, data: D): R =
|
||||
visitor.visitDeclarationStatus(this, data)
|
||||
}
|
||||
@@ -6,6 +6,7 @@
|
||||
package org.jetbrains.kotlin.fir.declarations
|
||||
|
||||
import org.jetbrains.kotlin.fir.BaseTransformedType
|
||||
import org.jetbrains.kotlin.fir.FirSession
|
||||
import org.jetbrains.kotlin.fir.VisitedSupertype
|
||||
import org.jetbrains.kotlin.fir.expressions.FirAnnotationContainer
|
||||
import org.jetbrains.kotlin.fir.visitors.FirVisitor
|
||||
@@ -13,6 +14,11 @@ import org.jetbrains.kotlin.name.FqName
|
||||
|
||||
@BaseTransformedType
|
||||
interface FirFile : @VisitedSupertype FirPackageFragment, FirDeclaration, FirAnnotationContainer {
|
||||
|
||||
@Suppress("DEPRECATION")
|
||||
val fileSession: FirSession
|
||||
get() = session
|
||||
|
||||
val name: String
|
||||
|
||||
val packageFqName: FqName
|
||||
|
||||
+3
-2
@@ -7,15 +7,16 @@ package org.jetbrains.kotlin.fir.declarations.impl
|
||||
|
||||
import org.jetbrains.kotlin.descriptors.Modality
|
||||
import org.jetbrains.kotlin.descriptors.Visibility
|
||||
import org.jetbrains.kotlin.fir.FirAbstractElement
|
||||
import org.jetbrains.kotlin.fir.FirSession
|
||||
import org.jetbrains.kotlin.fir.declarations.FirDeclarationStatus
|
||||
import org.jetbrains.kotlin.fir.declarations.impl.FirDeclarationStatusImpl.Modifier.*
|
||||
|
||||
open class FirDeclarationStatusImpl(
|
||||
final override val session: FirSession,
|
||||
session: FirSession,
|
||||
override val visibility: Visibility,
|
||||
override val modality: Modality?
|
||||
) : FirDeclarationStatus {
|
||||
) : FirAbstractElement(session, null), FirDeclarationStatus {
|
||||
protected var flags: Int = 0
|
||||
|
||||
private operator fun get(modifier: Modifier): Boolean = (flags and modifier.mask) != 0
|
||||
|
||||
+4
-7
@@ -8,24 +8,21 @@ package org.jetbrains.kotlin.fir.declarations.impl
|
||||
import com.intellij.psi.PsiElement
|
||||
import org.jetbrains.kotlin.descriptors.Modality
|
||||
import org.jetbrains.kotlin.descriptors.Visibility
|
||||
import org.jetbrains.kotlin.fir.FirElement
|
||||
import org.jetbrains.kotlin.fir.FirSession
|
||||
import org.jetbrains.kotlin.fir.*
|
||||
import org.jetbrains.kotlin.fir.declarations.FirPropertyAccessor
|
||||
import org.jetbrains.kotlin.fir.declarations.FirValueParameter
|
||||
import org.jetbrains.kotlin.fir.expressions.FirAnnotationCall
|
||||
import org.jetbrains.kotlin.fir.expressions.FirBlock
|
||||
import org.jetbrains.kotlin.fir.transformInplace
|
||||
import org.jetbrains.kotlin.fir.transformSingle
|
||||
import org.jetbrains.kotlin.fir.types.FirTypeRef
|
||||
import org.jetbrains.kotlin.fir.types.impl.FirImplicitUnitTypeRef
|
||||
import org.jetbrains.kotlin.fir.visitors.FirTransformer
|
||||
|
||||
abstract class FirDefaultPropertyAccessor(
|
||||
final override val session: FirSession,
|
||||
final override val psi: PsiElement?,
|
||||
session: FirSession,
|
||||
psi: PsiElement?,
|
||||
final override val isGetter: Boolean,
|
||||
visibility: Visibility
|
||||
) : FirPropertyAccessor {
|
||||
) : FirAbstractElement(session, psi), FirPropertyAccessor {
|
||||
override var status = FirDeclarationStatusImpl(
|
||||
session, visibility, Modality.FINAL
|
||||
)
|
||||
|
||||
+3
-8
@@ -5,7 +5,7 @@
|
||||
|
||||
package org.jetbrains.kotlin.fir.declarations.impl
|
||||
|
||||
import com.intellij.psi.PsiElement
|
||||
import org.jetbrains.kotlin.fir.FirAbstractElement
|
||||
import org.jetbrains.kotlin.fir.FirSession
|
||||
import org.jetbrains.kotlin.fir.declarations.FirImport
|
||||
import org.jetbrains.kotlin.fir.declarations.FirResolvedImport
|
||||
@@ -14,9 +14,10 @@ import org.jetbrains.kotlin.name.FqName
|
||||
import org.jetbrains.kotlin.name.Name
|
||||
|
||||
class FirResolvedImportImpl(
|
||||
session: FirSession,
|
||||
val delegate: FirImport,
|
||||
override val resolvedFqName: ClassId
|
||||
) : FirResolvedImport, FirImport {
|
||||
) : FirAbstractElement(session, delegate.psi), FirResolvedImport, FirImport {
|
||||
override val packageFqName: FqName
|
||||
get() = resolvedFqName.packageFqName
|
||||
|
||||
@@ -31,10 +32,4 @@ class FirResolvedImportImpl(
|
||||
|
||||
override val isAllUnder: Boolean
|
||||
get() = delegate.isAllUnder
|
||||
|
||||
override val psi: PsiElement?
|
||||
get() = delegate.psi
|
||||
|
||||
override val session: FirSession
|
||||
get() = delegate.session
|
||||
}
|
||||
+3
-8
@@ -5,7 +5,7 @@
|
||||
|
||||
package org.jetbrains.kotlin.fir.declarations.impl
|
||||
|
||||
import com.intellij.psi.PsiElement
|
||||
import org.jetbrains.kotlin.fir.FirAbstractElement
|
||||
import org.jetbrains.kotlin.fir.FirSession
|
||||
import org.jetbrains.kotlin.fir.declarations.FirImport
|
||||
import org.jetbrains.kotlin.fir.declarations.FirResolvedImport
|
||||
@@ -14,9 +14,10 @@ import org.jetbrains.kotlin.name.FqName
|
||||
import org.jetbrains.kotlin.name.Name
|
||||
|
||||
class FirResolvedPackageStarImport(
|
||||
session: FirSession,
|
||||
val delegate: FirImport,
|
||||
override val packageFqName: FqName
|
||||
) : FirResolvedImport, FirImport {
|
||||
) : FirAbstractElement(session, delegate.psi), FirResolvedImport, FirImport {
|
||||
override val relativeClassName: FqName?
|
||||
get() = null
|
||||
|
||||
@@ -31,10 +32,4 @@ class FirResolvedPackageStarImport(
|
||||
|
||||
override val isAllUnder: Boolean
|
||||
get() = delegate.isAllUnder
|
||||
|
||||
override val psi: PsiElement?
|
||||
get() = delegate.psi
|
||||
|
||||
override val session: FirSession
|
||||
get() = delegate.session
|
||||
}
|
||||
+3
-1
@@ -7,6 +7,7 @@ package org.jetbrains.kotlin.fir.types.impl
|
||||
|
||||
import org.jetbrains.kotlin.fir.FirAbstractElement
|
||||
import org.jetbrains.kotlin.fir.FirElement
|
||||
import org.jetbrains.kotlin.fir.FirSession
|
||||
import org.jetbrains.kotlin.fir.expressions.FirAnnotationCall
|
||||
import org.jetbrains.kotlin.fir.expressions.FirExpression
|
||||
import org.jetbrains.kotlin.fir.transformSingle
|
||||
@@ -15,9 +16,10 @@ import org.jetbrains.kotlin.fir.types.FirTypeRef
|
||||
import org.jetbrains.kotlin.fir.visitors.FirTransformer
|
||||
|
||||
class FirDelegatedTypeRefImpl(
|
||||
session: FirSession,
|
||||
override var typeRef: FirTypeRef,
|
||||
override var delegate: FirExpression?
|
||||
) : FirAbstractElement(typeRef.session, typeRef.psi), FirDelegatedTypeRef {
|
||||
) : FirAbstractElement(session, typeRef.psi), FirDelegatedTypeRef {
|
||||
override val annotations: List<FirAnnotationCall>
|
||||
get() = typeRef.annotations
|
||||
|
||||
|
||||
Reference in New Issue
Block a user