Skip to content

KaNamedFunctionSymbol

KaNamedFunctionSymbol represents a named function declaration, such as a top-level function, a class method, or a named local function.

Constructors

KaNamedFunctionSymbol

constructor()

Properties

allOverriddenSymbols

All explicitly declared (non-fake) callable symbols overridden by this callable symbol.

The sequence implicitly unwraps substituted and intersection override symbols (see INTERSECTION_OVERRIDE and SUBSTITUTION_OVERRIDE).

The sequence doesn't include the original overridden declaration of a delegated symbol (for that, use fakeOverrideOriginal).

Depending on this callable symbol, the sequence contains:

The sequence may include KaSyntheticJavaPropertySymbols in Java/Kotlin hierarchies.

Example

abstract class C {
    open fun foo() { ... }
}

abstract class B : C() {
    override fun foo() { ... }
}

class A : B() {
    override fun foo() { ... }
}

For A.foo, allOverriddenSymbols contains both overridden super-declarations, B.foo and C.foo.

See also

anchorPsi

abstract val anchorPsi: PsiElement?

A PsiElement associated with the symbol. Usually, it is the best PsiElement representation for a particular KaSymbol.

It reuses realPsi, but can also provide a value for other origins.

While anchorPsi aims to be the most related element, it is still an approximation, and there are no strict guarantees that it is a particular element.

Examples:

class MyClass

For this code, KaNamedClassSymbol represents the class, while KaConstructorSymbol represents the implicit constructor. The class is present in the code as a KtClassOrObject, so that element is used. In contrast, the constructor is not present in the code, but can be obtained from the class, so anchorPsi for it is the same KtClassOrObject.

For declarations generated by compiler plugins, it usually points to the declaration from which the symbol was generated, but the behavior is effectively defined by the compiler plugin itself, and the Analysis API use it unchanged.

An alternative can be getting realPsi or the containing declaration instead for more predictable behavior.

See also

annotations

A list of annotations applied to the annotated entity.

callableId

abstract val callableId: CallableId?

The callable's CallableId if it exists, or null if the declaration is local.

canBeOperator

Whether the function symbol meets all the requirements to be declared as an operator function.

In Kotlin, the set of functions which can be declared as an operator is predefined. canBeOperator not only checks the name of a potential operator function, but also its signature, depending on the operator.

canBeOperator does not determine whether the function symbol is declared as an operator. For this purpose, use KaNamedFunctionSymbol.isOperator instead.

Example

class A

fun A.plus(that: A): A = A() // canBeOperator = true, as it meets all requirements for `plus`.

operator fun A.contains(that: A): Boolean = true // canBeOperator = true, as it's already an operator.

fun A.something(that: A): A = A() // canBeOperator = false, as there is no operator with such a name.

fun A.minus(): A = A() // canBeOperator = false, as `minus` is a binary operator and should have one parameter.

containingDeclaration

The KaDeclarationSymbol which contains this symbol, or null if there is no containing declaration:

  • For top-level declarations, a containing KaScriptSymbol, or null for non-script declarations.

  • For class members, the containing class symbol.

  • For property members, the corresponding property.

  • For local declarations, the symbol of the containing declaration.

containingFile

context(session: KaSession)
val KaSymbol.containingFile: KaFileSymbol?

The KaFileSymbol which contains this symbol, or null if this symbol is already a KaFileSymbol, since it has no containing file. Also null for Java and library declarations.

containingFileAnnotations

File-level annotations (@file:SomeAnnotation) of the source file this top-level KaDeclarationSymbol was defined in, or null for a nested declaration.

This API is only intended to be used by the TypeScript export utility.

containingJvmClassName

The containing JVM class name for the given KaCallableSymbol.

containingModule

context(session: KaSession)
val KaSymbol.containingModule: KaModule

The KaModule which contains this symbol.

containingSymbol

context(session: KaSession)
val KaSymbol.containingSymbol: KaSymbol?

The KaSymbol which contains this symbol, or null if there is no containing declaration:

contextParameters

A list of KaContextParameterSymbols directly declared in the symbol.

contextReceivers

List of KaContextReceiver directly declared in the source code

contractEffects

The list of the function's defined contract effects.

contractEffects is experimental because contracts themselves are an experimental feature.

defaultAnnotationTargets

A set of annotation targets matching for the given symbol, or null if the symbol cannot be annotated. Annotations with one of targets from the returned set can be placed on the KaSymbol without an explicit use-site target.

