KtClassOrObject¶
@SubclassOptInRequired(markerClass = [KtImplementationDetail::class])
abstract class KtClassOrObject : KtTypeParameterListOwnerStub<KotlinClassOrObjectStub<out KtClassOrObject>> , KtDeclarationContainer, KtNamedDeclaration, KtPureClassOrObject, KtClassLikeDeclaration
Represents a class, interface, object, or enum entry declaration.
This is the common base for the concrete node types KtClass (classes and interfaces), KtObjectDeclaration (named and companion objects), and KtEnumEntry. It gives access to the shared structure of such declarations: the supertype list, the class body, the primary and secondary constructors, and the nested declarations.
Example:¶
class Foo : Bar() {
fun baz() {}
}
// ^__________________^
// The entire class-or-object declaration
Inheritors¶
Constructors¶
KtClassOrObject¶
constructor(node: ASTNode)
constructor(stub: KotlinClassOrObjectStub<out KtClassOrObject>, nodeType: IElementType)
Properties¶
allChildren¶
val PsiElement.allChildren: PsiChildRange
The range of all direct children of this element, or an empty range if it has none.
allConstructors¶
val KtClassOrObject.allConstructors: List<KtConstructor<*>>
All constructors of this class or object: the primary constructor (if present) followed by the secondary constructors, in source order.
allModifierLists¶
@get:NotNull
open override val allModifierLists: List<KtDeclarationModifierList?>
annotationEntries¶
@get:NotNull
open override val annotationEntries: List<KtAnnotationEntry?>
annotations¶
@get:NotNull
open override val annotations: List<KtAnnotation?>
body¶
open override val body: KtClassBody?
children¶
companionBlocks¶
The list of all companion blocks.
companionObjects¶
@get:NotNull
@get:ReadOnly
abstract val companionObjects: List<KtObjectDeclaration?>
containingClassId¶
val KtDeclaration.containingClassId: ClassId?
The containing ClassId for this declaration. REPL KtScripts are supported.
containingClassOrObject¶
The class or object that declares this declaration as a member (including constructors and nested classes), or null if it is not a class member — for example, a member function's parameter or local, or a property accessor.
containingClassOrScript¶
The containing class or script for a declaration.
containingFile¶
@get:NotNull
open override val containingFile: @NotNull PsiFile
containingKtFile¶
@get:NotNull
open override val containingKtFile: KtFile
containingScript¶
The containing script for top-level declarations.
context¶
open override val context: PsiElement?
contextReceiverList¶
open override val contextReceiverList: KtContextReceiverList?
contextReceiverLists¶
open override val contextReceiverLists: List<KtContextReceiverList?>
contextReceivers¶
open override val contextReceivers: List<KtContextReceiver>
declarations¶
open override val declarations: List<KtDeclaration>
docComment¶
@get:Nullable
open override val docComment: KDoc?
elementType¶
open override val elementType: @NotNull IStubElementType<*, *>
endOffset¶
The offset just past the end of this element's text range in the file.
firstChild¶
open override val firstChild: PsiElement?
fqName¶
@get:Nullable
open override val fqName: FqName?
greenStub¶
@get:Nullable
override val greenStub: @Nullable KotlinClassOrObjectStub<out KtClassOrObject>?
identifyingElement¶
@get:Nullable
open val identifyingElement: @Nullable PsiElement?
iElementType¶
open override val iElementType: IElementType?
isFromCompanionBlock¶
Whether this declaration is declared inside a companion object block.
isLocal¶
Returns true if this class or object is declared in a local scope (inside a function body or another block) rather than as a top-level or member declaration.
isPhysical¶
open override val isPhysical: Boolean
isPrivateNestedClassOrObject¶
true if this is a private nested (non-top-level) class or object.
isPublic¶
true if this declaration is effectively public (no visibility modifier or an explicit public), and not local.
isUserDataEmpty¶
open val isUserDataEmpty: Boolean
isValid¶
isWritable¶
open override val isWritable: Boolean
language¶
@get:NotNull
open override val language: Language
lastChild¶
open override val lastChild: PsiElement?
manager¶
open override val manager: PsiManagerEx?
modificationStamp¶
open override val modificationStamp: Long
modifierList¶
@get:Nullable
open override val modifierList: KtModifierList?
name¶
nameAsName¶
open override val nameAsName: Name?
nameAsSafeName¶
@get:NotNull
open override val nameAsSafeName: Name
nameIdentifier¶
open override val nameIdentifier: PsiElement?
navigationElement¶
@get:NotNull
open override val navigationElement: PsiElement
nextLeafs¶
The following leaf elements as a lazy sequence, nearest first.
nextSibling¶
open override val nextSibling: PsiElement?
node¶
@get:NotNull
open override var node: @NotNull ASTNode
originalElement¶
open override val originalElement: PsiElement?
ownDeclarations¶
@get:NotNull
open val ownDeclarations: @NotNull Collection<out @NotNull PsiSymbolDeclaration>
ownReferences¶
@get:NotNull
open val ownReferences: @NotNull Collection<out @NotNull PsiSymbolReference>
parent¶
open override val parent: PsiElement?
parents¶
The ancestors of this element, from its immediate parent up to and including the containing file.
parentsWithSelf¶
val PsiElement.parentsWithSelf: Sequence<PsiElement>
This element and its ancestors, from the element itself up to and including the containing file.
presentation¶
open override val presentation: ItemPresentation?
prevLeafs¶
The preceding leaf elements as a lazy sequence, nearest first.
prevSibling¶
open override val prevSibling: PsiElement?
primaryConstructor¶
open override val primaryConstructor: KtPrimaryConstructor?
primaryConstructorModifierList¶
open override val primaryConstructorModifierList: KtModifierList?
primaryConstructorParameters¶
open override val primaryConstructorParameters: List<KtParameter>
project¶
@get:NotNull
open override val project: @NotNull Project
psiOrParent¶
@get:NotNull
open override val psiOrParent: KtElement
pureEndOffset¶
The end offset of this element's source.
pureStartOffset¶
The start offset of this element's source, excluding any leading comments.
reference¶
open override val reference: PsiReference?
references¶
@get:NotNull
open override val references: Array<out PsiReference?>
resolveScope¶
@get:NotNull
open override val resolveScope: @NotNull GlobalSearchScope
secondaryConstructors¶
open override val secondaryConstructors: List<KtSecondaryConstructor>
startOffset¶
val PsiElement.startOffset: Int
The offset of the start of this element's text range in the file.
startOffsetInParent¶
open override val startOffsetInParent: Int
startOffsetSkippingComments¶
val PsiElement.startOffsetSkippingComments: Int
The start offset of this element, skipping leading comments and the whitespace that follows them.
stub¶
@get:Nullable
open override val stub: @Nullable KotlinClassOrObjectStub<out KtClassOrObject>?
superTypeListEntries¶
open override val superTypeListEntries: List<KtSuperTypeListEntry>
text¶
textLength¶
open override val textLength: Int
textOffset¶
open override val textOffset: Int
textRange¶
open override val textRange: TextRange?
textRangeInParent¶
@get:Contract(pure = true)
@get:NotNull
open val textRangeInParent: @NotNull TextRange
textRangeWithoutComments¶
val PsiElement.textRangeWithoutComments: TextRange
The text range of this element excluding any leading comments.
typeConstraintList¶
@get:Nullable
open override val typeConstraintList: KtTypeConstraintList?
typeConstraints¶
@get:NotNull
open override val typeConstraints: List<KtTypeConstraint?>
typeParameterList¶
@get:Nullable
open override val typeParameterList: KtTypeParameterList?
typeParameters¶
@get:NotNull
open override val typeParameters: List<KtTypeParameter?>
userDataString¶
@get:TestOnly
open val userDataString: String?
userMap¶
@get:NotNull
open var userMap: @NotNull KeyFMap
useScope¶
@get:NotNull
open override val useScope: SearchScope
Functions¶
accept¶
fun accept(@NotNull visitor: PsiElementVisitor)
Dispatches this element to the corresponding visit* method of the given visitor and returns its result.
acceptChildren¶
open fun acceptChildren(@NotNull visitor: @NotNull PsiElementVisitor)
Passes each direct child of this element to the given visitor.
add¶
open fun add(@NotNull element: @NotNull PsiElement): PsiElement?
addAfter¶
open fun addAfter(@NotNull element: @NotNull PsiElement, anchor: PsiElement?): PsiElement?
addBefore¶
open fun addBefore(@NotNull element: @NotNull PsiElement, anchor: PsiElement?): PsiElement?
addInternal¶
open fun addInternal(
first: @NotNull ASTNode,
last: @NotNull ASTNode,
anchor: @Nullable ASTNode?,
before: @Nullable Boolean?
): ASTNode?
addRange¶
open fun addRange(first: PsiElement?, last: PsiElement?): PsiElement?
addRangeAfter¶
open fun addRangeAfter(
first: PsiElement?,
last: PsiElement?,
anchor: PsiElement?
): PsiElement?
addRangeBefore¶
open fun addRangeBefore(
@NotNull first: @NotNull PsiElement,
@NotNull last: @NotNull PsiElement,
anchor: PsiElement?
): PsiElement?
anyDescendantOfType¶
inline fun <reified T : PsiElement> PsiElement.anyDescendantOfType(noinline predicate: (T) -> Boolean = { true }): Boolean
Returns true if this element or any descendant of type T satisfies predicate. canGoInside controls traversal into children but does not prevent the current element from being tested.
asAssignment¶
Returns this expression as a KtBinaryExpression if it is an assignment, or null otherwise.
before¶
blockExpressionsOrSingle¶
Returns the statements of this element if it is a block, otherwise a single-element sequence of this element.
canNavigate¶
open fun canNavigate(): Boolean
canNavigateToSource¶
open fun canNavigateToSource(): Boolean
checkAdd¶
open fun checkAdd(@NotNull element: @NotNull PsiElement)
checkDecompiledText¶
fun PsiElement.checkDecompiledText()
Throws if this element belongs to a compiled file that is backed by a stub. Loading decompiled text is slow and should be avoided; stubs should be used instead. Called by the descendant-traversal helpers as a guard.
checkDelete¶
open fun checkDelete()
collectDescendantsOfType¶
Collects this element and all descendants of type T satisfying predicate into a list in post-order. canGoInside controls traversal into children but does not prevent the current element from being collected.
collectDescendantsOfTypeTo¶
inline fun <reified T : PsiElement, C : MutableCollection<T>> PsiElement.collectDescendantsOfTypeTo(
to: C,
crossinline canGoInside: (PsiElement) -> Boolean,
noinline predicate: (T) -> Boolean = { true }
): C
Adds this element and all descendants of type T satisfying predicate to to in post-order. canGoInside controls traversal into children but does not prevent the current element from being added.
containingClass¶
fun KtElement.containingClass(): KtClass?
Returns the nearest enclosing KtClass, or null if there is none.
copy¶
open fun copy(): PsiElement?
copyCopyableDataTo¶
open fun copyCopyableDataTo(clone: @NotNull UserDataHolderBase)
copyUserDataTo¶
open fun copyUserDataTo(other: @NotNull UserDataHolderBase)
delete¶
open override fun delete()
Deletes this class or object.
When KtPsiMutationService is registered, as in the IntelliJ Kotlin plugin, the deletion may also adjust the surrounding code, e.g., delete a semicolon that follows the declaration, or delete the whole file instead if the declaration is the only one in it. Without the service, it performs only the plain platform deletion.
deleteChildInternal¶
open fun deleteChildInternal(child: @NotNull ASTNode)
deleteChildRange¶
open fun deleteChildRange(first: PsiElement?, last: PsiElement?)
effectiveDeclarations¶
Returns the body declarations of this class or object in source order, followed by the class's primary-constructor val/var property parameters in parameter order.
findDescendantOfType¶
inline fun <reified T : PsiElement> PsiElement.findDescendantOfType(noinline predicate: (T) -> Boolean = { true }): T?
Returns the first element of type T in a pre-order traversal of this element and its descendants that satisfies predicate, or null. canGoInside controls traversal into children but does not prevent the current element from being tested.
findElementAt¶
open fun findElementAt(offset: Int): PsiElement?
findFunctionByName¶
fun KtClassOrObject.findFunctionByName(name: String): KtNamedDeclaration?
Returns the member function with the given name, or null if there is none.
findPropertyByName¶
fun KtClassOrObject.findPropertyByName(name: String): KtNamedDeclaration?
Returns the member property (or primary-constructor property parameter) with the given name, or null.
findReferenceAt¶
open fun findReferenceAt(offset: Int): PsiReference?
forEachDescendantOfType¶
inline fun <reified T : PsiElement> PsiElement.forEachDescendantOfType(noinline action: (T) -> Unit)
inline fun <reified T : PsiElement> PsiElement.forEachDescendantOfType(crossinline canGoInside: (PsiElement) -> Boolean, noinline action: (T) -> Unit)
Applies action to this element and every descendant of type T, in post-order. canGoInside controls whether each visited element's children are traversed; the element itself is still passed to action when it is a T, even if canGoInside returns false for it.
forEachDescendantOfTypeInPreorder¶
inline fun <reified T : PsiElement> PsiElement.forEachDescendantOfTypeInPreorder(noinline action: (T) -> Unit)
inline fun <reified T : PsiElement> PsiElement.forEachDescendantOfTypeInPreorder(crossinline canGoInside: (PsiElement) -> Boolean, noinline action: (T) -> Unit)
Applies action to this element and every descendant of type T, in pre-order. canGoInside controls whether each visited element's children are traversed; the element itself is still passed to action when it is a T, even if canGoInside returns false for it.
getAnnotationEntries¶
@NotNull
open fun getAnnotationEntries(): List<KtAnnotationEntry>
Retrieves the list of KtAnnotationEntry associated with this element.
The list may contain directly declared KtAnnotationEntry or unwrapped entries from KtAnnotation.
** Example: **
The list will contain Anno1, Anno2, and Anno3.
getAnnotationEntries¶
Returns the annotation entries applied to this expression through an enclosing annotated (or labeled) expression, or an empty list if there are none.
getAnnotations¶
@NotNull
open fun getAnnotations(): List<KtAnnotation>
Retrieves the list of KtAnnotation associated with this element.
Important: this list contains only KtAnnotation and not KtAnnotationEntry.
See also
getAnonymousInitializers¶
Returns the init blocks declared in this class or object body, in source order; empty if there are none.
getAssignmentByLHS¶
Returns the assignment in which this expression is the left-hand side, or null if it is not assigned to.
getAssignmentLhsIfUnwrappable¶
fun PsiElement.getAssignmentLhsIfUnwrappable(): PsiElement?
Returns the operand this operation applies to, but only when that operand is wrapped in parentheses, a label, or annotations; returns null otherwise.
getBinaryWithTypeParent¶
Returns the as/as? expression whose left-hand side is a call with this expression as its direct child, normally its callee. The call may be the selector of a qualified expression, and the call or qualified expression may be parenthesized. Returns null otherwise.
getBody¶
open override fun getBody(): KtClassBody?
Returns the body of this class or object (the part enclosed in braces), or null if it has no body.
getChildOfType¶
inline fun <reified T : PsiElement> PsiElement.getChildOfType(): T?
Returns the first direct child of type T, or null if there is none.
getChildren¶
open fun getChildren(): @NotNull Array<out PsiElement>
getChildrenOfType¶
inline fun <reified T : PsiElement> PsiElement.getChildrenOfType(): Array<T>
Returns the direct children of type T, or an empty array if there are none.
getClassId¶
open override fun getClassId(): ClassId?
Return ClassId, if the class is not local (e.g., if a class can be accessed by that ClassId from another context)
For classes that are themselves local (declared inside a function or other local scope), returns null. For nested classes in local classes returns null. For KtEnumEntry returns null as enum entry is not a class semantically. And so, for nested classes in enum entry, returns null. Otherwise, returns non-null ClassId.
For returned ClassId, the ClassId.isLocal is always false.
getColon¶
fun getColon(): PsiElement?
Returns the colon token separating the declaration from its supertype list, or null if there is no supertype list.
getContainingFile¶
@NotNull
open fun getContainingFile(): @NotNull PsiFile
getContainingKtFile¶
@NotNull
open fun getContainingKtFile(): KtFile
Returns the KtFile this element belongs to.
getContext¶
open fun getContext(): PsiElement?
getContextReceivers¶
open override fun getContextReceivers(): List<KtContextReceiver>
Returns the unnamed context receivers declared on this class or object, or an empty list if there are none. This is the legacy context-receiver API; named context parameters are exposed by KtContextParameterList.
getCopyableUserData¶
open fun <T> getCopyableUserData(@NotNull key: @NotNull Key<T?>): T?
getDeclarationKeyword¶
fun getDeclarationKeyword(): PsiElement?
Returns the keyword that introduces this declaration (class, interface, or object), or null if it is absent in incomplete code.
getDeclarations¶
open override fun getDeclarations(): List<KtDeclaration>
Returns the declarations directly contained in this element, in their source order. Returns an empty list if there are none.
getDocComment¶
@Nullable
open fun getDocComment(): KDoc
Returns the KDoc comment attached to this declaration, or null if it has none.
getElementTextWithContext¶
fun PsiElement.getElementTextWithContext(): String
Returns this element's text with surrounding source context, for use in diagnostics and log messages.
getExplicitReceiverOfDotQualified¶
fun PsiElement.getExplicitReceiverOfDotQualified(): PsiElement?
Returns the source of the explicit receiver if this element is a dot-qualified expression, or null otherwise.
getFirstChild¶
open fun getFirstChild(): PsiElement?
getFqName¶
@Nullable
open fun getFqName(): FqName
Returns the fully qualified name of this declaration, or null if it cannot be determined (for example, for local declarations or an anonymous declaration).
getGreenStub¶
@Nullable
fun getGreenStub(): @Nullable KotlinClassOrObjectStub<out KtClassOrObject>?
getIcon¶
getLabeledParent¶
fun KtExpression.getLabeledParent(labelName: String): KtLabeledExpression?
Returns the nearest enclosing labeled expression with the given labelName, or null if there is none.
getLanguage¶
@NotNull
open fun getLanguage(): Language
getLastChild¶
open fun getLastChild(): PsiElement?
getLastParentOfTypeInRow¶
inline fun <reified T : PsiElement> PsiElement.getLastParentOfTypeInRow(): T?
getLastParentOfTypeInRowWithSelf¶
inline fun <reified T : PsiElement> PsiElement.getLastParentOfTypeInRowWithSelf(): T?
Like getLastParentOfTypeInRow, but the chain may start at this element itself.
getManager¶
open fun getManager(): PsiManagerEx?
getModificationStamp¶
fun KtElement.getModificationStamp(): Long
Returns the modification stamp of the nearest enclosing element that tracks one (a file, a stub-based declaration, or a supertype list). The stamp changes whenever that element's subtree is modified, so it can be used to invalidate caches keyed on this element.
getModifierList¶
@Nullable
open fun getModifierList(): KtModifierList
Returns the modifier list of this element, or null if it carries neither modifiers nor annotations.
getName¶
getNameAsName¶
open fun getNameAsName(): Name
Returns the name of this element as a Name, or null if the element is anonymous or its name is missing (for example, in incomplete or erroneous code).
getNameAsSafeName¶
@NotNull
open fun getNameAsSafeName(): Name
Returns the name of this declaration, or a special "no name provided" Name when the declaration is anonymous or its name is missing. Unlike getNameAsName, this method never returns null.
getNameIdentifier¶
open fun getNameIdentifier(): PsiElement
getNavigationElement¶
@NotNull
open fun getNavigationElement(): PsiElement
getNextSibling¶
open fun getNextSibling(): PsiElement?
getNextSiblingIgnoringWhitespace¶
fun PsiElement.getNextSiblingIgnoringWhitespace(withItself: Boolean = false): PsiElement?
Returns the next sibling that is not whitespace, or null. Considers this element if withItself.
getNextSiblingIgnoringWhitespaceAndComments¶
fun PsiElement.getNextSiblingIgnoringWhitespaceAndComments(withItself: Boolean = false): PsiElement?
Returns the next sibling that is neither whitespace nor a comment, or null. Considers this element if withItself.
getNode¶
@NotNull
open fun getNode(): @NotNull ASTNode
getNonStrictParentOfType¶
inline fun <reified T : PsiElement> PsiElement.getNonStrictParentOfType(): T?
Returns the nearest ancestor of type T including this element, or null if there is none.
fun <T : PsiElement> PsiElement.getNonStrictParentOfType(parentClass: Class<T>): T?
Returns the nearest ancestor of type T (including this element), or null if there is none.
getOriginalElement¶
open fun getOriginalElement(): PsiElement
getOutermostParentContainedIn¶
tailrec fun PsiElement.getOutermostParentContainedIn(container: PsiElement): PsiElement?
Returns the outermost element on the path from this element that is still strictly contained in container, or null.
getOutermostParenthesizerOrThis¶
Returns the outermost expression that wraps this one only through parentheses, labels, or annotations, or this expression itself.
getParent¶
open fun getParent(): PsiElement?
getParentOfType¶
inline fun <reified T : PsiElement> PsiElement.getParentOfType(strict: Boolean): T?
inline fun <reified T : PsiElement> PsiElement.getParentOfType(strict: Boolean, vararg stopAt: Class<out PsiElement>): T?
getParentOfTypeAndBranch¶
inline fun <reified T : PsiElement> PsiElement.getParentOfTypeAndBranch(strict: Boolean = false, noinline branch: T.() -> PsiElement?): T?
getParentOfTypeAndBranches¶
getParentOfTypes¶
Returns the nearest ancestor that is an instance of one of parentClasses, or null if there is none. When strict is false, this element itself is also considered.
getParentOfTypes2¶
inline fun <reified T : PsiElement, reified V : PsiElement> PsiElement.getParentOfTypes2(): PsiElement?
getParentOfTypes3¶
inline fun <reified T : PsiElement, reified V : PsiElement, reified U : PsiElement> PsiElement.getParentOfTypes3(): PsiElement?
getParentOfTypesAndPredicate¶
Returns the nearest ancestor that is an instance of one of parentClasses and satisfies predicate, or null. When parentClasses is empty, any type matches. When strict is false, this element itself is also considered.
getPossiblyQualifiedCallExpression¶
Returns the call expression this expression represents: the selector's call for a qualified expression, or this expression if it is itself a call. Returns null if there is no call.
getPresentation¶
open override fun getPresentation(): ItemPresentation?
getPrevSibling¶
open fun getPrevSibling(): PsiElement?
getPrevSiblingIgnoringWhitespace¶
fun PsiElement.getPrevSiblingIgnoringWhitespace(withItself: Boolean = false): PsiElement?
Returns the previous sibling that is not whitespace, or null. Considers this element if withItself.
getPrevSiblingIgnoringWhitespaceAndComments¶
fun PsiElement.getPrevSiblingIgnoringWhitespaceAndComments(withItself: Boolean = false): PsiElement?
Returns the previous sibling that is neither whitespace nor a comment, or null. Considers this element if withItself.
getPrimaryConstructor¶
open override fun getPrimaryConstructor(): KtPrimaryConstructor?
Returns the primary constructor, or null if there is no explicitly written primary constructor.
getPrimaryConstructorModifierList¶
open override fun getPrimaryConstructorModifierList(): KtModifierList?
Returns the modifier list of the primary constructor (for example, its visibility modifiers), or null if there is no explicitly written primary constructor or it has no modifiers.
getPrimaryConstructorParameterList¶
Returns the value parameter list of the primary constructor, or null if there is no explicit primary constructor.
getPrimaryConstructorParameters¶
open override fun getPrimaryConstructorParameters(): List<KtParameter>
Returns the value parameters of the primary constructor, or an empty list if there are none.
getProject¶
@NotNull
open fun getProject(): @NotNull Project
getPsiOrParent¶
@NotNull
open fun getPsiOrParent(): KtElement
Returns this or parent source element (for synthetic element declarations). Use it only for the purposes of source attribution.
getQualifiedElementSelector¶
Returns the rightmost selector of this qualified element, or null if there is no such selector.
getQualifiedExpressionForReceiver¶
Returns the qualified expression in which this expression is the receiver, or null if it is not a receiver.
getQualifiedExpressionForReceiverOrThis¶
Returns the qualified expression in which this expression is the receiver, or this expression itself otherwise.
getQualifiedExpressionForSelector¶
Returns the qualified expression in which this element is the selector, or null if it is not a selector.
getQualifiedExpressionForSelectorOrThis¶
Returns the qualified expression in which this expression is the selector, or this expression itself otherwise.
getReference¶
open fun getReference(): PsiReference
getReferences¶
@NotNull
open fun getReferences(): Array<PsiReference>
getRequiredStubOrPsiChild¶
fun getRequiredStubOrPsiChild(elementType: @NotNull IElementType): @NotNull PsiElement
getResolveScope¶
@NotNull
open fun getResolveScope(): @NotNull GlobalSearchScope
getSecondaryConstructors¶
open override fun getSecondaryConstructors(): List<KtSecondaryConstructor>
Returns the secondary constructors declared in this class or object body, or an empty list if there are none.
getStartOffsetIn¶
fun PsiElement.getStartOffsetIn(ancestor: PsiElement): Int
Returns the offset of this element relative to the start of ancestor (which must be an ancestor of this element).
getStartOffsetInParent¶
open fun getStartOffsetInParent(): Int
getStrictParentOfType¶
inline fun <reified T : PsiElement> PsiElement.getStrictParentOfType(): T?
Returns the nearest strict ancestor of type T, or null if there is none.
getStub¶
@Nullable
open fun getStub(): @Nullable KotlinClassOrObjectStub<out KtClassOrObject>?
getStubOrPsiChild¶
open fun <Psi : PsiElement?> getStubOrPsiChild(elementType: @NotNull IStubElementType<out StubElement<*>?, Psi?>): @Nullable Psi?
fun getStubOrPsiChild(elementType: @NotNull IElementType): @Nullable PsiElement?
fun <Psi : PsiElement?> getStubOrPsiChild(elementType: @NotNull IElementType, psiClass: @NotNull Class<Psi?>): @Nullable Psi?
getStubOrPsiChildren¶
fun <Psi : PsiElement?> getStubOrPsiChildren(elementType: @NotNull IElementType, f: @NotNull ArrayFactory<out Psi?>): @NotNull Array<out Psi?>
open fun <Psi : PsiElement?> getStubOrPsiChildren(filter: @NotNull TokenSet, f: @NotNull ArrayFactory<out Psi?>): @NotNull Array<out Psi?>
getSuperNames¶
fun StubBasedPsiElementBase<out KotlinClassOrObjectStub<out KtClassOrObject>>.getSuperNames(): List<String>
Returns the unqualified names indexed as this class's superclass names. For names that might be imported through an alias, this includes both the original and aliased names; reference resolution during inheritor search disambiguates them.
getSuperTypeList¶
fun getSuperTypeList(): KtSuperTypeList?
Returns the supertype list (the types after the :), or null if this declaration has no explicit supertypes.
getSuperTypeListEntries¶
open override fun getSuperTypeListEntries(): List<KtSuperTypeListEntry>
Returns the supertype list entries (the types and delegations written after the :), or an empty list if there are none.
getText¶
getTextLength¶
open fun getTextLength(): Int
getTextOffset¶
open fun getTextOffset(): Int
getTextRange¶
open fun getTextRange(): TextRange?
getTextWithLocation¶
fun PsiElement.getTextWithLocation(): String
Returns this element's text together with its source location, for use in diagnostics and log messages.
getTopmostParentOfType¶
inline fun <reified T : PsiElement> PsiElement.getTopmostParentOfType(): T?
Returns the outermost ancestor of type T including this element, or null if there is none.
getUserData¶
open fun <T> getUserData(@NotNull key: @NotNull Key<T?>): T?
getUseScope¶
@NotNull
open fun getUseScope(): SearchScope
getValueParameterList¶
Returns the value parameter list of this declaration (the primary constructor's for a class), or null.
getValueParameters¶
Returns the value parameters of this declaration (constructor value parameters for a class), or an empty list.
hasActualModifier¶
Returns true if this declaration has the actual modifier.
hasBody¶
fun KtDeclaration.hasBody(): Boolean
Returns true if this declaration is a function or property that defines a body.
hasExpectModifier¶
Returns true if this declaration has the expect modifier.
hasExplicitPrimaryConstructor¶
open override fun hasExplicitPrimaryConstructor(): Boolean
Returns true if this class or object has an explicitly written primary constructor.
hasExternalModifier¶
Returns true if this declaration has the external modifier.
hasInnerModifier¶
Returns true if this declaration has the inner modifier.
hasModifier¶
open fun hasModifier(@NotNull modifier: KtModifierKeywordToken): Boolean
hasPrimaryConstructor¶
open override fun hasPrimaryConstructor(): Boolean
Returns true if this class or object has an explicit primary constructor or has no secondary constructors. Consequently, this can be true for an object and when getPrimaryConstructor is null.
hasSecondaryConstructors¶
fun hasSecondaryConstructors(): Boolean
Returns true if this declaration has at least one secondary constructor.
isActualDeclaration¶
Returns true if this declaration is actual: either it has an explicit actual modifier, or it is a constructor of an actual annotation, value, or inline class.
isAncestor¶
fun PsiElement?.isAncestor(element: PsiElement, strict: Boolean = false): Boolean
isAnnotation¶
fun isAnnotation(): Boolean
Returns true if this declaration has the annotation modifier (that is, it declares an annotation class).
isContextualDeclaration¶
Returns true if this callable, class, or object declares at least one legacy context receiver. Named context parameters are ignored.
isContractDescriptionCallPsiCheck¶
Best-effort PSI check for whether this expression is a contract { ... } (or kotlin.contracts.contract { ... }) call.
isCopyableDataEqual¶
open fun isCopyableDataEqual(other: @NotNull UserDataHolderBase): Boolean
isData¶
isDotReceiver¶
fun KtExpression.isDotReceiver(): Boolean
Returns true if this expression is the receiver of an enclosing dot-qualified expression.
isDotSelector¶
fun KtExpression.isDotSelector(): Boolean
Returns true if this expression is the selector of an enclosing dot-qualified expression.
isEquivalentTo¶
open override fun isEquivalentTo(another: PsiElement?): Boolean
isExpectDeclaration¶
Returns true if this declaration is expect, either directly (via the modifier) or by being contained in an expect declaration.
isExtensionDeclaration¶
fun PsiElement.isExtensionDeclaration(): Boolean
Returns true if this element is an extension function or property (that is, it declares a receiver).
isFirstStatement¶
fun KtElement.isFirstStatement(): Boolean
Returns true if this element is the first statement of its enclosing block.
isFunctionalExpression¶
fun PsiElement.isFunctionalExpression(): Boolean
Returns true if this element is an anonymous function, such as the fun expression in val predicate = fun(x: Int): Boolean = x > 0.
isInImportDirective¶
Returns true if this expression appears inside an import directive.
isInsideOf¶
fun PsiElement.isInsideOf(elements: Iterable<PsiElement>): Boolean
Returns true if this element lies within, or is equal to, any of the given elements.
isLambdaOutsideParentheses¶
Returns true if this expression is a trailing lambda argument written outside the call parentheses.
isNull¶
fun KtExpression.isNull(): Boolean
Returns true if this expression is the null literal. Smart-casts the receiver to KtConstantExpression on true.
isObjectLiteral¶
Returns true if this is the body of an object literal (object : Foo { ... }).
isPhysical¶
open fun isPhysical(): Boolean
isPrivate¶
fun KtModifierListOwner.isPrivate(): Boolean
Returns true if this declaration has the private modifier.
isProtected¶
Returns true if this declaration has the protected modifier.
isTopLevel¶
fun isTopLevel(): Boolean
Returns true if this declaration is a top-level member of a file (not nested in another declaration or a local scope).
isTopLevelKtOrJavaMember¶
fun PsiElement.isTopLevelKtOrJavaMember(): Boolean
Returns true if this element is a top-level member of a Kotlin file or a top-level Java class.
isValid¶
isWritable¶
open fun isWritable(): Boolean
lastBlockStatementOrThis¶
Returns the last statement if this expression is a block, otherwise this expression itself.
modalityModifier¶
fun KtDeclaration.modalityModifier(): PsiElement?
Returns the modality modifier token (abstract/open/final/sealed), or null if none is present.
modalityModifierType¶
Returns the type of this declaration's modality modifier, or null if none is present.
navigate¶
navigationRequest¶
@RequiresReadLock
@RequiresBackgroundThread
@Nullable
open fun navigationRequest(): @Nullable NavigationRequest?
nextLeaf¶
Returns the next leaf element in the tree, or null if there is none. Empty leaves are skipped if skipEmptyElements.
Returns the nearest following leaf that satisfies filter, or null if there is none.
nonStaticOuterClasses¶
Returns the enclosing classes that this element can access an outer instance of, from innermost to outermost.
parameterIndex¶
fun PsiElement.parameterIndex(): Int
Returns the index of this parameter within its own parameter list (Kotlin or Java), or -1 if it is not a parameter.
prevLeaf¶
Returns the previous leaf element in the tree, or null if there is none. Empty leaves are skipped if skipEmptyElements.
Returns the nearest preceding leaf that satisfies filter, or null if there is none.
processDeclarations¶
open fun processDeclarations(
@NotNull processor: @NotNull PsiScopeProcessor,
@NotNull state: @NotNull ResolveState,
lastParent: PsiElement?,
@NotNull place: @NotNull PsiElement
): Boolean
putCopyableUserData¶
open fun <T> putCopyableUserData(@NotNull key: @NotNull Key<T?>, value: T?)
putUserData¶
open fun <T> putUserData(@NotNull key: @NotNull Key<T?>, @Nullable value: @Nullable T?)
putUserDataIfAbsent¶
rawDelete¶
open fun rawDelete()
Deletes this PSI element using the raw platform implementation, bypassing Kotlin PSI-specific delete overrides.
Regular clients should use delete instead. When KtPsiMutationService is not registered, it performs the same plain deletion, and when the service is registered, as in the IntelliJ Kotlin plugin, it may also adjust the surrounding code, e.g., delete a semicolon that follows the element.
referenceExpression¶
Returns the reference expression of this expression (the callee for a call), or null if it is not a reference.
replace¶
open fun replace(@NotNull newElement: @NotNull PsiElement): PsiElement?
replaceChildInternal¶
open fun replaceChildInternal(child: PsiElement?, newElement: TreeElement?)
safeFqNameForLazyResolve¶
fun KtNamedDeclaration.safeFqNameForLazyResolve(): FqName?
Returns this declaration's fully qualified name using the safe name for lazy resolution, or null if unavailable.
safeNameForLazyResolve¶
fun KtNamedDeclaration.safeNameForLazyResolve(): Name
Returns this declaration's name, substituting the "no name provided" special name for a missing or special name.
setName¶
setSubstrateRef¶
fun setSubstrateRef(substrateRef: @NotNull SubstrateRef)
siblings¶
Returns the siblings of this element as a lazy sequence, going forward (or backward) and optionally including the element itself (withItself).
startsWithComment¶
fun PsiElement.startsWithComment(): Boolean
Returns true if this element's first child is a comment.
subtreeChanged¶
open override fun subtreeChanged()
textContains¶
open fun textContains(c: Char): Boolean
textMatches¶
open fun textMatches(@NotNull text: @NotNull CharSequence): Boolean
open fun textMatches(@NotNull element: @NotNull PsiElement): Boolean
textToCharArray¶
open fun textToCharArray(): @NotNull CharArray
topParenthesizedParentOrMe¶
Returns the outermost enclosing expression that this expression is wrapped in only through parentheses, or this expression itself.
toString¶
unpackFunctionLiteral¶
fun KtExpression.unpackFunctionLiteral(allowParentheses: Boolean = false): KtLambdaExpression?
If this expression is a lambda expression, or wraps one in a label or an annotation, returns that KtLambdaExpression; otherwise returns null. Parentheses are unwrapped only when allowParentheses is true.
unwrapParenthesesLabelsAndAnnotations¶
fun PsiElement?.unwrapParenthesesLabelsAndAnnotations(): PsiElement?
Recursively unwraps this element while it is a parenthesized, labeled, or annotated expression, returning the innermost base element. A non-wrapper element is returned unchanged.
unwrapParenthesesLabelsAndAnnotationsDeeply¶
fun PsiElement.unwrapParenthesesLabelsAndAnnotationsDeeply(): PsiElement
Walks up through immediately enclosing parentheses, labels, and annotations, returning the first parent outside that wrapper chain.
visibilityModifier¶
fun KtModifierListOwner.visibilityModifier(): PsiElement?
Returns the visibility modifier token of this declaration, or null if none is present.
visibilityModifierType¶
Returns the type of this declaration's visibility modifier, or null if none is present.
visibilityModifierTypeOrDefault¶
Returns the type of this declaration's visibility modifier, or the default visibility (public) if none is present.