KtSimpleNameExpression¶
@SubclassOptInRequired(markerClass = [KtImplementationDetail::class])
interface KtSimpleNameExpression : KtReferenceExpression
Represents a simple name reference: an unqualified reference to a declaration by its name, or an operation sign that references a declaration (for example, the + of a binary expression).
Example:¶
See also¶
-
KtNameReferenceExpression: a plain identifier reference -
KtOperationReferenceExpression: an operation sign that references a declaration
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¶
containingFile¶
@get:Contract(pure = true)
abstract val containingFile: PsiFile?
containingKtFile¶
@get:NotNull
abstract val containingKtFile: KtFile
context¶
@get:Nullable
@get:Contract(pure = true)
abstract val context: @Nullable PsiElement?
endOffset¶
The offset just past the end of this element's text range in the file.
firstChild¶
@get:Contract(pure = true)
abstract val firstChild: PsiElement?
isPhysical¶
@get:Contract(pure = true)
abstract val isPhysical: Boolean
isValid¶
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?
name¶
navigationElement¶
@get:Contract(pure = true)
abstract val navigationElement: PsiElement?
nextLeafs¶
The following leaf elements as a lazy sequence, nearest first.
nextSibling¶
@get:Contract(pure = true)
abstract val nextSibling: PsiElement?
node¶
@get:Contract(pure = true)
abstract val node: ASTNode?
originalElement¶
@get:Contract(pure = true)
abstract 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¶
@get:Contract(pure = true)
abstract 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¶
@get:Nullable
abstract val presentation: @Nullable ItemPresentation?
prevLeafs¶
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
psiOrParent¶
@get:NotNull
abstract 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¶
abstract override val reference: 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¶
val PsiElement.startOffsetSkippingComments: Int
The start offset of this element, skipping leading comments and the whitespace that follows them.
text¶
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.
useScope¶
@get:NotNull
@get:Contract(pure = true)
abstract val useScope: @NotNull SearchScope
Functions¶
accept¶
abstract fun accept(p0: @NotNull PsiElementVisitor)
Dispatches this element to the corresponding visit* method of the given visitor and returns its result.
acceptChildren¶
abstract fun acceptChildren(p0: @NotNull PsiElementVisitor)
Passes each direct child of this element to the given visitor.
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?
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. 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¶
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()
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¶
abstract fun copy(): PsiElement?
delete¶
abstract fun delete()
deleteChildRange¶
abstract fun deleteChildRange(p0: PsiElement?, p1: PsiElement?)
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¶
abstract fun findElementAt(p0: Int): @Nullable PsiElement?
findReferenceAt¶
abstract fun findReferenceAt(p0: Int): @Nullable 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¶
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.
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¶
getIdentifier¶
abstract fun getIdentifier(): PsiElement?
Returns the identifier token of this reference, or null if the name is not a plain identifier (for example, an operation sign).
getLabeledParent¶
fun KtExpression.getLabeledParent(labelName: String): KtLabeledExpression?
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?
getLastParentOfTypeInRowWithSelf¶
inline fun <reified T : PsiElement> PsiElement.getLastParentOfTypeInRowWithSelf(): T?
Like getLastParentOfTypeInRow, but the chain may start at this element itself.
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.
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.
getParent¶
@Contract(pure = true)
abstract 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.
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.
getReferencedName¶
abstract fun getReferencedName(): String
Returns the referenced name as it appears in the source, with any surrounding backticks removed.
getReferencedNameAsName¶
abstract fun getReferencedNameAsName(): Name
Returns the referenced name as a Name.
getReferencedNameElement¶
abstract fun getReferencedNameElement(): PsiElement
Returns the token or element that carries the referenced name (for example, the identifier or the operation sign). Never null, even for operation references.
getReferencedNameElementType¶
abstract fun getReferencedNameElementType(): IElementType
Returns the element type of the referenced name element.
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.
getTopmostParentQualifiedExpressionForSelector¶
Returns the outermost qualified expression in which this name is (transitively) the selector, or null.
getUserData¶
abstract fun <T> getUserData(p0: @NotNull Key<T?>): @Nullable T?
isAncestor¶
fun PsiElement?.isAncestor(element: PsiElement, strict: Boolean = false): Boolean
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.
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¶
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).
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.
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.
isNull¶
fun KtExpression.isNull(): Boolean
Returns true if this expression is the null literal. Smart-casts the receiver to KtConstantExpression on true.
isPackageDirectiveExpression¶
Returns true if this name is part of a package directive.
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.
lastBlockStatementOrThis¶
Returns the last statement if this expression is a block, otherwise this expression itself.
navigate¶
navigationRequest¶
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¶
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?)
rawDelete¶
abstract 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¶
abstract fun replace(p0: @NotNull PsiElement): PsiElement?
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.
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
topParenthesizedParentOrMe¶
Returns the outermost enclosing expression that this expression is wrapped in only through parentheses, or this expression itself.
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.