org.jetbrains.kotlin.fir.resolve.transformers.FirAbstractTreeTransformerWithSuperTypes.kt Maven / Gradle / Ivy
/*
* Copyright 2010-2019 JetBrains s.r.o. and Kotlin Programming Language contributors.
* Use of this source code is governed by the Apache 2.0 license that can be found in the license/LICENSE.txt file.
*/
package org.jetbrains.kotlin.fir.resolve.transformers
import org.jetbrains.kotlin.fir.declarations.FirMemberDeclaration
import org.jetbrains.kotlin.fir.declarations.FirResolvePhase
import org.jetbrains.kotlin.fir.scopes.impl.FirCompositeScope
import org.jetbrains.kotlin.fir.scopes.impl.FirMemberTypeParameterScope
abstract class FirAbstractTreeTransformerWithSuperTypes(
phase: FirResolvePhase,
reversedScopePriority: Boolean
) : FirAbstractTreeTransformer(phase) {
protected val towerScope = FirCompositeScope(mutableListOf(), reversedPriority = reversedScopePriority)
protected inline fun withScopeCleanup(crossinline l: () -> T): T {
val sizeBefore = towerScope.scopes.size
val result = l()
val size = towerScope.scopes.size
assert(size >= sizeBefore)
repeat(size - sizeBefore) {
towerScope.scopes.let { it.removeAt(it.size - 1) }
}
return result
}
protected fun FirMemberDeclaration.addTypeParametersScope() {
val scopes = towerScope.scopes
if (typeParameters.isNotEmpty()) {
scopes += FirMemberTypeParameterScope(this)
}
}
}