Skip to content

KtBlockExpression

open class KtBlockExpression : LazyParseablePsiElement, KtElement, KtExpression, KtStatementExpression

Represents a block of statements enclosed in curly braces.

Example:

fun foo() {
    val x = 1
    println(x)
}
// The entire block from the opening curly brace to the closing curly brace

Constructors

KtBlockExpression

constructor(@Nullable text: CharSequence)

Companion properties

ARRAY_FACTORY

val ARRAY_FACTORY: ArrayFactory<PsiElement>
val ARRAY_FACTORY: ArrayFactory<KtExpression>

A factory for creating arrays of KtExpression, used by the PSI child-access machinery.

EMPTY_ARRAY

val EMPTY_ARRAY: Array<ASTNode>
val EMPTY_ARRAY: Array<LighterASTNode>
val EMPTY_ARRAY: Array<PsiElement>
val EMPTY_ARRAY: Array<CompositeElement>
val EMPTY_ARRAY: Array<TreeElement>

A shared empty array, which can be reused to avoid unnecessary allocations.

EMPTY_NAVIGATABLE_ARRAY

val EMPTY_NAVIGATABLE_ARRAY: Array<Navigatable>

EMPTY_NAVIGATABLE_ELEMENT_ARRAY

val EMPTY_NAVIGATABLE_ELEMENT_ARRAY: Array<NavigatablePsiElement>

EMPTY_NAVIGATION_ITEM_ARRAY

val EMPTY_NAVIGATION_ITEM_ARRAY: Array<NavigationItem>

FLAGS_LOCKED

val FLAGS_LOCKED: Int = 2048

ICON_FLAG_FAST_ONLY

val ICON_FLAG_FAST_ONLY: Int = -2147483648

ICON_FLAG_READ_STATUS

ICON_FLAG_VISIBILITY

Companion functions

buildRowIcon

open fun buildRowIcon(baseIcon: Icon, visibilityIcon: Icon): @NotNull RowIcon

iconWithVisibilityIfNeeded

open fun iconWithVisibilityIfNeeded(
    flags: Int, 
    baseIcon: Icon, 
    visibility: Icon
): Icon

isNativeFileType

open fun isNativeFileType(fileType: FileType): Boolean

setParsingAllowed

open fun setParsingAllowed(allowed: Boolean)

transformFlags

open fun transformFlags(element: PsiElement, _flags: Int): Int

withForcedDeferredIcons

open fun withForcedDeferredIcons(runnable: @NotNull Runnable)

Properties

allChildren

val PsiElement.allChildren: PsiChildRange

The range of all direct children of this element, or an empty range if it has none.

containingScript

The containing script for the block expression.

endOffset

val PsiElement.endOffset: Int

The offset just past the end of this element's text range in the file.

nextLeafs

val PsiElement.nextLeafs: Sequence<PsiElement>

The following leaf elements as a lazy sequence, nearest first.

parents

val PsiElement.parents: Sequence<PsiElement>

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.

prevLeafs

val PsiElement.prevLeafs: Sequence<PsiElement>

The preceding leaf elements as a lazy sequence, nearest first.

pureEndOffset

The end offset of this element's source.

pureStartOffset

The start offset of this element's source, excluding any leading comments.

startOffset

val PsiElement.startOffset: Int

The offset of the start of this element's text range in the file.

startOffsetSkippingComments

The start offset of this element, skipping leading comments and the whitespace that follows them.

textRangeWithoutComments

val PsiElement.textRangeWithoutComments: TextRange

The text range of this element excluding any leading comments.

Functions

accept

open fun <R, D> accept(@NotNull visitor: KtVisitor<R, D>, data: D): R

Dispatches this element to the corresponding visit* method of the given visitor and returns its result.

This is the type-safe way to handle an element based on its concrete Kotlin PSI type, as an alternative to a chain of is/instanceof checks.

fun accept(@NotNull visitor: PsiElementVisitor)

acceptChildren

open fun acceptChildren(visitor: @NotNull PsiElementVisitor)
open fun <D> acceptChildren(@NotNull visitor: KtVisitor<Void, D>, data: D)

Passes each direct child of this element to the given visitor.

acceptTree

open fun acceptTree(visitor: @NotNull TreeElementVisitor)

add

open fun add(element: @NotNull PsiElement): PsiElement

addAfter

open fun addAfter(element: @NotNull PsiElement, anchor: PsiElement): PsiElement

addBefore

open fun addBefore(element: @NotNull PsiElement, anchor: PsiElement): PsiElement