Such as, annotations with KaAnnotationTarget.PROPERTY or KaAnnotationTarget.VALUE_PARAMETER can be directly placed on a 'val' value parameter, while annotations for KaAnnotationTarget.PROPERTY_GETTER and KaAnnotationTarget.PROPERTY_SETTER can only be applied using the @set:AnnotationName syntax.

Check the Annotation use-site targets documentation for additional information.

deprecation

context(session: KaSession)
val KaSymbol.deprecation: KaDeprecation?

The deprecation status of the given symbol, or null if the symbol is not deprecated.

This considers deprecation annotations applied to the symbol itself and, for property-related symbols, deprecation annotations with appropriate use-site targets.

directlyOverriddenSymbols

Explicitly declared (non-fake) callable symbols that are directly overridden by this callable symbol.

The sequence implicitly unwraps substituted and intersection override symbols (see INTERSECTION_OVERRIDE and SUBSTITUTION_OVERRIDE).

The sequence doesn't include the original overridden declaration of a delegated symbol (for that, use fakeOverrideOriginal).

Symbol kinds follow the same mapping as allOverriddenSymbols. In particular, property accessor symbols and Java accessor methods of synthetic Java properties are represented by property symbols rather than accessor or Java method symbols. Setters include only mutable properties whose setters are directly overridden.

Example

abstract class C {
    open fun foo() { ... }
}

abstract class B : C() {
    override fun foo() { ... }
}

class A : B() {
    override fun foo() { ... }
}

For A.foo, directlyOverriddenSymbols contains only the directly overridden super-declaration, B.foo.

See also

equalityBound

The equality bound associated with this equals operator function, or null if the function is not an equals operator function or has no equality bound.

With more-specific equals, an equality bound narrows the contract of equals: the function is guaranteed to return false when its argument value is not an instance of the bound. A bound can be declared with the kotlin.EqualityBound annotation, inherited from overridden equals functions, or generated together with a compiler-generated equals implementation.

When several overridden functions contribute unrelated bounds, the result is their intersection and is represented as a KaIntersectionType. Generic class types participating in a bound are star-projected because type arguments do not affect equality compatibility. In erroneous code, the result can be a KaErrorType.

Note: this property describes the function symbol itself; it does not calculate an equality bound for a particular dispatch receiver type. For example, enum classes inherit kotlin.Enum.equals, whose symbol has no enum-class-specific bound. However, it's an error to compare by equality two enum entries of different types. The compiler-defined strict equality of those classifiers is therefore not represented by this property.

Example

open class Base {
    // equalityBound = Base, declared explicitly.
    override fun equals(@EqualityBound(Base::class) other: Any?): Boolean = true
}

class Derived : Base() {
    // equalityBound = Base, inherited from 'Base.equals'.
    override fun equals(other: Any?): Boolean = true
}

interface Left {
    override fun equals(@EqualityBound(Left::class) other: Any?): Boolean
}

interface Right {
    override fun equals(@EqualityBound(Right::class) other: Any?): Boolean
}

class Combined : Left, Right {
    // Invalid: Kotlin requires an explicit denotable equality bound here.
    // In this erroneous code, equalityBound = Left & Right, inherited from both overridden functions.
    override fun equals(other: Any?): Boolean = true
}

class Unbounded {
    // equalityBound = null, as neither this function nor any overridden one declares a bound.
    override fun equals(other: Any?): Boolean = true
}

// equalityBound = Data<*>, generated together with the 'equals' of the generic data class.
data class Data<T>(val value: T)

fakeOverrideOriginal

The original declared symbol for this callable symbol, after unwrapping fake override KaCallableSymbols if needed.

In a class scope, a symbol may be derived from symbols declared in super classes. For example, consider the following:

public interface A<T> {
  public fun foo(t: T)
}

public interface B : A<String> {
}

In the class scope of B, there is a callable symbol foo that takes a String. This symbol is derived from the original symbol in A that takes the type parameter T (fake override). Given such a fake override symbol, fakeOverrideOriginal is the original declared symbol.

Such a situation can also happen for intersection symbols (in case of multiple supertypes containing symbols with an identical signature after specialization) and delegation.

See also

hasStableParameterNames

Whether the function has stable parameter names. Parameters with stable names can be used with the named parameter call syntax (e.g. User(name = "Joe") instead of User("Joe")).

