Skip to content

org.jetbrains.kotlin.psi.psiUtil

Types

KtStringTemplateExpressionManipulator

The ElementManipulator of KtStringTemplateExpression, which edits the content of a string literal, e.g., when a language fragment injected into the string is edited or a reference contributed to the string is renamed.

PsiChildRange

data class PsiChildRange(val first: PsiElement?, val last: PsiElement?) : Sequence<PsiElement> 

A contiguous range of sibling PSI elements, from first to last inclusive, iterable as a Sequence.

Properties

allChildren

val PsiElement.allChildren: PsiChildRange

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

argumentIndex

The index of this argument within its enclosing value argument list.

containingClassId

The containing ClassId for this declaration. REPL KtScripts are supported.

containingClassOrObject

The containing class for the body.

The containing class for the companion block.

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.

containingScript

The containing script for the block expression.

The containing script for top-level declarations.

endOffset

val PsiElement.endOffset: Int

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

isCompanion

Whether the callable is a companion extension or comes from a companion block.

isFromCompanionBlock

Whether this declaration is declared inside a companion object block.

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.

isUnderscoreInBackticks

true if this reference is the backtick-escaped underscore identifier `_` (distinct from the plain _ placeholder).

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.

plainContent

The source text between the string delimiters, including any escape or interpolation syntax.

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.

UNWRAPPABLE_TOKEN_TYPES

val UNWRAPPABLE_TOKEN_TYPES: Set<IElementType>

See org.jetbrains.kotlin.fir.builder.AbstractRawFirBuilder.unwrap

Functions

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.

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.

canPlaceAfterSimpleNameEntry

fun canPlaceAfterSimpleNameEntry(element: PsiElement?): Boolean

Returns true if placing text after a $name simple-name template entry would not accidentally extend the name, that is, element does not begin with an identifier character.

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.

children

fun ASTNode.children(): Sequence<ASTNode>

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

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.

collectAnnotationEntriesFromStubOrPsi

Collects the annotation entries of this container, reading from the stub when available and falling back to the PSI.

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.

contains

operator fun SearchScope.contains(element: PsiElement): Boolean

Returns true if element lies within this search scope.

containsInside

fun TextRange.containsInside(offset: Int): Boolean

Returns true if offset lies strictly inside this range (excluding both endpoints).

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.

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.

elementsInRange

fun PsiFile.elementsInRange(range: TextRange): List<PsiElement>

Returns the top-level elements that together cover the given range within this file.

findAssignment

tailrec fun findAssignment(element: PsiElement?): KtBinaryExpression?

Walks up from element through qualified/simple-name expressions to find a plain = assignment whose LHS it is.

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.

findFunctionByName

Returns the member function with the given name, or null if there is none.

findLabelAndCall

