Skip to content

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

Checks if the KtSimpleNameExpression is an implicit reference to a companion object via the containing class.

Example

class A {
   companion object {
      fun foo() {}
   }
}

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

collectCallCandidates

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

Whether the lifetime owner is still valid, i.e. we are still in the scope of the lifetime owner's regular lifetime.

resolveCall

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

Resolves the given KtAnnotationEntry to an annotation constructor call.

Example

annotation class Anno(val x: Int)

@Anno(42)
fun foo() {}

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

Resolves the given KtSuperTypeCallEntry to a constructor call of the referenced supertype.

Example

open class Base(i: Int)

class Derived : Base(1)
//              ^^^^^^^

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

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

Resolves the given KtCallElement to a function call.

Example

fun foo(x: Int) {}

fun test() {
    foo(42)
//  ^^^^^^^
}

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

Resolves the given KtCallableReferenceExpression to a callable member call.

Example

class A { fun foo() {} }

val ref = A::foo
//        ^^^^^^

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

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

fun test(m: MyMap<String, Int>) {
    m["a"] += 1
//  ^^^^^^
}

See also

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

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

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

Resolves the given KtQualifiedExpression to a call representing the member or extension access.

Example

val len = str.length
//        ^________^

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

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

for (item in list) {
    println(item)
}

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

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 for var properties)

  • provideDelegate() on the delegate expression (if applicable)

Example

val name: String by lazy { "John" }
//               ^________________^

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

Resolves the given KtConstructorCalleeExpression to a constructor call.

Example

open class Base(i: Int)

class Derived : Base(1)
//              ^^^^

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

Resolves the given KtNameReferenceExpression to a call representing the referenced declaration.

Example

fun foo() {}

val x = foo
//      ^^^

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

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

Resolves the constructor symbol of the annotation referenced by the given KtAnnotationEntry.

Example

annotation class Anno(val x: Int)

@Anno(42)
fun foo() {}

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

Resolves the constructor symbol by the given KtSuperTypeCallEntry.

Example

open class Base(i: Int)

class Derived : Base(1)
//              ^^^^^^^

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

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

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

Resolves the function symbol targeted by the given KtCallElement.

Example

fun foo(x: Int) {}

fun test() {
    foo(42)
//  ^^^^^^^
}

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

Resolves the callable symbol targeted by the given KtCallableReferenceExpression.

Example

fun foo(x: Int) {}

val ref = ::foo
//        ^^^^^

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

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

fun test(m: MyMap<String, Int>) {
    m["a"] += 1
//  ^^^^^^
}

See also

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

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

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

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

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

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

Resolves the callable symbol targeted by the given KtQualifiedExpression.

Example

val len = str.length
//        ^________^

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

Resolves the constructor symbol referenced by the given KtConstructorCalleeExpression.

Example

open class Base(i: Int)

class Derived : Base(1)
//              ^^^^

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

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

Resolves the classifier symbol referenced by the given KtNullableType.

Example

val name: String? = null
//        ^^^^^^^  resolves to `kotlin.String`

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

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

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

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

Resolves the classifier symbol referenced by the given KtSuperTypeEntry (the no-parens form class Foo : Bar).

Example

class Foo : Runnable
//          ^^^^^^^^  resolves to `java.lang.Runnable`

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

Resolves the classifier symbol referenced by the given KtDelegatedSuperTypeEntry (class Foo : Bar by baz).

Example

class Foo(b: Base) : Base by b
//                   ^^^^      resolves to `Base`

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

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

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

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

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

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

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

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

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

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.