Kotlin functions always have stable parameter names that can be reliably used when calling them with named arguments. Functions loaded from platform definitions (e.g. Java binaries or JS) may have unstable parameter names that vary from one platform installation to another. These names cannot be used reliably for calls with named arguments.

importableFqName

context(session: KaSession)
val KaSymbol.importableFqName: FqName?

A FqName which can be used to import the given symbol, or null if the symbol cannot be imported.

intersectionOverriddenSymbols

All callable symbols overridden by this callable symbol if it is an intersection override, or an empty list otherwise.

Symbol kinds follow the same mapping as allOverriddenSymbols. In particular, property accessor symbols and Java accessor methods of synthetic Java properties are represented by property symbols rather than accessor or Java method symbols. Setters include only mutable properties whose setters are overridden by the intersection override.

Example

interface Foo<T> {
    fun foo(value: T)
}

interface Bar {
    fun foo(value: String)
}

interface Both : Foo<String>, Bar

The Both interface contains an automatically generated intersection override for foo(). For it, intersectionOverriddenSymbols is a list of two unsubstituted symbols: Foo.foo(T) and Bar.foo(String).

See also

isActual

abstract val isActual: Boolean

Whether the declaration is an actual declaration in a multiplatform project.

See the official Kotlin documentation for more details.

isBuiltinFunctionInvoke

Whether this symbol is the invoke method defined on the Kotlin builtin functional type.

isCompanion

abstract val isCompanion: Boolean

Whether the callable is a companion extension or comes from a companion block.

Java statics are also considered as from companion blocks.

Note:

  • According to the KEEP, KaEnumEntrySymbol (and its generated callables like valueOf) are also considered implicitly declared in a companion block.

  • Callables from companion objects are not considered as from companion blocks!

Examples:

enum class EnumClass {
  Entry; // true

  val entries: EnumEntries<EnumClass> // true
  // ^ auto-generated by the compiler

  fun regular() {} // false
  val regular: Int = 1 // false
}

class Foo {
  fun classMember() {} // false
  val classMember: Int = 1 // false

  companion {
    fun companionBlockMember() {} // true
    val companionBlockMember: Int = 1 // true
  }

  companion object {
    fun companionMember(){} // false

    @JvmStatic
    fun withJvmStatic(){} // false

    @JvmField
    val withJvmFiled: Int = 42 // false

    lateinit var lateinitVariable: String // false
  }
}

object Object {
  fun objectMember() // false
  val objectMember: Int = 1 // false
}

fun topLevel() {} // false
val topLevel: Int = 1 // false

companion fun Foo.companionExtension() {} // true
companion val Foo.companionExtension: Int get() = 1 // true

isDeprecated

context(session: KaSession)
val KaSymbol.isDeprecated: Boolean

Whether the symbol is deprecated at any level.

This is a convenience property equivalent to deprecation != null.

isExpect

abstract val isExpect: Boolean

Whether the declaration is an expect declaration in a multiplatform project.

See the official Kotlin documentation for more details.

Example

expect class A {
    class Nested
}

In this example, isExpect is true for both A and A.Nested.

isExtension

abstract val isExtension: Boolean

Whether the callable is an extension function or property.

isExternal

abstract val isExternal: Boolean

Indicates whether this declaration is external.

A declaration is considered external if any of the following is true:

  • it is explicitly marked with the external modifier (applicable to classes, functions, properties, and property accessors);

  • it is a member of an external class;

  • it is a Java native method.

External declarations have no Kotlin implementation and are expected to be provided externally — via JNI for the JVM target or JavaScript interop for the JS target.

Other kinds of declarations (parameters, destructuring declarations, local variables, etc.) are never considered external.

Example

external class C {
    fun foo()

    class Nested {
        fun bar()
    }
}

external val baz: Int

In this example (which is legal on the JS target), C, Nested, foo, bar, and baz are all external.

isInfix

abstract val isInfix: Boolean

Whether the function is an infix function.

isInline

abstract val isInline: Boolean

Whether the function is an inline function.

isLocal

Indicates whether a symbol is defined locally within a body.

See also

isOperator

abstract val isOperator: Boolean

Whether the function is an operator function.

isOverride

abstract val isOverride: Boolean

Whether the function is an override method.

isPublicApi

Whether the symbol is effectively public, including internal declarations with the PublishedApi annotation.

isStatic

abstract val isStatic: Boolean

Whether the function is static.

While Kotlin functions cannot be declared as static, the function symbol may represent, e.g., a static Java method.

