Add possibility to get line offsets from PsiIrFileEntry

This is needed for tests to be able to get offsets without explicit
file on disk.
This commit is contained in:
Ivan Kylchik
2021-10-25 14:39:40 +03:00
parent edd608446e
commit 68c9156053
2 changed files with 6 additions and 3 deletions
@@ -53,6 +53,8 @@ class PsiIrFileEntry(val psiFile: PsiFile) : IrFileEntry {
override fun toString(): String = getRecognizableName()
fun getLineOffsets() = lineStartOffsets.copyOf()
fun findPsiElement(irElement: IrElement): PsiElement? {
var psiElement = fileViewProvider.findElementAt(irElement.startOffset)
while (psiElement != null) {
@@ -175,9 +175,10 @@ val File.lineStartOffsets: IntArray
return buffer.toIntArray()
}
val IrFileEntry.lineStartOffsets
get() = File(name).let {
if (it.exists() && it.isFile) it.lineStartOffsets else IntArray(0)
val IrFileEntry.lineStartOffsets: IntArray
get() = when (this) {
is PsiIrFileEntry -> this.getLineOffsets()
else -> File(name).let { if (it.exists() && it.isFile) it.lineStartOffsets else IntArray(0) }
}
class NaiveSourceBasedFileEntryImpl(