Skip to content

KtCodeFragmentBase

interface KtCodeFragmentBase : JavaCodeFragment

The Java-interop base for KtCodeFragment, adapting the platform's JavaCodeFragment contract to Kotlin.

It exists so that Kotlin code fragments can participate in platform machinery (such as the debugger) that is defined in terms of JavaCodeFragment.

Inheritors

Properties

allChildren

val PsiElement.allChildren: PsiChildRange

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

children

@get:Contract(pure = true)
@get:NotNull
abstract val children: @NotNull Array<out @NotNull PsiElement>

containingDirectory

abstract val containingDirectory: PsiDirectory?

containingFile

@get:Contract(pure = true)
abstract val containingFile: PsiFile?

context

@get:Nullable
@get:Contract(pure = true)
abstract val context: @Nullable PsiElement?

endOffset

val PsiElement.endOffset: Int

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

exceptionHandler

abstract var exceptionHandler: JavaCodeFragment.ExceptionHandler?

fileDocument

@get:NotNull
open val fileDocument: @NotNull Document

fileElementType

@get:Nullable
open val fileElementType: @Nullable IFileElementType?

fileType

@get:NotNull
abstract val fileType: @NotNull FileType

firstChild

@get:Contract(pure = true)
abstract val firstChild: PsiElement?

forcedResolveScope

abstract val forcedResolveScope: GlobalSearchScope?

isDirectory

abstract val isDirectory: Boolean

isPhysical

@get:Contract(pure = true)
abstract val isPhysical: Boolean

isValid

@get:Contract(pure = true)
abstract val isValid: Boolean

isWritable

@get:Contract(pure = true)
abstract val isWritable: Boolean

language

@get:NotNull
@get:Contract(pure = true)
abstract val language: @NotNull Language

lastChild

@get:Contract(pure = true)
abstract val lastChild: PsiElement?

manager

@get:Contract(pure = true)
abstract val manager: PsiManager?

modificationStamp

abstract val modificationStamp: Long

name

@get:NotNull
@get:NlsSafe
abstract var name: @NotNull @NlsSafe String
@get:Contract(pure = true)
abstract val navigationElement: PsiElement?

nextLeafs

val PsiElement.nextLeafs: Sequence<PsiElement>

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

nextSibling

@get:Contract(pure = true)
abstract val nextSibling: PsiElement?

node

abstract val node: FileASTNode?

originalElement

@get:Contract(pure = true)
abstract val originalElement: PsiElement?

originalFile

@get:NotNull
abstract val originalFile: @NotNull PsiFile

ownDeclarations

@get:NotNull
open val ownDeclarations: @NotNull Collection<out @NotNull PsiSymbolDeclaration>

ownReferences

@get:NotNull
open val ownReferences: @NotNull Collection<out @NotNull PsiSymbolReference>

parent

abstract val parent: PsiDirectory?

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.

presentation

@get:Nullable
abstract val presentation: @Nullable ItemPresentation?

prevLeafs

val PsiElement.prevLeafs: Sequence<PsiElement>

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

prevSibling

@get:Contract(pure = true)
abstract val prevSibling: PsiElement?

project

@get:NotNull
@get:Contract(pure = true)
abstract val project: @NotNull Project

psiRoots

abstract val psiRoots: @NotNull Array<out PsiFile?>

reference

@get:Nullable
@get:Contract(pure = true)
abstract val reference: @Nullable PsiReference?

references

@get:Contract(pure = true)
abstract val references: @NotNull Array<out PsiReference?>

resolveScope

@get:NotNull
@get:Contract(pure = true)
abstract val resolveScope: @NotNull GlobalSearchScope

startOffset

val PsiElement.startOffset: Int

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

startOffsetInParent

@get:Contract(pure = true)
abstract val startOffsetInParent: Int

startOffsetSkippingComments

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

superType

abstract var superType: PsiType?

text

@get:Contract(pure = true)
@get:NlsSafe
abstract val text: @NlsSafe String?

textLength

@get:Contract(pure = true)
abstract val textLength: Int

textOffset

@get:Contract(pure = true)
abstract val textOffset: Int

textRange

@get:Contract(pure = true)
abstract 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.

thisType

abstract var thisType: PsiType?

useScope