Note: true doesn't guarantee the function is a Java one as Kotlin functions internally might be treated as static, but their behavior is not specified. Consider using isCompanion.

See also

isSuspend

abstract val isSuspend: Boolean

Whether the function is a suspend function.

isTailRec

abstract val isTailRec: Boolean

Whether the function is a tail-recursive function.

isTopLevel

Indicates whether a KaSymbol is at the top level.

A symbol is considered top-level if it is not a part of other symbols.

See also

javaMethodName

The visible Java method name for the given KaFunctionSymbol. The behavior is unspecified for modules other than the JVM.

klibSourceFileName

The source file name for the given KtDeclaration located in a Kotlin library (klib), or null if the declaration is not located in a klib, or when the source file name is not available.

location

abstract val location: KaSymbolLocation

The kind of location where a symbol is declared in code, e.g. KaSymbolLocation.TOP_LEVEL for top-level declarations.

The location is not to be confused with the origin, which is concerned with the kind of data source or generation the symbol originates from.

modality

abstract val modality: KaSymbolModality

The declaration's effective KaSymbolModality (e.g. open). Effective modality is the symbol's modality after all language rules and compiler plugins have been taken into account, in contrast to the syntactic modality.

name

abstract val name: Name

The simple name of this KaSymbol.

name

val KaSymbol.name: Name?

The name of the KaSymbol if it has one.

origin

abstract val origin: KaSymbolOrigin

The kind of data source or generation the symbol originates from (e.g. source files, libraries, compiler plugins).

The origin is not to be confused with the location, which is concerned with the symbol's location in code.

psi

abstract val psi: PsiElement?

The API is obsolete and will be deprecated soon. Use <strong>realPsi</strong> or <strong>anchorPsi</strong> instead.

A PsiElement corresponding to this KaSymbol.

The property is only defined for the following origins:

For other (usually synthetic) origins, the psi might be null or non-null. The Analysis API makes no consistent guarantees about the PSI of such origins.

See also

realPsi

abstract val realPsi: PsiElement?

A PsiElement explicitly present in the code (source or library). This PsiElement is sufficient to restore the symbol via the symbol API without any additional information.

It can have a value only for the following origins:

For all other origins, the value is null.

Examples:

class MyClass

For this code, KaNamedClassSymbol represents the class, while KaConstructorSymbol represents the implicit constructor. The class is present in the code as a KtClassOrObject, and this is sufficient to obtain the same symbol. In contrast, the constructor is not present in the code and can only be obtained via the class, so realPsi is null for it.

See also

receiverParameter

The receiver parameter of the callable, or null if the callable has no receiver.

The receiver parameter is present both for regular extensions and for companion extensions.

Example

fun String.foo() {} // the receiver parameter is 'String'
companion fun String.bar() {} // the receiver parameter is also 'String'

Note: a companion extension is called on the class itself (String.bar()) and not on an instance of it, so its receiver parameter never gets an actual value.

receiverType

The receiver parameter's type, or null if the callable has no receiver.

See also

returnType

abstract val returnType: KaType

The callable's return type. For variables, returnType is the type of the variable.

Note: For a vararg foo: T parameter, the resulting type is the vararg element T type (unlike KtDeclaration.returnType from KaExpressionTypeProvider, which is the full Array<out T> type).

The reasoning behind this is that KaCallableSymbol.returnType sees the parameter from the declaration's semantic perspective, representing the signature of the parameter, which contains just the element type. In this paradigm, vararg arrays are constructed separately under the hood.

At the same time KtDeclaration.returnType from KaExpressionTypeProvider represents a use-site perspective, which has to desugar vararg parameters because they are consumed as array types.

returnValueStatus

The return value status of the function (should it be used, or can it be ignored). See the KEEP for details.

token

abstract val token: KaLifetimeToken

The KaLifetimeToken which determines the lifetime of the lifetime owner.

typeParameters

The declaration's type parameters.

See Generics

typeParameters

The declaration's type parameters provided it can have them. Otherwise, an empty list.

See Generics

valueParameters

The function's value parameters. Value parameters are the "ordinary" parameters found in the function's parameter list. They should be differentiated from the receiverParameter and contextReceivers, which are other kinds of parameters.

visibility

The declaration's own KaSymbolVisibility (e.g. public).

This is the visibility declared directly on the symbol itself, after applying all language rules and compiler plugins, but not taking into account the visibility of any containing declarations.

