From 6a9ed82fdcf050c75793612b90f7f1ea9a6e1a18 Mon Sep 17 00:00:00 2001 From: Jinseong Jeon Date: Mon, 28 Mar 2022 01:11:10 -0700 Subject: [PATCH] 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 --- .../classes/symbol/FirLightIdentifier.kt | 23 +++----------- .../asJava/elements/KtLightIdentifier.kt | 30 ++++++++++++------- 2 files changed, 24 insertions(+), 29 deletions(-) diff --git a/analysis/symbol-light-classes/src/org/jetbrains/kotlin/light/classes/symbol/FirLightIdentifier.kt b/analysis/symbol-light-classes/src/org/jetbrains/kotlin/light/classes/symbol/FirLightIdentifier.kt index 15f6d5479bc..96bc7849641 100644 --- a/analysis/symbol-light-classes/src/org/jetbrains/kotlin/light/classes/symbol/FirLightIdentifier.kt +++ b/analysis/symbol-light-classes/src/org/jetbrains/kotlin/light/classes/symbol/FirLightIdentifier.kt @@ -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 { +) : 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 } diff --git a/compiler/light-classes/src/org/jetbrains/kotlin/asJava/elements/KtLightIdentifier.kt b/compiler/light-classes/src/org/jetbrains/kotlin/asJava/elements/KtLightIdentifier.kt index a2afe07ae83..be6cadebb83 100644 --- a/compiler/light-classes/src/org/jetbrains/kotlin/asJava/elements/KtLightIdentifier.kt +++ b/compiler/light-classes/src/org/jetbrains/kotlin/asJava/elements/KtLightIdentifier.kt @@ -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 { + 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 { +) : 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 -} \ No newline at end of file +}