FIR IDE: enable explicit API mode in idea-frontend-fir module

This commit is contained in:
Ilya Kirillov
2021-07-06 20:58:43 +02:00
committed by TeamCityServer
parent 51576c70b6
commit 30d0fea003
67 changed files with 593 additions and 589 deletions
+4
View File
@@ -15,6 +15,10 @@ dependencies {
compile(intellijCoreDep()) { includeJars("intellij-core", "guava", rootProject = rootProject) } compile(intellijCoreDep()) { includeJars("intellij-core", "guava", rootProject = rootProject) }
} }
kotlin {
explicitApi()
}
sourceSets { sourceSets {
"main" { projectDefault() } "main" { projectDefault() }
"test" { projectDefault() } "test" { projectDefault() }
@@ -5,14 +5,12 @@
package org.jetbrains.kotlin.idea.frontend.api package org.jetbrains.kotlin.idea.frontend.api
import kotlin.reflect.KProperty1
@RequiresOptIn @RequiresOptIn
annotation class ForbidKtResolveInternals public annotation class ForbidKtResolveInternals
object ForbidKtResolve { public object ForbidKtResolve {
@OptIn(ForbidKtResolveInternals::class) @OptIn(ForbidKtResolveInternals::class)
inline fun <R> forbidResolveIn(actionName: String, action: () -> R): R { public inline fun <R> forbidResolveIn(actionName: String, action: () -> R): R {
if (resovleIsForbidenInActionWithName.get() != null) return action() if (resovleIsForbidenInActionWithName.get() != null) return action()
resovleIsForbidenInActionWithName.set(actionName) resovleIsForbidenInActionWithName.set(actionName)
return try { return try {
@@ -23,5 +21,5 @@ object ForbidKtResolve {
} }
@ForbidKtResolveInternals @ForbidKtResolveInternals
val resovleIsForbidenInActionWithName: ThreadLocal<String?> = ThreadLocal.withInitial { null } public val resovleIsForbidenInActionWithName: ThreadLocal<String?> = ThreadLocal.withInitial { null }
} }
@@ -7,8 +7,8 @@ package org.jetbrains.kotlin.idea.frontend.api
import org.jetbrains.kotlin.idea.frontend.api.types.KtType import org.jetbrains.kotlin.idea.frontend.api.types.KtType
data class ImplicitReceiverSmartCast(val type: KtType, val kind: ImplicitReceiverSmartcastKind) public data class ImplicitReceiverSmartCast(val type: KtType, val kind: ImplicitReceiverSmartcastKind)
enum class ImplicitReceiverSmartcastKind { public enum class ImplicitReceiverSmartcastKind {
DISPATCH, EXTENSION DISPATCH, EXTENSION
} }
@@ -23,7 +23,7 @@ import org.jetbrains.kotlin.psi.*
* *
* To create analysis session consider using [analyse] * To create analysis session consider using [analyse]
*/ */
abstract class KtAnalysisSession(final override val token: ValidityToken) : ValidityTokenOwner, public abstract class KtAnalysisSession(final override val token: ValidityToken) : ValidityTokenOwner,
KtSmartCastProviderMixIn, KtSmartCastProviderMixIn,
KtCallResolverMixIn, KtCallResolverMixIn,
KtDiagnosticProviderMixIn, KtDiagnosticProviderMixIn,
@@ -50,7 +50,7 @@ abstract class KtAnalysisSession(final override val token: ValidityToken) : Vali
override val analysisSession: KtAnalysisSession get() = this override val analysisSession: KtAnalysisSession get() = this
abstract fun createContextDependentCopy(originalKtFile: KtFile, elementToReanalyze: KtElement): KtAnalysisSession public abstract fun createContextDependentCopy(originalKtFile: KtFile, elementToReanalyze: KtElement): KtAnalysisSession
internal val smartCastProvider: KtSmartCastProvider get() = smartCastProviderImpl internal val smartCastProvider: KtSmartCastProvider get() = smartCastProviderImpl
protected abstract val smartCastProviderImpl: KtSmartCastProvider protected abstract val smartCastProviderImpl: KtSmartCastProvider
@@ -112,6 +112,8 @@ abstract class KtAnalysisSession(final override val token: ValidityToken) : Vali
internal val inheritorsProvider: KtInheritorsProvider get() = inheritorsProviderImpl internal val inheritorsProvider: KtInheritorsProvider get() = inheritorsProviderImpl
protected abstract val inheritorsProviderImpl: KtInheritorsProvider protected abstract val inheritorsProviderImpl: KtInheritorsProvider
@PublishedApi internal val typesCreator: KtTypeCreator get() = typesCreatorImpl @PublishedApi
internal val typesCreator: KtTypeCreator
get() = typesCreatorImpl
protected abstract val typesCreatorImpl: KtTypeCreator protected abstract val typesCreatorImpl: KtTypeCreator
} }
@@ -20,26 +20,26 @@ import org.jetbrains.kotlin.psi.KtElement
import org.jetbrains.kotlin.psi.KtFile import org.jetbrains.kotlin.psi.KtFile
@RequiresOptIn("To use analysis session, consider using analyze/analyzeWithReadAction/analyseInModalWindow methods") @RequiresOptIn("To use analysis session, consider using analyze/analyzeWithReadAction/analyseInModalWindow methods")
annotation class InvalidWayOfUsingAnalysisSession public annotation class InvalidWayOfUsingAnalysisSession
@RequiresOptIn @RequiresOptIn
annotation class KtAnalysisSessionProviderInternals public annotation class KtAnalysisSessionProviderInternals
/** /**
* Provides [KtAnalysisSession] by [contextElement] * Provides [KtAnalysisSession] by [contextElement]
* Should not be used directly, consider using [analyse]/[analyseWithReadAction]/[analyseInModalWindow] instead * Should not be used directly, consider using [analyse]/[analyseWithReadAction]/[analyseInModalWindow] instead
*/ */
@InvalidWayOfUsingAnalysisSession @InvalidWayOfUsingAnalysisSession
abstract class KtAnalysisSessionProvider : Disposable { public abstract class KtAnalysisSessionProvider : Disposable {
@Suppress("LeakingThis") @Suppress("LeakingThis")
@OptIn(KtInternalApiMarker::class) @OptIn(KtInternalApiMarker::class)
val noWriteActionInAnalyseCallChecker = NoWriteActionInAnalyseCallChecker(this) public val noWriteActionInAnalyseCallChecker: NoWriteActionInAnalyseCallChecker = NoWriteActionInAnalyseCallChecker(this)
@InvalidWayOfUsingAnalysisSession @InvalidWayOfUsingAnalysisSession
abstract fun getAnalysisSession(contextElement: KtElement, factory: ValidityTokenFactory): KtAnalysisSession public abstract fun getAnalysisSession(contextElement: KtElement, factory: ValidityTokenFactory): KtAnalysisSession
@InvalidWayOfUsingAnalysisSession @InvalidWayOfUsingAnalysisSession
inline fun <R> analyseInDependedAnalysisSession( public inline fun <R> analyseInDependedAnalysisSession(
originalFile: KtFile, originalFile: KtFile,
elementToReanalyze: KtElement, elementToReanalyze: KtElement,
action: KtAnalysisSession.() -> R action: KtAnalysisSession.() -> R
@@ -50,12 +50,12 @@ abstract class KtAnalysisSessionProvider : Disposable {
} }
@InvalidWayOfUsingAnalysisSession @InvalidWayOfUsingAnalysisSession
inline fun <R> analyse(contextElement: KtElement, tokenFactory: ValidityTokenFactory, action: KtAnalysisSession.() -> R): R = public inline fun <R> analyse(contextElement: KtElement, tokenFactory: ValidityTokenFactory, action: KtAnalysisSession.() -> R): R =
analyse(getAnalysisSession(contextElement, tokenFactory), tokenFactory, action) analyse(getAnalysisSession(contextElement, tokenFactory), tokenFactory, action)
@OptIn(KtAnalysisSessionProviderInternals::class, KtInternalApiMarker::class) @OptIn(KtAnalysisSessionProviderInternals::class, KtInternalApiMarker::class)
@InvalidWayOfUsingAnalysisSession @InvalidWayOfUsingAnalysisSession
inline fun <R> analyse(analysisSession: KtAnalysisSession, factory: ValidityTokenFactory, action: KtAnalysisSession.() -> R): R { public inline fun <R> analyse(analysisSession: KtAnalysisSession, factory: ValidityTokenFactory, action: KtAnalysisSession.() -> R): R {
noWriteActionInAnalyseCallChecker.beforeEnteringAnalysisContext() noWriteActionInAnalyseCallChecker.beforeEnteringAnalysisContext()
factory.beforeEnteringAnalysisContext() factory.beforeEnteringAnalysisContext()
return try { return try {
@@ -67,12 +67,12 @@ abstract class KtAnalysisSessionProvider : Disposable {
} }
@TestOnly @TestOnly
abstract fun clearCaches() public abstract fun clearCaches()
override fun dispose() {} override fun dispose() {}
companion object { public companion object {
fun getInstance(project: Project): KtAnalysisSessionProvider = public fun getInstance(project: Project): KtAnalysisSessionProvider =
ServiceManager.getService(project, KtAnalysisSessionProvider::class.java) ServiceManager.getService(project, KtAnalysisSessionProvider::class.java)
} }
} }
@@ -90,12 +90,12 @@ abstract class KtAnalysisSessionProvider : Disposable {
* @see analyseWithReadAction * @see analyseWithReadAction
*/ */
@OptIn(InvalidWayOfUsingAnalysisSession::class) @OptIn(InvalidWayOfUsingAnalysisSession::class)
inline fun <R> analyse(contextElement: KtElement, action: KtAnalysisSession.() -> R): R = public inline fun <R> analyse(contextElement: KtElement, action: KtAnalysisSession.() -> R): R =
KtAnalysisSessionProvider.getInstance(contextElement.project) KtAnalysisSessionProvider.getInstance(contextElement.project)
.analyse(contextElement, ReadActionConfinementValidityTokenFactory, action) .analyse(contextElement, ReadActionConfinementValidityTokenFactory, action)
@OptIn(InvalidWayOfUsingAnalysisSession::class) @OptIn(InvalidWayOfUsingAnalysisSession::class)
inline fun <R> analyseWithCustomToken( public inline fun <R> analyseWithCustomToken(
contextElement: KtElement, contextElement: KtElement,
tokenFactory: ValidityTokenFactory, tokenFactory: ValidityTokenFactory,
action: KtAnalysisSession.() -> R action: KtAnalysisSession.() -> R
@@ -107,14 +107,14 @@ inline fun <R> analyseWithCustomToken(
* UAST-specific version of [analyse] that executes the given [action] in [KtAnalysisSession] context * UAST-specific version of [analyse] that executes the given [action] in [KtAnalysisSession] context
*/ */
@OptIn(InvalidWayOfUsingAnalysisSession::class) @OptIn(InvalidWayOfUsingAnalysisSession::class)
inline fun <R> analyseForUast( public inline fun <R> analyseForUast(
contextElement: KtElement, contextElement: KtElement,
action: KtAnalysisSession.() -> R action: KtAnalysisSession.() -> R
): R = ): R =
analyseWithCustomToken(contextElement, AlwaysAccessibleValidityTokenFactory, action) analyseWithCustomToken(contextElement, AlwaysAccessibleValidityTokenFactory, action)
@OptIn(InvalidWayOfUsingAnalysisSession::class) @OptIn(InvalidWayOfUsingAnalysisSession::class)
inline fun <R> analyseInDependedAnalysisSession( public inline fun <R> analyseInDependedAnalysisSession(
originalFile: KtFile, originalFile: KtFile,
elementToReanalyze: KtElement, elementToReanalyze: KtElement,
action: KtAnalysisSession.() -> R action: KtAnalysisSession.() -> R
@@ -134,7 +134,7 @@ inline fun <R> analyseInDependedAnalysisSession(
* @see KtAnalysisSession * @see KtAnalysisSession
* @see analyse * @see analyse
*/ */
inline fun <R> analyseWithReadAction( public inline fun <R> analyseWithReadAction(
contextElement: KtElement, contextElement: KtElement,
crossinline action: KtAnalysisSession.() -> R crossinline action: KtAnalysisSession.() -> R
): R = ApplicationManager.getApplication().runReadAction(Computable { ): R = ApplicationManager.getApplication().runReadAction(Computable {
@@ -148,7 +148,7 @@ inline fun <R> analyseWithReadAction(
* Should be executed from EDT only * Should be executed from EDT only
* If you want to analyse something from non-EDT thread, consider using [analyse]/[analyseWithReadAction] * If you want to analyse something from non-EDT thread, consider using [analyse]/[analyseWithReadAction]
*/ */
inline fun <R> analyseInModalWindow( public inline fun <R> analyseInModalWindow(
contextElement: KtElement, contextElement: KtElement,
windowTitle: String, windowTitle: String,
crossinline action: KtAnalysisSession.() -> R crossinline action: KtAnalysisSession.() -> R
@@ -8,6 +8,6 @@ package org.jetbrains.kotlin.idea.frontend.api
import org.jetbrains.kotlin.idea.frontend.api.symbols.KtSymbol import org.jetbrains.kotlin.idea.frontend.api.symbols.KtSymbol
import org.jetbrains.kotlin.idea.references.KtReference import org.jetbrains.kotlin.idea.references.KtReference
interface KtSymbolBasedReference : KtReference { public interface KtSymbolBasedReference : KtReference {
fun KtAnalysisSession.resolveToSymbols(): Collection<KtSymbol> public fun KtAnalysisSession.resolveToSymbols(): Collection<KtSymbol>
} }
@@ -9,13 +9,13 @@ import org.jetbrains.kotlin.idea.frontend.api.tokens.ValidityToken
import org.jetbrains.kotlin.idea.frontend.api.types.KtType import org.jetbrains.kotlin.idea.frontend.api.types.KtType
import org.jetbrains.kotlin.types.Variance import org.jetbrains.kotlin.types.Variance
sealed class KtTypeArgument : ValidityTokenOwner public sealed class KtTypeArgument : ValidityTokenOwner
class KtStarProjectionTypeArgument(override val token: ValidityToken) : KtTypeArgument() public class KtStarProjectionTypeArgument(override val token: ValidityToken) : KtTypeArgument()
class KtTypeArgumentWithVariance( public class KtTypeArgumentWithVariance(
val type: KtType, public val type: KtType,
val variance: Variance, public val variance: Variance,
override val token: ValidityToken, override val token: ValidityToken,
) : KtTypeArgument() ) : KtTypeArgument()
@@ -10,7 +10,7 @@ import com.intellij.openapi.application.ApplicationListener
import com.intellij.openapi.application.ApplicationManager import com.intellij.openapi.application.ApplicationManager
@KtInternalApiMarker @KtInternalApiMarker
class NoWriteActionInAnalyseCallChecker(parentDisposable: Disposable) { public class NoWriteActionInAnalyseCallChecker(parentDisposable: Disposable) {
init { init {
val listener = object : ApplicationListener { val listener = object : ApplicationListener {
override fun writeActionFinished(action: Any) { override fun writeActionFinished(action: Any) {
@@ -22,17 +22,17 @@ class NoWriteActionInAnalyseCallChecker(parentDisposable: Disposable) {
ApplicationManager.getApplication().addApplicationListener(listener, parentDisposable) ApplicationManager.getApplication().addApplicationListener(listener, parentDisposable)
} }
fun beforeEnteringAnalysisContext() { public fun beforeEnteringAnalysisContext() {
currentAnalysisContextEnteringCount.set(currentAnalysisContextEnteringCount.get() + 1) currentAnalysisContextEnteringCount.set(currentAnalysisContextEnteringCount.get() + 1)
} }
fun afterLeavingAnalysisContext() { public fun afterLeavingAnalysisContext() {
currentAnalysisContextEnteringCount.set(currentAnalysisContextEnteringCount.get() - 1) currentAnalysisContextEnteringCount.set(currentAnalysisContextEnteringCount.get() - 1)
} }
private val currentAnalysisContextEnteringCount = ThreadLocal.withInitial { 0 } private val currentAnalysisContextEnteringCount = ThreadLocal.withInitial { 0 }
} }
class WriteActionStartInsideAnalysisContextException : IllegalStateException( public class WriteActionStartInsideAnalysisContextException : IllegalStateException(
"write action should be never executed inside analysis context (e,g. analyse call)" "write action should be never executed inside analysis context (e,g. analyse call)"
) )
@@ -8,18 +8,18 @@ package org.jetbrains.kotlin.idea.frontend.api
import org.jetbrains.kotlin.idea.frontend.api.tokens.ValidityToken import org.jetbrains.kotlin.idea.frontend.api.tokens.ValidityToken
import org.jetbrains.kotlin.idea.frontend.api.tokens.assertIsValidAndAccessible import org.jetbrains.kotlin.idea.frontend.api.tokens.assertIsValidAndAccessible
interface ValidityTokenOwner { public interface ValidityTokenOwner {
val token: ValidityToken public val token: ValidityToken
} }
fun ValidityTokenOwner.isValid(): Boolean = token.isValid() public fun ValidityTokenOwner.isValid(): Boolean = token.isValid()
@Suppress("NOTHING_TO_INLINE") @Suppress("NOTHING_TO_INLINE")
inline fun ValidityTokenOwner.assertIsValidAndAccessible() { public inline fun ValidityTokenOwner.assertIsValidAndAccessible() {
token.assertIsValidAndAccessible() token.assertIsValidAndAccessible()
} }
inline fun <R> ValidityTokenOwner.withValidityAssertion(action: () -> R): R { public inline fun <R> ValidityTokenOwner.withValidityAssertion(action: () -> R): R {
assertIsValidAndAccessible() assertIsValidAndAccessible()
return action() return action()
} }
@@ -6,4 +6,4 @@
package org.jetbrains.kotlin.idea.frontend.api package org.jetbrains.kotlin.idea.frontend.api
@RequiresOptIn @RequiresOptIn
annotation class KtInternalApiMarker public annotation class KtInternalApiMarker
@@ -12,9 +12,9 @@ import org.jetbrains.kotlin.idea.frontend.api.symbols.KtVariableLikeSymbol
/** /**
* Represents direct or indirect (via invoke) function call from Kotlin code * Represents direct or indirect (via invoke) function call from Kotlin code
*/ */
sealed class KtCall { public sealed class KtCall {
abstract val isErrorCall: Boolean public abstract val isErrorCall: Boolean
abstract val targetFunction: KtCallTarget public abstract val targetFunction: KtCallTarget
} }
/** /**
@@ -24,8 +24,8 @@ sealed class KtCall {
* f() // functional type call * f() // functional type call
* } * }
*/ */
class KtFunctionalTypeVariableCall( public class KtFunctionalTypeVariableCall(
val target: KtVariableLikeSymbol, public val target: KtVariableLikeSymbol,
override val targetFunction: KtCallTarget override val targetFunction: KtCallTarget
) : KtCall() { ) : KtCall() {
override val isErrorCall: Boolean get() = false override val isErrorCall: Boolean get() = false
@@ -34,7 +34,7 @@ class KtFunctionalTypeVariableCall(
/** /**
* Direct or indirect call of function declared by user * Direct or indirect call of function declared by user
*/ */
sealed class KtDeclaredFunctionCall : KtCall() { public sealed class KtDeclaredFunctionCall : KtCall() {
override val isErrorCall: Boolean override val isErrorCall: Boolean
get() = targetFunction is KtErrorCallTarget get() = targetFunction is KtErrorCallTarget
} }
@@ -48,8 +48,8 @@ sealed class KtDeclaredFunctionCall : KtCall() {
* *
* fun Int.invoke() {} * fun Int.invoke() {}
*/ */
class KtVariableWithInvokeFunctionCall( public class KtVariableWithInvokeFunctionCall(
val target: KtVariableLikeSymbol, public val target: KtVariableLikeSymbol,
override val targetFunction: KtCallTarget override val targetFunction: KtCallTarget
) : KtDeclaredFunctionCall() ) : KtDeclaredFunctionCall()
@@ -58,21 +58,21 @@ class KtVariableWithInvokeFunctionCall(
* *
* x.toString() // function call * x.toString() // function call
*/ */
data class KtFunctionCall(override val targetFunction: KtCallTarget) : KtDeclaredFunctionCall() public data class KtFunctionCall(override val targetFunction: KtCallTarget) : KtDeclaredFunctionCall()
/** /**
* Represents function(s) in which call was resolved, * Represents function(s) in which call was resolved,
* Can be success [KtSuccessCallTarget] in this case there only one such function * Can be success [KtSuccessCallTarget] in this case there only one such function
* Or erroneous [KtErrorCallTarget] in this case there can be any count of candidates * Or erroneous [KtErrorCallTarget] in this case there can be any count of candidates
*/ */
sealed class KtCallTarget { public sealed class KtCallTarget {
abstract val candidates: Collection<KtFunctionLikeSymbol> public abstract val candidates: Collection<KtFunctionLikeSymbol>
} }
/** /**
* Success call of [symbol] * Success call of [symbol]
*/ */
class KtSuccessCallTarget(val symbol: KtFunctionLikeSymbol) : KtCallTarget() { public class KtSuccessCallTarget(public val symbol: KtFunctionLikeSymbol) : KtCallTarget() {
override val candidates: Collection<KtFunctionLikeSymbol> override val candidates: Collection<KtFunctionLikeSymbol>
get() = listOf(symbol) get() = listOf(symbol)
} }
@@ -80,4 +80,7 @@ class KtSuccessCallTarget(val symbol: KtFunctionLikeSymbol) : KtCallTarget() {
/** /**
* Function all with errors, possible candidates are [candidates] * Function all with errors, possible candidates are [candidates]
*/ */
class KtErrorCallTarget(override val candidates: Collection<KtFunctionLikeSymbol>, val diagnostic: KtDiagnostic) : KtCallTarget() public class KtErrorCallTarget(
override val candidates: Collection<KtFunctionLikeSymbol>,
public val diagnostic: KtDiagnostic
) : KtCallTarget()
@@ -7,12 +7,12 @@ package org.jetbrains.kotlin.idea.frontend.api.calls
import org.jetbrains.kotlin.idea.frontend.api.symbols.KtFunctionLikeSymbol import org.jetbrains.kotlin.idea.frontend.api.symbols.KtFunctionLikeSymbol
fun KtCallTarget.getSuccessCallSymbolOrNull(): KtFunctionLikeSymbol? = when (this) { public fun KtCallTarget.getSuccessCallSymbolOrNull(): KtFunctionLikeSymbol? = when (this) {
is KtSuccessCallTarget -> symbol is KtSuccessCallTarget -> symbol
is KtErrorCallTarget -> null is KtErrorCallTarget -> null
} }
inline fun <reified S : KtFunctionLikeSymbol> KtCall.isSuccessCallOf(predicate: (S) -> Boolean): Boolean { public inline fun <reified S : KtFunctionLikeSymbol> KtCall.isSuccessCallOf(predicate: (S) -> Boolean): Boolean {
if (this !is KtFunctionCall) return false if (this !is KtFunctionCall) return false
val symbol = targetFunction.getSuccessCallSymbolOrNull() ?: return false val symbol = targetFunction.getSuccessCallSymbolOrNull() ?: return false
if (symbol !is S) return false if (symbol !is S) return false
@@ -8,7 +8,7 @@ package org.jetbrains.kotlin.idea.frontend.api.components
import org.jetbrains.kotlin.idea.frontend.api.KtAnalysisSession import org.jetbrains.kotlin.idea.frontend.api.KtAnalysisSession
import org.jetbrains.kotlin.idea.frontend.api.ValidityTokenOwner import org.jetbrains.kotlin.idea.frontend.api.ValidityTokenOwner
abstract class KtAnalysisSessionComponent : ValidityTokenOwner { public abstract class KtAnalysisSessionComponent : ValidityTokenOwner {
protected abstract val analysisSession: KtAnalysisSession protected abstract val analysisSession: KtAnalysisSession
} }
@@ -7,6 +7,6 @@ package org.jetbrains.kotlin.idea.frontend.api.components
import org.jetbrains.kotlin.idea.frontend.api.KtAnalysisSession import org.jetbrains.kotlin.idea.frontend.api.KtAnalysisSession
interface KtAnalysisSessionMixIn { public interface KtAnalysisSessionMixIn {
val analysisSession: KtAnalysisSession public val analysisSession: KtAnalysisSession
} }
@@ -10,19 +10,19 @@ import org.jetbrains.kotlin.psi.KtBinaryExpression
import org.jetbrains.kotlin.psi.KtCallExpression import org.jetbrains.kotlin.psi.KtCallExpression
import org.jetbrains.kotlin.psi.KtUnaryExpression import org.jetbrains.kotlin.psi.KtUnaryExpression
abstract class KtCallResolver : KtAnalysisSessionComponent() { public abstract class KtCallResolver : KtAnalysisSessionComponent() {
abstract fun resolveCall(call: KtCallExpression): KtCall? public abstract fun resolveCall(call: KtCallExpression): KtCall?
abstract fun resolveCall(call: KtBinaryExpression): KtCall? public abstract fun resolveCall(call: KtBinaryExpression): KtCall?
abstract fun resolveCall(call: KtUnaryExpression): KtCall? public abstract fun resolveCall(call: KtUnaryExpression): KtCall?
} }
interface KtCallResolverMixIn : KtAnalysisSessionMixIn { public interface KtCallResolverMixIn : KtAnalysisSessionMixIn {
fun KtCallExpression.resolveCall(): KtCall? = public fun KtCallExpression.resolveCall(): KtCall? =
analysisSession.callResolver.resolveCall(this) analysisSession.callResolver.resolveCall(this)
fun KtBinaryExpression.resolveCall(): KtCall? = public fun KtBinaryExpression.resolveCall(): KtCall? =
analysisSession.callResolver.resolveCall(this) analysisSession.callResolver.resolveCall(this)
fun KtUnaryExpression.resolveCall(): KtCall? = public fun KtUnaryExpression.resolveCall(): KtCall? =
analysisSession.callResolver.resolveCall(this) analysisSession.callResolver.resolveCall(this)
} }
@@ -8,11 +8,11 @@ package org.jetbrains.kotlin.idea.frontend.api.components
import org.jetbrains.kotlin.idea.frontend.api.symbols.markers.KtSimpleConstantValue import org.jetbrains.kotlin.idea.frontend.api.symbols.markers.KtSimpleConstantValue
import org.jetbrains.kotlin.psi.KtExpression import org.jetbrains.kotlin.psi.KtExpression
abstract class KtCompileTimeConstantProvider : KtAnalysisSessionComponent() { public abstract class KtCompileTimeConstantProvider : KtAnalysisSessionComponent() {
abstract fun evaluate(expression: KtExpression): KtSimpleConstantValue<*>? public abstract fun evaluate(expression: KtExpression): KtSimpleConstantValue<*>?
} }
interface KtCompileTimeConstantProviderMixIn : KtAnalysisSessionMixIn { public interface KtCompileTimeConstantProviderMixIn : KtAnalysisSessionMixIn {
fun KtExpression.evaluate(): KtSimpleConstantValue<*>? = public fun KtExpression.evaluate(): KtSimpleConstantValue<*>? =
analysisSession.compileTimeConstantProvider.evaluate(this) analysisSession.compileTimeConstantProvider.evaluate(this)
} }
@@ -10,8 +10,8 @@ import org.jetbrains.kotlin.psi.KtExpression
import org.jetbrains.kotlin.psi.KtFile import org.jetbrains.kotlin.psi.KtFile
import org.jetbrains.kotlin.psi.KtSimpleNameExpression import org.jetbrains.kotlin.psi.KtSimpleNameExpression
abstract class KtCompletionCandidateChecker : KtAnalysisSessionComponent() { public abstract class KtCompletionCandidateChecker : KtAnalysisSessionComponent() {
abstract fun checkExtensionFitsCandidate( public abstract fun checkExtensionFitsCandidate(
firSymbolForCandidate: KtCallableSymbol, firSymbolForCandidate: KtCallableSymbol,
originalFile: KtFile, originalFile: KtFile,
nameExpression: KtSimpleNameExpression, nameExpression: KtSimpleNameExpression,
@@ -19,14 +19,14 @@ abstract class KtCompletionCandidateChecker : KtAnalysisSessionComponent() {
): KtExtensionApplicabilityResult ): KtExtensionApplicabilityResult
} }
enum class KtExtensionApplicabilityResult(val isApplicable: Boolean) { public enum class KtExtensionApplicabilityResult(public val isApplicable: Boolean) {
ApplicableAsExtensionCallable(isApplicable = true), ApplicableAsExtensionCallable(isApplicable = true),
ApplicableAsFunctionalVariableCall(isApplicable = true), ApplicableAsFunctionalVariableCall(isApplicable = true),
NonApplicable(isApplicable = false), NonApplicable(isApplicable = false),
} }
interface KtCompletionCandidateCheckerMixIn : KtAnalysisSessionMixIn { public interface KtCompletionCandidateCheckerMixIn : KtAnalysisSessionMixIn {
fun KtCallableSymbol.checkExtensionIsSuitable( public fun KtCallableSymbol.checkExtensionIsSuitable(
originalPsiFile: KtFile, originalPsiFile: KtFile,
psiFakeCompletionExpression: KtSimpleNameExpression, psiFakeCompletionExpression: KtSimpleNameExpression,
psiReceiverExpression: KtExpression?, psiReceiverExpression: KtExpression?,
@@ -10,20 +10,20 @@ import org.jetbrains.kotlin.idea.frontend.api.diagnostics.KtDiagnosticWithPsi
import org.jetbrains.kotlin.psi.KtElement import org.jetbrains.kotlin.psi.KtElement
import org.jetbrains.kotlin.psi.KtFile import org.jetbrains.kotlin.psi.KtFile
abstract class KtDiagnosticProvider : KtAnalysisSessionComponent() { public abstract class KtDiagnosticProvider : KtAnalysisSessionComponent() {
abstract fun getDiagnosticsForElement(element: KtElement, filter: KtDiagnosticCheckerFilter): Collection<KtDiagnosticWithPsi<*>> public abstract fun getDiagnosticsForElement(element: KtElement, filter: KtDiagnosticCheckerFilter): Collection<KtDiagnosticWithPsi<*>>
abstract fun collectDiagnosticsForFile(ktFile: KtFile, filter: KtDiagnosticCheckerFilter): Collection<KtDiagnosticWithPsi<*>> public abstract fun collectDiagnosticsForFile(ktFile: KtFile, filter: KtDiagnosticCheckerFilter): Collection<KtDiagnosticWithPsi<*>>
} }
interface KtDiagnosticProviderMixIn : KtAnalysisSessionMixIn { public interface KtDiagnosticProviderMixIn : KtAnalysisSessionMixIn {
fun KtElement.getDiagnostics(filter: KtDiagnosticCheckerFilter): Collection<KtDiagnostic> = public fun KtElement.getDiagnostics(filter: KtDiagnosticCheckerFilter): Collection<KtDiagnostic> =
analysisSession.diagnosticProvider.getDiagnosticsForElement(this, filter) analysisSession.diagnosticProvider.getDiagnosticsForElement(this, filter)
fun KtFile.collectDiagnosticsForFile(filter: KtDiagnosticCheckerFilter): Collection<KtDiagnosticWithPsi<*>> = public fun KtFile.collectDiagnosticsForFile(filter: KtDiagnosticCheckerFilter): Collection<KtDiagnosticWithPsi<*>> =
analysisSession.diagnosticProvider.collectDiagnosticsForFile(this, filter) analysisSession.diagnosticProvider.collectDiagnosticsForFile(this, filter)
} }
enum class KtDiagnosticCheckerFilter { public enum class KtDiagnosticCheckerFilter {
ONLY_COMMON_CHECKERS, ONLY_COMMON_CHECKERS,
ONLY_EXTENDED_CHECKERS, ONLY_EXTENDED_CHECKERS,
EXTENDED_AND_COMMON_CHECKERS, EXTENDED_AND_COMMON_CHECKERS,
@@ -10,14 +10,14 @@ import org.jetbrains.kotlin.idea.frontend.api.symbols.KtCallableSymbol
import org.jetbrains.kotlin.psi.KtReturnExpression import org.jetbrains.kotlin.psi.KtReturnExpression
import org.jetbrains.kotlin.psi.KtWhenExpression import org.jetbrains.kotlin.psi.KtWhenExpression
abstract class KtExpressionInfoProvider : KtAnalysisSessionComponent() { public abstract class KtExpressionInfoProvider : KtAnalysisSessionComponent() {
abstract fun getReturnExpressionTargetSymbol(returnExpression: KtReturnExpression): KtCallableSymbol? public abstract fun getReturnExpressionTargetSymbol(returnExpression: KtReturnExpression): KtCallableSymbol?
abstract fun getWhenMissingCases(whenExpression: KtWhenExpression): List<WhenMissingCase> public abstract fun getWhenMissingCases(whenExpression: KtWhenExpression): List<WhenMissingCase>
} }
interface KtExpressionInfoProviderMixIn : KtAnalysisSessionMixIn { public interface KtExpressionInfoProviderMixIn : KtAnalysisSessionMixIn {
fun KtReturnExpression.getReturnTargetSymbol(): KtCallableSymbol? = public fun KtReturnExpression.getReturnTargetSymbol(): KtCallableSymbol? =
analysisSession.expressionInfoProvider.getReturnExpressionTargetSymbol(this) analysisSession.expressionInfoProvider.getReturnExpressionTargetSymbol(this)
fun KtWhenExpression.getMissingCases(): List<WhenMissingCase> = analysisSession.expressionInfoProvider.getWhenMissingCases(this) public fun KtWhenExpression.getMissingCases(): List<WhenMissingCase> = analysisSession.expressionInfoProvider.getWhenMissingCases(this)
} }
@@ -10,33 +10,33 @@ import org.jetbrains.kotlin.idea.frontend.api.types.KtType
import org.jetbrains.kotlin.psi.KtDeclaration import org.jetbrains.kotlin.psi.KtDeclaration
import org.jetbrains.kotlin.psi.KtExpression import org.jetbrains.kotlin.psi.KtExpression
abstract class KtExpressionTypeProvider : KtAnalysisSessionComponent() { public abstract class KtExpressionTypeProvider : KtAnalysisSessionComponent() {
abstract fun getReturnTypeForKtDeclaration(declaration: KtDeclaration): KtType public abstract fun getReturnTypeForKtDeclaration(declaration: KtDeclaration): KtType
abstract fun getKtExpressionType(expression: KtExpression): KtType public abstract fun getKtExpressionType(expression: KtExpression): KtType
abstract fun getExpectedType(expression: PsiElement): KtType? public abstract fun getExpectedType(expression: PsiElement): KtType?
abstract fun isDefinitelyNull(expression: KtExpression): Boolean public abstract fun isDefinitelyNull(expression: KtExpression): Boolean
abstract fun isDefinitelyNotNull(expression: KtExpression): Boolean public abstract fun isDefinitelyNotNull(expression: KtExpression): Boolean
} }
interface KtExpressionTypeProviderMixIn : KtAnalysisSessionMixIn { public interface KtExpressionTypeProviderMixIn : KtAnalysisSessionMixIn {
fun KtExpression.getKtType(): KtType = public fun KtExpression.getKtType(): KtType =
analysisSession.expressionTypeProvider.getKtExpressionType(this) analysisSession.expressionTypeProvider.getKtExpressionType(this)
fun KtDeclaration.getReturnKtType(): KtType = public fun KtDeclaration.getReturnKtType(): KtType =
analysisSession.expressionTypeProvider.getReturnTypeForKtDeclaration(this) analysisSession.expressionTypeProvider.getReturnTypeForKtDeclaration(this)
/** /**
* Returns the expected [KtType] of this [PsiElement] if it is an expression. The returned value should not be a * Returns the expected [KtType] of this [PsiElement] if it is an expression. The returned value should not be a
* [org.jetbrains.kotlin.idea.frontend.api.types.KtClassErrorType]. * [org.jetbrains.kotlin.idea.frontend.api.types.KtClassErrorType].
*/ */
fun PsiElement.getExpectedType(): KtType? = public fun PsiElement.getExpectedType(): KtType? =
analysisSession.expressionTypeProvider.getExpectedType(this) analysisSession.expressionTypeProvider.getExpectedType(this)
/** /**
* Returns `true` if this expression is definitely null, based on declared nullability and smart cast types derived from * Returns `true` if this expression is definitely null, based on declared nullability and smart cast types derived from
* data-flow analysis facts. Examples: * data-flow analysis facts. Examples:
* ``` * ```
* fun <T : Any> foo(t: T, nt: T?, s: String, ns: String?) { * public fun <T : Any> foo(t: T, nt: T?, s: String, ns: String?) {
* t // t.isDefinitelyNull() == false && t.isDefinitelyNotNull() == true * t // t.isDefinitelyNull() == false && t.isDefinitelyNotNull() == true
* nt // nt.isDefinitelyNull() == false && nt.isDefinitelyNotNull() == false * nt // nt.isDefinitelyNull() == false && nt.isDefinitelyNotNull() == false
* s // s.isDefinitelyNull() == false && s.isDefinitelyNotNull() == true * s // s.isDefinitelyNull() == false && s.isDefinitelyNotNull() == true
@@ -54,12 +54,12 @@ interface KtExpressionTypeProviderMixIn : KtAnalysisSessionMixIn {
* Note that only nullability from "stable" smart cast types is considered. The * Note that only nullability from "stable" smart cast types is considered. The
* [spec](https://kotlinlang.org/spec/type-inference.html#smart-cast-sink-stability) provides an explanation on smart cast stability. * [spec](https://kotlinlang.org/spec/type-inference.html#smart-cast-sink-stability) provides an explanation on smart cast stability.
*/ */
fun KtExpression.isDefinitelyNull(): Boolean = public fun KtExpression.isDefinitelyNull(): Boolean =
analysisSession.expressionTypeProvider.isDefinitelyNull(this) analysisSession.expressionTypeProvider.isDefinitelyNull(this)
/** /**
* Returns `true` if this expression is definitely not null. See [isDefinitelyNull] for examples. * Returns `true` if this expression is definitely not null. See [isDefinitelyNull] for examples.
*/ */
fun KtExpression.isDefinitelyNotNull(): Boolean = public fun KtExpression.isDefinitelyNotNull(): Boolean =
analysisSession.expressionTypeProvider.isDefinitelyNotNull(this) analysisSession.expressionTypeProvider.isDefinitelyNotNull(this)
} }
@@ -8,15 +8,15 @@ package org.jetbrains.kotlin.idea.frontend.api.components
import org.jetbrains.kotlin.idea.frontend.api.symbols.KtEnumEntrySymbol import org.jetbrains.kotlin.idea.frontend.api.symbols.KtEnumEntrySymbol
import org.jetbrains.kotlin.idea.frontend.api.symbols.KtNamedClassOrObjectSymbol import org.jetbrains.kotlin.idea.frontend.api.symbols.KtNamedClassOrObjectSymbol
abstract class KtInheritorsProvider : KtAnalysisSessionComponent() { public abstract class KtInheritorsProvider : KtAnalysisSessionComponent() {
abstract fun getInheritorsOfSealedClass(classSymbol: KtNamedClassOrObjectSymbol): List<KtNamedClassOrObjectSymbol> public abstract fun getInheritorsOfSealedClass(classSymbol: KtNamedClassOrObjectSymbol): List<KtNamedClassOrObjectSymbol>
abstract fun getEnumEntries(classSymbol: KtNamedClassOrObjectSymbol): List<KtEnumEntrySymbol> public abstract fun getEnumEntries(classSymbol: KtNamedClassOrObjectSymbol): List<KtEnumEntrySymbol>
} }
interface KtInheritorsProviderMixIn : KtAnalysisSessionMixIn { public interface KtInheritorsProviderMixIn : KtAnalysisSessionMixIn {
fun KtNamedClassOrObjectSymbol.getSealedClassInheritors(): List<KtNamedClassOrObjectSymbol> = public fun KtNamedClassOrObjectSymbol.getSealedClassInheritors(): List<KtNamedClassOrObjectSymbol> =
analysisSession.inheritorsProvider.getInheritorsOfSealedClass(this) analysisSession.inheritorsProvider.getInheritorsOfSealedClass(this)
fun KtNamedClassOrObjectSymbol.getEnumEntries(): List<KtEnumEntrySymbol> = public fun KtNamedClassOrObjectSymbol.getEnumEntries(): List<KtEnumEntrySymbol> =
analysisSession.inheritorsProvider.getEnumEntries(this) analysisSession.inheritorsProvider.getEnumEntries(this)
} }
@@ -9,24 +9,28 @@ import org.jetbrains.kotlin.util.ImplementationStatus
import org.jetbrains.kotlin.idea.frontend.api.symbols.KtCallableSymbol import org.jetbrains.kotlin.idea.frontend.api.symbols.KtCallableSymbol
import org.jetbrains.kotlin.idea.frontend.api.symbols.KtClassOrObjectSymbol import org.jetbrains.kotlin.idea.frontend.api.symbols.KtClassOrObjectSymbol
abstract class KtOverrideInfoProvider : KtAnalysisSessionComponent() { public abstract class KtOverrideInfoProvider : KtAnalysisSessionComponent() {
abstract fun isVisible(memberSymbol: KtCallableSymbol, classSymbol: KtClassOrObjectSymbol): Boolean public abstract fun isVisible(memberSymbol: KtCallableSymbol, classSymbol: KtClassOrObjectSymbol): Boolean
abstract fun getImplementationStatus(memberSymbol: KtCallableSymbol, parentClassSymbol: KtClassOrObjectSymbol): ImplementationStatus? public abstract fun getImplementationStatus(
abstract fun getOriginalOverriddenSymbol(symbol: KtCallableSymbol): KtCallableSymbol? memberSymbol: KtCallableSymbol,
abstract fun getOriginalContainingClassForOverride(symbol: KtCallableSymbol): KtClassOrObjectSymbol? parentClassSymbol: KtClassOrObjectSymbol
): ImplementationStatus?
public abstract fun getOriginalOverriddenSymbol(symbol: KtCallableSymbol): KtCallableSymbol?
public abstract fun getOriginalContainingClassForOverride(symbol: KtCallableSymbol): KtClassOrObjectSymbol?
} }
interface KtMemberSymbolProviderMixin : KtAnalysisSessionMixIn { public interface KtMemberSymbolProviderMixin : KtAnalysisSessionMixIn {
/** Checks if the given symbol (possibly a symbol inherited from a super class) is visible in the given class. */ /** Checks if the given symbol (possibly a symbol inherited from a super class) is visible in the given class. */
fun KtCallableSymbol.isVisibleInClass(classSymbol: KtClassOrObjectSymbol): Boolean = public fun KtCallableSymbol.isVisibleInClass(classSymbol: KtClassOrObjectSymbol): Boolean =
analysisSession.overrideInfoProvider.isVisible(this, classSymbol) analysisSession.overrideInfoProvider.isVisible(this, classSymbol)
/** /**
* Gets the [ImplementationStatus] of the [this] member symbol in the given [parentClassSymbol]. Or null if this symbol is not a * Gets the [ImplementationStatus] of the [this] member symbol in the given [parentClassSymbol]. Or null if this symbol is not a
* member. * member.
*/ */
fun KtCallableSymbol.getImplementationStatus(parentClassSymbol: KtClassOrObjectSymbol): ImplementationStatus? = public fun KtCallableSymbol.getImplementationStatus(parentClassSymbol: KtClassOrObjectSymbol): ImplementationStatus? =
analysisSession.overrideInfoProvider.getImplementationStatus(this, parentClassSymbol) analysisSession.overrideInfoProvider.getImplementationStatus(this, parentClassSymbol)
/** /**
@@ -34,11 +38,11 @@ interface KtMemberSymbolProviderMixin : KtAnalysisSessionMixIn {
* classes. For example, consider * classes. For example, consider
* *
* ``` * ```
* interface A<T> { * public interface A<T> {
* fun foo(t:T) * public fun foo(t:T)
* } * }
* *
* interface B: A<String> { * public interface B: A<String> {
* } * }
* ``` * ```
* *
@@ -49,12 +53,12 @@ interface KtMemberSymbolProviderMixin : KtAnalysisSessionMixIn {
* Such situation can also happens for intersection symbols (in case of multiple super types containing symbols with identical signature * Such situation can also happens for intersection symbols (in case of multiple super types containing symbols with identical signature
* after specialization) and delegation. * after specialization) and delegation.
*/ */
val KtCallableSymbol.originalOverriddenSymbol: KtCallableSymbol? public val KtCallableSymbol.originalOverriddenSymbol: KtCallableSymbol?
get() = analysisSession.overrideInfoProvider.getOriginalOverriddenSymbol(this) get() = analysisSession.overrideInfoProvider.getOriginalOverriddenSymbol(this)
/** /**
* Gets the class symbol where the given callable symbol is declared. See [originalOverriddenSymbol] for more details. * Gets the class symbol where the given callable symbol is declared. See [originalOverriddenSymbol] for more details.
*/ */
val KtCallableSymbol.originalContainingClassForOverride: KtClassOrObjectSymbol? public val KtCallableSymbol.originalContainingClassForOverride: KtClassOrObjectSymbol?
get() = analysisSession.overrideInfoProvider.getOriginalContainingClassForOverride(this) get() = analysisSession.overrideInfoProvider.getOriginalContainingClassForOverride(this)
} }
@@ -11,22 +11,22 @@ import org.jetbrains.kotlin.psi.KtDoubleColonExpression
import org.jetbrains.kotlin.psi.KtExpression import org.jetbrains.kotlin.psi.KtExpression
import org.jetbrains.kotlin.psi.KtTypeReference import org.jetbrains.kotlin.psi.KtTypeReference
abstract class KtPsiTypeProvider : KtAnalysisSessionComponent() { public abstract class KtPsiTypeProvider : KtAnalysisSessionComponent() {
abstract fun getPsiTypeForKtExpression(expression: KtExpression, mode: TypeMappingMode): PsiType public abstract fun getPsiTypeForKtExpression(expression: KtExpression, mode: TypeMappingMode): PsiType
abstract fun getPsiTypeForKtTypeReference(ktTypeReference: KtTypeReference, mode: TypeMappingMode): PsiType public abstract fun getPsiTypeForKtTypeReference(ktTypeReference: KtTypeReference, mode: TypeMappingMode): PsiType
abstract fun getPsiTypeForReceiverOfDoubleColonExpression( public abstract fun getPsiTypeForReceiverOfDoubleColonExpression(
ktDoubleColonExpression: KtDoubleColonExpression, ktDoubleColonExpression: KtDoubleColonExpression,
mode: TypeMappingMode mode: TypeMappingMode
): PsiType? ): PsiType?
} }
interface KtPsiTypeProviderMixIn : KtAnalysisSessionMixIn { public interface KtPsiTypeProviderMixIn : KtAnalysisSessionMixIn {
fun KtExpression.getPsiType(mode: TypeMappingMode = TypeMappingMode.DEFAULT): PsiType = public fun KtExpression.getPsiType(mode: TypeMappingMode = TypeMappingMode.DEFAULT): PsiType =
analysisSession.psiTypeProvider.getPsiTypeForKtExpression(this, mode) analysisSession.psiTypeProvider.getPsiTypeForKtExpression(this, mode)
fun KtTypeReference.getPsiType(mode: TypeMappingMode = TypeMappingMode.DEFAULT): PsiType = public fun KtTypeReference.getPsiType(mode: TypeMappingMode = TypeMappingMode.DEFAULT): PsiType =
analysisSession.psiTypeProvider.getPsiTypeForKtTypeReference(this, mode) analysisSession.psiTypeProvider.getPsiTypeForKtTypeReference(this, mode)
fun KtDoubleColonExpression.getReceiverPsiType(mode: TypeMappingMode = TypeMappingMode.DEFAULT): PsiType? = public fun KtDoubleColonExpression.getReceiverPsiType(mode: TypeMappingMode = TypeMappingMode.DEFAULT): PsiType? =
analysisSession.psiTypeProvider.getPsiTypeForReceiverOfDoubleColonExpression(this, mode) analysisSession.psiTypeProvider.getPsiTypeForReceiverOfDoubleColonExpression(this, mode)
} }
@@ -9,13 +9,13 @@ import org.jetbrains.kotlin.idea.frontend.api.KtSymbolBasedReference
import org.jetbrains.kotlin.idea.frontend.api.symbols.KtSymbol import org.jetbrains.kotlin.idea.frontend.api.symbols.KtSymbol
import org.jetbrains.kotlin.idea.references.KtReference import org.jetbrains.kotlin.idea.references.KtReference
interface KtReferenceResolveMixIn : KtAnalysisSessionMixIn { public interface KtReferenceResolveMixIn : KtAnalysisSessionMixIn {
fun KtReference.resolveToSymbols(): Collection<KtSymbol> { public fun KtReference.resolveToSymbols(): Collection<KtSymbol> {
check(this is KtSymbolBasedReference) { "To get reference symbol the one should be KtSymbolBasedReference" } check(this is KtSymbolBasedReference) { "To get reference symbol the one should be KtSymbolBasedReference" }
return analysisSession.resolveToSymbols() return analysisSession.resolveToSymbols()
} }
fun KtReference.resolveToSymbol(): KtSymbol? { public fun KtReference.resolveToSymbol(): KtSymbol? {
check(this is KtSymbolBasedReference) { "To get reference symbol the one should be KtSymbolBasedReference but was ${this::class}" } check(this is KtSymbolBasedReference) { "To get reference symbol the one should be KtSymbolBasedReference but was ${this::class}" }
return resolveToSymbols().singleOrNull() return resolveToSymbols().singleOrNull()
} }
@@ -12,7 +12,7 @@ import org.jetbrains.kotlin.idea.frontend.api.symbols.KtEnumEntrySymbol
import org.jetbrains.kotlin.psi.KtElement import org.jetbrains.kotlin.psi.KtElement
import org.jetbrains.kotlin.psi.KtFile import org.jetbrains.kotlin.psi.KtFile
enum class ShortenOption { public enum class ShortenOption {
/** Skip shortening references to this symbol. */ /** Skip shortening references to this symbol. */
DO_NOT_SHORTEN, DO_NOT_SHORTEN,
@@ -26,8 +26,8 @@ enum class ShortenOption {
SHORTEN_AND_STAR_IMPORT SHORTEN_AND_STAR_IMPORT
} }
abstract class KtReferenceShortener : KtAnalysisSessionComponent() { public abstract class KtReferenceShortener : KtAnalysisSessionComponent() {
abstract fun collectShortenings( public abstract fun collectShortenings(
file: KtFile, file: KtFile,
selection: TextRange, selection: TextRange,
classShortenOption: (KtClassLikeSymbol) -> ShortenOption, classShortenOption: (KtClassLikeSymbol) -> ShortenOption,
@@ -35,8 +35,8 @@ abstract class KtReferenceShortener : KtAnalysisSessionComponent() {
): ShortenCommand ): ShortenCommand
} }
interface KtReferenceShortenerMixIn : KtAnalysisSessionMixIn { public interface KtReferenceShortenerMixIn : KtAnalysisSessionMixIn {
companion object { public companion object {
private val defaultClassShortenOption: (KtClassLikeSymbol) -> ShortenOption = { private val defaultClassShortenOption: (KtClassLikeSymbol) -> ShortenOption = {
if (it.classIdIfNonLocal?.isNestedClass == true) { if (it.classIdIfNonLocal?.isNestedClass == true) {
ShortenOption.SHORTEN_IF_ALREADY_IMPORTED ShortenOption.SHORTEN_IF_ALREADY_IMPORTED
@@ -55,7 +55,7 @@ interface KtReferenceShortenerMixIn : KtAnalysisSessionMixIn {
* Collects possible references to shorten. By default, it shortens a fully-qualified members to the outermost class and does not * Collects possible references to shorten. By default, it shortens a fully-qualified members to the outermost class and does not
* shorten enum entries. * shorten enum entries.
*/ */
fun collectPossibleReferenceShortenings( public fun collectPossibleReferenceShortenings(
file: KtFile, file: KtFile,
selection: TextRange = file.textRange, selection: TextRange = file.textRange,
classShortenOption: (KtClassLikeSymbol) -> ShortenOption = defaultClassShortenOption, classShortenOption: (KtClassLikeSymbol) -> ShortenOption = defaultClassShortenOption,
@@ -63,7 +63,7 @@ interface KtReferenceShortenerMixIn : KtAnalysisSessionMixIn {
): ShortenCommand = ): ShortenCommand =
analysisSession.referenceShortener.collectShortenings(file, selection, classShortenOption, callableShortenOption) analysisSession.referenceShortener.collectShortenings(file, selection, classShortenOption, callableShortenOption)
fun collectPossibleReferenceShorteningsInElement( public fun collectPossibleReferenceShorteningsInElement(
element: KtElement, element: KtElement,
classShortenOption: (KtClassLikeSymbol) -> ShortenOption = defaultClassShortenOption, classShortenOption: (KtClassLikeSymbol) -> ShortenOption = defaultClassShortenOption,
callableShortenOption: (KtCallableSymbol) -> ShortenOption = defaultCallableShortenOption callableShortenOption: (KtCallableSymbol) -> ShortenOption = defaultCallableShortenOption
@@ -76,7 +76,7 @@ interface KtReferenceShortenerMixIn : KtAnalysisSessionMixIn {
) )
} }
interface ShortenCommand { public interface ShortenCommand {
fun invokeShortening() public fun invokeShortening()
val isEmpty: Boolean public val isEmpty: Boolean
} }
@@ -17,56 +17,56 @@ import org.jetbrains.kotlin.idea.frontend.api.types.KtType
import org.jetbrains.kotlin.psi.KtElement import org.jetbrains.kotlin.psi.KtElement
import org.jetbrains.kotlin.psi.KtFile import org.jetbrains.kotlin.psi.KtFile
abstract class KtScopeProvider : KtAnalysisSessionComponent() { public abstract class KtScopeProvider : KtAnalysisSessionComponent() {
abstract fun getMemberScope(classSymbol: KtSymbolWithMembers): KtMemberScope public abstract fun getMemberScope(classSymbol: KtSymbolWithMembers): KtMemberScope
abstract fun getStaticMemberScope(symbol: KtSymbolWithMembers): KtScope public abstract fun getStaticMemberScope(symbol: KtSymbolWithMembers): KtScope
abstract fun getDeclaredMemberScope(classSymbol: KtSymbolWithMembers): KtDeclaredMemberScope public abstract fun getDeclaredMemberScope(classSymbol: KtSymbolWithMembers): KtDeclaredMemberScope
abstract fun getFileScope(fileSymbol: KtFileSymbol): KtDeclarationScope<KtSymbolWithDeclarations> public abstract fun getFileScope(fileSymbol: KtFileSymbol): KtDeclarationScope<KtSymbolWithDeclarations>
abstract fun getPackageScope(packageSymbol: KtPackageSymbol): KtPackageScope public abstract fun getPackageScope(packageSymbol: KtPackageSymbol): KtPackageScope
abstract fun getCompositeScope(subScopes: List<KtScope>): KtCompositeScope public abstract fun getCompositeScope(subScopes: List<KtScope>): KtCompositeScope
abstract fun getTypeScope(type: KtType): KtScope? public abstract fun getTypeScope(type: KtType): KtScope?
abstract fun getScopeContextForPosition( public abstract fun getScopeContextForPosition(
originalFile: KtFile, originalFile: KtFile,
positionInFakeFile: KtElement positionInFakeFile: KtElement
): KtScopeContext ): KtScopeContext
} }
interface KtScopeProviderMixIn : KtAnalysisSessionMixIn { public interface KtScopeProviderMixIn : KtAnalysisSessionMixIn {
fun KtSymbolWithMembers.getMemberScope(): KtMemberScope = public fun KtSymbolWithMembers.getMemberScope(): KtMemberScope =
analysisSession.scopeProvider.getMemberScope(this) analysisSession.scopeProvider.getMemberScope(this)
fun KtSymbolWithMembers.getDeclaredMemberScope(): KtDeclaredMemberScope = public fun KtSymbolWithMembers.getDeclaredMemberScope(): KtDeclaredMemberScope =
analysisSession.scopeProvider.getDeclaredMemberScope(this) analysisSession.scopeProvider.getDeclaredMemberScope(this)
fun KtSymbolWithMembers.getStaticMemberScope(): KtScope = public fun KtSymbolWithMembers.getStaticMemberScope(): KtScope =
analysisSession.scopeProvider.getStaticMemberScope(this) analysisSession.scopeProvider.getStaticMemberScope(this)
fun KtFileSymbol.getFileScope(): KtDeclarationScope<KtSymbolWithDeclarations> = public fun KtFileSymbol.getFileScope(): KtDeclarationScope<KtSymbolWithDeclarations> =
analysisSession.scopeProvider.getFileScope(this) analysisSession.scopeProvider.getFileScope(this)
fun KtPackageSymbol.getPackageScope(): KtPackageScope = public fun KtPackageSymbol.getPackageScope(): KtPackageScope =
analysisSession.scopeProvider.getPackageScope(this) analysisSession.scopeProvider.getPackageScope(this)
fun List<KtScope>.asCompositeScope(): KtCompositeScope = public fun List<KtScope>.asCompositeScope(): KtCompositeScope =
analysisSession.scopeProvider.getCompositeScope(this) analysisSession.scopeProvider.getCompositeScope(this)
fun KtType.getTypeScope(): KtScope? = public fun KtType.getTypeScope(): KtScope? =
analysisSession.scopeProvider.getTypeScope(this) analysisSession.scopeProvider.getTypeScope(this)
fun KtFile.getScopeContextForPosition(positionInFakeFile: KtElement): KtScopeContext = public fun KtFile.getScopeContextForPosition(positionInFakeFile: KtElement): KtScopeContext =
analysisSession.scopeProvider.getScopeContextForPosition(this, positionInFakeFile) analysisSession.scopeProvider.getScopeContextForPosition(this, positionInFakeFile)
fun KtFile.getScopeContextForFile(): KtScopeContext = public fun KtFile.getScopeContextForFile(): KtScopeContext =
analysisSession.scopeProvider.getScopeContextForPosition(this, this) analysisSession.scopeProvider.getScopeContextForPosition(this, this)
} }
data class KtScopeContext(val scopes: KtCompositeScope, val implicitReceivers: List<KtImplicitReceiver>) public data class KtScopeContext(val scopes: KtCompositeScope, val implicitReceivers: List<KtImplicitReceiver>)
class KtImplicitReceiver( public class KtImplicitReceiver(
override val token: ValidityToken, override val token: ValidityToken,
val type: KtType, public val type: KtType,
val ownerSymbol: KtSymbol public val ownerSymbol: KtSymbol
): ValidityTokenOwner ) : ValidityTokenOwner
@@ -9,15 +9,15 @@ import org.jetbrains.kotlin.idea.frontend.api.ImplicitReceiverSmartCast
import org.jetbrains.kotlin.idea.frontend.api.types.KtType import org.jetbrains.kotlin.idea.frontend.api.types.KtType
import org.jetbrains.kotlin.psi.KtExpression import org.jetbrains.kotlin.psi.KtExpression
abstract class KtSmartCastProvider : KtAnalysisSessionComponent() { public abstract class KtSmartCastProvider : KtAnalysisSessionComponent() {
abstract fun getSmartCastedToType(expression: KtExpression): KtType? public abstract fun getSmartCastedToType(expression: KtExpression): KtType?
abstract fun getImplicitReceiverSmartCast(expression: KtExpression): Collection<ImplicitReceiverSmartCast> public abstract fun getImplicitReceiverSmartCast(expression: KtExpression): Collection<ImplicitReceiverSmartCast>
} }
interface KtSmartCastProviderMixIn : KtAnalysisSessionMixIn { public interface KtSmartCastProviderMixIn : KtAnalysisSessionMixIn {
fun KtExpression.getSmartCast(): KtType? = public fun KtExpression.getSmartCast(): KtType? =
analysisSession.smartCastProvider.getSmartCastedToType(this) analysisSession.smartCastProvider.getSmartCastedToType(this)
fun KtExpression.getImplicitReceiverSmartCast(): Collection<ImplicitReceiverSmartCast> = public fun KtExpression.getImplicitReceiverSmartCast(): Collection<ImplicitReceiverSmartCast> =
analysisSession.smartCastProvider.getImplicitReceiverSmartCast(this) analysisSession.smartCastProvider.getImplicitReceiverSmartCast(this)
} }
@@ -7,18 +7,18 @@ package org.jetbrains.kotlin.idea.frontend.api.components
import org.jetbrains.kotlin.idea.frontend.api.types.KtType import org.jetbrains.kotlin.idea.frontend.api.types.KtType
abstract class KtSubtypingComponent : KtAnalysisSessionComponent() { public abstract class KtSubtypingComponent : KtAnalysisSessionComponent() {
abstract fun isEqualTo(first: KtType, second: KtType): Boolean public abstract fun isEqualTo(first: KtType, second: KtType): Boolean
abstract fun isSubTypeOf(subType: KtType, superType: KtType): Boolean public abstract fun isSubTypeOf(subType: KtType, superType: KtType): Boolean
} }
interface KtSubtypingComponentMixIn : KtAnalysisSessionMixIn { public interface KtSubtypingComponentMixIn : KtAnalysisSessionMixIn {
infix fun KtType.isEqualTo(other: KtType): Boolean = infix public fun KtType.isEqualTo(other: KtType): Boolean =
analysisSession.subtypingComponent.isEqualTo(this, other) analysisSession.subtypingComponent.isEqualTo(this, other)
infix fun KtType.isSubTypeOf(superType: KtType): Boolean = infix public fun KtType.isSubTypeOf(superType: KtType): Boolean =
analysisSession.subtypingComponent.isSubTypeOf(this, superType) analysisSession.subtypingComponent.isSubTypeOf(this, superType)
infix fun KtType.isNotSubTypeOf(superType: KtType): Boolean = infix public fun KtType.isNotSubTypeOf(superType: KtType): Boolean =
!analysisSession.subtypingComponent.isSubTypeOf(this, superType) !analysisSession.subtypingComponent.isSubTypeOf(this, superType)
} }
@@ -7,17 +7,17 @@ package org.jetbrains.kotlin.idea.frontend.api.components
import org.jetbrains.kotlin.idea.frontend.api.symbols.markers.KtSymbolWithKind import org.jetbrains.kotlin.idea.frontend.api.symbols.markers.KtSymbolWithKind
abstract class KtSymbolContainingDeclarationProvider : KtAnalysisSessionComponent() { public abstract class KtSymbolContainingDeclarationProvider : KtAnalysisSessionComponent() {
abstract fun getContainingDeclaration(symbol: KtSymbolWithKind): KtSymbolWithKind? public abstract fun getContainingDeclaration(symbol: KtSymbolWithKind): KtSymbolWithKind?
} }
interface KtSymbolContainingDeclarationProviderMixIn : KtAnalysisSessionMixIn { public interface KtSymbolContainingDeclarationProviderMixIn : KtAnalysisSessionMixIn {
/** /**
* Returns containing declaration for symbol: * Returns containing declaration for symbol:
* for top-level declarations returns null * for top-level declarations returns null
* for class members returns containing class * for class members returns containing class
* for local declaration returns declaration it was declared it * for local declaration returns declaration it was declared it
*/ */
fun KtSymbolWithKind.getContainingSymbol(): KtSymbolWithKind? = public fun KtSymbolWithKind.getContainingSymbol(): KtSymbolWithKind? =
analysisSession.containingDeclarationProvider.getContainingDeclaration(this) analysisSession.containingDeclarationProvider.getContainingDeclaration(this)
} }
@@ -9,14 +9,14 @@ import org.jetbrains.kotlin.idea.frontend.api.symbols.KtCallableSymbol
import org.jetbrains.kotlin.idea.frontend.api.symbols.KtClassOrObjectSymbol import org.jetbrains.kotlin.idea.frontend.api.symbols.KtClassOrObjectSymbol
import org.jetbrains.kotlin.idea.frontend.api.symbols.KtSymbol import org.jetbrains.kotlin.idea.frontend.api.symbols.KtSymbol
abstract class KtSymbolDeclarationOverridesProvider : KtAnalysisSessionComponent() { public abstract class KtSymbolDeclarationOverridesProvider : KtAnalysisSessionComponent() {
abstract fun <T : KtSymbol> getAllOverriddenSymbols(callableSymbol: T): List<KtCallableSymbol> public abstract fun <T : KtSymbol> getAllOverriddenSymbols(callableSymbol: T): List<KtCallableSymbol>
abstract fun <T : KtSymbol> getDirectlyOverriddenSymbols(callableSymbol: T): List<KtCallableSymbol> public abstract fun <T : KtSymbol> getDirectlyOverriddenSymbols(callableSymbol: T): List<KtCallableSymbol>
abstract fun getIntersectionOverriddenSymbols(symbol: KtCallableSymbol): Collection<KtCallableSymbol> public abstract fun getIntersectionOverriddenSymbols(symbol: KtCallableSymbol): Collection<KtCallableSymbol>
} }
interface KtSymbolDeclarationOverridesProviderMixIn : KtAnalysisSessionMixIn { public interface KtSymbolDeclarationOverridesProviderMixIn : KtAnalysisSessionMixIn {
/** /**
* Return a list of **all** symbols which are overridden by symbol * Return a list of **all** symbols which are overridden by symbol
* *
@@ -26,7 +26,7 @@ interface KtSymbolDeclarationOverridesProviderMixIn : KtAnalysisSessionMixIn {
* *
* @see getDirectlyOverriddenSymbols * @see getDirectlyOverriddenSymbols
*/ */
fun KtCallableSymbol.getAllOverriddenSymbols(): List<KtCallableSymbol> = public fun KtCallableSymbol.getAllOverriddenSymbols(): List<KtCallableSymbol> =
analysisSession.symbolDeclarationOverridesProvider.getAllOverriddenSymbols(this) analysisSession.symbolDeclarationOverridesProvider.getAllOverriddenSymbols(this)
/** /**
@@ -38,9 +38,9 @@ interface KtSymbolDeclarationOverridesProviderMixIn : KtAnalysisSessionMixIn {
* *
* @see getAllOverriddenSymbols * @see getAllOverriddenSymbols
*/ */
fun KtCallableSymbol.getDirectlyOverriddenSymbols(): List<KtCallableSymbol> = public fun KtCallableSymbol.getDirectlyOverriddenSymbols(): List<KtCallableSymbol> =
analysisSession.symbolDeclarationOverridesProvider.getDirectlyOverriddenSymbols(this) analysisSession.symbolDeclarationOverridesProvider.getDirectlyOverriddenSymbols(this)
fun KtCallableSymbol.getIntersectionOverriddenSymbols(): Collection<KtCallableSymbol> = public fun KtCallableSymbol.getIntersectionOverriddenSymbols(): Collection<KtCallableSymbol> =
analysisSession.symbolDeclarationOverridesProvider.getIntersectionOverriddenSymbols(this) analysisSession.symbolDeclarationOverridesProvider.getIntersectionOverriddenSymbols(this)
} }
@@ -13,28 +13,28 @@ import org.jetbrains.kotlin.idea.frontend.api.types.KtType
* @see KtType * @see KtType
* @see KtSymbolDeclarationRendererProvider.render * @see KtSymbolDeclarationRendererProvider.render
*/ */
data class KtTypeRendererOptions( public data class KtTypeRendererOptions(
/** /**
* Render type name without package name for not local types * Render type name without package name for not local types
*/ */
val shortQualifiedNames: Boolean = false, public val shortQualifiedNames: Boolean = false,
/** /**
* Render function types FunctionN using Kotlin function type syntax * Render public function types public functionN using Kotlin public function type syntax
* @see Function * @see public function
* @sample Function0<Int> returns () -> Int * @sample public function0<Int> returns () -> Int
*/ */
val renderFunctionType: Boolean = true, public val renderFunctionType: Boolean = true,
/** /**
* When met type with unresolved qualifier, render it as it is resolved * When met type with unresolved qualifier, render it as it is resolved
* When `true` will render as `UnresolvedQualifier` * When `true` will render as `UnresolvedQualifier`
* When `false` will render as "ERROR_TYPE <symbol not found for UnresolvedQualifier>" * When `false` will render as "ERROR_TYPE <symbol not found for UnresolvedQualifier>"
*/ */
val renderUnresolvedTypeAsResolved: Boolean = true public val renderUnresolvedTypeAsResolved: Boolean = true
) { ) {
companion object { public companion object {
val DEFAULT = KtTypeRendererOptions() public val DEFAULT: KtTypeRendererOptions = KtTypeRendererOptions()
val SHORT_NAMES = DEFAULT.copy(shortQualifiedNames = true) public val SHORT_NAMES: KtTypeRendererOptions = DEFAULT.copy(shortQualifiedNames = true)
} }
} }
@@ -43,7 +43,7 @@ data class KtTypeRendererOptions(
* @see KtSymbol * @see KtSymbol
* @see KtSymbolDeclarationRendererProvider.render * @see KtSymbolDeclarationRendererProvider.render
*/ */
data class KtDeclarationRendererOptions( public data class KtDeclarationRendererOptions(
/** /**
* Set of modifiers that needed to be rendered * Set of modifiers that needed to be rendered
* @see RendererModifier * @see RendererModifier
@@ -55,7 +55,7 @@ data class KtDeclarationRendererOptions(
*/ */
val typeRendererOptions: KtTypeRendererOptions = KtTypeRendererOptions.DEFAULT, val typeRendererOptions: KtTypeRendererOptions = KtTypeRendererOptions.DEFAULT,
/** /**
* Render Unit return type for functions * Render Unit return type for public functions
*/ */
val renderUnitReturnType: Boolean = false, val renderUnitReturnType: Boolean = false,
/** /**
@@ -72,24 +72,24 @@ data class KtDeclarationRendererOptions(
val approximateTypes: Boolean = false, val approximateTypes: Boolean = false,
/** /**
* Declaration header is something like `abstract class`, `fun`, or `private interface` in a declaration. * Declaration header is something like `public abstract class`, `public fun`, or `private public interface ` in a declaration.
*/ */
val renderDeclarationHeader: Boolean = true, val renderDeclarationHeader: Boolean = true,
/** /**
* Whether to forcefully add `override` modifier when rendering functions or properties. Note that the [modifiers] option still * Whether to forcefully add `override` modifier when rendering public functions or properties. Note that the [modifiers] option still
* controls whether `override` is rendered. That is, if [modifiers] don't contain `override`, then this flag does not have any effect. * controls whether `override` is rendered. That is, if [modifiers] don't contain `override`, then this flag does not have any effect.
*/ */
val forceRenderingOverrideModifier: Boolean = false, val forceRenderingOverrideModifier: Boolean = false,
val renderDefaultParameterValue: Boolean = true, val renderDefaultParameterValue: Boolean = true,
) { ) {
companion object { public companion object {
val DEFAULT = KtDeclarationRendererOptions() public val DEFAULT: KtDeclarationRendererOptions = KtDeclarationRendererOptions()
} }
} }
enum class RendererModifier(val includeByDefault: Boolean) { public enum class RendererModifier(public val includeByDefault: Boolean) {
VISIBILITY(true), VISIBILITY(true),
MODALITY(true), MODALITY(true),
OVERRIDE(true), OVERRIDE(true),
@@ -106,29 +106,29 @@ enum class RendererModifier(val includeByDefault: Boolean) {
OPERATOR(true) OPERATOR(true)
; ;
companion object { public companion object {
val ALL = values().toSet() public val ALL: Set<RendererModifier> = values().toSet()
} }
} }
abstract class KtSymbolDeclarationRendererProvider : KtAnalysisSessionComponent() { public abstract class KtSymbolDeclarationRendererProvider : KtAnalysisSessionComponent() {
abstract fun render(symbol: KtSymbol, options: KtDeclarationRendererOptions): String public abstract fun render(symbol: KtSymbol, options: KtDeclarationRendererOptions): String
abstract fun render(type: KtType, options: KtTypeRendererOptions): String public abstract fun render(type: KtType, options: KtTypeRendererOptions): String
} }
/** /**
* Provides services for rendering Symbols and Types into the Kotlin strings * Provides services for rendering Symbols and Types into the Kotlin strings
*/ */
interface KtSymbolDeclarationRendererMixIn : KtAnalysisSessionMixIn { public interface KtSymbolDeclarationRendererMixIn : KtAnalysisSessionMixIn {
/** /**
* Render symbol into the representable Kotlin string * Render symbol into the representable Kotlin string
*/ */
fun KtSymbol.render(options: KtDeclarationRendererOptions = KtDeclarationRendererOptions.DEFAULT): String = public fun KtSymbol.render(options: KtDeclarationRendererOptions = KtDeclarationRendererOptions.DEFAULT): String =
analysisSession.symbolDeclarationRendererProvider.render(this, options) analysisSession.symbolDeclarationRendererProvider.render(this, options)
/** /**
* Render kotlin type into the representable Kotlin type string * Render kotlin type into the representable Kotlin type string
*/ */
fun KtType.render(options: KtTypeRendererOptions = KtTypeRendererOptions.DEFAULT): String = public fun KtType.render(options: KtTypeRendererOptions = KtTypeRendererOptions.DEFAULT): String =
analysisSession.symbolDeclarationRendererProvider.render(this, options) analysisSession.symbolDeclarationRendererProvider.render(this, options)
} }
@@ -8,7 +8,7 @@ package org.jetbrains.kotlin.idea.frontend.api.components
import org.jetbrains.kotlin.idea.frontend.api.symbols.KtSymbol import org.jetbrains.kotlin.idea.frontend.api.symbols.KtSymbol
import org.jetbrains.kotlin.idea.frontend.api.symbols.pointers.KtSymbolPointer import org.jetbrains.kotlin.idea.frontend.api.symbols.pointers.KtSymbolPointer
interface KtSymbolsMixIn : KtAnalysisSessionMixIn { public interface KtSymbolsMixIn : KtAnalysisSessionMixIn {
@Suppress("DEPRECATION") @Suppress("DEPRECATION")
fun <S : KtSymbol> KtSymbolPointer<S>.restoreSymbol(): S? = restoreSymbol(analysisSession) public fun <S : KtSymbol> KtSymbolPointer<S>.restoreSymbol(): S? = restoreSymbol(analysisSession)
} }
@@ -14,44 +14,44 @@ import org.jetbrains.kotlin.idea.frontend.api.types.KtTypeNullability
import org.jetbrains.kotlin.name.ClassId import org.jetbrains.kotlin.name.ClassId
import org.jetbrains.kotlin.types.Variance import org.jetbrains.kotlin.types.Variance
abstract class KtTypeCreator : KtAnalysisSessionComponent() { public abstract class KtTypeCreator : KtAnalysisSessionComponent() {
abstract fun buildClassType(builder: KtClassTypeBuilder): KtClassType public abstract fun buildClassType(builder: KtClassTypeBuilder): KtClassType
} }
interface KtTypeCreatorMixIn : KtAnalysisSessionMixIn public interface KtTypeCreatorMixIn : KtAnalysisSessionMixIn
inline fun KtTypeCreatorMixIn.buildClassType( public inline fun KtTypeCreatorMixIn.buildClassType(
classId: ClassId, classId: ClassId,
build: KtClassTypeBuilder.() -> Unit = {} build: KtClassTypeBuilder.() -> Unit = {}
): KtClassType = ): KtClassType =
analysisSession.typesCreator.buildClassType(KtClassTypeBuilder.ByClassId(classId).apply(build)) analysisSession.typesCreator.buildClassType(KtClassTypeBuilder.ByClassId(classId).apply(build))
inline fun KtTypeCreatorMixIn.buildClassType( public inline fun KtTypeCreatorMixIn.buildClassType(
symbol: KtClassOrObjectSymbol, symbol: KtClassOrObjectSymbol,
build: KtClassTypeBuilder.() -> Unit = {} build: KtClassTypeBuilder.() -> Unit = {}
): KtClassType = ): KtClassType =
analysisSession.typesCreator.buildClassType(KtClassTypeBuilder.BySymbol(symbol).apply(build)) analysisSession.typesCreator.buildClassType(KtClassTypeBuilder.BySymbol(symbol).apply(build))
sealed class KtTypeBuilder public sealed class KtTypeBuilder
sealed class KtClassTypeBuilder : KtTypeBuilder() { public sealed class KtClassTypeBuilder : KtTypeBuilder() {
private val _arguments = mutableListOf<KtTypeArgument>() private val _arguments = mutableListOf<KtTypeArgument>()
var nullability: KtTypeNullability = KtTypeNullability.NON_NULLABLE public var nullability: KtTypeNullability = KtTypeNullability.NON_NULLABLE
val arguments: List<KtTypeArgument> get() = _arguments public val arguments: List<KtTypeArgument> get() = _arguments
fun argument(argument: KtTypeArgument) { public fun argument(argument: KtTypeArgument) {
_arguments += argument _arguments += argument
} }
fun argument(type: KtType, variance: Variance = Variance.INVARIANT) { public fun argument(type: KtType, variance: Variance = Variance.INVARIANT) {
_arguments += KtTypeArgumentWithVariance(type, variance, type.token) _arguments += KtTypeArgumentWithVariance(type, variance, type.token)
} }
class ByClassId(val classId: ClassId) : KtClassTypeBuilder() public class ByClassId(public val classId: ClassId) : KtClassTypeBuilder()
class BySymbol(val symbol: KtClassOrObjectSymbol) : KtClassTypeBuilder() public class BySymbol(public val symbol: KtClassOrObjectSymbol) : KtClassTypeBuilder()
} }
@@ -11,43 +11,43 @@ import org.jetbrains.kotlin.idea.frontend.api.symbols.KtTypeAliasSymbol
import org.jetbrains.kotlin.idea.frontend.api.types.* import org.jetbrains.kotlin.idea.frontend.api.types.*
import org.jetbrains.kotlin.name.ClassId import org.jetbrains.kotlin.name.ClassId
abstract class KtTypeInfoProvider : KtAnalysisSessionComponent() { public abstract class KtTypeInfoProvider : KtAnalysisSessionComponent() {
abstract fun canBeNull(type: KtType): Boolean public abstract fun canBeNull(type: KtType): Boolean
} }
interface KtTypeInfoProviderMixIn : KtAnalysisSessionMixIn { public interface KtTypeInfoProviderMixIn : KtAnalysisSessionMixIn {
/** /**
* Returns true if a value of this type can potentially be null. This means this type is not a subtype of [Any]. However, it does not * Returns true if a public value of this type can potentially be null. This means this type is not a subtype of [Any]. However, it does not
* mean one can assign `null` to a variable of this type because it may be unknown if this type can accept `null`. For example, a value * mean one can assign `null` to a variable of this type because it may be unknown if this type can accept `null`. For example, a public value
* of type `T:Any?` can potentially be null. But one can not assign `null` to such a variable because the instantiated type may not be * of type `T:Any?` can potentially be null. But one can not assign `null` to such a variable because the instantiated type may not be
* nullable. * nullable.
*/ */
val KtType.canBeNull: Boolean get() = analysisSession.typeInfoProvider.canBeNull(this) public val KtType.canBeNull: Boolean get() = analysisSession.typeInfoProvider.canBeNull(this)
/** Returns true if the type is explicitly marked as nullable. This means it's safe to assign `null` to a variable with this type. */ /** Returns true if the type is explicitly marked as nullable. This means it's safe to assign `null` to a variable with this type. */
val KtType.isMarkedNullable: Boolean get() = (this as? KtTypeWithNullability)?.nullability == KtTypeNullability.NULLABLE public val KtType.isMarkedNullable: Boolean get() = (this as? KtTypeWithNullability)?.nullability == KtTypeNullability.NULLABLE
val KtType.isUnit: Boolean get() = isClassTypeWithClassId(DefaultTypeClassIds.UNIT) public val KtType.isUnit: Boolean get() = isClassTypeWithClassId(DefaultTypeClassIds.UNIT)
val KtType.isInt: Boolean get() = isClassTypeWithClassId(DefaultTypeClassIds.INT) public val KtType.isInt: Boolean get() = isClassTypeWithClassId(DefaultTypeClassIds.INT)
val KtType.isLong: Boolean get() = isClassTypeWithClassId(DefaultTypeClassIds.LONG) public val KtType.isLong: Boolean get() = isClassTypeWithClassId(DefaultTypeClassIds.LONG)
val KtType.isShort: Boolean get() = isClassTypeWithClassId(DefaultTypeClassIds.SHORT) public val KtType.isShort: Boolean get() = isClassTypeWithClassId(DefaultTypeClassIds.SHORT)
val KtType.isByte: Boolean get() = isClassTypeWithClassId(DefaultTypeClassIds.BYTE) public val KtType.isByte: Boolean get() = isClassTypeWithClassId(DefaultTypeClassIds.BYTE)
val KtType.isFloat: Boolean get() = isClassTypeWithClassId(DefaultTypeClassIds.FLOAT) public val KtType.isFloat: Boolean get() = isClassTypeWithClassId(DefaultTypeClassIds.FLOAT)
val KtType.isDouble: Boolean get() = isClassTypeWithClassId(DefaultTypeClassIds.DOUBLE) public val KtType.isDouble: Boolean get() = isClassTypeWithClassId(DefaultTypeClassIds.DOUBLE)
val KtType.isChar: Boolean get() = isClassTypeWithClassId(DefaultTypeClassIds.CHAR) public val KtType.isChar: Boolean get() = isClassTypeWithClassId(DefaultTypeClassIds.CHAR)
val KtType.isBoolean: Boolean get() = isClassTypeWithClassId(DefaultTypeClassIds.BOOLEAN) public val KtType.isBoolean: Boolean get() = isClassTypeWithClassId(DefaultTypeClassIds.BOOLEAN)
val KtType.isString: Boolean get() = isClassTypeWithClassId(DefaultTypeClassIds.STRING) public val KtType.isString: Boolean get() = isClassTypeWithClassId(DefaultTypeClassIds.STRING)
val KtType.isCharSequence: Boolean get() = isClassTypeWithClassId(DefaultTypeClassIds.CHAR_SEQUENCE) public val KtType.isCharSequence: Boolean get() = isClassTypeWithClassId(DefaultTypeClassIds.CHAR_SEQUENCE)
val KtType.isAny: Boolean get() = isClassTypeWithClassId(DefaultTypeClassIds.ANY) public val KtType.isAny: Boolean get() = isClassTypeWithClassId(DefaultTypeClassIds.ANY)
val KtType.isNothing: Boolean get() = isClassTypeWithClassId(DefaultTypeClassIds.NOTHING) public val KtType.isNothing: Boolean get() = isClassTypeWithClassId(DefaultTypeClassIds.NOTHING)
val KtType.isUInt: Boolean get() = isClassTypeWithClassId(StandardNames.FqNames.uInt) public val KtType.isUInt: Boolean get() = isClassTypeWithClassId(StandardNames.FqNames.uInt)
val KtType.isULong: Boolean get() = isClassTypeWithClassId(StandardNames.FqNames.uLong) public val KtType.isULong: Boolean get() = isClassTypeWithClassId(StandardNames.FqNames.uLong)
val KtType.isUShort: Boolean get() = isClassTypeWithClassId(StandardNames.FqNames.uShort) public val KtType.isUShort: Boolean get() = isClassTypeWithClassId(StandardNames.FqNames.uShort)
val KtType.isUByte: Boolean get() = isClassTypeWithClassId(StandardNames.FqNames.uByte) public val KtType.isUByte: Boolean get() = isClassTypeWithClassId(StandardNames.FqNames.uByte)
/** Gets the class symbol backing the given type, if available. */ /** Gets the class symbol backing the given type, if available. */
val KtType.expandedClassSymbol: KtClassOrObjectSymbol? public val KtType.expandedClassSymbol: KtClassOrObjectSymbol?
get() { get() {
return when (this) { return when (this) {
is KtNonErrorClassType -> when (val classSymbol = classSymbol) { is KtNonErrorClassType -> when (val classSymbol = classSymbol) {
@@ -58,18 +58,18 @@ interface KtTypeInfoProviderMixIn : KtAnalysisSessionMixIn {
} }
} }
fun KtType.isClassTypeWithClassId(classId: ClassId): Boolean { public fun KtType.isClassTypeWithClassId(classId: ClassId): Boolean {
if (this !is KtNonErrorClassType) return false if (this !is KtNonErrorClassType) return false
return this.classId == classId return this.classId == classId
} }
val KtType.isPrimitive: Boolean public val KtType.isPrimitive: Boolean
get() { get() {
if (this !is KtNonErrorClassType) return false if (this !is KtNonErrorClassType) return false
return this.classId in DefaultTypeClassIds.PRIMITIVES return this.classId in DefaultTypeClassIds.PRIMITIVES
} }
val KtType.defaultInitializer: String? public val KtType.defaultInitializer: String?
get() = when { get() = when {
isMarkedNullable -> "null" isMarkedNullable -> "null"
isInt || isLong || isShort || isByte -> "0" isInt || isLong || isShort || isByte -> "0"
@@ -87,19 +87,19 @@ interface KtTypeInfoProviderMixIn : KtAnalysisSessionMixIn {
} }
} }
object DefaultTypeClassIds { public object DefaultTypeClassIds {
val UNIT = ClassId.topLevel(StandardNames.FqNames.unit.toSafe()) public val UNIT: ClassId = ClassId.topLevel(StandardNames.FqNames.unit.toSafe())
val INT = ClassId.topLevel(StandardNames.FqNames._int.toSafe()) public val INT: ClassId = ClassId.topLevel(StandardNames.FqNames._int.toSafe())
val LONG = ClassId.topLevel(StandardNames.FqNames._long.toSafe()) public val LONG: ClassId = ClassId.topLevel(StandardNames.FqNames._long.toSafe())
val SHORT = ClassId.topLevel(StandardNames.FqNames._short.toSafe()) public val SHORT: ClassId = ClassId.topLevel(StandardNames.FqNames._short.toSafe())
val BYTE = ClassId.topLevel(StandardNames.FqNames._byte.toSafe()) public val BYTE: ClassId = ClassId.topLevel(StandardNames.FqNames._byte.toSafe())
val FLOAT = ClassId.topLevel(StandardNames.FqNames._float.toSafe()) public val FLOAT: ClassId = ClassId.topLevel(StandardNames.FqNames._float.toSafe())
val DOUBLE = ClassId.topLevel(StandardNames.FqNames._double.toSafe()) public val DOUBLE: ClassId = ClassId.topLevel(StandardNames.FqNames._double.toSafe())
val CHAR = ClassId.topLevel(StandardNames.FqNames._char.toSafe()) public val CHAR: ClassId = ClassId.topLevel(StandardNames.FqNames._char.toSafe())
val BOOLEAN = ClassId.topLevel(StandardNames.FqNames._boolean.toSafe()) public val BOOLEAN: ClassId = ClassId.topLevel(StandardNames.FqNames._boolean.toSafe())
val STRING = ClassId.topLevel(StandardNames.FqNames.string.toSafe()) public val STRING: ClassId = ClassId.topLevel(StandardNames.FqNames.string.toSafe())
val CHAR_SEQUENCE = ClassId.topLevel(StandardNames.FqNames.charSequence.toSafe()) public val CHAR_SEQUENCE: ClassId = ClassId.topLevel(StandardNames.FqNames.charSequence.toSafe())
val ANY = ClassId.topLevel(StandardNames.FqNames.any.toSafe()) public val ANY: ClassId = ClassId.topLevel(StandardNames.FqNames.any.toSafe())
val NOTHING = ClassId.topLevel(StandardNames.FqNames.nothing.toSafe()) public val NOTHING: ClassId = ClassId.topLevel(StandardNames.FqNames.nothing.toSafe())
val PRIMITIVES = setOf(INT, LONG, SHORT, BYTE, FLOAT, DOUBLE, CHAR, BOOLEAN) public val PRIMITIVES: Set<ClassId> = setOf(INT, LONG, SHORT, BYTE, FLOAT, DOUBLE, CHAR, BOOLEAN)
} }
@@ -10,18 +10,18 @@ import org.jetbrains.kotlin.idea.frontend.api.symbols.KtNamedClassOrObjectSymbol
import org.jetbrains.kotlin.idea.frontend.api.types.KtType import org.jetbrains.kotlin.idea.frontend.api.types.KtType
import org.jetbrains.kotlin.idea.frontend.api.types.KtTypeNullability import org.jetbrains.kotlin.idea.frontend.api.types.KtTypeNullability
abstract class KtTypeProvider : KtAnalysisSessionComponent() { public abstract class KtTypeProvider : KtAnalysisSessionComponent() {
abstract val builtinTypes: KtBuiltinTypes public abstract val builtinTypes: KtBuiltinTypes
abstract fun approximateToSuperPublicDenotableType(type: KtType): KtType? public abstract fun approximateToSuperPublicDenotableType(type: KtType): KtType?
abstract fun buildSelfClassType(symbol: KtNamedClassOrObjectSymbol): KtType public abstract fun buildSelfClassType(symbol: KtNamedClassOrObjectSymbol): KtType
abstract fun withNullability(type: KtType, newNullability: KtTypeNullability): KtType public abstract fun withNullability(type: KtType, newNullability: KtTypeNullability): KtType
} }
interface KtTypeProviderMixIn : KtAnalysisSessionMixIn { public interface KtTypeProviderMixIn : KtAnalysisSessionMixIn {
val builtinTypes: KtBuiltinTypes public val builtinTypes: KtBuiltinTypes
get() = analysisSession.typeProvider.builtinTypes get() = analysisSession.typeProvider.builtinTypes
/** /**
@@ -30,36 +30,36 @@ interface KtTypeProviderMixIn : KtAnalysisSessionMixIn {
* Return `null` if the type do not need approximation and can be rendered as is * Return `null` if the type do not need approximation and can be rendered as is
* Otherwise, for type `T` return type `S` such `T <: S` and `T` and every it type argument is [org.jetbrains.kotlin.idea.frontend.api.types.KtDenotableType]` * Otherwise, for type `T` return type `S` such `T <: S` and `T` and every it type argument is [org.jetbrains.kotlin.idea.frontend.api.types.KtDenotableType]`
*/ */
fun KtType.approximateToSuperPublicDenotable(): KtType? = public fun KtType.approximateToSuperPublicDenotable(): KtType? =
analysisSession.typeProvider.approximateToSuperPublicDenotableType(this) analysisSession.typeProvider.approximateToSuperPublicDenotableType(this)
fun KtType.approximateToSuperPublicDenotableOrSelf(): KtType = approximateToSuperPublicDenotable() ?: this public fun KtType.approximateToSuperPublicDenotableOrSelf(): KtType = approximateToSuperPublicDenotable() ?: this
fun KtNamedClassOrObjectSymbol.buildSelfClassType(): KtType = public fun KtNamedClassOrObjectSymbol.buildSelfClassType(): KtType =
analysisSession.typeProvider.buildSelfClassType(this) analysisSession.typeProvider.buildSelfClassType(this)
fun KtType.withNullability(newNullability: KtTypeNullability): KtType = public fun KtType.withNullability(newNullability: KtTypeNullability): KtType =
analysisSession.typeProvider.withNullability(this, newNullability) analysisSession.typeProvider.withNullability(this, newNullability)
} }
@Suppress("PropertyName") @Suppress("PropertyName")
abstract class KtBuiltinTypes : ValidityTokenOwner { public abstract class KtBuiltinTypes : ValidityTokenOwner {
abstract val INT: KtType public abstract val INT: KtType
abstract val LONG: KtType public abstract val LONG: KtType
abstract val SHORT: KtType public abstract val SHORT: KtType
abstract val BYTE: KtType public abstract val BYTE: KtType
abstract val FLOAT: KtType public abstract val FLOAT: KtType
abstract val DOUBLE: KtType public abstract val DOUBLE: KtType
abstract val BOOLEAN: KtType public abstract val BOOLEAN: KtType
abstract val CHAR: KtType public abstract val CHAR: KtType
abstract val STRING: KtType public abstract val STRING: KtType
abstract val UNIT: KtType public abstract val UNIT: KtType
abstract val NOTHING: KtType public abstract val NOTHING: KtType
abstract val ANY: KtType public abstract val ANY: KtType
abstract val NULLABLE_ANY: KtType public abstract val NULLABLE_ANY: KtType
abstract val NULLABLE_NOTHING: KtType public abstract val NULLABLE_NOTHING: KtType
} }
@@ -10,8 +10,8 @@ import org.jetbrains.kotlin.idea.frontend.api.symbols.KtFileSymbol
import org.jetbrains.kotlin.idea.frontend.api.symbols.markers.KtSymbolWithVisibility import org.jetbrains.kotlin.idea.frontend.api.symbols.markers.KtSymbolWithVisibility
import org.jetbrains.kotlin.psi.KtExpression import org.jetbrains.kotlin.psi.KtExpression
abstract class KtVisibilityChecker : KtAnalysisSessionComponent() { public abstract class KtVisibilityChecker : KtAnalysisSessionComponent() {
abstract fun isVisible( public abstract fun isVisible(
candidateSymbol: KtSymbolWithVisibility, candidateSymbol: KtSymbolWithVisibility,
useSiteFile: KtFileSymbol, useSiteFile: KtFileSymbol,
position: PsiElement, position: PsiElement,
@@ -19,8 +19,8 @@ abstract class KtVisibilityChecker : KtAnalysisSessionComponent() {
): Boolean ): Boolean
} }
interface KtVisibilityCheckerMixIn : KtAnalysisSessionMixIn { public interface KtVisibilityCheckerMixIn : KtAnalysisSessionMixIn {
fun isVisible( public fun isVisible(
candidateSymbol: KtSymbolWithVisibility, candidateSymbol: KtSymbolWithVisibility,
useSiteFile: KtFileSymbol, useSiteFile: KtFileSymbol,
receiverExpression: KtExpression? = null, receiverExpression: KtExpression? = null,
@@ -12,19 +12,19 @@ import org.jetbrains.kotlin.idea.frontend.api.tokens.ValidityToken
import org.jetbrains.kotlin.idea.frontend.api.ValidityTokenOwner import org.jetbrains.kotlin.idea.frontend.api.ValidityTokenOwner
import kotlin.reflect.KClass import kotlin.reflect.KClass
interface KtDiagnostic : ValidityTokenOwner { public interface KtDiagnostic : ValidityTokenOwner {
val severity: Severity public val severity: Severity
val factoryName: String? public val factoryName: String?
val defaultMessage: String public val defaultMessage: String
} }
interface KtDiagnosticWithPsi<out PSI: PsiElement> : KtDiagnostic { public interface KtDiagnosticWithPsi<out PSI : PsiElement> : KtDiagnostic {
val psi: PSI public val psi: PSI
val textRanges: Collection<TextRange> public val textRanges: Collection<TextRange>
val diagnosticClass: KClass<out KtDiagnosticWithPsi<PSI>> public val diagnosticClass: KClass<out KtDiagnosticWithPsi<PSI>>
} }
class KtNonBoundToPsiErrorDiagnostic( public class KtNonBoundToPsiErrorDiagnostic(
override val factoryName: String?, override val factoryName: String?,
override val defaultMessage: String, override val defaultMessage: String,
override val token: ValidityToken, override val token: ValidityToken,
@@ -32,6 +32,6 @@ class KtNonBoundToPsiErrorDiagnostic(
override val severity: Severity get() = Severity.ERROR override val severity: Severity get() = Severity.ERROR
} }
fun KtDiagnostic.getDefaultMessageWithFactoryName(): String = public fun KtDiagnostic.getDefaultMessageWithFactoryName(): String =
if (factoryName == null) defaultMessage if (factoryName == null) defaultMessage
else "[$factoryName] $defaultMessage" else "[$factoryName] $defaultMessage"
@@ -9,33 +9,33 @@ import org.jetbrains.kotlin.name.ClassId
import org.jetbrains.kotlin.name.FqName import org.jetbrains.kotlin.name.FqName
import org.jetbrains.kotlin.name.Name import org.jetbrains.kotlin.name.Name
interface KtImportingScope : KtScope { public interface KtImportingScope : KtScope {
val imports: List<Import> public val imports: List<Import>
val isDefaultImportingScope: Boolean public val isDefaultImportingScope: Boolean
} }
interface KtStarImportingScope : KtImportingScope { public interface KtStarImportingScope : KtImportingScope {
override val imports: List<StarImport> override val imports: List<StarImport>
} }
interface KtNonStarImportingScope : KtImportingScope { public interface KtNonStarImportingScope : KtImportingScope {
override val imports: List<NonStarImport> override val imports: List<NonStarImport>
} }
sealed class Import { public sealed class Import {
abstract val packageFqName: FqName public abstract val packageFqName: FqName
abstract val relativeClassName: FqName? public abstract val relativeClassName: FqName?
abstract val resolvedClassId: ClassId? public abstract val resolvedClassId: ClassId?
} }
class NonStarImport( public class NonStarImport(
override val packageFqName: FqName, public override val packageFqName: FqName,
override val relativeClassName: FqName?, override val relativeClassName: FqName?,
override val resolvedClassId: ClassId?, override val resolvedClassId: ClassId?,
val callableName: Name?, public val callableName: Name?,
) : Import() ) : Import()
class StarImport( public class StarImport(
override val packageFqName: FqName, override val packageFqName: FqName,
override val relativeClassName: FqName?, override val relativeClassName: FqName?,
override val resolvedClassId: ClassId?, override val resolvedClassId: ClassId?,
@@ -14,12 +14,12 @@ import org.jetbrains.kotlin.name.FqName
import org.jetbrains.kotlin.name.Name import org.jetbrains.kotlin.name.Name
interface KtScope : ValidityTokenOwner { public interface KtScope : ValidityTokenOwner {
/** /**
* Returns a **subset** of names which current scope may contain. * Returns a **subset** of names which current scope may contain.
* In other words `ALL_NAMES(scope)` is a subset of `scope.getAllNames()` * In other words `ALL_NAMES(scope)` is a subset of `scope.getAllNames()`
*/ */
fun getAllPossibleNames(): Set<Name> = withValidityAssertion { public fun getAllPossibleNames(): Set<Name> = withValidityAssertion {
getPossibleCallableNames() + getPossibleClassifierNames() getPossibleCallableNames() + getPossibleClassifierNames()
} }
@@ -27,19 +27,19 @@ interface KtScope : ValidityTokenOwner {
* Returns a **subset** of callable names which current scope may contain. * Returns a **subset** of callable names which current scope may contain.
* In other words `ALL_CALLABLE_NAMES(scope)` is a subset of `scope.getCallableNames()` * In other words `ALL_CALLABLE_NAMES(scope)` is a subset of `scope.getCallableNames()`
*/ */
fun getPossibleCallableNames(): Set<Name> public fun getPossibleCallableNames(): Set<Name>
/** /**
* Returns a **subset** of classifier names which current scope may contain. * Returns a **subset** of classifier names which current scope may contain.
* In other words `ALL_CLASSIFIER_NAMES(scope)` is a subset of `scope.getClassifierNames()` * In other words `ALL_CLASSIFIER_NAMES(scope)` is a subset of `scope.getClassifierNames()`
*/ */
fun getPossibleClassifierNames(): Set<Name> public fun getPossibleClassifierNames(): Set<Name>
/** /**
* Return a sequence of all [KtSymbol] which current scope contain * Return a sequence of all [KtSymbol] which current scope contain
*/ */
fun getAllSymbols(): Sequence<KtSymbol> = withValidityAssertion { public fun getAllSymbols(): Sequence<KtSymbol> = withValidityAssertion {
sequence { sequence {
yieldAll(getCallableSymbols()) yieldAll(getCallableSymbols())
yieldAll(getClassifierSymbols()) yieldAll(getClassifierSymbols())
@@ -50,50 +50,50 @@ interface KtScope : ValidityTokenOwner {
/** /**
* Return a sequence of [KtCallableSymbol] which current scope contain if declaration name matches [nameFilter] * Return a sequence of [KtCallableSymbol] which current scope contain if declaration name matches [nameFilter]
*/ */
fun getCallableSymbols(nameFilter: KtScopeNameFilter = { true }): Sequence<KtCallableSymbol> public fun getCallableSymbols(nameFilter: KtScopeNameFilter = { true }): Sequence<KtCallableSymbol>
/** /**
* Return a sequence of [KtClassifierSymbol] which current scope contain if declaration name matches [nameFilter] * Return a sequence of [KtClassifierSymbol] which current scope contain if declaration name matches [nameFilter]
*/ */
fun getClassifierSymbols(nameFilter: KtScopeNameFilter = { true }): Sequence<KtClassifierSymbol> public fun getClassifierSymbols(nameFilter: KtScopeNameFilter = { true }): Sequence<KtClassifierSymbol>
/** /**
* Return a sequence of [KtConstructorSymbol] which current scope contain * Return a sequence of [KtConstructorSymbol] which current scope contain
*/ */
fun getConstructors(): Sequence<KtConstructorSymbol> public fun getConstructors(): Sequence<KtConstructorSymbol>
/** /**
* return true if the scope may contain name, false otherwise. * return true if the scope may contain name, false otherwise.
* *
* In other words `(mayContainName(name) == false) => (name !in scope)`; vice versa is not always true * In other words `(mayContainName(name) == false) => (name !in scope)`; vice versa is not always true
*/ */
fun mayContainName(name: Name): Boolean = withValidityAssertion { public fun mayContainName(name: Name): Boolean = withValidityAssertion {
name in getPossibleCallableNames() || name in getPossibleClassifierNames() name in getPossibleCallableNames() || name in getPossibleClassifierNames()
} }
} }
typealias KtScopeNameFilter = (Name) -> Boolean public typealias KtScopeNameFilter = (Name) -> Boolean
interface KtCompositeScope : KtScope { public interface KtCompositeScope : KtScope {
val subScopes: List<KtScope> public val subScopes: List<KtScope>
} }
interface KtMemberScope : KtDeclarationScope<KtSymbolWithMembers> { public interface KtMemberScope : KtDeclarationScope<KtSymbolWithMembers> {
override val owner: KtSymbolWithMembers override val owner: KtSymbolWithMembers
} }
interface KtDeclaredMemberScope : KtDeclarationScope<KtSymbolWithMembers> { public interface KtDeclaredMemberScope : KtDeclarationScope<KtSymbolWithMembers> {
override val owner: KtSymbolWithMembers override val owner: KtSymbolWithMembers
} }
interface KtDeclarationScope<out T : KtSymbolWithDeclarations> : KtScope { public interface KtDeclarationScope<out T : KtSymbolWithDeclarations> : KtScope {
val owner: T public val owner: T
} }
interface KtPackageScope : KtScope { public interface KtPackageScope : KtScope {
val fqName: FqName public val fqName: FqName
fun getPackageSymbols(nameFilter: KtScopeNameFilter = { true }): Sequence<KtPackageSymbol> public fun getPackageSymbols(nameFilter: KtScopeNameFilter = { true }): Sequence<KtPackageSymbol>
override fun getAllSymbols(): Sequence<KtSymbol> = withValidityAssertion { override fun getAllSymbols(): Sequence<KtSymbol> = withValidityAssertion {
super.getAllSymbols() + getPackageSymbols() super.getAllSymbols() + getPackageSymbols()
@@ -15,8 +15,8 @@ import java.lang.reflect.InvocationTargetException
import kotlin.reflect.KProperty import kotlin.reflect.KProperty
import kotlin.reflect.jvm.javaGetter import kotlin.reflect.jvm.javaGetter
object DebugSymbolRenderer { public object DebugSymbolRenderer {
fun render(symbol: KtSymbol): String = buildString { public fun render(symbol: KtSymbol): String = buildString {
val klass = symbol::class val klass = symbol::class
appendLine("${klass.simpleName}:") appendLine("${klass.simpleName}:")
klass.members.filterIsInstance<KProperty<*>>().sortedBy { it.name }.forEach { property -> klass.members.filterIsInstance<KProperty<*>>().sortedBy { it.name }.forEach { property ->
@@ -10,12 +10,12 @@ import org.jetbrains.kotlin.idea.frontend.api.symbols.markers.KtTypeAndAnnotatio
import org.jetbrains.kotlin.idea.frontend.api.symbols.pointers.KtSymbolPointer import org.jetbrains.kotlin.idea.frontend.api.symbols.pointers.KtSymbolPointer
import org.jetbrains.kotlin.name.CallableId import org.jetbrains.kotlin.name.CallableId
abstract class KtCallableSymbol : KtSymbol, KtSymbolWithKind { public abstract class KtCallableSymbol : KtSymbol, KtSymbolWithKind {
abstract val callableIdIfNonLocal: CallableId? public abstract val callableIdIfNonLocal: CallableId?
abstract val annotatedType: KtTypeAndAnnotations public abstract val annotatedType: KtTypeAndAnnotations
abstract val receiverType: KtTypeAndAnnotations? public abstract val receiverType: KtTypeAndAnnotations?
abstract val isExtension: Boolean public abstract val isExtension: Boolean
abstract override fun createPointer(): KtSymbolPointer<KtCallableSymbol> abstract override fun createPointer(): KtSymbolPointer<KtCallableSymbol>
} }
@@ -13,48 +13,48 @@ import org.jetbrains.kotlin.name.Name
import org.jetbrains.kotlin.name.SpecialNames import org.jetbrains.kotlin.name.SpecialNames
import org.jetbrains.kotlin.types.Variance import org.jetbrains.kotlin.types.Variance
sealed class KtClassifierSymbol : KtSymbol, KtPossiblyNamedSymbol public sealed class KtClassifierSymbol : KtSymbol, KtPossiblyNamedSymbol
val KtClassifierSymbol.nameOrAnonymous: Name public val KtClassifierSymbol.nameOrAnonymous: Name
get() = name ?: SpecialNames.ANONYMOUS_FUNCTION get() = name ?: SpecialNames.ANONYMOUS_FUNCTION
abstract class KtTypeParameterSymbol : KtClassifierSymbol(), KtNamedSymbol { public abstract class KtTypeParameterSymbol : KtClassifierSymbol(), KtNamedSymbol {
abstract override fun createPointer(): KtSymbolPointer<KtTypeParameterSymbol> abstract override fun createPointer(): KtSymbolPointer<KtTypeParameterSymbol>
abstract val upperBounds: List<KtType> public abstract val upperBounds: List<KtType>
abstract val variance: Variance public abstract val variance: Variance
abstract val isReified: Boolean public abstract val isReified: Boolean
} }
sealed class KtClassLikeSymbol : KtClassifierSymbol(), KtSymbolWithKind { public sealed class KtClassLikeSymbol : KtClassifierSymbol(), KtSymbolWithKind {
abstract val classIdIfNonLocal: ClassId? public abstract val classIdIfNonLocal: ClassId?
abstract override fun createPointer(): KtSymbolPointer<KtClassLikeSymbol> abstract override fun createPointer(): KtSymbolPointer<KtClassLikeSymbol>
} }
abstract class KtTypeAliasSymbol : KtClassLikeSymbol(), KtNamedSymbol { public abstract class KtTypeAliasSymbol : KtClassLikeSymbol(), KtNamedSymbol {
final override val symbolKind: KtSymbolKind get() = KtSymbolKind.TOP_LEVEL final override val symbolKind: KtSymbolKind get() = KtSymbolKind.TOP_LEVEL
/** /**
* Returns type from right-hand site of type alias * Returns type from right-hand site of type alias
* If type alias has type parameters, then those type parameters will be present in result type * If type alias has type parameters, then those type parameters will be present in result type
*/ */
abstract val expandedType: KtType public abstract val expandedType: KtType
abstract override fun createPointer(): KtSymbolPointer<KtTypeAliasSymbol> abstract override fun createPointer(): KtSymbolPointer<KtTypeAliasSymbol>
} }
sealed class KtClassOrObjectSymbol : KtClassLikeSymbol(), public sealed class KtClassOrObjectSymbol : KtClassLikeSymbol(),
KtAnnotatedSymbol, KtAnnotatedSymbol,
KtSymbolWithMembers { KtSymbolWithMembers {
abstract val classKind: KtClassKind public abstract val classKind: KtClassKind
abstract val superTypes: List<KtTypeAndAnnotations> public abstract val superTypes: List<KtTypeAndAnnotations>
abstract override fun createPointer(): KtSymbolPointer<KtClassOrObjectSymbol> abstract override fun createPointer(): KtSymbolPointer<KtClassOrObjectSymbol>
} }
abstract class KtAnonymousObjectSymbol : KtClassOrObjectSymbol() { public abstract class KtAnonymousObjectSymbol : KtClassOrObjectSymbol() {
final override val classKind: KtClassKind get() = KtClassKind.ANONYMOUS_OBJECT final override val classKind: KtClassKind get() = KtClassKind.ANONYMOUS_OBJECT
final override val classIdIfNonLocal: ClassId? get() = null final override val classIdIfNonLocal: ClassId? get() = null
final override val symbolKind: KtSymbolKind get() = KtSymbolKind.LOCAL final override val symbolKind: KtSymbolKind get() = KtSymbolKind.LOCAL
@@ -63,25 +63,25 @@ abstract class KtAnonymousObjectSymbol : KtClassOrObjectSymbol() {
abstract override fun createPointer(): KtSymbolPointer<KtAnonymousObjectSymbol> abstract override fun createPointer(): KtSymbolPointer<KtAnonymousObjectSymbol>
} }
abstract class KtNamedClassOrObjectSymbol : KtClassOrObjectSymbol(), public abstract class KtNamedClassOrObjectSymbol : KtClassOrObjectSymbol(),
KtSymbolWithTypeParameters, KtSymbolWithTypeParameters,
KtSymbolWithModality, KtSymbolWithModality,
KtSymbolWithVisibility, KtSymbolWithVisibility,
KtNamedSymbol { KtNamedSymbol {
abstract val isInner: Boolean public abstract val isInner: Boolean
abstract val isData: Boolean public abstract val isData: Boolean
abstract val isInline: Boolean public abstract val isInline: Boolean
abstract val isFun: Boolean public abstract val isFun: Boolean
abstract val isExternal: Boolean public abstract val isExternal: Boolean
abstract val companionObject: KtNamedClassOrObjectSymbol? public abstract val companionObject: KtNamedClassOrObjectSymbol?
abstract override fun createPointer(): KtSymbolPointer<KtNamedClassOrObjectSymbol> abstract override fun createPointer(): KtSymbolPointer<KtNamedClassOrObjectSymbol>
} }
enum class KtClassKind { public enum class KtClassKind {
CLASS, CLASS,
ENUM_CLASS, ENUM_CLASS,
ENUM_ENTRY, ENUM_ENTRY,
@@ -91,5 +91,5 @@ enum class KtClassKind {
INTERFACE, INTERFACE,
ANONYMOUS_OBJECT; ANONYMOUS_OBJECT;
val isObject: Boolean get() = this == OBJECT || this == COMPANION_OBJECT || this == ANONYMOUS_OBJECT public val isObject: Boolean get() = this == OBJECT || this == COMPANION_OBJECT || this == ANONYMOUS_OBJECT
} }
@@ -8,6 +8,6 @@ package org.jetbrains.kotlin.idea.frontend.api.symbols
import org.jetbrains.kotlin.idea.frontend.api.symbols.markers.KtAnnotatedSymbol import org.jetbrains.kotlin.idea.frontend.api.symbols.markers.KtAnnotatedSymbol
import org.jetbrains.kotlin.idea.frontend.api.symbols.pointers.KtSymbolPointer import org.jetbrains.kotlin.idea.frontend.api.symbols.pointers.KtSymbolPointer
abstract class KtFileSymbol : KtAnnotatedSymbol { public abstract class KtFileSymbol : KtAnnotatedSymbol {
abstract override fun createPointer(): KtSymbolPointer<KtFileSymbol> abstract override fun createPointer(): KtSymbolPointer<KtFileSymbol>
} }
@@ -11,20 +11,20 @@ import org.jetbrains.kotlin.name.CallableId
import org.jetbrains.kotlin.name.ClassId import org.jetbrains.kotlin.name.ClassId
import org.jetbrains.kotlin.name.FqName import org.jetbrains.kotlin.name.FqName
abstract class KtFunctionLikeSymbol : KtCallableSymbol(), KtSymbolWithKind { public abstract class KtFunctionLikeSymbol : KtCallableSymbol(), KtSymbolWithKind {
abstract val valueParameters: List<KtValueParameterSymbol> public abstract val valueParameters: List<KtValueParameterSymbol>
abstract override fun createPointer(): KtSymbolPointer<KtFunctionLikeSymbol> abstract override fun createPointer(): KtSymbolPointer<KtFunctionLikeSymbol>
} }
abstract class KtAnonymousFunctionSymbol : KtFunctionLikeSymbol() { public abstract class KtAnonymousFunctionSymbol : KtFunctionLikeSymbol() {
final override val symbolKind: KtSymbolKind get() = KtSymbolKind.LOCAL final override val symbolKind: KtSymbolKind get() = KtSymbolKind.LOCAL
final override val callableIdIfNonLocal: CallableId? get() = null final override val callableIdIfNonLocal: CallableId? get() = null
abstract override fun createPointer(): KtSymbolPointer<KtAnonymousFunctionSymbol> abstract override fun createPointer(): KtSymbolPointer<KtAnonymousFunctionSymbol>
} }
abstract class KtFunctionSymbol : KtFunctionLikeSymbol(), public abstract class KtFunctionSymbol : KtFunctionLikeSymbol(),
KtNamedSymbol, KtNamedSymbol,
KtPossibleMemberSymbol, KtPossibleMemberSymbol,
KtSymbolWithTypeParameters, KtSymbolWithTypeParameters,
@@ -32,24 +32,24 @@ abstract class KtFunctionSymbol : KtFunctionLikeSymbol(),
KtSymbolWithVisibility, KtSymbolWithVisibility,
KtAnnotatedSymbol { KtAnnotatedSymbol {
abstract val isSuspend: Boolean public abstract val isSuspend: Boolean
abstract val isOperator: Boolean public abstract val isOperator: Boolean
abstract val isExternal: Boolean public abstract val isExternal: Boolean
abstract val isInline: Boolean public abstract val isInline: Boolean
abstract val isOverride: Boolean public abstract val isOverride: Boolean
abstract val isInfix: Boolean public abstract val isInfix: Boolean
abstract val isStatic: Boolean public abstract val isStatic: Boolean
abstract override fun createPointer(): KtSymbolPointer<KtFunctionSymbol> abstract override fun createPointer(): KtSymbolPointer<KtFunctionSymbol>
} }
abstract class KtConstructorSymbol : KtFunctionLikeSymbol(), public abstract class KtConstructorSymbol : KtFunctionLikeSymbol(),
KtPossibleMemberSymbol, KtPossibleMemberSymbol,
KtAnnotatedSymbol, KtAnnotatedSymbol,
KtSymbolWithVisibility, KtSymbolWithVisibility,
KtSymbolWithTypeParameters { KtSymbolWithTypeParameters {
abstract val isPrimary: Boolean public abstract val isPrimary: Boolean
abstract val containingClassIdIfNonLocal: ClassId? public abstract val containingClassIdIfNonLocal: ClassId?
final override val callableIdIfNonLocal: CallableId? get() = null final override val callableIdIfNonLocal: CallableId? get() = null
final override val symbolKind: KtSymbolKind get() = KtSymbolKind.MEMBER final override val symbolKind: KtSymbolKind get() = KtSymbolKind.MEMBER
@@ -8,8 +8,8 @@ package org.jetbrains.kotlin.idea.frontend.api.symbols
import org.jetbrains.kotlin.idea.frontend.api.symbols.pointers.KtSymbolPointer import org.jetbrains.kotlin.idea.frontend.api.symbols.pointers.KtSymbolPointer
import org.jetbrains.kotlin.name.FqName import org.jetbrains.kotlin.name.FqName
abstract class KtPackageSymbol : KtSymbol { public abstract class KtPackageSymbol : KtSymbol {
abstract val fqName: FqName public abstract val fqName: FqName
abstract override fun createPointer(): KtSymbolPointer<KtPackageSymbol> abstract override fun createPointer(): KtSymbolPointer<KtPackageSymbol>
} }
@@ -9,7 +9,7 @@ import org.jetbrains.kotlin.idea.frontend.api.symbols.markers.*
import org.jetbrains.kotlin.idea.frontend.api.symbols.pointers.KtSymbolPointer import org.jetbrains.kotlin.idea.frontend.api.symbols.pointers.KtSymbolPointer
import org.jetbrains.kotlin.name.CallableId import org.jetbrains.kotlin.name.CallableId
sealed class KtPropertyAccessorSymbol : KtCallableSymbol(), public sealed class KtPropertyAccessorSymbol : KtCallableSymbol(),
KtPossibleMemberSymbol, KtPossibleMemberSymbol,
KtSymbolWithModality, KtSymbolWithModality,
KtSymbolWithVisibility, KtSymbolWithVisibility,
@@ -20,22 +20,22 @@ sealed class KtPropertyAccessorSymbol : KtCallableSymbol(),
final override val isExtension: Boolean get() = false final override val isExtension: Boolean get() = false
final override val receiverType: KtTypeAndAnnotations? get() = null final override val receiverType: KtTypeAndAnnotations? get() = null
abstract val isDefault: Boolean public abstract val isDefault: Boolean
abstract val isInline: Boolean public abstract val isInline: Boolean
abstract val isOverride: Boolean public abstract val isOverride: Boolean
abstract val hasBody: Boolean public abstract val hasBody: Boolean
final override val symbolKind: KtSymbolKind get() = KtSymbolKind.ACCESSOR final override val symbolKind: KtSymbolKind get() = KtSymbolKind.ACCESSOR
abstract override fun createPointer(): KtSymbolPointer<KtPropertyAccessorSymbol> abstract override fun createPointer(): KtSymbolPointer<KtPropertyAccessorSymbol>
} }
abstract class KtPropertyGetterSymbol : KtPropertyAccessorSymbol() { public abstract class KtPropertyGetterSymbol : KtPropertyAccessorSymbol() {
abstract override fun createPointer(): KtSymbolPointer<KtPropertyGetterSymbol> abstract override fun createPointer(): KtSymbolPointer<KtPropertyGetterSymbol>
} }
abstract class KtPropertySetterSymbol : KtPropertyAccessorSymbol() { public abstract class KtPropertySetterSymbol : KtPropertyAccessorSymbol() {
abstract val parameter: KtValueParameterSymbol public abstract val parameter: KtValueParameterSymbol
abstract override fun createPointer(): KtSymbolPointer<KtPropertySetterSymbol> abstract override fun createPointer(): KtSymbolPointer<KtPropertySetterSymbol>
} }
@@ -9,8 +9,8 @@ import com.intellij.psi.PsiElement
import org.jetbrains.kotlin.idea.frontend.api.ValidityTokenOwner import org.jetbrains.kotlin.idea.frontend.api.ValidityTokenOwner
import org.jetbrains.kotlin.idea.frontend.api.symbols.pointers.KtSymbolPointer import org.jetbrains.kotlin.idea.frontend.api.symbols.pointers.KtSymbolPointer
interface KtSymbol : ValidityTokenOwner { public interface KtSymbol : ValidityTokenOwner {
val origin: KtSymbolOrigin public val origin: KtSymbolOrigin
/** /**
* [PsiElement] which corresponds to given [KtSymbol] * [PsiElement] which corresponds to given [KtSymbol]
@@ -19,9 +19,9 @@ interface KtSymbol : ValidityTokenOwner {
* *
* For [KtSymbolOrigin.LIBRARY] the generated by Kotlin class file source element is returned * For [KtSymbolOrigin.LIBRARY] the generated by Kotlin class file source element is returned
*/ */
val psi: PsiElement? public val psi: PsiElement?
fun createPointer(): KtSymbolPointer<KtSymbol> public fun createPointer(): KtSymbolPointer<KtSymbol>
} }
/** /**
@@ -29,7 +29,7 @@ interface KtSymbol : ValidityTokenOwner {
* *
* @see KtSymbol.psi * @see KtSymbol.psi
*/ */
inline fun <reified PSI : PsiElement> KtSymbol.psi(): PSI = public inline fun <reified PSI : PsiElement> KtSymbol.psi(): PSI =
psi as PSI psi as PSI
/** /**
@@ -37,13 +37,13 @@ inline fun <reified PSI : PsiElement> KtSymbol.psi(): PSI =
* *
* @see KtSymbol.psi * @see KtSymbol.psi
*/ */
inline fun <reified PSI : PsiElement> KtSymbol.psiSafe(): PSI? = public inline fun <reified PSI : PsiElement> KtSymbol.psiSafe(): PSI? =
psi as? PSI psi as? PSI
/** /**
* A place where [KtSymbol] came from * A place where [KtSymbol] came from
*/ */
enum class KtSymbolOrigin { public enum class KtSymbolOrigin {
/** /**
* Declaration from Kotlin sources * Declaration from Kotlin sources
*/ */
@@ -12,8 +12,8 @@ import org.jetbrains.kotlin.name.FqName
import org.jetbrains.kotlin.name.Name import org.jetbrains.kotlin.name.Name
import org.jetbrains.kotlin.psi.* import org.jetbrains.kotlin.psi.*
abstract class KtSymbolProvider : KtAnalysisSessionComponent() { public abstract class KtSymbolProvider : KtAnalysisSessionComponent() {
open fun getSymbol(psi: KtDeclaration): KtSymbol = when (psi) { public open fun getSymbol(psi: KtDeclaration): KtSymbol = when (psi) {
is KtParameter -> getParameterSymbol(psi) is KtParameter -> getParameterSymbol(psi)
is KtNamedFunction -> getFunctionLikeSymbol(psi) is KtNamedFunction -> getFunctionLikeSymbol(psi)
is KtConstructor<*> -> getConstructorSymbol(psi) is KtConstructor<*> -> getConstructorSymbol(psi)
@@ -30,34 +30,34 @@ abstract class KtSymbolProvider : KtAnalysisSessionComponent() {
else -> error("Cannot build symbol for ${psi::class}") else -> error("Cannot build symbol for ${psi::class}")
} }
abstract fun getParameterSymbol(psi: KtParameter): KtValueParameterSymbol public abstract fun getParameterSymbol(psi: KtParameter): KtValueParameterSymbol
abstract fun getFileSymbol(psi: KtFile): KtFileSymbol public abstract fun getFileSymbol(psi: KtFile): KtFileSymbol
abstract fun getFunctionLikeSymbol(psi: KtNamedFunction): KtFunctionLikeSymbol public abstract fun getFunctionLikeSymbol(psi: KtNamedFunction): KtFunctionLikeSymbol
abstract fun getConstructorSymbol(psi: KtConstructor<*>): KtConstructorSymbol public abstract fun getConstructorSymbol(psi: KtConstructor<*>): KtConstructorSymbol
abstract fun getTypeParameterSymbol(psi: KtTypeParameter): KtTypeParameterSymbol public abstract fun getTypeParameterSymbol(psi: KtTypeParameter): KtTypeParameterSymbol
abstract fun getTypeAliasSymbol(psi: KtTypeAlias): KtTypeAliasSymbol public abstract fun getTypeAliasSymbol(psi: KtTypeAlias): KtTypeAliasSymbol
abstract fun getEnumEntrySymbol(psi: KtEnumEntry): KtEnumEntrySymbol public abstract fun getEnumEntrySymbol(psi: KtEnumEntry): KtEnumEntrySymbol
abstract fun getAnonymousFunctionSymbol(psi: KtNamedFunction): KtAnonymousFunctionSymbol public abstract fun getAnonymousFunctionSymbol(psi: KtNamedFunction): KtAnonymousFunctionSymbol
abstract fun getAnonymousFunctionSymbol(psi: KtFunctionLiteral): KtAnonymousFunctionSymbol public abstract fun getAnonymousFunctionSymbol(psi: KtFunctionLiteral): KtAnonymousFunctionSymbol
abstract fun getVariableSymbol(psi: KtProperty): KtVariableSymbol public abstract fun getVariableSymbol(psi: KtProperty): KtVariableSymbol
abstract fun getAnonymousObjectSymbol(psi: KtObjectLiteralExpression): KtAnonymousObjectSymbol public abstract fun getAnonymousObjectSymbol(psi: KtObjectLiteralExpression): KtAnonymousObjectSymbol
abstract fun getClassOrObjectSymbol(psi: KtClassOrObject): KtClassOrObjectSymbol public abstract fun getClassOrObjectSymbol(psi: KtClassOrObject): KtClassOrObjectSymbol
abstract fun getNamedClassOrObjectSymbol(psi: KtClassOrObject): KtNamedClassOrObjectSymbol public abstract fun getNamedClassOrObjectSymbol(psi: KtClassOrObject): KtNamedClassOrObjectSymbol
abstract fun getPropertyAccessorSymbol(psi: KtPropertyAccessor): KtPropertyAccessorSymbol public abstract fun getPropertyAccessorSymbol(psi: KtPropertyAccessor): KtPropertyAccessorSymbol
abstract fun getClassOrObjectSymbolByClassId(classId: ClassId): KtClassOrObjectSymbol? public abstract fun getClassOrObjectSymbolByClassId(classId: ClassId): KtClassOrObjectSymbol?
abstract fun getTopLevelCallableSymbols(packageFqName: FqName, name: Name): Sequence<KtSymbol> public abstract fun getTopLevelCallableSymbols(packageFqName: FqName, name: Name): Sequence<KtSymbol>
@Suppress("PropertyName") @Suppress("PropertyName")
abstract val ROOT_PACKAGE_SYMBOL: KtPackageSymbol public abstract val ROOT_PACKAGE_SYMBOL: KtPackageSymbol
} }
interface KtSymbolProviderMixIn : KtAnalysisSessionMixIn { public interface KtSymbolProviderMixIn : KtAnalysisSessionMixIn {
fun KtDeclaration.getSymbol(): KtSymbol = public fun KtDeclaration.getSymbol(): KtSymbol =
analysisSession.symbolProvider.getSymbol(this) analysisSession.symbolProvider.getSymbol(this)
fun KtParameter.getParameterSymbol(): KtValueParameterSymbol = public fun KtParameter.getParameterSymbol(): KtValueParameterSymbol =
analysisSession.symbolProvider.getParameterSymbol(this) analysisSession.symbolProvider.getParameterSymbol(this)
/** /**
@@ -66,55 +66,55 @@ interface KtSymbolProviderMixIn : KtAnalysisSessionMixIn {
* If [KtNamedFunction.getName] is `null` then returns [KtAnonymousFunctionSymbol] * If [KtNamedFunction.getName] is `null` then returns [KtAnonymousFunctionSymbol]
* Otherwise, returns [KtFunctionSymbol] * Otherwise, returns [KtFunctionSymbol]
*/ */
fun KtNamedFunction.getFunctionLikeSymbol(): KtFunctionLikeSymbol = public fun KtNamedFunction.getFunctionLikeSymbol(): KtFunctionLikeSymbol =
analysisSession.symbolProvider.getFunctionLikeSymbol(this) analysisSession.symbolProvider.getFunctionLikeSymbol(this)
fun KtConstructor<*>.getConstructorSymbol(): KtConstructorSymbol = public fun KtConstructor<*>.getConstructorSymbol(): KtConstructorSymbol =
analysisSession.symbolProvider.getConstructorSymbol(this) analysisSession.symbolProvider.getConstructorSymbol(this)
fun KtTypeParameter.getTypeParameterSymbol(): KtTypeParameterSymbol = public fun KtTypeParameter.getTypeParameterSymbol(): KtTypeParameterSymbol =
analysisSession.symbolProvider.getTypeParameterSymbol(this) analysisSession.symbolProvider.getTypeParameterSymbol(this)
fun KtTypeAlias.getTypeAliasSymbol(): KtTypeAliasSymbol = public fun KtTypeAlias.getTypeAliasSymbol(): KtTypeAliasSymbol =
analysisSession.symbolProvider.getTypeAliasSymbol(this) analysisSession.symbolProvider.getTypeAliasSymbol(this)
fun KtEnumEntry.getEnumEntrySymbol(): KtEnumEntrySymbol = public fun KtEnumEntry.getEnumEntrySymbol(): KtEnumEntrySymbol =
analysisSession.symbolProvider.getEnumEntrySymbol(this) analysisSession.symbolProvider.getEnumEntrySymbol(this)
fun KtNamedFunction.getAnonymousFunctionSymbol(): KtAnonymousFunctionSymbol = public fun KtNamedFunction.getAnonymousFunctionSymbol(): KtAnonymousFunctionSymbol =
analysisSession.symbolProvider.getAnonymousFunctionSymbol(this) analysisSession.symbolProvider.getAnonymousFunctionSymbol(this)
fun KtFunctionLiteral.getAnonymousFunctionSymbol(): KtAnonymousFunctionSymbol = public fun KtFunctionLiteral.getAnonymousFunctionSymbol(): KtAnonymousFunctionSymbol =
analysisSession.symbolProvider.getAnonymousFunctionSymbol(this) analysisSession.symbolProvider.getAnonymousFunctionSymbol(this)
fun KtProperty.getVariableSymbol(): KtVariableSymbol = public fun KtProperty.getVariableSymbol(): KtVariableSymbol =
analysisSession.symbolProvider.getVariableSymbol(this) analysisSession.symbolProvider.getVariableSymbol(this)
fun KtObjectLiteralExpression.getAnonymousObjectSymbol(): KtAnonymousObjectSymbol = public fun KtObjectLiteralExpression.getAnonymousObjectSymbol(): KtAnonymousObjectSymbol =
analysisSession.symbolProvider.getAnonymousObjectSymbol(this) analysisSession.symbolProvider.getAnonymousObjectSymbol(this)
fun KtClassOrObject.getClassOrObjectSymbol(): KtClassOrObjectSymbol = public fun KtClassOrObject.getClassOrObjectSymbol(): KtClassOrObjectSymbol =
analysisSession.symbolProvider.getClassOrObjectSymbol(this) analysisSession.symbolProvider.getClassOrObjectSymbol(this)
fun KtClassOrObject.getNamedClassOrObjectSymbol(): KtNamedClassOrObjectSymbol = public fun KtClassOrObject.getNamedClassOrObjectSymbol(): KtNamedClassOrObjectSymbol =
analysisSession.symbolProvider.getNamedClassOrObjectSymbol(this) analysisSession.symbolProvider.getNamedClassOrObjectSymbol(this)
fun KtPropertyAccessor.getPropertyAccessorSymbol(): KtPropertyAccessorSymbol = public fun KtPropertyAccessor.getPropertyAccessorSymbol(): KtPropertyAccessorSymbol =
analysisSession.symbolProvider.getPropertyAccessorSymbol(this) analysisSession.symbolProvider.getPropertyAccessorSymbol(this)
fun KtFile.getFileSymbol(): KtFileSymbol = public fun KtFile.getFileSymbol(): KtFileSymbol =
analysisSession.symbolProvider.getFileSymbol(this) analysisSession.symbolProvider.getFileSymbol(this)
/** /**
* @return symbol with specified [this@getClassOrObjectSymbolByClassId] or `null` in case such symbol is not found * @return symbol with specified [this@getClassOrObjectSymbolByClassId] or `null` in case such symbol is not found
*/ */
fun ClassId.getCorrespondingToplevelClassOrObjectSymbol(): KtClassOrObjectSymbol? = public fun ClassId.getCorrespondingToplevelClassOrObjectSymbol(): KtClassOrObjectSymbol? =
analysisSession.symbolProvider.getClassOrObjectSymbolByClassId(this) analysisSession.symbolProvider.getClassOrObjectSymbolByClassId(this)
fun FqName.getContainingCallableSymbolsWithName(name: Name): Sequence<KtSymbol> = public fun FqName.getContainingCallableSymbolsWithName(name: Name): Sequence<KtSymbol> =
analysisSession.symbolProvider.getTopLevelCallableSymbols(this, name) analysisSession.symbolProvider.getTopLevelCallableSymbols(this, name)
@Suppress("PropertyName") @Suppress("PropertyName")
val ROOT_PACKAGE_SYMBOL: KtPackageSymbol public val ROOT_PACKAGE_SYMBOL: KtPackageSymbol
get() = analysisSession.symbolProvider.ROOT_PACKAGE_SYMBOL get() = analysisSession.symbolProvider.ROOT_PACKAGE_SYMBOL
} }
@@ -13,7 +13,7 @@ import org.jetbrains.kotlin.name.ClassId
import org.jetbrains.kotlin.name.FqName import org.jetbrains.kotlin.name.FqName
import org.jetbrains.kotlin.name.Name import org.jetbrains.kotlin.name.Name
sealed class KtVariableLikeSymbol : KtCallableSymbol(), KtNamedSymbol, KtSymbolWithKind { public sealed class KtVariableLikeSymbol : KtCallableSymbol(), KtNamedSymbol, KtSymbolWithKind {
abstract override fun createPointer(): KtSymbolPointer<KtVariableLikeSymbol> abstract override fun createPointer(): KtSymbolPointer<KtVariableLikeSymbol>
} }
@@ -28,8 +28,8 @@ sealed class KtVariableLikeSymbol : KtCallableSymbol(), KtNamedSymbol, KtSymbolW
* *
* Symbol at caret will be resolved to a [KtBackingFieldSymbol] * Symbol at caret will be resolved to a [KtBackingFieldSymbol]
*/ */
abstract class KtBackingFieldSymbol : KtVariableLikeSymbol() { public abstract class KtBackingFieldSymbol : KtVariableLikeSymbol() {
abstract val owningProperty: KtKotlinPropertySymbol public abstract val owningProperty: KtKotlinPropertySymbol
final override val name: Name get() = fieldName final override val name: Name get() = fieldName
final override val psi: PsiElement? get() = null final override val psi: PsiElement? get() = null
@@ -41,29 +41,29 @@ abstract class KtBackingFieldSymbol : KtVariableLikeSymbol() {
abstract override fun createPointer(): KtSymbolPointer<KtVariableLikeSymbol> abstract override fun createPointer(): KtSymbolPointer<KtVariableLikeSymbol>
companion object { public companion object {
private val fieldName = Name.identifier("field") private val fieldName = Name.identifier("field")
} }
} }
abstract class KtEnumEntrySymbol : KtVariableLikeSymbol(), KtSymbolWithMembers, KtSymbolWithKind { public abstract class KtEnumEntrySymbol : KtVariableLikeSymbol(), KtSymbolWithMembers, KtSymbolWithKind {
final override val symbolKind: KtSymbolKind get() = KtSymbolKind.MEMBER final override val symbolKind: KtSymbolKind get() = KtSymbolKind.MEMBER
final override val isExtension: Boolean get() = false final override val isExtension: Boolean get() = false
final override val receiverType: KtTypeAndAnnotations? get() = null final override val receiverType: KtTypeAndAnnotations? get() = null
abstract val containingEnumClassIdIfNonLocal: ClassId? public abstract val containingEnumClassIdIfNonLocal: ClassId?
abstract override fun createPointer(): KtSymbolPointer<KtEnumEntrySymbol> abstract override fun createPointer(): KtSymbolPointer<KtEnumEntrySymbol>
} }
sealed class KtVariableSymbol : KtVariableLikeSymbol() { public sealed class KtVariableSymbol : KtVariableLikeSymbol() {
abstract val isVal: Boolean public abstract val isVal: Boolean
abstract override fun createPointer(): KtSymbolPointer<KtVariableSymbol> abstract override fun createPointer(): KtSymbolPointer<KtVariableSymbol>
} }
abstract class KtJavaFieldSymbol : public abstract class KtJavaFieldSymbol :
KtVariableSymbol(), KtVariableSymbol(),
KtSymbolWithModality, KtSymbolWithModality,
KtSymbolWithVisibility, KtSymbolWithVisibility,
@@ -71,56 +71,56 @@ abstract class KtJavaFieldSymbol :
final override val symbolKind: KtSymbolKind get() = KtSymbolKind.MEMBER final override val symbolKind: KtSymbolKind get() = KtSymbolKind.MEMBER
final override val isExtension: Boolean get() = false final override val isExtension: Boolean get() = false
final override val receiverType: KtTypeAndAnnotations? get() = null final override val receiverType: KtTypeAndAnnotations? get() = null
abstract val isStatic: Boolean public abstract val isStatic: Boolean
abstract override fun createPointer(): KtSymbolPointer<KtJavaFieldSymbol> abstract override fun createPointer(): KtSymbolPointer<KtJavaFieldSymbol>
} }
sealed class KtPropertySymbol : KtVariableSymbol(), public sealed class KtPropertySymbol : KtVariableSymbol(),
KtPossibleMemberSymbol, KtPossibleMemberSymbol,
KtSymbolWithModality, KtSymbolWithModality,
KtSymbolWithVisibility, KtSymbolWithVisibility,
KtAnnotatedSymbol, KtAnnotatedSymbol,
KtSymbolWithKind { KtSymbolWithKind {
abstract val hasGetter: Boolean public abstract val hasGetter: Boolean
abstract val hasSetter: Boolean public abstract val hasSetter: Boolean
abstract val getter: KtPropertyGetterSymbol? public abstract val getter: KtPropertyGetterSymbol?
abstract val setter: KtPropertySetterSymbol? public abstract val setter: KtPropertySetterSymbol?
abstract val hasBackingField: Boolean public abstract val hasBackingField: Boolean
abstract val isOverride: Boolean public abstract val isOverride: Boolean
abstract val isStatic: Boolean public abstract val isStatic: Boolean
abstract val initializer: KtConstantValue? public abstract val initializer: KtConstantValue?
abstract override fun createPointer(): KtSymbolPointer<KtPropertySymbol> abstract override fun createPointer(): KtSymbolPointer<KtPropertySymbol>
} }
abstract class KtKotlinPropertySymbol : KtPropertySymbol() { public abstract class KtKotlinPropertySymbol : KtPropertySymbol() {
abstract val isLateInit: Boolean public abstract val isLateInit: Boolean
abstract val isConst: Boolean public abstract val isConst: Boolean
abstract override fun createPointer(): KtSymbolPointer<KtKotlinPropertySymbol> abstract override fun createPointer(): KtSymbolPointer<KtKotlinPropertySymbol>
} }
abstract class KtSyntheticJavaPropertySymbol : KtPropertySymbol() { public abstract class KtSyntheticJavaPropertySymbol : KtPropertySymbol() {
final override val hasBackingField: Boolean get() = true final override val hasBackingField: Boolean get() = true
final override val hasGetter: Boolean get() = true final override val hasGetter: Boolean get() = true
final override val symbolKind: KtSymbolKind get() = KtSymbolKind.MEMBER final override val symbolKind: KtSymbolKind get() = KtSymbolKind.MEMBER
abstract override val getter: KtPropertyGetterSymbol abstract override val getter: KtPropertyGetterSymbol
abstract val javaGetterName: Name public abstract val javaGetterName: Name
abstract val javaSetterName: Name? public abstract val javaSetterName: Name?
abstract override fun createPointer(): KtSymbolPointer<KtSyntheticJavaPropertySymbol> abstract override fun createPointer(): KtSymbolPointer<KtSyntheticJavaPropertySymbol>
} }
abstract class KtLocalVariableSymbol : KtVariableSymbol(), KtSymbolWithKind { public abstract class KtLocalVariableSymbol : KtVariableSymbol(), KtSymbolWithKind {
final override val callableIdIfNonLocal: CallableId? get() = null final override val callableIdIfNonLocal: CallableId? get() = null
final override val isExtension: Boolean get() = false final override val isExtension: Boolean get() = false
final override val receiverType: KtTypeAndAnnotations? get() = null final override val receiverType: KtTypeAndAnnotations? get() = null
@@ -128,14 +128,14 @@ abstract class KtLocalVariableSymbol : KtVariableSymbol(), KtSymbolWithKind {
abstract override fun createPointer(): KtSymbolPointer<KtLocalVariableSymbol> abstract override fun createPointer(): KtSymbolPointer<KtLocalVariableSymbol>
} }
abstract class KtValueParameterSymbol : KtVariableLikeSymbol(), KtSymbolWithKind, KtAnnotatedSymbol { public abstract class KtValueParameterSymbol : KtVariableLikeSymbol(), KtSymbolWithKind, KtAnnotatedSymbol {
final override val symbolKind: KtSymbolKind get() = KtSymbolKind.LOCAL final override val symbolKind: KtSymbolKind get() = KtSymbolKind.LOCAL
final override val callableIdIfNonLocal: CallableId? get() = null final override val callableIdIfNonLocal: CallableId? get() = null
final override val isExtension: Boolean get() = false final override val isExtension: Boolean get() = false
final override val receiverType: KtTypeAndAnnotations? get() = null final override val receiverType: KtTypeAndAnnotations? get() = null
abstract val hasDefaultValue: Boolean public abstract val hasDefaultValue: Boolean
abstract val isVararg: Boolean public abstract val isVararg: Boolean
abstract override fun createPointer(): KtSymbolPointer<KtValueParameterSymbol> abstract override fun createPointer(): KtSymbolPointer<KtValueParameterSymbol>
} }
@@ -11,18 +11,18 @@ import org.jetbrains.kotlin.idea.frontend.api.symbols.KtSymbol
import org.jetbrains.kotlin.name.ClassId import org.jetbrains.kotlin.name.ClassId
import org.jetbrains.kotlin.psi.KtCallElement import org.jetbrains.kotlin.psi.KtCallElement
abstract class KtAnnotationCall : ValidityTokenOwner { public abstract class KtAnnotationCall : ValidityTokenOwner {
abstract val classId: ClassId? public abstract val classId: ClassId?
abstract val useSiteTarget: AnnotationUseSiteTarget? public abstract val useSiteTarget: AnnotationUseSiteTarget?
abstract val psi: KtCallElement? public abstract val psi: KtCallElement?
abstract val arguments: List<KtNamedConstantValue> public abstract val arguments: List<KtNamedConstantValue>
} }
data class KtNamedConstantValue(val name: String, val expression: KtConstantValue) public data class KtNamedConstantValue(val name: String, val expression: KtConstantValue)
interface KtAnnotatedSymbol : KtSymbol { public interface KtAnnotatedSymbol : KtSymbol {
val annotations: List<KtAnnotationCall> public val annotations: List<KtAnnotationCall>
fun containsAnnotation(classId: ClassId): Boolean public fun containsAnnotation(classId: ClassId): Boolean
val annotationClassIds: Collection<ClassId> public val annotationClassIds: Collection<ClassId>
} }
@@ -7,7 +7,7 @@ package org.jetbrains.kotlin.idea.frontend.api.symbols.markers
import org.jetbrains.kotlin.types.ConstantValueKind import org.jetbrains.kotlin.types.ConstantValueKind
sealed class KtConstantValue public sealed class KtConstantValue
object KtUnsupportedConstantValue : KtConstantValue() public object KtUnsupportedConstantValue : KtConstantValue()
data class KtSimpleConstantValue<T>(val constantValueKind: ConstantValueKind<T>, val value: T) : KtConstantValue() public data class KtSimpleConstantValue<T>(val constantValueKind: ConstantValueKind<T>, val value: T) : KtConstantValue()
@@ -7,6 +7,6 @@ package org.jetbrains.kotlin.idea.frontend.api.symbols.markers
import org.jetbrains.kotlin.idea.frontend.api.types.KtType import org.jetbrains.kotlin.idea.frontend.api.types.KtType
interface KtPossibleMemberSymbol { public interface KtPossibleMemberSymbol {
val dispatchType: KtType? public val dispatchType: KtType?
} }
@@ -10,11 +10,11 @@ import org.jetbrains.kotlin.name.ClassId
import org.jetbrains.kotlin.name.FqName import org.jetbrains.kotlin.name.FqName
interface KtSymbolWithKind : KtSymbol { public interface KtSymbolWithKind : KtSymbol {
val symbolKind: KtSymbolKind public val symbolKind: KtSymbolKind
} }
enum class KtSymbolKind { public enum class KtSymbolKind {
TOP_LEVEL, MEMBER, LOCAL, ACCESSOR TOP_LEVEL, MEMBER, LOCAL, ACCESSOR
} }
@@ -7,6 +7,6 @@ package org.jetbrains.kotlin.idea.frontend.api.symbols.markers
import org.jetbrains.kotlin.idea.frontend.api.symbols.KtSymbol import org.jetbrains.kotlin.idea.frontend.api.symbols.KtSymbol
interface KtSymbolWithMembers : KtSymbolWithDeclarations public interface KtSymbolWithMembers : KtSymbolWithDeclarations
interface KtSymbolWithDeclarations : KtSymbol public interface KtSymbolWithDeclarations : KtSymbol
@@ -7,6 +7,6 @@ package org.jetbrains.kotlin.idea.frontend.api.symbols.markers
import org.jetbrains.kotlin.descriptors.Modality import org.jetbrains.kotlin.descriptors.Modality
interface KtSymbolWithModality { public interface KtSymbolWithModality {
val modality: Modality public val modality: Modality
} }
@@ -8,10 +8,10 @@ package org.jetbrains.kotlin.idea.frontend.api.symbols.markers
import org.jetbrains.kotlin.descriptors.Visibilities import org.jetbrains.kotlin.descriptors.Visibilities
import org.jetbrains.kotlin.descriptors.Visibility import org.jetbrains.kotlin.descriptors.Visibility
interface KtSymbolWithVisibility { public interface KtSymbolWithVisibility {
val visibility: Visibility public val visibility: Visibility
} }
fun Visibility.isPrivateOrPrivateToThis(): Boolean = public fun Visibility.isPrivateOrPrivateToThis(): Boolean =
this == Visibilities.Private || this == Visibilities.PrivateToThis this == Visibilities.Private || this == Visibilities.PrivateToThis
@@ -9,7 +9,7 @@ import org.jetbrains.kotlin.idea.frontend.api.ValidityTokenOwner
import org.jetbrains.kotlin.idea.frontend.api.symbols.KtCallableSymbol import org.jetbrains.kotlin.idea.frontend.api.symbols.KtCallableSymbol
import org.jetbrains.kotlin.idea.frontend.api.types.KtType import org.jetbrains.kotlin.idea.frontend.api.types.KtType
abstract class KtTypeAndAnnotations : ValidityTokenOwner { public abstract class KtTypeAndAnnotations : ValidityTokenOwner {
abstract val type: KtType public abstract val type: KtType
abstract val annotations: List<KtAnnotationCall> public abstract val annotations: List<KtAnnotationCall>
} }
@@ -10,14 +10,14 @@ import org.jetbrains.kotlin.idea.frontend.api.symbols.KtTypeParameterSymbol
import org.jetbrains.kotlin.idea.frontend.api.types.KtType import org.jetbrains.kotlin.idea.frontend.api.types.KtType
import org.jetbrains.kotlin.name.Name import org.jetbrains.kotlin.name.Name
interface KtPossiblyNamedSymbol : KtSymbol { public interface KtPossiblyNamedSymbol : KtSymbol {
val name: Name? public val name: Name?
} }
interface KtNamedSymbol : KtPossiblyNamedSymbol { public interface KtNamedSymbol : KtPossiblyNamedSymbol {
abstract override val name: Name override val name: Name
} }
interface KtSymbolWithTypeParameters { public interface KtSymbolWithTypeParameters {
val typeParameters: List<KtTypeParameterSymbol> public val typeParameters: List<KtTypeParameterSymbol>
} }
@@ -5,5 +5,5 @@
package org.jetbrains.kotlin.idea.frontend.api.symbols.pointers package org.jetbrains.kotlin.idea.frontend.api.symbols.pointers
class CanNotCreateSymbolPointerForLocalLibraryDeclarationException(description: String) : public class CanNotCreateSymbolPointerForLocalLibraryDeclarationException(description: String) :
IllegalStateException("Could not create a symbol pointer for local symbol $description") IllegalStateException("Could not create a symbol pointer for local symbol $description")
@@ -13,7 +13,8 @@ import org.jetbrains.kotlin.psi.KtDeclaration
import org.jetbrains.kotlin.psi.KtObjectLiteralExpression import org.jetbrains.kotlin.psi.KtObjectLiteralExpression
import org.jetbrains.kotlin.psi.psiUtil.createSmartPointer import org.jetbrains.kotlin.psi.psiUtil.createSmartPointer
class KtPsiBasedSymbolPointer<S : KtSymbol>(private val psiPointer: SmartPsiElementPointer<out KtDeclaration>) : KtSymbolPointer<S>() { public class KtPsiBasedSymbolPointer<S : KtSymbol>(private val psiPointer: SmartPsiElementPointer<out KtDeclaration>) :
KtSymbolPointer<S>() {
override fun restoreSymbol(analysisSession: KtAnalysisSession): S? { override fun restoreSymbol(analysisSession: KtAnalysisSession): S? {
val psi = psiPointer.element ?: return null val psi = psiPointer.element ?: return null
@@ -21,10 +22,10 @@ class KtPsiBasedSymbolPointer<S : KtSymbol>(private val psiPointer: SmartPsiElem
return with(analysisSession) { psi.getSymbol() } as S? return with(analysisSession) { psi.getSymbol() } as S?
} }
companion object { public companion object {
fun <S : KtSymbol> createForSymbolFromSource(symbol: S): KtPsiBasedSymbolPointer<S>? { public fun <S : KtSymbol> createForSymbolFromSource(symbol: S): KtPsiBasedSymbolPointer<S>? {
if (symbol.origin == KtSymbolOrigin.LIBRARY) return null if (symbol.origin == KtSymbolOrigin.LIBRARY) return null
val psi = when(val psi = symbol.psi) { val psi = when (val psi = symbol.psi) {
is KtDeclaration -> psi is KtDeclaration -> psi
is KtObjectLiteralExpression -> psi.objectDeclaration is KtObjectLiteralExpression -> psi.objectDeclaration
else -> null else -> null
@@ -23,16 +23,17 @@ import org.jetbrains.kotlin.idea.frontend.api.symbols.KtSymbol
* *
* @see org.jetbrains.kotlin.idea.frontend.api.ReadActionConfinementValidityToken * @see org.jetbrains.kotlin.idea.frontend.api.ReadActionConfinementValidityToken
*/ */
abstract class KtSymbolPointer<out S : KtSymbol> { public abstract class KtSymbolPointer<out S : KtSymbol> {
/** /**
* @return restored symbol (possibly the new symbol instance) if one is still valid, `null` otherwise * @return restored symbol (possibly the new symbol instance) if one is still valid, `null` otherwise
* *
* Consider using [org.jetbrains.kotlin.idea.frontend.api.KtAnalysisSession.restoreSymbol] * Consider using [org.jetbrains.kotlin.idea.frontend.api.KtAnalysisSession.restoreSymbol]
*/ */
@Deprecated("Consider using org.jetbrains.kotlin.idea.frontend.api.KtAnalysisSession.restoreSymbol") @Deprecated("Consider using org.jetbrains.kotlin.idea.frontend.api.KtAnalysisSession.restoreSymbol")
abstract fun restoreSymbol(analysisSession: KtAnalysisSession): S? public abstract fun restoreSymbol(analysisSession: KtAnalysisSession): S?
} }
inline fun <S : KtSymbol> symbolPointer(crossinline getSymbol: (KtAnalysisSession) -> S?) = object : KtSymbolPointer<S>() { public inline fun <S : KtSymbol> symbolPointer(crossinline getSymbol: (KtAnalysisSession) -> S?): KtSymbolPointer<S> =
override fun restoreSymbol(analysisSession: KtAnalysisSession): S? = getSymbol(analysisSession) object : KtSymbolPointer<S>() {
} override fun restoreSymbol(analysisSession: KtAnalysisSession): S? = getSymbol(analysisSession)
}
@@ -9,7 +9,7 @@ import com.intellij.openapi.project.Project
import org.jetbrains.kotlin.idea.fir.low.level.api.api.createProjectWideOutOfBlockModificationTracker import org.jetbrains.kotlin.idea.fir.low.level.api.api.createProjectWideOutOfBlockModificationTracker
import kotlin.reflect.KClass import kotlin.reflect.KClass
class AlwaysAccessibleValidityToken(project: Project) : ValidityToken() { public class AlwaysAccessibleValidityToken(project: Project) : ValidityToken() {
private val modificationTracker = project.createProjectWideOutOfBlockModificationTracker() private val modificationTracker = project.createProjectWideOutOfBlockModificationTracker()
private val onCreatedTimeStamp = modificationTracker.modificationCount private val onCreatedTimeStamp = modificationTracker.modificationCount
@@ -31,7 +31,7 @@ class AlwaysAccessibleValidityToken(project: Project) : ValidityToken() {
} }
} }
object AlwaysAccessibleValidityTokenFactory : ValidityTokenFactory() { public object AlwaysAccessibleValidityTokenFactory : ValidityTokenFactory() {
override val identifier: KClass<out ValidityToken> = AlwaysAccessibleValidityToken::class override val identifier: KClass<out ValidityToken> = AlwaysAccessibleValidityToken::class
override fun create(project: Project): ValidityToken = override fun create(project: Project): ValidityToken =
@@ -11,7 +11,7 @@ import org.jetbrains.kotlin.idea.fir.low.level.api.api.createProjectWideOutOfBlo
import org.jetbrains.kotlin.idea.frontend.api.* import org.jetbrains.kotlin.idea.frontend.api.*
import kotlin.reflect.KClass import kotlin.reflect.KClass
class ReadActionConfinementValidityToken(project: Project) : ValidityToken() { public class ReadActionConfinementValidityToken(project: Project) : ValidityToken() {
private val modificationTracker = project.createProjectWideOutOfBlockModificationTracker() private val modificationTracker = project.createProjectWideOutOfBlockModificationTracker()
private val onCreatedTimeStamp = modificationTracker.modificationCount private val onCreatedTimeStamp = modificationTracker.modificationCount
@@ -48,13 +48,13 @@ class ReadActionConfinementValidityToken(project: Project) : ValidityToken() {
} }
companion object { public companion object {
@HackToForceAllowRunningAnalyzeOnEDT @HackToForceAllowRunningAnalyzeOnEDT
val allowOnEdt: ThreadLocal<Boolean> = ThreadLocal.withInitial { false } public val allowOnEdt: ThreadLocal<Boolean> = ThreadLocal.withInitial { false }
} }
} }
object ReadActionConfinementValidityTokenFactory : ValidityTokenFactory() { public object ReadActionConfinementValidityTokenFactory : ValidityTokenFactory() {
override val identifier: KClass<out ValidityToken> = ReadActionConfinementValidityToken::class override val identifier: KClass<out ValidityToken> = ReadActionConfinementValidityToken::class
override fun create(project: Project): ValidityToken = ReadActionConfinementValidityToken(project) override fun create(project: Project): ValidityToken = ReadActionConfinementValidityToken(project)
@@ -73,7 +73,7 @@ object ReadActionConfinementValidityTokenFactory : ValidityTokenFactory() {
} }
@RequiresOptIn("All frontend related work should not be allowed to be ran from EDT thread. Only use it as a temporary solution") @RequiresOptIn("All frontend related work should not be allowed to be ran from EDT thread. Only use it as a temporary solution")
annotation class HackToForceAllowRunningAnalyzeOnEDT public annotation class HackToForceAllowRunningAnalyzeOnEDT
/** /**
* All frontend related work should not be allowed to be ran from EDT thread. Only use it as a temporary solution. * All frontend related work should not be allowed to be ran from EDT thread. Only use it as a temporary solution.
@@ -82,7 +82,7 @@ annotation class HackToForceAllowRunningAnalyzeOnEDT
* @see ReadActionConfinementValidityToken * @see ReadActionConfinementValidityToken
*/ */
@HackToForceAllowRunningAnalyzeOnEDT @HackToForceAllowRunningAnalyzeOnEDT
inline fun <T> hackyAllowRunningOnEdt(action: () -> T): T { public inline fun <T> hackyAllowRunningOnEdt(action: () -> T): T {
if (ReadActionConfinementValidityToken.allowOnEdt.get()) return action() if (ReadActionConfinementValidityToken.allowOnEdt.get()) return action()
ReadActionConfinementValidityToken.allowOnEdt.set(true) ReadActionConfinementValidityToken.allowOnEdt.set(true)
try { try {
@@ -8,25 +8,25 @@ package org.jetbrains.kotlin.idea.frontend.api.tokens
import com.intellij.openapi.project.Project import com.intellij.openapi.project.Project
import kotlin.reflect.KClass import kotlin.reflect.KClass
abstract class ValidityToken { public abstract class ValidityToken {
abstract fun isValid(): Boolean public abstract fun isValid(): Boolean
abstract fun getInvalidationReason(): String public abstract fun getInvalidationReason(): String
abstract fun isAccessible(): Boolean public abstract fun isAccessible(): Boolean
abstract fun getInaccessibilityReason(): String public abstract fun getInaccessibilityReason(): String
} }
abstract class ValidityTokenFactory { public abstract class ValidityTokenFactory {
abstract val identifier: KClass<out ValidityToken> public abstract val identifier: KClass<out ValidityToken>
abstract fun create(project: Project): ValidityToken public abstract fun create(project: Project): ValidityToken
open fun beforeEnteringAnalysisContext() {} public open fun beforeEnteringAnalysisContext() {}
open fun afterLeavingAnalysisContext() {} public open fun afterLeavingAnalysisContext() {}
} }
@Suppress("NOTHING_TO_INLINE") @Suppress("NOTHING_TO_INLINE")
inline fun ValidityToken.assertIsValidAndAccessible() { public inline fun ValidityToken.assertIsValidAndAccessible() {
if (!isValid()) { if (!isValid()) {
throw InvalidEntityAccessException("Access to invalid $this: ${getInvalidationReason()}") throw InvalidEntityAccessException("Access to invalid $this: ${getInvalidationReason()}")
} }
@@ -35,8 +35,8 @@ inline fun ValidityToken.assertIsValidAndAccessible() {
} }
} }
abstract class BadEntityAccessException() : IllegalStateException() public abstract class BadEntityAccessException() : IllegalStateException()
class InvalidEntityAccessException(override val message: String) : BadEntityAccessException() public class InvalidEntityAccessException(override val message: String) : BadEntityAccessException()
class InaccessibleEntityAccessException(override val message: String) : BadEntityAccessException() public class InaccessibleEntityAccessException(override val message: String) : BadEntityAccessException()
@@ -12,73 +12,73 @@ import org.jetbrains.kotlin.idea.frontend.api.symbols.KtTypeParameterSymbol
import org.jetbrains.kotlin.name.ClassId import org.jetbrains.kotlin.name.ClassId
import org.jetbrains.kotlin.name.Name import org.jetbrains.kotlin.name.Name
sealed interface KtType : ValidityTokenOwner { public sealed interface KtType : ValidityTokenOwner {
fun asStringForDebugging(): String public fun asStringForDebugging(): String
} }
interface KtTypeWithNullability : KtType { public interface KtTypeWithNullability : KtType {
val nullability: KtTypeNullability public val nullability: KtTypeNullability
} }
enum class KtTypeNullability(val isNullable: Boolean) { public enum class KtTypeNullability(public val isNullable: Boolean) {
NULLABLE(true), NON_NULLABLE(false); NULLABLE(true), NON_NULLABLE(false);
companion object { public companion object {
fun create(isNullable: Boolean) = if (isNullable) NULLABLE else NON_NULLABLE public fun create(isNullable: Boolean): KtTypeNullability = if (isNullable) NULLABLE else NON_NULLABLE
} }
} }
sealed class KtClassType : KtType { public sealed class KtClassType : KtType {
override fun toString(): String = asStringForDebugging() override fun toString(): String = asStringForDebugging()
} }
sealed class KtNonErrorClassType : KtClassType(), KtTypeWithNullability { public sealed class KtNonErrorClassType : KtClassType(), KtTypeWithNullability {
abstract val classId: ClassId public abstract val classId: ClassId
abstract val classSymbol: KtClassLikeSymbol public abstract val classSymbol: KtClassLikeSymbol
abstract val typeArguments: List<KtTypeArgument> public abstract val typeArguments: List<KtTypeArgument>
} }
abstract class KtFunctionalType : KtNonErrorClassType() { public abstract class KtFunctionalType : KtNonErrorClassType() {
abstract val isSuspend: Boolean public abstract val isSuspend: Boolean
abstract val arity: Int public abstract val arity: Int
abstract val receiverType: KtType? public abstract val receiverType: KtType?
abstract val hasReceiver: Boolean public abstract val hasReceiver: Boolean
abstract val parameterTypes: List<KtType> public abstract val parameterTypes: List<KtType>
abstract val returnType: KtType public abstract val returnType: KtType
} }
abstract class KtUsualClassType : KtNonErrorClassType() public abstract class KtUsualClassType : KtNonErrorClassType()
abstract class KtClassErrorType : KtClassType() { public abstract class KtClassErrorType : KtClassType() {
abstract val error: String public abstract val error: String
} }
abstract class KtTypeParameterType : KtTypeWithNullability { public abstract class KtTypeParameterType : KtTypeWithNullability {
abstract val name: Name public abstract val name: Name
abstract val symbol: KtTypeParameterSymbol public abstract val symbol: KtTypeParameterSymbol
} }
abstract class KtCapturedType : KtType { public abstract class KtCapturedType : KtType {
override fun toString(): String = asStringForDebugging() override fun toString(): String = asStringForDebugging()
} }
abstract class KtDefinitelyNotNullType : KtType, KtTypeWithNullability { public abstract class KtDefinitelyNotNullType : KtType, KtTypeWithNullability {
abstract val original: KtType public abstract val original: KtType
final override val nullability: KtTypeNullability get() = KtTypeNullability.NON_NULLABLE final override val nullability: KtTypeNullability get() = KtTypeNullability.NON_NULLABLE
override fun toString(): String = asStringForDebugging() override fun toString(): String = asStringForDebugging()
} }
abstract class KtFlexibleType : KtType { public abstract class KtFlexibleType : KtType {
abstract val lowerBound: KtType public abstract val lowerBound: KtType
abstract val upperBound: KtType public abstract val upperBound: KtType
override fun toString(): String = asStringForDebugging() override fun toString(): String = asStringForDebugging()
} }
abstract class KtIntersectionType : KtType { public abstract class KtIntersectionType : KtType {
abstract val conjuncts: List<KtType> public abstract val conjuncts: List<KtType>
override fun toString(): String = asStringForDebugging() override fun toString(): String = asStringForDebugging()
} }
@@ -1,9 +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.idea.frontend.api.types
import org.jetbrains.kotlin.idea.frontend.api.*
import org.jetbrains.kotlin.name.ClassId