org.jetbrains.kotlin.psi.KtNameReferenceExpression.kt Maven / Gradle / Ivy
The newest version!
/*
* Copyright 2010-2024 JetBrains s.r.o. and Kotlin Programming Language contributors.
* Use of this source code is governed by the Apache 2.0 license that can be found in the license/LICENSE.txt file.
*/
package org.jetbrains.kotlin.psi
import com.intellij.lang.ASTNode
import com.intellij.psi.PsiElement
import com.intellij.psi.tree.IElementType
import com.intellij.psi.tree.TokenSet
import org.jetbrains.kotlin.lexer.KtTokens
import org.jetbrains.kotlin.lexer.KtTokens.*
import org.jetbrains.kotlin.name.Name
import org.jetbrains.kotlin.psi.stubs.KotlinNameReferenceExpressionStub
import org.jetbrains.kotlin.psi.stubs.elements.KtStubElementTypes
class KtNameReferenceExpression : KtExpressionImplStub, KtSimpleNameExpression {
constructor(node: ASTNode) : super(node)
constructor(stub: KotlinNameReferenceExpressionStub) : super(stub, KtStubElementTypes.REFERENCE_EXPRESSION)
override fun getReferencedName(): String {
val stub = greenStub
if (stub != null) {
return stub.getReferencedName()
}
return KtSimpleNameExpressionImpl.getReferencedNameImpl(this)
}
override fun getReferencedNameAsName(): Name {
return KtSimpleNameExpressionImpl.getReferencedNameAsNameImpl(this)
}
override fun getReferencedNameElement(): PsiElement {
return findChildByType(NAME_REFERENCE_EXPRESSIONS) ?: this
}
override fun getIdentifier(): PsiElement? {
return findChildByType(KtTokens.IDENTIFIER)
}
override fun getReferencedNameElementType(): IElementType {
return KtSimpleNameExpressionImpl.getReferencedNameElementTypeImpl(this)
}
override fun accept(visitor: KtVisitor, data: D): R {
return visitor.visitSimpleNameExpression(this, data)
}
val isPlaceholder: Boolean
get() = getIdentifier()?.text?.equals("_") == true
companion object {
private val NAME_REFERENCE_EXPRESSIONS = TokenSet.create(IDENTIFIER, THIS_KEYWORD, SUPER_KEYWORD)
}
}
© 2015 - 2025 Weber Informatics LLC | Privacy Policy