@get:NotNull
@get:Contract(pure = true)
abstract val useScope: @NotNull SearchScope

viewProvider

@get:NotNull
abstract val viewProvider: @NotNull FileViewProvider

virtualFile

abstract val virtualFile: VirtualFile?

visibilityChecker

abstract var visibilityChecker: JavaCodeFragment.VisibilityChecker?

Functions

accept

abstract fun accept(p0: @NotNull PsiElementVisitor)

acceptChildren

abstract fun acceptChildren(p0: @NotNull PsiElementVisitor)

add

abstract fun add(p0: @NotNull PsiElement): PsiElement?

addAfter

abstract fun addAfter(p0: @NotNull PsiElement, p1: @Nullable PsiElement?): PsiElement?

addBefore

abstract fun addBefore(p0: @NotNull PsiElement, p1: @Nullable PsiElement?): PsiElement?

addImportsFromString

abstract fun addImportsFromString(p0: String?)

addRange

abstract fun addRange(p0: PsiElement?, p1: PsiElement?): PsiElement?

addRangeAfter

abstract fun addRangeAfter(
    p0: PsiElement?, 
    p1: PsiElement?, 
    p2: PsiElement?
): PsiElement?

addRangeBefore

abstract fun addRangeBefore(
    p0: @NotNull PsiElement, 
    p1: @NotNull PsiElement, 
    p2: 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.

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

canNavigate

open fun canNavigate(): Boolean

canNavigateToSource

checkAdd

abstract fun checkAdd(p0: @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

abstract fun checkDelete()

checkSetName

abstract fun checkSetName(p0: String?)

clearCaches

open fun clearCaches()

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.

copy

abstract fun copy(): PsiElement?

delete

abstract fun delete()

deleteChildRange

abstract fun deleteChildRange(p0: PsiElement?, p1: PsiElement?)

elementsInRange

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

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

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

abstract fun findElementAt(p0: Int): @Nullable PsiElement?

findReferenceAt

abstract fun findReferenceAt(p0: Int): @Nullable PsiReference?

forceResolveScope

abstract fun forceResolveScope(p0: GlobalSearchScope?)

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.

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.

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.

getCopyableUserData

abstract fun <T> getCopyableUserData(p0: @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.

getExplicitReceiverOfDotQualified

fun PsiElement.getExplicitReceiverOfDotQualified(): PsiElement?

Returns the source of the explicit receiver if this element is a dot-qualified expression, or null otherwise.

getIcon

abstract fun getIcon(p0: Int): Icon?

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.

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.

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.

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.

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

abstract fun <T> getUserData(p0: @NotNull Key<T?>): @Nullable T?

importClass

open override fun importClass(aClass: PsiClass): Boolean

Accepts a class import request from the platform. Kotlin code fragments manage imports themselves, so this always returns true without modifying the fragment.

importsToString

abstract fun importsToString(): String?

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.

isEquivalentTo

abstract fun isEquivalentTo(p0: PsiElement?): Boolean

isExtensionDeclaration

fun PsiElement.isExtensionDeclaration(): Boolean

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

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.

isInsideOf

fun PsiElement.isInsideOf(elements: Iterable<PsiElement>): Boolean

Returns true if this element lies within, or is equal to, any of the given elements.

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.

open fun navigate(requestFocus: Boolean)
open fun navigationRequest(): @Nullable 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.

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

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.

processChildren

abstract fun processChildren(p0: @NotNull PsiElementProcessor<in PsiFileSystemItem?>): Boolean

processDeclarations

abstract fun processDeclarations(
    p0: @NotNull PsiScopeProcessor, 
    p1: @NotNull ResolveState, 
    p2: @Nullable PsiElement?, 
    p3: @NotNull PsiElement
): Boolean

putCopyableUserData

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

putUserData

abstract fun <T> putUserData(p0: @NotNull Key<T?>, p1: @Nullable T?)

replace

abstract fun replace(p0: @NotNull PsiElement): PsiElement?

siblings

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

abstract fun subtreeChanged()

textContains

abstract fun textContains(p0: Char): Boolean

textMatches

abstract fun textMatches(p0: @NotNull PsiElement): Boolean
abstract fun textMatches(p0: @NotNull @NonNls CharSequence): Boolean

textToCharArray

abstract fun textToCharArray(): @NotNull CharArray

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.