Skip to content

Commit 6bd6fe2

Browse files
committed
refactor(kotlin): improve KotlinMethodContextBuilder
- Refactored the `KotlinMethodContextBuilder` class in the `kotlin` package. - Improved the logic for extracting a substring from the `text` variable. - Added a check to ensure that `docEnd` is less than `startOffsetInParent` before extracting the substring.
1 parent 016fe00 commit 6bd6fe2

File tree

1 file changed

+5
-2
lines changed

1 file changed

+5
-2
lines changed

kotlin/src/main/kotlin/cc/unitmesh/kotlin/context/KotlinMethodContextBuilder.kt

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -53,8 +53,11 @@ class KotlinMethodContextBuilder : MethodContextBuilder {
5353
val docEnd = ktNamedFunction.docComment?.endOffset ?: 0
5454

5555
val text = ktNamedFunction.text
56-
val substring = text.substring(docEnd, startOffsetInParent)
57-
return substring.replace('\n', ' ').trim()
56+
if (docEnd < startOffsetInParent) {
57+
return text.substring(docEnd, startOffsetInParent)
58+
}
59+
60+
return text.substring(docEnd, startOffsetInParent)
5861
}
5962
}
6063
}

0 commit comments

Comments
 (0)