addChild

open fun addChild(child: @NotNull ASTNode, anchorBefore: @Nullable ASTNode)

addChildren

open fun addChildren(
    firstChild: @NotNull ASTNode, 
    lastChild: @Nullable ASTNode, 
    anchorBefore: @Nullable ASTNode
)

addInternal

open fun addInternal(
    first: TreeElement, 
    last: ASTNode, 
    anchor: @Nullable ASTNode, 
    before: @Nullable Boolean
): TreeElement

addLeaf

open fun addLeaf(
    leafType: @NotNull IElementType, 
    leafText: @NotNull CharSequence, 
    anchorBefore: ASTNode
)

addRange

fun addRange(first: PsiElement, last: PsiElement): PsiElement

addRangeAfter

fun addRangeAfter(
    first: PsiElement, 
    last: PsiElement, 
    anchor: PsiElement
): PsiElement

addRangeBefore

fun addRangeBefore(
    first: @NotNull PsiElement, 
    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.

inline fun <reified T : PsiElement> PsiElement.anyDescendantOfType(crossinline canGoInside: (PsiElement) -> Boolean, 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.

applyDeleteOnReparse

fun applyDeleteOnReparse(oldChild: @NotNull ASTNode)

applyInsertOnReparse

fun applyInsertOnReparse(newChild: @NotNull ASTNode, anchor: ASTNode)

applyReplaceFileOnReparse

fun applyReplaceFileOnReparse(psiFile: @NotNull PsiFile, newNode: @NotNull FileASTNode)

applyReplaceOnReparse

fun applyReplaceOnReparse(newChild: @NotNull ASTNode)

asAssignment

Returns this expression as a KtBinaryExpression if it is an assignment, or null otherwise.

before

fun PsiElement.before(element: PsiElement): Boolean

Returns true if this element ends at or before element starts (that is, it precedes element in the file).

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

checkAdd

fun checkAdd(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()

children

fun ASTNode.children(): Sequence<ASTNode>

The direct child nodes of this AST node, as a lazy sequence.

clearCaches

open fun clearCaches()

clone

open fun clone(): @NotNull CompositeElement
open fun clone(): @NotNull LazyParseablePsiElement
open fun clone(): @NotNull Any

closestPsiElement

fun ASTNode.closestPsiElement(): PsiElement?

Returns the nearest PSI element for this node, walking up to a parent node if this node has no PSI of its own.

collectDescendantsOfType

inline fun <reified T : PsiElement> PsiElement.collectDescendantsOfType(noinline predicate: (T) -> Boolean = { true }): List<T>

Collects this element and all descendants of type T satisfying predicate into a list in post-order.

inline fun <reified T : PsiElement> PsiElement.collectDescendantsOfType(crossinline canGoInside: (PsiElement) -> Boolean, noinline predicate: (T) -> Boolean = { true }): List<T>

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

Returns the nearest enclosing KtClass, or null if there is none.

contentRange

Returns the range of direct PSI children between this block's braces after excluding outer whitespace. The range may contain comments and other non-statement elements. Returns an empty range if either brace is missing or no non-whitespace content remains.

copy

open fun copy(): PsiElement

copyCopyableDataTo

open fun copyCopyableDataTo(clone: @NotNull UserDataHolderBase)

copyElement

open fun copyElement(): ASTNode

copyTo

open fun copyTo(buffer: @Nullable Array<Char>, start: Int): Int

copyUserDataTo

open fun copyUserDataTo(other: @NotNull UserDataHolderBase)

countChildren

open fun countChildren(filter: @Nullable TokenSet): Int

delete

open fun delete()

Deletes this block.

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 block. 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)

equals

fun equals(obj: Any): Boolean

findChildByRole

open fun findChildByRole(role: Int): @Nullable ASTNode

findChildByRoleAsPsiElement

fun findChildByRoleAsPsiElement(role: Int): @Nullable PsiElement

findChildByType

open fun findChildByType(type: @NotNull IElementType): ASTNode

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 if there is none.

inline fun <reified T : PsiElement> PsiElement.findDescendantOfType(crossinline canGoInside: (PsiElement) -> Boolean, 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

findLeafElementAt

abstract fun findLeafElementAt(p: Int): @Nullable ASTNode
open fun findLeafElementAt(offset: Int): LeafElement

findPsiChildByType

open fun findPsiChildByType(type: @NotNull IElementType): @Nullable PsiElement

findReferenceAt

open fun findReferenceAt(offset: Int): PsiReference

forEachDescendantOfType

inline fun <reified T : PsiElement> PsiElement.forEachDescendantOfType(noinline action: (T) -> Unit)

Applies action to this element and every descendant of type T, in post-order (children before parents).

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)

Applies action to this element and every descendant of type T, in pre-order (parents before children).

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

Returns the annotation entries applied to this expression through an enclosing annotated (or labeled) expression, or an empty list 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.

getCachedLength

open fun getCachedLength(): Int

getChars

open fun getChars(): @NotNull CharSequence

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(filter: @Nullable TokenSet): @NotNull Array<ASTNode>
@NotNull
open fun getChildren(): Array<PsiElement>

getChildrenAsPsiElements

open fun <T : PsiElement?> getChildrenAsPsiElements(filter: @Nullable TokenSet, constructor: @NotNull ArrayFactory<out T>): @NotNull Array<T>

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.

getChildRole

open fun getChildRole(child: @NotNull ASTNode): Int

getContainingFile

open fun getContainingFile(): PsiFile

getContainingKtFile

@NotNull
open fun getContainingKtFile(): KtFile

Returns the KtFile this element belongs to.

getContainingKtFile

fun LazyParseablePsiElement.getContainingKtFile(): KtFile

Returns the KtFile containing this element.

getContext

open fun getContext(): PsiElement

getCopyableUserData

abstract fun <T> getCopyableUserData(p: @NotNull Key<T>): @Nullable T

getElementTextWithContext

fun PsiElement.getElementTextWithContext(): String

Returns this element's text with surrounding source context, for use in diagnostics and log messages.

getElementType

open fun getElementType(): @NotNull IElementType

getEndOffset

open fun getEndOffset(): Int

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

getFirstChildNode

abstract fun getFirstChildNode(): ASTNode
open fun getFirstChildNode(): TreeElement

getFirstStatement

@Nullable
open fun getFirstStatement(): KtExpression

Returns the first statement of this block, or null if the block is empty.

getIcon

open fun getIcon(flags: Int): @Nullable Icon

getLabeledParent

Returns the nearest enclosing labeled expression with the given labelName, or null if there is none.

getLanguage

@NotNull
open fun getLanguage(): Language

getLastBracketRange

@Nullable
open fun getLastBracketRange(): TextRange

Returns the text range of the closing brace, or null if it is absent (for example, in incomplete code).

getLastChild

open fun getLastChild(): PsiElement

getLastChildNode

abstract fun getLastChildNode(): ASTNode
open fun getLastChildNode(): TreeElement

getLastParentOfTypeInRow

inline fun <reified T : PsiElement> PsiElement.getLastParentOfTypeInRow(): T?

Returns the outermost element in an uninterrupted chain of ancestors of type T, or null if the parent is not a T.

getLastParentOfTypeInRowWithSelf

inline fun <reified T : PsiElement> PsiElement.getLastParentOfTypeInRowWithSelf(): T?

Like getLastParentOfTypeInRow, but the chain may start at this element itself.

getLBrace

@Nullable
open fun getLBrace(): PsiElement

Returns the opening brace token of this block, or null if it is absent.

getManager

abstract fun getManager(): PsiManager
open fun getManager(): PsiManagerEx

getModificationStamp

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.

getName

open fun getName(): String

getNavigationElement

open fun getNavigationElement(): @NotNull 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

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.

getOwnDeclarations

open fun getOwnDeclarations(): @NotNull Collection<out @NotNull PsiSymbolDeclaration>

getOwnReferences

open fun getOwnReferences(): @NotNull Collection<out @NotNull PsiSymbolReference>

getParent

open fun getParent(): PsiElement
abstract fun getParent(): PsiElement

Returns parent source element.

getParentOfType

inline fun <reified T : PsiElement> PsiElement.getParentOfType(strict: Boolean): T?

Returns the nearest ancestor of type T, or null. When strict is false, this element itself is also considered.

inline fun <reified T : PsiElement> PsiElement.getParentOfType(strict: Boolean, vararg stopAt: Class<out PsiElement>): T?

Returns the nearest ancestor of type T, stopping the search once an ancestor of any type in stopAt is reached, or null. When strict is false, this element itself is also considered.

getParentOfTypeAndBranch

inline fun <reified T : PsiElement> PsiElement.getParentOfTypeAndBranch(strict: Boolean = false, noinline branch: T.() -> PsiElement?): T?

Checks the nearest element of type T and returns it if this element lies within the subtree selected by branch. If that candidate's branch does not contain this element, returns null without checking higher ancestors. When strict is false, this element itself is also considered as the candidate.

getParentOfTypeAndBranches

inline fun <reified T : PsiElement> PsiElement.getParentOfTypeAndBranches(strict: Boolean = false, noinline branches: T.() -> Iterable<PsiElement?>): T?

Checks the nearest element of type T and returns it if this element lies within any subtree selected by branches. If none of that candidate's branches contain this element, returns null without checking higher ancestors. When strict is false, this element itself is also considered as the candidate.

getParentOfTypes

fun <T : PsiElement> PsiElement.getParentOfTypes(strict: Boolean = false, vararg parentClasses: Class<out T>): T?

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?

Returns the nearest strict ancestor that is a T or V, or null if there is none.

getParentOfTypes3

inline fun <reified T : PsiElement, reified V : PsiElement, reified U : PsiElement> PsiElement.getParentOfTypes3(): PsiElement?

Returns the nearest strict ancestor that is a T, V, or U, or null if there is none.

getParentOfTypesAndPredicate

fun <T : PsiElement> PsiElement.getParentOfTypesAndPredicate(
    strict: Boolean = false, 
    vararg parentClasses: Class<out T>, 
    predicate: (T) -> Boolean
): T?

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 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.

getProject

open fun getProject(): @NotNull Project

getPsi

fun getPsi(): PsiElement
open fun <T : PsiElement?> getPsi(clazz: @NotNull Class<T>): T

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.

getRBrace

@Nullable
open fun getRBrace(): PsiElement

Returns the closing brace token of this block, or null if it is absent.

getReference

open fun getReference(): PsiReference
abstract fun getReference(): PsiReference

getReferences

open fun getReferences(): @NotNull Array<PsiReference>

getResolveScope

open fun getResolveScope(): @NotNull GlobalSearchScope

getStartOffset

open fun getStartOffset(): Int

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

abstract fun getStartOffsetInParent(): Int

getStatements

@ReadOnly
@NotNull
open fun getStatements(): List<KtExpression>

Returns the statements of this block in source order, or an empty list if the block is empty.

getStrictParentOfType

inline fun <reified T : PsiElement> PsiElement.getStrictParentOfType(): T?

Returns the nearest strict ancestor of type T, or null if there is none.

getText

open fun getText(): @NotNull String

getTextLength

open fun getTextLength(): Int

getTextOffset

abstract fun getTextOffset(): Int

getTextRange

abstract fun getTextRange(): TextRange

getTextRangeInParent

open fun getTextRangeInParent(): @NotNull TextRange

getTextWithLocation

fun PsiElement.getTextWithLocation(): String

Returns this element's text together with its source location, for use in diagnostics and log messages.

getTokenType

open fun getTokenType(): IElementType

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.

getTreeNext

abstract fun getTreeNext(): ASTNode
fun getTreeNext(): TreeElement

getTreeParent

abstract fun getTreeParent(): ASTNode
fun getTreeParent(): CompositeElement

getTreePrev

abstract fun getTreePrev(): ASTNode
fun getTreePrev(): TreeElement

getUserData

open fun <T> getUserData(key: @NotNull Key<T>): T

getUserDataString

getUserMap

open fun getUserMap(): @NotNull KeyFMap

getUseScope

open fun getUseScope(): @NotNull SearchScope

hc

open fun hc(): Int

isAncestor

fun PsiElement?.isAncestor(element: PsiElement, strict: Boolean = false): Boolean

Returns true if this element is an ancestor of element. When strict is false, an element is its own ancestor.

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

isDotReceiver

Returns true if this expression is the receiver of an enclosing dot-qualified expression.

isDotSelector

Returns true if this expression is the selector of an enclosing dot-qualified expression.

isEquivalentTo

open fun isEquivalentTo(another: PsiElement): Boolean

isExtensionDeclaration

fun PsiElement.isExtensionDeclaration(): Boolean

Returns true if this element is an extension function or property (that is, it declares a receiver).

isFirstStatement

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

Returns true if this expression is the null literal. Smart-casts the receiver to KtConstantExpression on true.

isParsed

open fun isParsed(): Boolean

isPhysical

open fun isPhysical(): Boolean

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.

isUserDataEmpty

open fun isUserDataEmpty(): Boolean

isValid

open fun isValid(): Boolean

isWritable

open fun isWritable(): Boolean

lastBlockStatementOrThis

Returns the last statement if this expression is a block, otherwise this expression itself.

leaves

fun ASTNode.leaves(forward: Boolean = true): Sequence<ASTNode>

The leaf nodes following (or preceding, if not forward) this AST node, as a lazy sequence.

open fun navigate(requestFocus: Boolean)
open fun navigationRequest(): NavigationRequest

nextLeaf

fun PsiElement.nextLeaf(skipEmptyElements: Boolean = false): PsiElement?

Returns the next leaf element in the tree, or null if there is none. Empty leaves are skipped if skipEmptyElements.

fun PsiElement.nextLeaf(filter: (PsiElement) -> Boolean): PsiElement?

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.

parents

fun ASTNode.parents(): Sequence<ASTNode>

The ancestor nodes of this AST node, from its parent upward, as a lazy sequence.

prevLeaf

fun PsiElement.prevLeaf(skipEmptyElements: Boolean = false): PsiElement?

Returns the previous leaf element in the tree, or null if there is none. Empty leaves are skipped if skipEmptyElements.

fun PsiElement.prevLeaf(filter: (PsiElement) -> Boolean): PsiElement?

Returns the nearest preceding leaf that satisfies filter, or null if there is none.

processDeclarations

open fun processDeclarations(
    processor: @NotNull PsiScopeProcessor, 
    state: @NotNull ResolveState, 
    lastParent: PsiElement, 
    place: @NotNull PsiElement
): Boolean

putCopyableUserData

abstract fun <T> putCopyableUserData(p: @NotNull Key<T>, p1: @Nullable T)

putUserData

open fun <T> putUserData(key: @NotNull Key<T>, value: @Nullable T)

putUserDataIfAbsent

open fun <T> putUserDataIfAbsent(key: @NotNull Key<T>, value: @NotNull T): @NotNull T

rawAddChildren

fun rawAddChildren(first: @NotNull TreeElement)

rawAddChildrenWithoutNotifications

open fun rawAddChildrenWithoutNotifications(first: @NotNull TreeElement)

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.

rawFirstChild

open fun rawFirstChild(): TreeElement

rawInsertAfterMe

open fun rawInsertAfterMe(firstNew: @NotNull TreeElement)

rawInsertBeforeMe

open fun rawInsertBeforeMe(firstNew: @NotNull TreeElement)

rawLastChild

open fun rawLastChild(): TreeElement

rawRemove

open fun rawRemove()

rawRemoveAllChildren

rawRemoveUpTo

open fun rawRemoveUpTo(end: @Nullable TreeElement)

rawRemoveUpToLast

open fun rawRemoveUpToLast()

rawReplaceWithList

open fun rawReplaceWithList(firstNew: @Nullable TreeElement)

referenceExpression

Returns the reference expression of this expression (the callee for a call), or null if it is not a reference.

removeAllChildren

open fun removeAllChildren()

removeChild

open fun removeChild(child: @NotNull ASTNode)

removeRange

open fun removeRange(first: @NotNull ASTNode, firstWhichStayInTree: @Nullable ASTNode)

replace

open fun <T> replace(
    key: @NotNull Key<T>, 
    oldValue: @Nullable T, 
    newValue: @Nullable T
): Boolean
open fun replace(newElement: @NotNull PsiElement): PsiElement

replaceAllChildrenToChildrenOf

open fun replaceAllChildrenToChildrenOf(anotherParent: @NotNull ASTNode)

replaceChild

open fun replaceChild(oldChild: @NotNull ASTNode, newChild: @NotNull ASTNode)

replaceChildInternal

open fun replaceChildInternal(child: @NotNull ASTNode, newElement: @NotNull TreeElement)

setPsi

open fun setPsi(psi: @NotNull PsiElement)

shouldChangeModificationCount

open fun shouldChangeModificationCount(place: PsiElement): Boolean

siblings

fun ASTNode.siblings(forward: Boolean = true): Sequence<ASTNode>

The sibling nodes of this AST node, going forward (or backward), as a lazy sequence.

fun PsiElement.siblings(forward: Boolean = true, withItself: Boolean = true): Sequence<PsiElement>

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 fun subtreeChanged()

textContains

open fun textContains(c: Char): Boolean

textMatches

abstract fun textMatches(p: @NotNull @NonNls CharSequence): Boolean

textToCharArray

abstract fun textToCharArray(): @NotNull Array<Char>

topParenthesizedParentOrMe

Returns the outermost enclosing expression that this expression is wrapped in only through parentheses, or this expression itself.

toString

open fun toString(): String

unpackFunctionLiteral

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.