KaNamedClassSymbol¶
@SubclassOptInRequired(markerClass = [KaImplementationDetail::class])
abstract class KaNamedClassSymbol : KaClassSymbol, KaNamedSymbol, KaContextReceiversOwner
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:
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¶
abstract val annotations: KaAnnotationList
A list of annotations applied to the annotated entity.
applicableAnnotationTargets¶
context(session: KaSession)
val KaClassSymbol.applicableAnnotationTargets: Set<KaAnnotationTarget>?
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¶
context(session: KaSession)
val KaDeclarationContainerSymbol.combinedDeclaredMemberScope: KaScope
A KaScope containing all members explicitly declared in the given KaDeclarationContainerSymbol.
combinedMemberScope¶
context(session: KaSession)
val KaDeclarationContainerSymbol.combinedMemberScope: KaScope
A KaScope containing all members from memberScope and staticMemberScope.
companionObject¶
abstract val companionObject: KaNamedClassSymbol?
The nested companion object, or null if there is no companion object.
containingDeclaration¶
context(session: KaSession)
val KaSymbol.containingDeclaration: KaDeclarationSymbol?
The KaDeclarationSymbol which contains this symbol, or null if there is no containing declaration:
-
For top-level declarations, a containing
KaScriptSymbol, ornullfor 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¶
context(session: KaSession)
val KaDeclarationSymbol.containingFileAnnotations: KaAnnotationList?
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:
-
For top-level declarations, a
KaFileSymbol, or aKaScriptSymbolif the file is a script file. -
For
KaScriptSymbols, aKaFileSymbol. -
For class members, the containing class symbol.
-
For local declarations, the symbol of the containing declaration.
contextReceivers¶
abstract val contextReceivers: List<KaContextReceiver>
List of KaContextReceiver directly declared in the source code
declaredMemberScope¶
context(session: KaSession)
val KaDeclarationContainerSymbol.declaredMemberScope: KaScope
A KaScope containing the non-static callables (functions, properties, and constructors) and inner classes explicitly declared in the given KaDeclarationContainerSymbol.
defaultAnnotationTargets¶
context(session: KaSession)
val KaSymbol.defaultAnnotationTargets: Set<KaAnnotationTarget>?
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¶
context(session: KaSession)
val KaClassifierSymbol.defaultType: KaType
defaultTypeWithStarProjections¶
context(session: KaSession)
val KaClassifierSymbol.defaultTypeWithStarProjections: KaType
delegatedMemberScope¶
context(session: KaSession)
val KaDeclarationContainerSymbol.delegatedMemberScope: KaScope
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¶
context(session: KaSession)
val KaClassLikeSymbol.functionalInterfaceFunction: KaNamedFunctionSymbol?
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
For MyPredicate, functionalInterfaceFunction is the symbol for the test function.
See also
context(session: KaSession)
val KaSamConstructorSymbol.functionalInterfaceFunction: KaNamedFunctionSymbol
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¶
Whether the declaration is an actual declaration in a multiplatform project.
See the official Kotlin documentation for more details.
isData¶
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¶
Whether the declaration is an expect declaration in a multiplatform project.
See the official Kotlin documentation for more details.
Example
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
externalmodifier (applicable to classes, functions, properties, and property accessors); -
it is a member of an
externalclass; -
it is a Java
nativemethod.
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
In this example (which is legal on the JS target), C, Nested, foo, bar, and baz are all external.
isFun¶
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¶
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 classin a module whose target platform includes JVM, with the experimentalFullValueClasseslanguage 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 classon Common or a non-JVM target withFullValueClassesdisabled. -
The deprecated
inline classform on every target, withFullValueClasseseither 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¶
Whether the class is an inner class.
isLocal¶
isPublicApi¶
context(session: KaSession)
val KaDeclarationSymbol.isPublicApi: Boolean
Whether the symbol is effectively public, including internal declarations with the PublishedApi annotation.
isTopLevel¶
val KaSymbol.isTopLevel: Boolean
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¶
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 classon JVM and Common targets, an unannotatedvalue classon Common or a non-JVM target with the experimentalFullValueClasseslanguage feature disabled, and the deprecatedinline classform on every target. -
An unannotated
value classcompiled withFullValueClassesenabled, regardless of its number of primary properties or target platform. -
A
value objectcompiled withFullValueClassesenabled.
This property is false for ordinary Kotlin classes and Java classes. To distinguish inline from full value declarations, use isInline.
See also
klibSourceFileName¶
context(session: KaSession)
val KaDeclarationSymbol.klibSourceFileName: String?
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¶
context(session: KaSession)
val KaDeclarationContainerSymbol.memberScope: KaScope
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¶
nameOrAnonymous¶
val KaClassifierSymbol.nameOrAnonymous: Name
The name of the KaClassifierSymbol, or SpecialNames.ANONYMOUS if it's an anonymous object.
origin¶
abstract val origin: KaSymbolOrigin
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:
-
KaSymbolOrigin.LIBRARY(thepsisource element is taken from the generated Kotlin class file)
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:
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¶
context(session: KaSession)
val KaClassLikeSymbol.samConstructor: KaSamConstructorSymbol?
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¶
context(session: KaSession)
val KaNamedClassSymbol.sealedClassInheritors: List<KaNamedClassSymbol>
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¶
context(session: KaSession)
val KaDeclarationContainerSymbol.staticDeclaredMemberScope: KaScope
A KaScope containing the static callables (functions and properties) and all classifiers (classes and objects) explicitly declared in the given KaDeclarationContainerSymbol.
staticMemberScope¶
context(session: KaSession)
val KaDeclarationContainerSymbol.staticMemberScope: KaScope
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¶
abstract val typeParameters: List<KaTypeParameterSymbol>
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¶
abstract val visibility: KaSymbolVisibility
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
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¶
inline fun KaLifetimeOwner.assertIsValidAndAccessible()
createPointer¶
abstract override fun createPointer(): KaSymbolPointer<KaNamedClassSymbol>
Creates a KaSymbolPointer which can be used to retrieve the symbol in a different analyze block (i.e. a different KaSession).
findKDoc¶
context(session: KaSession)
fun KaDeclarationSymbol.findKDoc(): KDocCommentDescriptor?
Resolves KDoc for this KaDeclarationSymbol.
getExpectsForActual¶
context(session: KaSession)
fun KaDeclarationSymbol.getExpectsForActual(): List<KaDeclarationSymbol>
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¶
fun KaLifetimeOwner.isValid(): Boolean
Whether the lifetime owner is still valid, i.e. we are still in the scope of the lifetime owner's regular lifetime.
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¶
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).
context(session: KaSession)
fun KaDeclarationSymbol.render(renderer: KaDeclarationRenderer): String
Renders the given KaDeclarationSymbol to a string. The particular rendering strategy is defined by the renderer.
sourcePsi¶
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.