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:
committed by
Ilya Kirillov
parent
daa17b433c
commit
6a9ed82fdc
+4
-19
@@ -5,26 +5,17 @@
|
|||||||
|
|
||||||
package org.jetbrains.kotlin.light.classes.symbol
|
package org.jetbrains.kotlin.light.classes.symbol
|
||||||
|
|
||||||
import com.intellij.openapi.util.TextRange
|
|
||||||
import com.intellij.psi.PsiElement
|
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.KtSymbol
|
||||||
import org.jetbrains.kotlin.analysis.api.symbols.markers.KtNamedSymbol
|
import org.jetbrains.kotlin.analysis.api.symbols.markers.KtNamedSymbol
|
||||||
import org.jetbrains.kotlin.psi.KtNamedDeclaration
|
import org.jetbrains.kotlin.asJava.elements.KtLightIdentifierBase
|
||||||
import org.jetbrains.kotlin.psi.KtPrimaryConstructor
|
import org.jetbrains.kotlin.psi.*
|
||||||
import org.jetbrains.kotlin.psi.KtPropertyAccessor
|
|
||||||
import org.jetbrains.kotlin.psi.KtSecondaryConstructor
|
|
||||||
import org.jetbrains.kotlin.psi.psiUtil.containingClassOrObject
|
import org.jetbrains.kotlin.psi.psiUtil.containingClassOrObject
|
||||||
|
|
||||||
internal class FirLightIdentifier(
|
internal class FirLightIdentifier(
|
||||||
private val lightOwner: PsiElement,
|
lightOwner: PsiElement,
|
||||||
private val firSymbol: KtSymbol?
|
private val firSymbol: KtSymbol?
|
||||||
) : LightIdentifier(
|
) : KtLightIdentifierBase(lightOwner, (firSymbol as? KtNamedSymbol)?.name?.identifierOrNullIfSpecial) {
|
||||||
lightOwner.manager,
|
|
||||||
(firSymbol as? KtNamedSymbol)?.name?.identifierOrNullIfSpecial
|
|
||||||
), PsiElementWithOrigin<PsiElement> {
|
|
||||||
|
|
||||||
override val origin: PsiElement?
|
override val origin: PsiElement?
|
||||||
get() = when (val ktDeclaration = firSymbol?.psi) {
|
get() = when (val ktDeclaration = firSymbol?.psi) {
|
||||||
@@ -36,10 +27,4 @@ internal class FirLightIdentifier(
|
|||||||
is KtNamedDeclaration -> ktDeclaration.nameIdentifier
|
is KtNamedDeclaration -> ktDeclaration.nameIdentifier
|
||||||
else -> null
|
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
|
|
||||||
}
|
}
|
||||||
|
|||||||
+19
-9
@@ -24,11 +24,21 @@ import com.intellij.psi.impl.light.LightIdentifier
|
|||||||
import org.jetbrains.kotlin.psi.*
|
import org.jetbrains.kotlin.psi.*
|
||||||
import org.jetbrains.kotlin.psi.psiUtil.containingClassOrObject
|
import org.jetbrains.kotlin.psi.psiUtil.containingClassOrObject
|
||||||
|
|
||||||
open class KtLightIdentifier(
|
abstract class KtLightIdentifierBase(
|
||||||
private val lightOwner: PsiElement,
|
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?
|
private val ktDeclaration: KtDeclaration?
|
||||||
) : LightIdentifier(lightOwner.manager, ktDeclaration?.name ?: ""), PsiCompiledElement,
|
) : KtLightIdentifierBase(lightOwner, ktDeclaration?.name) {
|
||||||
PsiElementWithOrigin<PsiElement> {
|
|
||||||
override val origin: PsiElement?
|
override val origin: PsiElement?
|
||||||
get() = when (ktDeclaration) {
|
get() = when (ktDeclaration) {
|
||||||
is KtSecondaryConstructor -> ktDeclaration.getConstructorKeyword()
|
is KtSecondaryConstructor -> ktDeclaration.getConstructorKeyword()
|
||||||
@@ -39,12 +49,12 @@ open class KtLightIdentifier(
|
|||||||
is KtNamedDeclaration -> ktDeclaration.nameIdentifier
|
is KtNamedDeclaration -> ktDeclaration.nameIdentifier
|
||||||
else -> null
|
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 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
|
|
||||||
}
|
}
|
||||||
Reference in New Issue
Block a user