Use KotlinExceptionWithAttachments for ToFromOriginalFileMapper and MainFunctionDetector

This commit is contained in:
Vladimir Dolzhenko
2019-08-19 16:38:01 +02:00
parent fa29297fb1
commit dd0e296af1
2 changed files with 14 additions and 2 deletions
@@ -21,6 +21,7 @@ import com.intellij.psi.PsiElement
import com.intellij.psi.util.PsiTreeUtil
import org.jetbrains.kotlin.psi.KtFile
import org.jetbrains.kotlin.psi.psiUtil.startOffset
import org.jetbrains.kotlin.utils.KotlinExceptionWithAttachments
import kotlin.math.min
class ToFromOriginalFileMapper private constructor(
@@ -46,7 +47,16 @@ class ToFromOriginalFileMapper private constructor(
init {
val originalText = originalFile.text
val syntheticText = syntheticFile.text
assert(originalText.subSequence(0, completionOffset) == syntheticText.subSequence(0, completionOffset))
val originalSubSequence = originalText.subSequence(0, completionOffset)
val syntheticSubSequence = syntheticText.subSequence(0, completionOffset)
if (originalSubSequence != syntheticSubSequence) {
throw KotlinExceptionWithAttachments(
"original subText [len: ${originalSubSequence.length}]" +
" does not match synthetic subText [len: ${syntheticSubSequence.length}]"
)
.withAttachment("original subText", originalSubSequence.toString())
.withAttachment("synthetic subText", syntheticSubSequence.toString())
}
syntheticLength = syntheticText.length
originalLength = originalText.length