Returns the label (explicit or the enclosing call's name) and the call that this lambda is passed to, as a pair. Either component may be null if it cannot be determined.

findPropertyByName

Returns the member property (or primary-constructor property parameter) with the given name, or null.

flatMapDescendantsOfTypeVisitor

inline fun <reified T : KtElement, R> flatMapDescendantsOfTypeVisitor(accumulator: MutableCollection<R>, noinline map: (T) -> Collection<R>): KtVisitorVoid

Returns a recursive visitor that maps each visited element of type T, including the element passed to accept, and adds all results to accumulator in DFS-exit order.

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.

forEachDescendantOfTypeVisitor

inline fun <reified T : KtElement> forEachDescendantOfTypeVisitor(noinline block: (T) -> Unit): KtVisitorVoid

Returns a recursive visitor that calls block on each visited element of type T, including the element passed to accept. Calls happen in DFS-exit order, so deeper nodes are visited before their ancestors.

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.

getCallNameExpression

Returns the simple-name reference of this call's callee (its function or constructor name), or null.

getChildOfType

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

Returns the first direct child of type T, or null if there is none.

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.

getContainingKtFile

fun LazyParseablePsiElement.getContainingKtFile(): KtFile

Returns the KtFile containing this element.

getContentRange

Returns the text range of the string content, excluding the interpolation prefix and the opening/closing quotes.

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.

getFileOrScriptDeclarations

Returns the top-level declarations of this file, taking them from the script if the file is a script.

getIfChildIsInBranch

fun <T : PsiElement> T.getIfChildIsInBranch(element: PsiElement, branch: T.() -> PsiElement?): T?

Returns this element if element lies within the subtree returned by branch, otherwise null.

getIfChildIsInBranches

fun <T : PsiElement> T.getIfChildIsInBranches(element: PsiElement, branches: T.() -> Iterable<PsiElement?>): T?

Returns this element if element lies within any of the subtrees returned by branches, otherwise null.

getImportedSimpleNameByImportAlias

Returns the original short name imported under the alias aliasName in file, or null if there is no such alias.

getLabeledParent

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

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.

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.

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.

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.

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.

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.

getQualifiedElement

Returns the enclosing qualified element for this name: a KtQualifiedExpression, a KtUserType, or this expression itself if there is no such qualifier.

getQualifiedElementOrCallableRef

Like getQualifiedElement, but also returns the enclosing KtCallableReferenceExpression when this name is its callable reference.

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.

getReceiverExpression

Returns the receiver this name is applied to, considering qualified expressions, binary/unary operators, and qualified user types, or null if this name has no receiver.

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

getStrictParentOfType

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

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

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.

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.

getTopmostParentQualifiedExpressionForSelector

Returns the outermost qualified expression in which this name is (transitively) the selector, or null.

getTrailingCommaByClosingElement

fun getTrailingCommaByClosingElement(closingElement: PsiElement?): PsiElement?

Returns the trailing comma immediately before closingElement (a closing bracket/parenthesis), or null.

getTrailingCommaByElementsList

fun getTrailingCommaByElementsList(elementList: PsiElement?): PsiElement?

Returns the trailing comma at the end of elementList (skipping a trailing comment), or null if there is none.

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 modifier list contains the actual modifier.

Returns true if this declaration has the actual modifier.

hasBody

Returns true if this declaration is a function or property that defines a body.

hasExpectModifier

Returns true if this modifier list contains the expect modifier.

Returns true if this declaration has the expect modifier.

hasExternalModifier

Returns true if this declaration has the external modifier.

hasFunModifier

Returns true if this modifier list contains the fun modifier (a functional interface).

hasInnerModifier

Returns true if this declaration has the inner modifier.

hasSuspendModifier

Returns true if this modifier list contains the suspend modifier.

hasValueModifier

Returns true if this modifier list contains the value modifier (a value class).

inferClassIdByPsi

A best-effort way to get the ClassId of this expression's type without semantic resolution.

isAbstract

Returns true if this class is abstract, that is, it is an interface or has the abstract modifier.

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

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

isCallee

Returns true if this expression can be the callee of a call with the same name.

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.

Best-effort PSI check for whether this qualified expression is a kotlin.contracts.contract { ... } call.

isContractPresentPsiCheck

Best-effort PSI check for whether this function's body begins with a contract { ... } call, taking into account whether contracts are allowed on member functions via isAllowedOnMembers. false is definitive; true is not a guarantee.

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.

isDoubleColonReceiver

Returns true if expression is the receiver of an enclosing :: (callable reference or class literal) expression.

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

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.

isIdentifier

Checks if this string is a valid Kotlin identifier.

isImportDirectiveExpression

Returns true if this name is part of an import directive.

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.

isLegacyContractPresentPsiCheck

Whether the declaration may have a legacy contract (a contract defined inside the body).

isNull

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 { ... }).

isPackageDirectiveExpression

Returns true if this name is part of a package directive.

isPlain

Returns true if this string consists only of literal text, with no interpolation or escape sequences.

isPlainWithEscapes

Returns true if this string consists only of literal text and escape sequences, with no interpolation.

isPrivate

Returns true if this declaration has the private modifier.

isPropertyParameter

Returns true if this parameter is a primary-constructor val/var property parameter.

isProtected

Returns true if this declaration has the protected modifier.

isSingleQuoted

Returns true if this uses the regular one-character quote delimiter (") rather than a triple-quote delimiter (""").

isTopLevelInFileOrScript

fun isTopLevelInFileOrScript(element: PsiElement): Boolean

Returns true if element is a top-level element of a file or a top-level statement of a script.

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.

isTypeConstructorReference

fun isTypeConstructorReference(e: PsiElement): Boolean

Returns true if e is the reference expression naming the classifier in a user type.

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.

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.

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.

nextSiblingOfSameType

inline fun <reified T : PsiElement> T.nextSiblingOfSameType(): @Nullable T?

Returns the next sibling of the same type T, 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.

prevSiblingOfSameType

inline fun <reified T : PsiElement> T.prevSiblingOfSameType(): @Nullable T?

Returns the previous sibling of the same type T, or null if there is none.

quoteIfNeeded

Returns this string as-is if it is a valid identifier, otherwise wrapped in backticks.

referenceExpression

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

safeFqNameForLazyResolve

Returns this declaration's fully qualified name using the safe name for lazy resolution, or null if unavailable.

safeNameForLazyResolve

fun Name?.safeNameForLazyResolve(): Name

Returns this name, or the "no name provided" special name if it is null or special.

Returns this declaration's name, substituting the "no name provided" special name for a missing or special name.

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.

topParenthesizedParentOrMe

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

tryFlattenStringConcatenationArguments

Returns the string-template arguments of this expression if it is a string-literal concatenation; otherwise, returns null.

tryFlattenStringConcatenationDescendants

Returns all descendants of this expression in flattened form if it is a string-literal concatenation; otherwise, returns null.

unwrapNullability

Returns this type after stripping all outer KtNullableType layers. Returns null only if a nullable-type node is malformed and has no inner type.

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 KtModifierList.visibilityModifier(): PsiElement?

Returns the visibility modifier token (public/private/protected/internal), or null if none is present.

Returns the visibility modifier token of this declaration, or null if none is present.

visibilityModifierType

Returns the type of the visibility modifier, or null if none is present.

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.