Skip to content

KaNamedClassSymbol

KaNamedClassSymbol represents a named class, object, or interface declaration. The symbol covers most class declarations except for anonymous objects, which are represented by KaAnonymousObjectSymbol.

Constructors

KaNamedClassSymbol

constructor()

Properties

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.

applicableAnnotationTargets

A set of applicable targets for an annotation class symbol, or null if the symbol is not an annotation class.

classId

abstract val classId: ClassId?

The fully-qualified ClassId of this class, or null if the class is local.

classKind

abstract val classKind: KaClassKind

The kind of the class (e.g. ordinary class, interface, enum class, etc.).

combinedDeclaredMemberScope

A KaScope containing all members explicitly declared in the given KaDeclarationContainerSymbol.

combinedMemberScope

A KaScope containing all members from memberScope and staticMemberScope.

companionObject

The nested companion object, or null if there is no companion object.

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.

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:

contextReceivers

List of KaContextReceiver directly declared in the source code

declaredMemberScope

A KaScope containing the non-static callables (functions, properties, and constructors) and inner classes explicitly declared in the given KaDeclarationContainerSymbol.

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.

defaultType

The representation of this in terms of KaType.

defaultTypeWithStarProjections

The representation of this in terms of KaType.

delegatedMemberScope

A KaScope containing synthetic callables (functions and properties) created by interface delegation.

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.

functionalInterfaceFunction

The single abstract function of a functional interface, or null if this class is not a functional interface.

A functional interface has exactly one abstract function. In Kotlin, it must be declared with the fun modifier. The function may be inherited from a parent interface.

Example

fun interface MyPredicate {
    fun test(value: Int): Boolean
}

For MyPredicate, functionalInterfaceFunction is the symbol for the test function.

See also

The single abstract function of the functional interface that this SAM constructor creates.

Example

fun interface MyPredicate {
    fun test(value: Int): Boolean
}

val p = MyPredicate { it > 0 }  // MyPredicate is a SAM constructor call

For the MyPredicate SAM constructor symbol, functionalInterfaceFunction is the symbol for the test function.

See also

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.

isActual

abstract val isActual: Boolean

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

See the official Kotlin documentation for more details.

isData

abstract val isData: Boolean

Whether the class is a data class.

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.

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.

isFun

abstract val isFun: Boolean

Indicates whether the class is a functional interface (i.e., supports SAM conversions).

A Kotlin or Java interface is considered a functional interface if it has exactly one abstract method. In Kotlin, a functional interface must also be marked with the fun modifier.

See also

isInline

abstract val isInline: Boolean

Whether the class uses Kotlin's single-field inline value class representation.

This is a declaration-level property. It does not predict whether a value is boxed at a particular use site, nor whether a backend can optimize a compatible full value class to an unboxed form. In particular, a full value class with exactly one primary property still returns false. Use isValue to recognize both inline and full value classes.

For valid declarations, this property is true for all of the following:

  • A single-property @JvmInline value class in a module whose target platform includes JVM, with the experimental FullValueClasses language feature either enabled or disabled. This covers JVM modules and common modules that target JVM among other platforms. On a JS, Wasm, or Native module, the annotation has no effect on this property.

  • An unannotated single-property value class on Common or a non-JVM target with FullValueClasses disabled.

  • The deprecated inline class form on every target, with FullValueClasses either enabled or disabled.

This property is false for full value classes and value objects. With FullValueClasses enabled, an unannotated value class uses the full representation on every target, even if it has exactly one primary property.

See also

isInner

abstract val isInner: Boolean

Whether the class is an inner class.

isLocal

Indicates whether a symbol is defined locally within a body.

See also

isPublicApi

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

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

isValue

abstract val isValue: Boolean

Whether the class is any Kotlin value declaration: an inline value class, a full value class, or a value object.

This property describes language-level value semantics independently of runtime representation. It does not imply that values are unboxed: boxing depends on the target and use site.

