FIR/LC: restructure light identifiers

* introduced KtLightIdentifierBase so that both FIR LC and ULC share
  basic implementations

* detach PsiCompiledElement as per KTIJ-21412,
  while introducing KtLightIdentifierWithOrigin so that
  UastLightIdentifier can still inherit origin computation logic

^KTIJ-21412 In Progress
This commit is contained in:
Jinseong Jeon
2022-03-28 01:11:10 -07:00
committed by Ilya Kirillov
parent daa17b433c
commit 6a9ed82fdc
2 changed files with 24 additions and 29 deletions
@@ -5,26 +5,17 @@
package org.jetbrains.kotlin.light.classes.symbol
import com.intellij.openapi.util.TextRange
import com.intellij.psi.PsiElement
import com.intellij.psi.PsiFile
import com.intellij.psi.impl.light.LightIdentifier
import org.jetbrains.kotlin.asJava.elements.PsiElementWithOrigin
import org.jetbrains.kotlin.analysis.api.symbols.KtSymbol
import org.jetbrains.kotlin.analysis.api.symbols.markers.KtNamedSymbol
import org.jetbrains.kotlin.psi.KtNamedDeclaration
import org.jetbrains.kotlin.psi.KtPrimaryConstructor
import org.jetbrains.kotlin.psi.KtPropertyAccessor
import org.jetbrains.kotlin.psi.KtSecondaryConstructor
import org.jetbrains.kotlin.asJava.elements.KtLightIdentifierBase
import org.jetbrains.kotlin.psi.*
import org.jetbrains.kotlin.psi.psiUtil.containingClassOrObject
internal class FirLightIdentifier(
private val lightOwner: PsiElement,
lightOwner: PsiElement,
private val firSymbol: KtSymbol?
) : LightIdentifier(
lightOwner.manager,
(firSymbol as? KtNamedSymbol)?.name?.identifierOrNullIfSpecial
), PsiElementWithOrigin<PsiElement> {
) : KtLightIdentifierBase(lightOwner, (firSymbol as? KtNamedSymbol)?.name?.identifierOrNullIfSpecial) {
override val origin: PsiElement?
get() = when (val ktDeclaration = firSymbol?.psi) {
@@ -36,10 +27,4 @@ internal class FirLightIdentifier(
is KtNamedDeclaration -> ktDeclaration.nameIdentifier
else -> null
}
override fun isPhysical(): Boolean = true
override fun getParent(): PsiElement = lightOwner
override fun getContainingFile(): PsiFile = lightOwner.containingFile
override fun getTextRange(): TextRange = origin?.textRange ?: TextRange.EMPTY_RANGE
override fun getTextOffset(): Int = origin?.textOffset ?: -1
}
@@ -24,11 +24,21 @@ import com.intellij.psi.impl.light.LightIdentifier
import org.jetbrains.kotlin.psi.*
import org.jetbrains.kotlin.psi.psiUtil.containingClassOrObject
open class KtLightIdentifier(
abstract class KtLightIdentifierBase(
private val lightOwner: PsiElement,
text: String?
) : LightIdentifier(lightOwner.manager, text), PsiElementWithOrigin<PsiElement> {
override fun isPhysical() = true
override fun getParent() = lightOwner
override fun getContainingFile() = lightOwner.containingFile
override fun getTextRange() = origin?.textRange ?: TextRange.EMPTY_RANGE
override fun getTextOffset(): Int = origin?.textOffset ?: -1
}
open class KtLightIdentifierWithOrigin(
lightOwner: PsiElement,
private val ktDeclaration: KtDeclaration?
) : LightIdentifier(lightOwner.manager, ktDeclaration?.name ?: ""), PsiCompiledElement,
PsiElementWithOrigin<PsiElement> {
) : KtLightIdentifierBase(lightOwner, ktDeclaration?.name) {
override val origin: PsiElement?
get() = when (ktDeclaration) {
is KtSecondaryConstructor -> ktDeclaration.getConstructorKeyword()
@@ -39,12 +49,12 @@ open class KtLightIdentifier(
is KtNamedDeclaration -> ktDeclaration.nameIdentifier
else -> null
}
}
class KtLightIdentifier(
private val lightOwner: PsiElement,
ktDeclaration: KtDeclaration?
) : KtLightIdentifierWithOrigin(lightOwner, ktDeclaration), PsiCompiledElement {
override fun getMirror() = ((lightOwner as? KtLightElement<*, *>)?.clsDelegate as? PsiNameIdentifierOwner)?.nameIdentifier
override fun isPhysical() = true
override fun getParent() = lightOwner
override fun getContainingFile() = lightOwner.containingFile
override fun getTextRange() = origin?.textRange ?: TextRange.EMPTY_RANGE
override fun getTextOffset(): Int = origin?.textOffset ?: -1
}
}