For example, a public function declared inside an internal class will still have KaSymbolVisibility.PUBLIC as its own visibility, even though it is not accessible from outside the module due to its containing class being internal.

Example

internal class InternalClass {
    fun implicitlyPublicFun() {}
    public fun explicitlyPublicFun() {}
}

In this example, both implicitlyPublicFun and explicitlyPublicFun have KaSymbolVisibility.PUBLIC as their own visibility (the default visibility in Kotlin), even though they are effectively only accessible within the same module because their containing class is internal.

To check whether a declaration is actually visible from a specific use-site (taking into account the visibility of all containing declarations), see KaUseSiteVisibilityChecker.isVisible.

Functions

asPsiMethods

context(session: KaSession)
fun KaFunctionSymbol.asPsiMethods(): List<PsiMethod>

Converts the given KaFunctionSymbol to Java PsiMethods in the context of the useSiteModule.

assertIsValidAndAccessible

createPointer

Creates a KaSymbolPointer which can be used to retrieve the symbol in a different analyze block (i.e. a different KaSession).

findKDoc

Resolves KDoc for this KaDeclarationSymbol.

getExpectsForActual

Returns an expect symbol for the given actual symbol, if it is available. The function may return multiple expect symbols in case of ambiguity errors.

hasConflictingSignatureWith

context(session: KaSession)
fun KaFunctionSymbol.hasConflictingSignatureWith(other: KaFunctionSymbol, targetPlatform: TargetPlatform): Boolean

Returns whether this declaration has a conflicting signature with other based on platform-specific checks from targetPlatform.

Note that it doesn't consider function names or their visibility, only their signatures. In other words, it calculates whether two functions would conflict with each other when named equally and positioned in the same scope.

Example for JVM platform:

fun foo(vararg x: Int) {}

fun bar(x: IntArray) {}

Two functions foo and bar have the same JVM signature (as vararg parameter is transformed into a regular IntArray parameter). However, these two functions can coexist on non-JVM platforms.

``kotlin fun foo() {}

fun main() { fun bar() {} }

These two functions `foo` and `bar` have signatures, which are conflicting on every platform.

implementationState

Returns the KaCallableImplementationState of the given KaCallableSymbol in the context of implementerClassSymbol.

Returns null if:

The implementation state describes whether a callable is already implemented, has an inherited implementation, can be overridden, or must be explicitly overridden in the given class.

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.

isVisibleInClass

context(session: KaSession)
fun KaCallableSymbol.isVisibleInClass(classSymbol: KaClassSymbol): Boolean

Checks whether the given KaCallableSymbol (possibly inherited from a superclass) is visible in the given classSymbol.

psi

inline fun <reified PSI : PsiElement> KaSymbol.psi(): PSI

The API is obsolete and will be deprecated soon. Use <strong>realPsi</strong> or <strong>anchorPsi</strong> instead.

Returns the symbol's PsiElement if its type is PSI, and otherwise throws a ClassCastException.

See also

psiSafe

inline fun <reified PSI : PsiElement> KaSymbol.psiSafe(): PSI?

The API is obsolete and will be deprecated soon. Use <strong>realPsi</strong> or <strong>anchorPsi</strong> instead.

Returns the symbol's PsiElement if its type is PSI, or null otherwise.

See also

render

context(session: KaSession)
fun KaDeclarationSymbol.render(): String

Renders the given KaDeclarationSymbol to a string using the default rendering strategy (KaDeclarationRendererForSource.WITH_QUALIFIED_NAMES).

Renders the given KaDeclarationSymbol to a string. The particular rendering strategy is defined by the renderer.

sourcePsi

inline fun <reified PSI : PsiElement> KaSymbol.sourcePsi(): PSI?

The API is obsolete and will be deprecated soon. Use <strong>realPsi</strong> or <strong>anchorPsi</strong> instead.

Returns the symbol's PsiElement. Returns null if its KaSymbol.origin is not KaSymbolOrigin.SOURCE. Throws a ClassCastException if its type is not PSI.

See also

sourcePsiSafe

inline fun <reified PSI : PsiElement> KaSymbol.sourcePsiSafe(): PSI?

The API is obsolete and will be deprecated soon. Use <strong>realPsi</strong> or <strong>anchorPsi</strong> instead.

Returns the symbol's PsiElement if its type is PSI and KaSymbol.origin is KaSymbolOrigin.SOURCE or KaSymbolOrigin.JAVA_SOURCE, and null otherwise.

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.