FIR IDE: add validity token to data classes related to smartcast API

Also move KtImplicitReceiverSmartCast closer to where it's used.
This commit is contained in:
Tianyu Geng
2021-11-03 16:21:51 -07:00
committed by Ilya Kirillov
parent 7de0937031
commit ae50d52131
4 changed files with 53 additions and 42 deletions
@@ -1,14 +0,0 @@
/*
* Copyright 2010-2020 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.analysis.api
import org.jetbrains.kotlin.analysis.api.types.KtType
public data class ImplicitReceiverSmartCast(val type: KtType, val kind: ImplicitReceiverSmartcastKind)
public enum class ImplicitReceiverSmartcastKind {
DISPATCH, EXTENSION
}
@@ -5,24 +5,46 @@
package org.jetbrains.kotlin.analysis.api.components
import org.jetbrains.kotlin.analysis.api.ImplicitReceiverSmartCast
import org.jetbrains.kotlin.analysis.api.ValidityTokenOwner
import org.jetbrains.kotlin.analysis.api.tokens.ValidityToken
import org.jetbrains.kotlin.analysis.api.types.KtType
import org.jetbrains.kotlin.analysis.api.withValidityAssertion
import org.jetbrains.kotlin.psi.KtExpression
public abstract class KtSmartCastProvider : KtAnalysisSessionComponent() {
public abstract fun getSmartCastedInfo(expression: KtExpression): SmartCastInfo?
public abstract fun getImplicitReceiverSmartCast(expression: KtExpression): Collection<ImplicitReceiverSmartCast>
public abstract fun getSmartCastedInfo(expression: KtExpression): KtSmartCastInfo?
public abstract fun getImplicitReceiverSmartCast(expression: KtExpression): Collection<KtImplicitReceiverSmartCast>
}
public class SmartCastInfo(public val smartCastType: KtType, public val isStable: Boolean)
public interface KtSmartCastProviderMixIn : KtAnalysisSessionMixIn {
/**
* Gets the smart-cast information of the given expression or null if the expression is not smart casted.
*/
public fun KtExpression.getSmartCastInfo(): SmartCastInfo? =
public fun KtExpression.getSmartCastInfo(): KtSmartCastInfo? =
analysisSession.smartCastProvider.getSmartCastedInfo(this)
public fun KtExpression.getImplicitReceiverSmartCast(): Collection<ImplicitReceiverSmartCast> =
public fun KtExpression.getImplicitReceiverSmartCast(): Collection<KtImplicitReceiverSmartCast> =
analysisSession.smartCastProvider.getImplicitReceiverSmartCast(this)
}
}
public data class KtSmartCastInfo(
private val _smartCastType: KtType,
private val _isStable: Boolean,
override val token: ValidityToken
) : ValidityTokenOwner {
public val isStable: Boolean get() = withValidityAssertion { _isStable }
public val smartCastType: KtType get() = withValidityAssertion { _smartCastType }
}
public data class KtImplicitReceiverSmartCast(
private val _type: KtType,
private val _kind: KtImplicitReceiverSmartCastKind,
override val token: ValidityToken
) : ValidityTokenOwner {
public val type: KtType get() = withValidityAssertion { _type }
public val kind: KtImplicitReceiverSmartCastKind get() = withValidityAssertion { _kind }
}
public enum class KtImplicitReceiverSmartCastKind {
DISPATCH, EXTENSION
}