Skip to content

Commit 418cc29

Browse files
committed
fix(ErrorMessageProcessor): simplify null-check logic and enhance readability.
1 parent b28ad10 commit 418cc29

File tree

1 file changed

+9
-14
lines changed

1 file changed

+9
-14
lines changed

src/main/kotlin/com/intellij/temporary/error/ErrorMessageProcessor.kt

Lines changed: 9 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -27,31 +27,26 @@ object ErrorMessageProcessor {
2727
val editor = event.getData(CommonDataKeys.EDITOR) ?: return null
2828
val selectionModel = editor.selectionModel
2929
val text = selectionModel.selectedText ?: return null
30-
val selectionStartPosition = selectionModel.selectionStartPosition ?: return null
30+
val position = selectionModel.selectionStartPosition ?: return null
3131

32-
val lineFrom = selectionStartPosition.line
33-
val selectionEndPosition = selectionModel.selectionEndPosition ?: return null
34-
val lineTo = selectionEndPosition.line
35-
return ErrorDescription(text, lineFrom, lineTo, editor)
32+
val endPosition = selectionModel.selectionEndPosition ?: return null
33+
return ErrorDescription(text, position.line, endPosition.line, editor)
3634
}
3735

3836
private fun extractTextFromRunPanel(
3937
project: Project, lineFrom: Int,
4038
lineTo: Int?,
4139
consoleEditor: Editor?,
4240
): String? {
43-
var editor = consoleEditor
44-
if (editor == null) editor = getConsoleEditor(project)
45-
if (editor == null) return null
46-
41+
val editor = consoleEditor ?: getConsoleEditor(project) ?: return null
4742
val document = editor.document
4843

49-
return document.getText(
50-
TextRange(
51-
document.getLineStartOffset(lineFrom),
52-
document.getLineEndOffset(lineTo ?: (document.lineCount - 1))
53-
)
44+
val textRange = TextRange(
45+
document.getLineStartOffset(lineFrom),
46+
document.getLineEndOffset(lineTo ?: (document.lineCount - 1))
5447
)
48+
49+
return document.getText(textRange)
5550
}
5651

5752
private fun getConsoleEditor(project: Project): Editor? {

0 commit comments

Comments
 (0)