[PL] Fix line/column numbers in error messages
This commit is contained in:
committed by
Space Team
parent
9a3eece944
commit
eec511a767
@@ -6,6 +6,8 @@
|
||||
package org.jetbrains.kotlin.ir
|
||||
|
||||
const val UNDEFINED_OFFSET: Int = -1
|
||||
const val UNDEFINED_LINE_NUMBER: Int = UNDEFINED_OFFSET
|
||||
const val UNDEFINED_COLUMN_NUMBER: Int = UNDEFINED_OFFSET
|
||||
|
||||
data class SourceRangeInfo(
|
||||
val filePath: String,
|
||||
|
||||
@@ -24,15 +24,15 @@ class PsiIrFileEntry(val psiFile: PsiFile) : IrFileEntry {
|
||||
}
|
||||
|
||||
override fun getLineNumber(offset: Int): Int {
|
||||
if (offset < 0) return -1
|
||||
if (offset < 0) return UNDEFINED_LINE_NUMBER
|
||||
val index = lineStartOffsets.binarySearch(offset)
|
||||
return if (index >= 0) index else -index - 2
|
||||
}
|
||||
|
||||
override fun getColumnNumber(offset: Int): Int {
|
||||
if (offset < 0) return -1
|
||||
if (offset < 0) return UNDEFINED_COLUMN_NUMBER
|
||||
val lineNumber = getLineNumber(offset)
|
||||
if (lineNumber < 0) return -1
|
||||
if (lineNumber < 0) return UNDEFINED_COLUMN_NUMBER
|
||||
return offset - lineStartOffsets[lineNumber]
|
||||
}
|
||||
|
||||
|
||||
@@ -227,15 +227,15 @@ class NaiveSourceBasedFileEntryImpl(
|
||||
|
||||
override fun getLineNumber(offset: Int): Int {
|
||||
if (offset == SYNTHETIC_OFFSET) return 0
|
||||
if (offset < 0) return -1
|
||||
if (offset < 0) return UNDEFINED_LINE_NUMBER
|
||||
return synchronized(lineNumberLock) { calculatedBeforeLineNumbers.get(offset) }
|
||||
}
|
||||
|
||||
override fun getColumnNumber(offset: Int): Int {
|
||||
if (offset == SYNTHETIC_OFFSET) return 0
|
||||
if (offset < 0) return -1
|
||||
if (offset < 0) return UNDEFINED_COLUMN_NUMBER
|
||||
val lineNumber = getLineNumber(offset)
|
||||
return if (lineNumber < 0) -1 else offset - lineStartOffsets[lineNumber]
|
||||
return if (lineNumber < 0) UNDEFINED_COLUMN_NUMBER else offset - lineStartOffsets[lineNumber]
|
||||
}
|
||||
|
||||
override fun getSourceRangeInfo(beginOffset: Int, endOffset: Int): SourceRangeInfo =
|
||||
|
||||
Reference in New Issue
Block a user