KaResolver¶
@SubclassOptInRequired(markerClass = [KaSessionComponentImplementationDetail::class])
interface KaResolver : KaSessionComponent
Inheritors¶
Properties¶
contextSensitiveResolutionStatus¶
The context-sensitive resolution status of the KtSimpleNameExpression: whether the name is already resolved through context-sensitive resolution, and whether a redundant explicit qualifier or import could be removed in favor of it.
The information is available even when the -Xcontext-sensitive-resolution feature is not enabled.
Example
enum class Foo { BAR }
fun usage(): Foo {
return Foo.BAR // the 'Foo.' qualifier can be removed -> KaContextSensitiveResolutionStatus.QualifierCanBeRemoved
}
See also
isImplicitReferenceToCompanion¶
abstract val KtSimpleNameExpression.isImplicitReferenceToCompanion: Boolean
Checks if the KtSimpleNameExpression is an implicit reference to a companion object via the containing class.
Example
Given a call A.foo(), A is an implicit reference to the companion object, so isImplicitReferenceToCompanion returns true.
token¶
abstract val token: KaLifetimeToken
The KaLifetimeToken which determines the lifetime of the lifetime owner.
Functions¶
assertIsValidAndAccessible¶
inline fun KaLifetimeOwner.assertIsValidAndAccessible()
collectCallCandidates¶
abstract fun KtResolvableCall.collectCallCandidates(): List<KaCallCandidate>
Returns all candidates considered during overload resolution for the call corresponding to the given KtResolvableCall.
In contrast, resolveCall returns only the final result, i.e., the most specific callable that passes all compatibility checks.
See also
isValid¶
fun KaLifetimeOwner.isValid(): Boolean
Whether the lifetime owner is still valid, i.e. we are still in the scope of the lifetime owner's regular lifetime.
resolveCall¶
abstract fun KtResolvableCall.resolveCall(): KaSimpleOrMultiCall?
Resolves the call for the given KtResolvableCall.
Usage Example:
fun KaSession.resolveSymbol(expression: KtCallExpression): KaSymbol? {
return expression.resolveCall()?.simple?.symbol
}
Returns the resolved KaSimpleOrMultiCall on success; otherwise, null
See also
abstract fun KtAnnotationEntry.resolveCall(): KaAnnotationCall?
Resolves the given KtAnnotationEntry to an annotation constructor call.
Example
Returns the corresponding KaAnnotationCall if resolution succeeds; otherwise, it returns null (e.g., when unresolved or ambiguous).
This is a specialized counterpart of KtResolvableCall.resolveCall focused specifically on annotation entries. Use collectCallCandidates to inspect all candidates considered during overload resolution
See also
abstract fun KtSuperTypeCallEntry.resolveCall(): KaFunctionCall<KaConstructorSymbol>?
Resolves the given KtSuperTypeCallEntry to a constructor call of the referenced supertype.
Example
Returns the corresponding KaFunctionCall if resolution succeeds; otherwise, it returns null (e.g., when unresolved or ambiguous).
This is a specialized counterpart of KtResolvableCall.resolveCall focused specifically on supertype constructor calls
See also
abstract fun KtConstructorDelegationCall.resolveCall(): KaDelegatedConstructorCall?
Resolves the given KtConstructorDelegationCall to a delegated constructor call.
Example
open class Base(val i: Int)
class Derived : Base {
constructor() : this(0)
// ^^^^^^^
constructor(x: Int) : super(x)
// ^^^^^^^^
}
Returns the corresponding KaDelegatedConstructorCall if resolution succeeds; otherwise, it returns null (e.g., when unresolved or ambiguous).
This is a specialized counterpart of KtResolvableCall.resolveCall focused specifically on constructor delegation calls
See also
Resolves the given KtConstructorDelegationReferenceExpression to a delegated constructor call.
Example
open class Base(val i: Int)
class Derived : Base {
constructor() : this(0)
// ^^^^
constructor(x: Int) : super(x)
// ^^^^^
}
Returns the corresponding KaDelegatedConstructorCall if resolution succeeds; otherwise, it returns null (e.g., when unresolved or ambiguous).
This is a specialized counterpart of KtResolvableCall.resolveCall focused specifically on constructor delegation calls
See also
abstract fun KtCallElement.resolveCall(): KaFunctionCall<*>?
Resolves the given KtCallElement to a function call.
Example
Returns the corresponding KaSimpleCall if resolution succeeds; otherwise, it returns null (e.g., when unresolved or ambiguous).
This is a specialized counterpart of KtResolvableCall.resolveCall focused specifically on call elements
See also
abstract fun KtCallableReferenceExpression.resolveCall(): KaCallableReferenceCall<*, *>?
Resolves the given KtCallableReferenceExpression to a callable member call.
Example
Returns the corresponding KaCallableReferenceCall if resolution succeeds; otherwise, it returns null (e.g., when unresolved or ambiguous).
This is a specialized counterpart of KtResolvableCall.resolveCall focused specifically on callable reference expressions
See also
abstract fun KtArrayAccessExpression.resolveCall(): KaFunctionCall<KaNamedFunctionSymbol>?
Resolves the given KtArrayAccessExpression to a simple function call representing get/set operator invocation.
Example
class A {
operator fun get(i: Int): Int = i
operator fun set(i: Int, value: Int) {}
}
fun test(a: A) {
a[0]
// ^^^^ resolves to `get`
a[0] = 1
// ^^^^ resolves to `set`
}
Returns the corresponding KaSimpleFunctionCall if resolution succeeds; otherwise, it returns null (e.g., when unresolved or ambiguous).
This is a specialized counterpart of KtResolvableCall.resolveCall focused specifically on array access operations.
Note: the get call is prefered in the case of a compound assignent
See also
abstract fun KtCollectionLiteralExpression.resolveCall(): KaFunctionCall<KaNamedFunctionSymbol>?
Resolves the given KtCollectionLiteralExpression to a simple function call representing the corresponding array factory invocation.
Example
annotation class Anno(val arr: IntArray)
@Anno([1, 2, 3])
// ^^^^^^^^^ resolves to a call of `intArrayOf`
fun use() {}
Returns the corresponding KaSimpleFunctionCall if resolution succeeds; otherwise, it returns null (e.g., when unresolved or ambiguous).
This is a specialized counterpart of KtResolvableCall.resolveCall focused specifically on collection literal expressions
See also
Resolves the given KtEnumEntrySuperclassReferenceExpression to a delegated constructor call.
Example
enum class EnumWithConstructor(val x: Int) {
Entry(1)
// ^ resolves to the constructor of `EnumWithConstructor`
}
Returns the corresponding KaDelegatedConstructorCall if resolution succeeds; otherwise, it returns null (e.g., when unresolved or ambiguous).
This is a specialized counterpart of KtResolvableCall.resolveCall focused specifically on enum entry superclass constructor calls
See also
abstract fun KtWhenConditionInRange.resolveCall(): KaFunctionCall<KaNamedFunctionSymbol>?
Resolves the given KtWhenConditionInRange to a simple function call representing the corresponding contains operator invocation used by the in/!in branch condition.
Example
fun test(x: Int) {
when (x) {
in 1..10 -> {}
// ^^^^^^^^ resolves to a call of `IntRange.contains`
!in setOf(1, 2, 3) -> {}
// ^^^^^^^^^^^^^^^^^^ resolves to a call of `Set<Int>.contains`
}
}
Returns the corresponding KaSimpleFunctionCall if resolution succeeds; otherwise, it returns null (e.g., when unresolved or ambiguous).
This is a specialized counterpart of KtResolvableCall.resolveCall focused specifically on in/!in range conditions inside when entries
See also
abstract fun KtDestructuringDeclarationEntry.resolveCall(): KaSimpleCall<*, *>?
Resolves the given KtDestructuringDeclarationEntry to a call representing the componentN invocation (for positional destructuring) or the property access (for name-based destructuring).
Example
data class Point(val x: Int, val y: Int)
fun test(p: Point) {
val (x, y) = p
// ^ resolves to a call of `component1`
// ^ resolves to a call of `component2`
}
Returns the corresponding KaSimpleCall if resolution succeeds; otherwise, it returns null (e.g., when unresolved or ambiguous).
This is a specialized counterpart of KtResolvableCall.resolveCall focused specifically on destructuring declaration entries
See also
abstract fun KtQualifiedExpression.resolveCall(): KaSimpleCall<*, *>?
Resolves the given KtQualifiedExpression to a call representing the member or extension access.
Example
Calling resolveCall() on the KtQualifiedExpression (str.length) returns the corresponding KaSimpleCall if resolution succeeds; otherwise, it returns null (e.g., when unresolved or ambiguous).
This is a specialized counterpart of KtResolvableCall.resolveCall focused specifically on qualified expressions
See also
abstract fun KtForExpression.resolveCall(): KaForLoopCall?
Resolves the given KtForExpression to a KaForLoopCall representing the desugared for loop.
A for loop desugars into three operator calls:
-
iterator()on the loop range expression -
hasNext()on the iterator -
next()on the iterator
Example
Calling resolveCall() on the KtForExpression returns a KaForLoopCall containing the three desugared operator calls if resolution succeeds; otherwise, it returns null (e.g., when unresolved or ambiguous).
This is a specialized counterpart of KtResolvableCall.resolveCall focused specifically on for loops
See also
abstract fun KtPropertyDelegate.resolveCall(): KaDelegatedPropertyCall?
Resolves the given KtPropertyDelegate to a KaDelegatedPropertyCall representing the desugared delegated property.
A delegated property desugars into up to three operator calls:
-
getValue()on the delegate object -
setValue()on the delegate object (only forvarproperties) -
provideDelegate()on the delegate expression (if applicable)
Example
Calling resolveCall() on the KtPropertyDelegate returns a KaDelegatedPropertyCall containing the desugared operator calls if resolution succeeds; otherwise, it returns null (e.g., when unresolved or ambiguous).
This is a specialized counterpart of KtResolvableCall.resolveCall focused specifically on delegated properties
See also
abstract fun KtConstructorCalleeExpression.resolveCall(): KaFunctionCall<KaConstructorSymbol>?
Resolves the given KtConstructorCalleeExpression to a constructor call.
Example
Returns the corresponding KaFunctionCall if resolution succeeds; otherwise, it returns null (e.g., when unresolved or ambiguous).
This is a specialized counterpart of KtResolvableCall.resolveCall focused specifically on constructor callee expressions
See also
abstract fun KtNameReferenceExpression.resolveCall(): KaSimpleCall<*, *>?
Resolves the given KtNameReferenceExpression to a call representing the referenced declaration.
Example
Calling resolveCall() on the KtNameReferenceExpression (foo) returns the corresponding KaSimpleCall if resolution succeeds; otherwise, it returns null (e.g., when unresolved or ambiguous).
This is a specialized counterpart of KtResolvableCall.resolveCall focused specifically on name reference expressions
See also
resolveSymbol¶
abstract fun KtResolvable.resolveSymbol(): KaSymbol?
Resolves a single symbol for the given KtResolvable.
Returns the KaSymbol if there is exactly one target; otherwise, null
In contract to resolveCall, it could represent any KaSymbol, not only KaCallableSymbol.
In most cases, a not-null result of resolveCall will represent the same symbol. The only exceptions are:
For which the behavior could be different depending on the context.
The main idea is that resolveSymbol could represent more cases, so it prefers exactly the referenced symbol and not the parent call. For more details, see the mentioned elements.
See also
abstract fun KtAnnotationEntry.resolveSymbol(): KaConstructorSymbol?
Resolves the constructor symbol of the annotation referenced by the given KtAnnotationEntry.
Example
Calling resolveSymbol() on the KtAnnotationEntry (@Anno(42)) returns the KaConstructorSymbol of Anno's annotation constructor if resolution succeeds; otherwise, it returns null (e.g., when unresolved or ambiguous).
This is a specialized counterpart of KtResolvable.resolveSymbol focused specifically on annotation entries
See also
abstract fun KtSuperTypeCallEntry.resolveSymbol(): KaConstructorSymbol?
Resolves the constructor symbol by the given KtSuperTypeCallEntry.
Example
Calling resolveSymbol() on the KtSuperTypeCallEntry (Base(1)) returns the KaConstructorSymbol of Base's constructor if resolution succeeds; otherwise, it returns null (e.g., when unresolved or ambiguous).
This is a specialized counterpart of KtResolvable.resolveSymbol focused specifically on supertype constructor calls
See also
abstract fun KtConstructorDelegationCall.resolveSymbol(): KaConstructorSymbol?
Resolves the constructor symbol referenced by the given KtConstructorDelegationCall.
Example
open class Base(val i: Int)
class Derived : Base {
constructor() : this(0)
// ^^^^^^^
constructor(x: Int) : super(x)
// ^^^^^^^^
}
Calling resolveSymbol() on a KtConstructorDelegationCall (either this(...) or super(...)) returns the KaConstructorSymbol of the target constructor if resolution succeeds; otherwise, it returns null (e.g., when unresolved or ambiguous).
This is a specialized counterpart of KtResolvable.resolveSymbol focused specifically on constructor delegation calls
See also
abstract fun KtConstructorDelegationReferenceExpression.resolveSymbol(): KaConstructorSymbol?
Resolves the constructor symbol referenced by the given KtConstructorDelegationReferenceExpression.
Example
open class Base(val i: Int)
class Derived : Base {
constructor() : this(0)
// ^^^^
constructor(x: Int) : super(x)
// ^^^^^
}
Calling resolveSymbol() on a KtConstructorDelegationReferenceExpression (either this or super) returns the KaConstructorSymbol of the target constructor if resolution succeeds; otherwise, it returns null (e.g., when unresolved or ambiguous).
This is a specialized counterpart of KtResolvable.resolveSymbol focused specifically on constructor delegation calls
See also
abstract fun KtCallElement.resolveSymbol(): KaFunctionSymbol?
Resolves the function symbol targeted by the given KtCallElement.
Example
Calling resolveSymbol() on the KtCallElement (foo(42)) returns the KaFunctionSymbol of foo if resolution succeeds; otherwise, it returns null (e.g., when unresolved or ambiguous).
This is a specialized counterpart of KtResolvable.resolveSymbol focused specifically on call elements
See also
abstract fun KtCallableReferenceExpression.resolveSymbol(): KaCallableSymbol?
Resolves the callable symbol targeted by the given KtCallableReferenceExpression.
Example
Calling resolveSymbol() on the KtCallableReferenceExpression (::foo) returns the KaCallableSymbol of foo if resolution succeeds; otherwise, it returns null (e.g., when unresolved or ambiguous).
This is a specialized counterpart of KtResolvable.resolveSymbol focused specifically on callable reference expressions
See also
abstract fun KtArrayAccessExpression.resolveSymbol(): KaNamedFunctionSymbol?
Resolves the operator function symbol targeted by the given KtArrayAccessExpression.
Example
class A {
operator fun get(i: Int): Int = i
operator fun set(i: Int, value: Int) {}
}
fun test(a: A) {
a[0]
// ^^^^ resolves to `get`
a[0] = 1
// ^^^^ resolves to `set`
}
Calling resolveSymbol() on a KtArrayAccessExpression (a[0]) returns the KaNamedFunctionSymbol of the corresponding get/set operator if resolution succeeds; otherwise, it returns null (e.g., when unresolved or ambiguous).
This is a specialized counterpart of KtResolvable.resolveSymbol focused specifically on array access operations.
Note: the get call is prefered in the case of a compound assignent
See also
abstract fun KtCollectionLiteralExpression.resolveSymbol(): KaNamedFunctionSymbol?
Resolves the function symbol targeted by the given KtCollectionLiteralExpression.
Example
annotation class Anno(val arr: IntArray)
@Anno([1, 2, 3])
// ^^^^^^^^^ resolves to the `intArrayOf` function
fun use() {}
Calling resolveSymbol() on a KtCollectionLiteralExpression ([1, 2, 3]) returns the KaNamedFunctionSymbol of the corresponding array factory (e.g., arrayOf, intArrayOf) if resolution succeeds; otherwise, it returns null (e.g., when unresolved or ambiguous).
This is a specialized counterpart of KtResolvable.resolveSymbol focused specifically on collection literal expressions
See also
abstract fun KtEnumEntrySuperclassReferenceExpression.resolveSymbol(): KaNamedClassSymbol?
Resolves the enum class symbol referenced by the given KtEnumEntrySuperclassReferenceExpression.
Example
enum class EnumWithConstructor(val x: Int) {
Entry(1)
// ^ resolves to the enum class `EnumWithConstructor`
}
Calling resolveSymbol() on a KtEnumEntrySuperclassReferenceExpression returns the KaNamedClassSymbol of the enclosing enum class if resolution succeeds; otherwise, it returns null (e.g., when unresolved or ambiguous).
Mirrors how KtNameReferenceExpression prefers the class over the constructor: while the surrounding super-type call (resolveCall) maps to the constructor, the reference itself denotes the class.
This is a specialized counterpart of KtResolvable.resolveSymbol focused specifically on enum entry super-type references
See also
abstract fun KtLabelReferenceExpression.resolveSymbol(): KaDeclarationSymbol?
Resolves the declaration symbol targeted by the given KtLabelReferenceExpression.
Example
fun myAction(action: () -> Unit) {
action {
return@action // resolves to the anonymous function
// ^^^^^^^
}
return@main
// ^^^^^
}
Calling resolveSymbol() on a KtLabelReferenceExpression (@action and @main) returns the corresponding KaDeclarationSymbol of the labeled declaration if resolution succeeds; otherwise, it returns null (e.g., when unresolved or ambiguous).
This is a specialized counterpart of KtResolvable.resolveSymbol focused specifically on label references
See also
abstract fun KtReturnExpression.resolveSymbol(): KaFunctionSymbol?
Resolves the function symbol targeted by the given KtReturnExpression.
Example
fun foo() {
return
// ^^^^^^ resolves to `foo`
}
fun main() {
listOf(1).forEach label@{
if (it == 0) return@label
// ^^^^^^^^^^^^ resolves to the anonymous function of this lambda
}
}
Calling resolveSymbol() on a KtReturnExpression (return or return@label) returns the KaFunctionSymbol of the enclosing function (for unlabeled returns) or of the labeled target (for return@label) if resolution succeeds; otherwise, it returns null (e.g., when unresolved or ambiguous).
This is a specialized counterpart of KtResolvable.resolveSymbol focused specifically on return expressions
See also
abstract fun KtWhenConditionInRange.resolveSymbol(): KaNamedFunctionSymbol?
Resolves the operator function symbol targeted by the given KtWhenConditionInRange.
Example
fun test(x: Int) {
when (x) {
in 1..10 -> {}
// ^^^^^^^^ resolves to a call of `IntRange.contains`
!in setOf(1, 2, 3) -> {}
// ^^^^^^^^^^^^^^^^^^ resolves to a call of `Set<Int>.contains`
}
}
Calling resolveSymbol() on a KtWhenConditionInRange (in 1..10 or !in setOf(1, 2, 3)) returns the KaNamedFunctionSymbol of the labeled declaration if resolution succeeds; otherwise, it returns null (e.g., when unresolved or ambiguous).
This is a specialized counterpart of KtResolvable.resolveSymbol focused specifically on in/!in range conditions inside when entries
See also
abstract fun KtDestructuringDeclarationEntry.resolveSymbol(): KaCallableSymbol?
Resolves the callable symbol targeted by the given KtDestructuringDeclarationEntry.
Example
data class Point(val x: Int, val y: Int)
fun test(p: Point) {
val (x, y) = p
// ^ resolves to `component1`
// ^ resolves to `component2`
}
Calling resolveSymbol() on a KtDestructuringDeclarationEntry returns the KaCallableSymbol of the corresponding componentN function (for positional destructuring) or the accessed property (for name-based destructuring) if resolution succeeds; otherwise, it returns null (e.g., when unresolved or ambiguous).
This is a specialized counterpart of KtResolvable.resolveSymbol focused specifically on destructuring declaration entries
See also
abstract fun KtQualifiedExpression.resolveSymbol(): KaCallableSymbol?
Resolves the callable symbol targeted by the given KtQualifiedExpression.
Example
Calling resolveSymbol() on the KtQualifiedExpression (str.length) returns the KaCallableSymbol of length if resolution succeeds; otherwise, it returns null (e.g., when unresolved or ambiguous).
This is a specialized counterpart of KtResolvable.resolveSymbol focused specifically on qualified expressions
See also
abstract fun KtConstructorCalleeExpression.resolveSymbol(): KaConstructorSymbol?
Resolves the constructor symbol referenced by the given KtConstructorCalleeExpression.
Example
Calling resolveSymbol() on the KtConstructorCalleeExpression (Base) returns the KaConstructorSymbol of Base's constructor if resolution succeeds; otherwise, it returns null (e.g., when unresolved or ambiguous).
This is a specialized counterpart of KtResolvable.resolveSymbol focused specifically on constructor callee expressions
See also
abstract fun KtInstanceExpressionWithLabel.resolveSymbol(): KaDeclarationSymbol?
Resolves the declaration symbol referenced by the given KtInstanceExpressionWithLabel.
Example
class Foo {
fun bar() = this
// ^^^^ resolves to the class `Foo`
}
fun String.ext() = this
// ^^^^ resolves to the receiver parameter of `ext`
open class Base {
open fun baz() {}
}
class Derived : Base() {
override fun baz() {
super.baz()
// ^^^^^ resolves to the class `Base`
}
}
Calling resolveSymbol() on a KtInstanceExpressionWithLabel (this or super) returns the KaDeclarationSymbol of the referenced class, receiver, or other target declaration if resolution succeeds; otherwise, it returns null (e.g., when unresolved or ambiguous).
This is a specialized counterpart of KtResolvable.resolveSymbol focused specifically on instance expressions
See also
abstract fun KtNullableType.resolveSymbol(): KaClassifierSymbol?
Resolves the classifier symbol referenced by the given KtNullableType.
Example
Resolution unwraps the nullability marker and recurses into the inner type element. The result is the KaClassifierSymbol of the underlying class, type alias, or type parameter if resolution succeeds; otherwise, it returns null (e.g., when unresolved or when the inner element has no single classifier).
Unlike KtUserType, a KtNullableType cannot stand for a package qualifier, so the result is always a classifier when present.
This is a specialized counterpart of KtResolvable.resolveSymbol focused specifically on nullable types
See also
abstract fun KtFunctionType.resolveSymbol(): KaClassSymbol?
Resolves the synthetic function class symbol referenced by the given KtFunctionType.
Example
val a: (Int, String) -> Boolean = TODO()
// ^^^^^^^^^^^^^^^^^^^^^^^ resolves to `kotlin.Function2`
val b: suspend () -> Unit = TODO()
// ^^^^^^^^^^^^^^^^^ resolves to `kotlin.coroutines.SuspendFunction0`
Returns the KaClassSymbol of the corresponding FunctionN/SuspendFunctionN class (the receiver and context parameters count as parameters towards the arity), or null if resolution fails.
This is a specialized counterpart of KtResolvable.resolveSymbol focused specifically on function types
See also
abstract fun KtTypeReference.resolveSymbol(): KaClassifierSymbol?
Resolves the classifier symbol referenced by the given KtTypeReference.
Example
val a: String = ""
// ^^^^^^ resolves to `kotlin.String`
val b: List<Int>? = null
// ^^^^^^^^^^ resolves to `kotlin.collections.List`
val c: (Int) -> Int = { it }
// ^^^^^^^^^^^^ resolves to `kotlin.Function1`
Resolution delegates to the inner KtTypeReference.typeElement and returns the underlying KaClassifierSymbol (a class, type alias, or type parameter), or null for type elements that don't denote a single classifier (e.g. dynamic and intersection types).
Unlike KtUserType, a KtTypeReference never stands for the package portion of a qualified path: the inner qualifier chain is built from raw KtUserType nodes and is never wrapped in its own type reference, so the result is always a classifier when present.
This is a specialized counterpart of KtResolvable.resolveSymbol focused specifically on type references
See also
abstract fun KtClassLiteralExpression.resolveSymbol(): KaClassifierSymbol?
Resolves the classifier symbol referenced by the given KtClassLiteralExpression (Foo::class).
Example
val a = String::class
// ^^^^^^^^^^^^^ resolves to `kotlin.String`
val b = kotlin.String::class
// ^^^^^^^^^^^^^^^^^^^^ resolves to `kotlin.String`
Resolution delegates to the receiver expression on the left of ::class. Returns the underlying KaClassifierSymbol of the referenced class, type alias, or type parameter if resolution succeeds; otherwise, it returns null (e.g., when unresolved or ambiguous).
This is a specialized counterpart of KtResolvable.resolveSymbol focused specifically on class literal expressions
See also
abstract fun KtSuperTypeEntry.resolveSymbol(): KaClassifierSymbol?
Resolves the classifier symbol referenced by the given KtSuperTypeEntry (the no-parens form class Foo : Bar).
Example
Resolution delegates to the entry's KtSuperTypeEntry.getTypeReference. Returns the underlying KaClassifierSymbol of the supertype if resolution succeeds; otherwise, it returns null.
Companion to KtSuperTypeCallEntry.resolveSymbol, which returns the KaConstructorSymbol for the class Foo : Bar() form.
This is a specialized counterpart of KtResolvable.resolveSymbol focused specifically on supertype entries
See also
abstract fun KtDelegatedSuperTypeEntry.resolveSymbol(): KaClassifierSymbol?
Resolves the classifier symbol referenced by the given KtDelegatedSuperTypeEntry (class Foo : Bar by baz).
Example
Resolution delegates to the entry's KtDelegatedSuperTypeEntry.getTypeReference — the supertype side of the by clause, not the delegate expression. Returns the underlying KaClassifierSymbol if resolution succeeds; otherwise, it returns null.
This is a specialized counterpart of KtResolvable.resolveSymbol focused specifically on delegated supertype entries
See also
resolveSymbols¶
abstract fun KtResolvable.resolveSymbols(): Collection<KaSymbol>
Resolves symbols for the given KtResolvable.
Returns all resolved KaSymbols if successful; otherwise, an empty list. Might contain multiple symbols for a compound case
In contract to resolveCall, it could represent any KaSymbol, not only KaCallableSymbol.
In most cases, a not-null result of resolveCall will represent the same symbol. The only exceptions are:
For which the behavior could be different depending on the context.
The main idea is that resolveSymbols could represent more cases, so it prefers exactly the referenced symbol and not the parent call. For more details, see the mentioned elements.
See also
resolveToCall¶
abstract fun KtElement.resolveToCall(): KaCallInfo?
Resolves the given KtElement to a KaCallInfo object. KaCallInfo either contains a successfully resolved call or an error with a list of candidate calls and a diagnostic.
Returns null if the element does not correspond to a call.
Consider using the new resolution API.
See also
resolveToCallCandidates¶
abstract fun KtElement.resolveToCallCandidates(): List<KaCallCandidateInfo>
Returns all candidates considered during overload resolution for the call corresponding to this KtElement.
To compare, the resolveToCall function only returns the final result of overload resolution, i.e. the most specific callable passing all compatibility checks.
Consider using the new resolution API.
See also
resolveToSymbol¶
abstract fun KtReference.resolveToSymbol(): KaSymbol?
Resolves the given KtReference to a symbol.
Returns null if the reference cannot be resolved, or resolves to multiple symbols due to being ambiguous.
Consider using the new resolution API.
See also
resolveToSymbols¶
abstract fun KtReference.resolveToSymbols(): Collection<KaSymbol>
Resolves the given KtReference to symbols.
Returns an empty collection if the reference cannot be resolved, or multiple symbols if the reference is ambiguous.
Consider using the new resolution API.
See also
tryResolveCall¶
abstract fun KtResolvableCall.tryResolveCall(): KaCallResolutionAttempt?
Attempts to resolve the call for the given KtResolvableCall.
Usage Example:
fun KaSession.findResolutionDiagnostic(expression: KtCallExpression): KaDiagnostic? {
val attempt = expression.tryResolveCall() ?: return null
return attempt.errors.firstOrNull()?.diagnostic
}
Returns a KaCallResolutionAttempt, or null when there is no call to resolve: the element is not call-shaped, or its reference resolves to something non-callable, such as a qualifier, an import, or a type. Broken code can end up here as well.
A non-null result describes the outcome of an actual resolution. Check it with errors or isSuccessful rather than with a type check, which only covers simple attempts. A reported error may carry an empty candidateCalls list.
See References and Calls for a top-level overview.
See also
abstract fun KtForExpression.tryResolveCall(): KaForLoopCallResolutionAttempt?
Attempts to resolve the given KtForExpression to a KaForLoopCallResolutionAttempt containing the individual resolution results for each desugared operator call (iterator, hasNext, next).
This is a specialized counterpart of KtResolvableCall.tryResolveCall focused specifically on for loops.
See also
abstract fun KtPropertyDelegate.tryResolveCall(): KaDelegatedPropertyCallResolutionAttempt?
Attempts to resolve the given KtPropertyDelegate to a KaDelegatedPropertyCallResolutionAttempt containing the individual resolution results for each desugared operator call (getValue, setValue, provideDelegate).
This is a specialized counterpart of KtResolvableCall.tryResolveCall focused specifically on delegated properties.
See also
tryResolveSymbols¶
abstract fun KtResolvable.tryResolveSymbols(): KaSymbolResolutionAttempt?
Attempts to resolve a symbol for the given KtResolvable.
Usage Example:
fun KaSession.findSymbol(reference: KtNameReferenceExpression): KaSymbol? {
val attempt = reference.tryResolveSymbols() ?: return null
return attempt.fold(
onSuccess = { symbols -> symbols.singleOrNull() },
onFailure = { errors ->
val name = reference.getReferencedName()
errors.forEach { println("Cannot resolve '$name': ${it.diagnostic.defaultMessage}") }
null
},
)
}
Returns a KaSymbolResolutionAttempt that describes either success (KaSimpleSymbolResolutionSuccess) or failure (KaSimpleSymbolResolutionError, or KaCompoundSymbolResolutionError for a compound call), or null when there is nothing to resolve: the element carries no resolvable reference, such as a type reference to a dynamic or intersection type, or the engine has no result for it, which broken code can cause.
A non-null result describes the outcome of an actual resolution. Check it with errors or isSuccessful rather than with a type check, which only covers simple attempts. A reported error may carry an empty candidateSymbols list.
In contract to tryResolveCall, it could represent any KaSymbol, not only KaCallableSymbol.
In most cases, a not-null result of tryResolveCall will represent the same symbol. The only exceptions are:
For which the behavior could be different depending on the context.
The main idea is that tryResolveSymbols could represent more cases, so it prefers exactly the referenced symbol and not the parent call. For more details, see the mentioned elements.
See References and Calls for a top-level overview.
See also
withValidityAssertion¶
inline fun <R> KaLifetimeOwner.withValidityAssertion(action: () -> R): R
Executes action only if the KaLifetimeOwner is still valid and accessible. Otherwise, throws a validity exception based on the concrete violation.