For valid declarations, this property is true for all of the following:

  • A single-property inline value class. This includes a @JvmInline value class on JVM and Common targets, an unannotated value class on Common or a non-JVM target with the experimental FullValueClasses language feature disabled, and the deprecated inline class form on every target.

  • An unannotated value class compiled with FullValueClasses enabled, regardless of its number of primary properties or target platform.

  • A value object compiled with FullValueClasses enabled.

This property is false for ordinary Kotlin classes and Java classes. To distinguish inline from full value declarations, use isInline.

See also

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.

memberScope

A KaScope containing non-static callable members (functions, properties, and constructors) and all classifier members (classes and objects) of the given KaDeclarationContainerSymbol. The scope includes members inherited from the symbol's supertypes, in addition to members which are declared explicitly inside the symbol's body.

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?

name

val KaSymbol.name: Name?

The name of the KaSymbol if it has one.

nameOrAnonymous

The name of the KaClassifierSymbol, or SpecialNames.ANONYMOUS if it's an anonymous object.

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

samConstructor

The associated KaSamConstructorSymbol if this KaClassLikeSymbol is a functional interface type (SAM).

Example

fun interface MyPredicate {
    fun test(value: Int): Boolean
}

val p = MyPredicate { it > 0 }  // MyPredicate is a SAM constructor call

For MyPredicate, samConstructor is the symbol for the synthetic SAM constructor that enables the MyPredicate { ... } lambda syntax.

sealedClassInheritors

The inheritors of the given sealed class.

The list is limited to class symbols which are analyzable in the use-site KaModule. While sealed class inheritors can usually only be defined in the same module, there are more complex rules around multiplatform projects. If the use-site module is a common source set and additional sealed inheritors are declared in a platform source set, sealedClassInheritors will not include those additional platform sealed inheritors.

Throws

IllegalArgumentException

if the given class is not a sealed class.

staticDeclaredMemberScope

A KaScope containing the static callables (functions and properties) and all classifiers (classes and objects) explicitly declared in the given KaDeclarationContainerSymbol.

staticMemberScope

A KaScope containing the static members of the given KaDeclarationContainerSymbol.

superTypes

abstract val superTypes: List<KaType>

A list of the direct supertypes. If the class has no explicit supertypes, the supertype will be Any, or a special supertype such as Enum for enum classes.

Type parameters are included in supertype type arguments in an unsubstituted form. For example, if we have class A<T> : B<T>, superTypes for A contains B<T> as a type, with an unsubstituted KaTypeParameterType T.

For a list of all supertypes, consider using KaType.allSupertypes on KaNamedClassSymbol.defaultType. To check whether this symbol is a subtype of another symbol, consider using KaClassSymbol.isSubClassOf, or KaType.isSubtypeOf.

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

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

asPsiClass

context(session: KaSession)
fun KaClassSymbol.asPsiClass(): PsiClass?

Converts the given KaClassSymbol to Java PsiClass in the context of the useSiteModule.

asPsiField

context(session: KaSession)
fun KaClassSymbol.asPsiField(): PsiField?

Converts the given KaClassSymbol to Java PsiField 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.

isDirectSubClassOf

context(session: KaSession)
fun KaClassSymbol.isDirectSubClassOf(superClass: KaClassSymbol): Boolean

Checks if this class has superClass listed as its direct superclass.

The class is not considered to be a direct subclass of itself, so myClass.isDirectSubClassOf(myClass) is always false.

isSubClassOf

context(session: KaSession)
fun KaClassSymbol.isSubClassOf(superClass: KaClassSymbol): Boolean

Checks if this class has superClass as its superclass somewhere in the inheritance hierarchy.

The class is not considered to be a subclass of itself, so myClass.isSubClassOf(myClass) is always false.

isValid

Whether the lifetime owner is still valid, i.e. we are still in the scope of the lifetime owner's regular lifetime.

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.