FIR IDE: precalculate DuplicatedFirSourceElementsException error message

It may be called from non-read action
This commit is contained in:
Ilya Kirillov
2020-07-06 19:35:39 +03:00
parent 964becf138
commit 45e01a8b3d
@@ -152,23 +152,21 @@ internal class FirModuleResolveStateImpl(override val sessionProvider: FirProjec
} }
class DuplicatedFirSourceElementsException( class DuplicatedFirSourceElementsException(
private val existingFir: FirElement, existingFir: FirElement,
private val newFir: FirElement, newFir: FirElement,
private val psi: KtElement psi: KtElement
) : IllegalStateException() { ) : IllegalStateException() {
override val message: String? override val message: String? = """|The PSI element should be used only once as a real PSI source of FirElement,
get() = |the elements ${if (existingFir.source === newFir.source) "HAVE" else "DON'T HAVE"} the same instances of source elements
"""|The PSI element should be used only once as a real PSI source of FirElement, |
|the elements ${if (existingFir.source === newFir.source) "HAVE" else "DON'T HAVE"} the same instances of source elements |existing FIR element is $existingFir with text:
| |${existingFir.render().trim()}
|existing FIR element is $existingFir with text: |
|${existingFir.render().trim()} |new FIR element is $newFir with text:
| | ${newFir.render().trim()}
|new FIR element is $newFir with text: |
| ${newFir.render().trim()} |PSI element is $psi with text in context:
| |${getElementInContext(psi)}""".trimMargin()
|PSI element is $psi with text in context:
|${getElementInContext(psi)}""".trimMargin()
private fun getElementInContext(neededElement: KtElement): String { private fun getElementInContext(neededElement: KtElement): String {
val context = neededElement.containingDeclarationForPseudocode ?: neededElement.containingKtFile val context = neededElement.containingDeclarationForPseudocode ?: neededElement.containingKtFile