Skip to content

KotlinPsiReferenceProviderContributor

Extension-point contributor for Kotlin PSI reference providers.

The EP allows registering custom reference contributors for KtElements.

Contributors are supposed to be registered via the org.jetbrains.kotlin.psiReferenceProvider EP. Each contributor binds a particular PSI element type (represented by elementClass) to a referenceProvider function which may produce PsiReferences for a given element instance.

Implementation notes for contributors:

  • Keep referenceProvider fast and side‑effect free; return an empty list when no references should be produced.

  • Perform inexpensive guards before any expensive analysis (e.g., quick kind checks, token/parent filters) to minimize overhead.

Types

ReferenceProvider

fun interface ReferenceProvider<in T : KtElement> : Function1<T, List<PsiReference>> 

Functional interface used to create references for a specific PSI element of type T. The function must be pure and must return a (possibly empty) list of PsiReferences. Returning an empty list is preferred to doing unnecessary work when the element is not applicable.

Properties

elementClass

abstract val elementClass: Class<out T>

The base PSI class this contributor applies to. A contributor is considered applicable to an element if elementClass.isAssignableFrom(element.javaClass)

referenceProvider

The function that produces references for elements of elementClass