[FIR] add utilities to FIR compiler to throw error with attachment

This commit is contained in:
Ilya Kirillov
2023-06-30 18:17:50 +02:00
committed by Space Team
parent c5014d4765
commit a9cd881a07
20 changed files with 127 additions and 69 deletions
@@ -14,6 +14,7 @@ import com.intellij.psi.PsiFile
import com.intellij.psi.PsiWhiteSpace
import com.intellij.psi.tree.IElementType
import com.intellij.util.diff.FlyweightCapableTreeStructure
import org.jetbrains.kotlin.utils.getElementTextWithContext
sealed class KtSourceElementKind {
abstract val shouldSkipErrorTypeReporting: Boolean
@@ -309,6 +310,8 @@ sealed class KtSourceElement : AbstractKtSourceElement() {
abstract val lighterASTNode: LighterASTNode
abstract val treeStructure: FlyweightCapableTreeStructure<LighterASTNode>
abstract fun getElementTextInContextForDebug(): String
/** Implementation must compute the hashcode from the source element. */
abstract override fun hashCode(): Int
@@ -336,6 +339,10 @@ sealed class KtPsiSourceElement(val psi: PsiElement) : KtSourceElement() {
WrappedTreeStructure(psi.containingFile)
}
override fun getElementTextInContextForDebug(): String {
return getElementTextWithContext(psi)
}
internal class WrappedTreeStructure(file: PsiFile) : FlyweightCapableTreeStructure<LighterASTNode> {
private val lighterAST = TreeBackedLighterAST(file.node)
@@ -521,6 +528,10 @@ class KtLightSourceElement(
return node.psi?.toKtPsiSourceElement(kind)
}
override fun getElementTextInContextForDebug(): String {
return treeStructure.toString(lighterASTNode).toString()
}
override fun equals(other: Any?): Boolean {
if (this === other) return true
if (javaClass != other?.javaClass) return false