Kotlin Analysis API Documentation Help

KaSymbol

A base interface of the symbol hierarchy.

Members

val location: KaSymbolLocation

A symbol location kind (e.g., top-level or class member).

val origin: KaSymbolOrigin

A place the symbol comes from (e.g., a source, a library, or a compiler plugin).

val psi: PsiElement?

A PSI element corresponding to the declaration. Might be null for certain, usually synthetic, origins.

fun createPointer(): KaSymbolPointer<KaSymbol>

Create a declaration pointer which can be used to retrieve the symbol back in another KaSession.

Relation utilities

val KaSymbol.containingSymbol: KaSymbol?

A containing symbol:

  • For top-level declarations, a KaFileSymbol, or a KaScriptSymbol if the file is a script file;

  • For scripts, a KaFileSymbol;

  • For class members, a containing class;

  • For local declarations, a declaration it was declared in.

val KaSymbol.containingDeclaration: KaDeclarationSymbol?

A containing declaration:

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

  • For class members, a containing class;

  • For local declarations, a declaration it was declared in.

val KaSymbol.containingFile: KaFileSymbol?

The containing file symbol, or null if the given file symbol is already a KaFileSymbol.

val KaSymbol.containingModule: KaModule

The containing module.

Other utilities

val KaSymbol.deprecationStatus: DeprecationInfo?

Deprecation status for the given symbol, or null if the declaration is not deprecated.

Experimental API.

fun KaSymbol.deprecationStatus(annotationUseSiteTarget: AnnotationUseSiteTarget?): DeprecationInfo?

Deprecation status for the given symbol related to the specified annotation use-site target, or null if the declaration is not deprecated.

Experimental API.

KaSymbolLocation

The location property indicates the relation between the declaration represented by a symbol and its container (a file, a class, etc.).

Member

Description

TOP_LEVEL

A declaration placed directly in a file, or in a script.

CLASS

A member of some class, object, or interface.

PROPERTY

A part of some property declaration (e.g., an accessor or a backing field).

LOCAL

A declaration inside some callable declaration body.

KaSymbolOrigin

The origin property indicates the origin of the symbol. Below you can find a comprehensive list of possible KaSymbolOrigin values and their descriptions.

Member

Description

SOURCE

A declaration directly written in Kotlin source code.

Examples: Classes, functions, properties, and other declarations defined in Kotlin source files.

SOURCE_MEMBER_GENERATED

A declaration automatically generated by the Kotlin compiler as a member of another declaration.

Examples:

  • Default constructors of classes.

  • copy(), componentN(), and other synthetic functions for data classes.

  • values() and valueOf() functions for enum classes.

  • Implicit it parameter for lambda expressions with a single parameter.

LIBRARY

A declaration from a compiled Kotlin library (.jar or .klib file).

Examples: Classes, functions, properties, and other declarations defined in Kotlin source files.

JAVA_SOURCE

A declaration from Java source code.

Examples: Classes, methods, and fields defined in Java source files.

JAVA_LIBRARY

A declaration from a compiled Java library.

Examples: Classes, methods, and fields from Java libraries, or from the JDK.

SAM_CONSTRUCTOR

A synthetic function generated by the SAM (Single Abstract Method) conversion. This occurs when a lambda expression is passed as an argument where a functional interface is expected.

Example:

val runnable = Runnable { println("Hello") }

In this case, the lambda expression is converted to a synthetic function that implements the Runnable interface.

INTERSECTION_OVERRIDE

A synthetic declaration automatically created by the Kotlin compiler for callable intersections.

Example:

interface A { fun x() } interface B { fun x() } interface C : A, B

In C, there appears the function C.foo, an intersection of A.foo and B.foo, with the INTERSECTION_OVERRIDE origin.

SUBSTITUTION_OVERRIDE

A synthetic declaration automatically created by the Kotlin compiler for callable type substitutions.

Example:

interface A<T> { fun x(): T } interface B : A<Int>

Interface B will have a member B.foo(): Int with a substituted return type with the SUBSTITUTION_OVERRIDE origin.

DELEGATED

A member generated by the compiler for interface delegation. This occurs when a class delegates the implementation of an interface to another object.

Example:

interface MyInterface { fun perform() } class MyClass(private val delegate: MyInterface) : MyInterface by delegate

The compiler generates a member function perform() in MyClass that calls the perform() function from delegate.

JAVA_SYNTHETIC_PROPERTY

A synthetic property generated by the compiler for a Java field with a getter or setter. This allows Java fields to be accessed like Kotlin properties.

Example:

public class JavaClass { private int field; public int getField() { return field; } public void setField(int field) { this.field = field; } }

The compiler generates a synthetic property field with a getter and setter based on the Java methods getField() and setField().

PROPERTY_BACKING_FIELD

A backing field of a property declaration (a field that stores the value of the property).

Example:

class MyClass { var property: Int = 0 get() = field set(value) { field = value } }

The field identifier in the getter and setter refers to the backing field of the property.

PLUGIN

A declaration generated by a compiler plugin.

JS_DYNAMIC

A declaration from a dynamic Kotlin/JS scope.

NATIVE_FORWARD_DECLARATION

A Kotlin/Native forward declaration. See the forward declarations section in the Kotlin documentation.

Last modified: 01 August 2024