resolveSuccessfulSymbol¶
context(session: KaSession)
fun KtResolvable.resolveSuccessfulSymbol(): KaSymbol?
Resolves a single symbol for the given KtResolvable.
Returns the KaSymbol if there is exactly one target; otherwise, null
In contract to resolveSuccessfulCall, it could represent any KaSymbol, not only KaCallableSymbol.
In most cases, a not-null result of resolveSuccessfulCall 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 resolveSuccessfulSymbol 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¶
context(session: KaSession)
fun KtAnnotationEntry.resolveSuccessfulSymbol(): KaConstructorSymbol?
Resolves the constructor symbol of the annotation referenced by the given KtAnnotationEntry.
Example¶
Calling resolveSuccessfulSymbol() 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.resolveSuccessfulSymbol focused specifically on annotation entries
See also¶
context(session: KaSession)
fun KtSuperTypeCallEntry.resolveSuccessfulSymbol(): KaConstructorSymbol?
Resolves the constructor symbol by the given KtSuperTypeCallEntry.
Example¶
Calling resolveSuccessfulSymbol() 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.resolveSuccessfulSymbol focused specifically on supertype constructor calls
See also¶
context(session: KaSession)
fun KtConstructorDelegationCall.resolveSuccessfulSymbol(): 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 resolveSuccessfulSymbol() 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.resolveSuccessfulSymbol focused specifically on constructor delegation calls
See also¶
context(session: KaSession)
fun KtConstructorDelegationReferenceExpression.resolveSuccessfulSymbol(): 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 resolveSuccessfulSymbol() 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.resolveSuccessfulSymbol focused specifically on constructor delegation calls
See also¶
context(session: KaSession)
fun KtCallElement.resolveSuccessfulSymbol(): KaFunctionSymbol?
Resolves the function symbol targeted by the given KtCallElement.
Example¶
Calling resolveSuccessfulSymbol() 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.resolveSuccessfulSymbol focused specifically on call elements
See also¶
context(session: KaSession)
fun KtCallableReferenceExpression.resolveSuccessfulSymbol(): KaCallableSymbol?
Resolves the callable symbol targeted by the given KtCallableReferenceExpression.
Example¶
Calling resolveSuccessfulSymbol() 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.resolveSuccessfulSymbol focused specifically on callable reference expressions
See also¶
context(session: KaSession)
fun KtArrayAccessExpression.resolveSuccessfulSymbol(): 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 resolveSuccessfulSymbol() 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.resolveSuccessfulSymbol focused specifically on array access operations.
Note: the get call is prefered in the case of a compound assignent
See also¶
context(session: KaSession)
fun KtCollectionLiteralExpression.resolveSuccessfulSymbol(): 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 resolveSuccessfulSymbol() 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.resolveSuccessfulSymbol focused specifically on collection literal expressions
See also¶
context(session: KaSession)
fun KtEnumEntrySuperclassReferenceExpression.resolveSuccessfulSymbol(): 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 resolveSuccessfulSymbol() 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 (resolveSuccessfulCall) maps to the constructor, the reference itself denotes the class.
This is a specialized counterpart of KtResolvable.resolveSuccessfulSymbol focused specifically on enum entry super-type references
See also¶
context(session: KaSession)
fun KtLabelReferenceExpression.resolveSuccessfulSymbol(): 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 resolveSuccessfulSymbol() 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.resolveSuccessfulSymbol focused specifically on label references
See also¶
context(session: KaSession)
fun KtReturnExpression.resolveSuccessfulSymbol(): 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 resolveSuccessfulSymbol() 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.resolveSuccessfulSymbol focused specifically on return expressions
See also¶
context(session: KaSession)
fun KtWhenConditionInRange.resolveSuccessfulSymbol(): 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 resolveSuccessfulSymbol() 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.resolveSuccessfulSymbol focused specifically on in/!in range conditions inside when entries
See also¶
context(session: KaSession)
fun KtDestructuringDeclarationEntry.resolveSuccessfulSymbol(): 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 resolveSuccessfulSymbol() 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.resolveSuccessfulSymbol focused specifically on destructuring declaration entries
See also¶
context(session: KaSession)
fun KtQualifiedExpression.resolveSuccessfulSymbol(): KaCallableSymbol?
Resolves the callable symbol targeted by the given KtQualifiedExpression.
Example¶
Calling resolveSuccessfulSymbol() 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.resolveSuccessfulSymbol focused specifically on qualified expressions
See also¶
context(session: KaSession)
fun KtConstructorCalleeExpression.resolveSuccessfulSymbol(): KaConstructorSymbol?
Resolves the constructor symbol referenced by the given KtConstructorCalleeExpression.
Example¶
Calling resolveSuccessfulSymbol() 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.resolveSuccessfulSymbol focused specifically on constructor callee expressions
See also¶
context(session: KaSession)
fun KtInstanceExpressionWithLabel.resolveSuccessfulSymbol(): 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 resolveSuccessfulSymbol() 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.resolveSuccessfulSymbol focused specifically on instance expressions
See also¶
context(session: KaSession)
fun KtNullableType.resolveSuccessfulSymbol(): 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.resolveSuccessfulSymbol focused specifically on nullable types
See also¶
context(session: KaSession)
fun KtFunctionType.resolveSuccessfulSymbol(): 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.resolveSuccessfulSymbol focused specifically on function types
See also¶
context(session: KaSession)
fun KtTypeReference.resolveSuccessfulSymbol(): 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.resolveSuccessfulSymbol focused specifically on type references
See also¶
context(session: KaSession)
fun KtClassLiteralExpression.resolveSuccessfulSymbol(): 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.resolveSuccessfulSymbol focused specifically on class literal expressions
See also¶
context(session: KaSession)
fun KtSuperTypeEntry.resolveSuccessfulSymbol(): 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.resolveSuccessfulSymbol, which returns the KaConstructorSymbol for the class Foo : Bar() form.
This is a specialized counterpart of KtResolvable.resolveSuccessfulSymbol focused specifically on supertype entries
See also¶
context(session: KaSession)
fun KtDelegatedSuperTypeEntry.resolveSuccessfulSymbol(): 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.resolveSuccessfulSymbol focused specifically on delegated supertype entries