KaClassInitializerSymbol¶
@SubclassOptInRequired(markerClass = [KaImplementationDetail::class])
abstract class KaClassInitializerSymbol : KaDeclarationSymbol
KaClassInitializerSymbol represents an anonymous initializer declaration in a class body.
Constructors¶
KaClassInitializerSymbol¶
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.
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.
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.
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.
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.
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¶
override 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.
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
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¶
override 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¶
override 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¶
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
token¶
abstract val token: KaLifetimeToken
The KaLifetimeToken which determines the lifetime of the lifetime owner.
typeParameters¶
The declaration's type parameters provided it can have them. Otherwise, an empty list.
See Generics
visibility¶
override 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¶
assertIsValidAndAccessible¶
inline fun KaLifetimeOwner.assertIsValidAndAccessible()
createPointer¶
abstract override fun createPointer(): KaSymbolPointer<KaClassInitializerSymbol>
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.
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.