Skip to content

KtReference

@SubclassOptInRequired(markerClass = [KtImplementationDetail::class])
interface KtReference : PsiPolyVariantReference

Properties

absoluteRange

@get:NotNull
open val absoluteRange: @NotNull TextRange

canonicalText

@get:NotNull
@get:NlsSafe
abstract val canonicalText: @NotNull @NlsSafe String

element

abstract override val element: KtElement

isSoft

abstract val isSoft: Boolean

rangeInElement

@get:NotNull
abstract val rangeInElement: @NotNull TextRange

resolver

abstract val resolver: ResolveCache.PolyVariantResolver<KtReference>

resolvesByNames

abstract val resolvesByNames: Collection<Name>

Exhaustive collection of names that this reference may resolve to, or an empty collection if it cannot be predicted.

Exceptional cases

Note that there might be cases where the resolved element won't have a name from this resolvesByNames collection, so the client should handle it accordingly.

Here is a list of known cases:

  • Import aliases

    • E.g., a function might be imported with a different name (and called via it), so the result name won't be the same
  • Implicit companion object usages

    • If you have a companion object, and you use it implicitly via the class (e.g., String as an expression will be resolved to String.Companion)
  • Constructor references

    • Constructors don't have a name by their nature, but resolvesByNames has the class name instead

Unpredictable cases

  • this/super usages

  • Labels

    • KtLabelReferenceExpression is context-sensitive and might be resolved to anonymous elements, so the result cannot be fully expressed in the terms of this API
  • KtConstructorDelegationReference

    • It resolves into constructors, but the result class name cannot be predicted properly since it might be generated by compiler plugins

Return

an exhaustive collection of names that this reference may resolve to, or an empty collection if it cannot be predicted

variants

open val variants: @NotNull Array<out Any?>

Functions

bindToElement

abstract fun bindToElement(p0: @NotNull PsiElement): PsiElement?

getElement

abstract override fun getElement(): KtElement

handleElementRename

abstract fun handleElementRename(p0: @NotNull String): PsiElement?

isReferenceTo

abstract fun isReferenceTo(p0: @NotNull PsiElement): Boolean

multiResolve

abstract fun multiResolve(p0: Boolean): @NotNull Array<out ResolveResult?>

resolve

abstract fun resolve(): @Nullable PsiElement?