File tree Expand file tree Collapse file tree 2 files changed +4
-30
lines changed
src/main/kotlin/wu/seal/jsontokotlin Expand file tree Collapse file tree 2 files changed +4
-30
lines changed Original file line number Diff line number Diff line change @@ -78,19 +78,11 @@ object ImportClassWriter : IImportClassWriter {
7878
7979 if (importClassLineString !in text) {
8080
81- val packageIndex = try {
82- " ^[\\ s]*package" .toRegex(RegexOption .MULTILINE ).find(text)!! .range.endInclusive
83- } catch (e: Exception ) {
84- - 1
85- }
86- val lastImportKeywordIndex = try {
87- " ^[\\ s]*import" .toRegex(RegexOption .MULTILINE ).findAll(text).last().range.endInclusive
88- } catch (e: Exception ) {
89- - 1
90- }
91- val index = Math .max(lastImportKeywordIndex, packageIndex)
81+ val packageIndex = text.indexOf(" package " )
82+ val importIndex = Math .max(text.lastIndexOf(" import" ), packageIndex)
9283 val insertIndex =
93- if (index == - 1 ) 0 else editFile.getLineEndOffset(editFile.getLineNumber(index))
84+ if (importIndex == - 1 ) 0 else editFile.getLineEndOffset(editFile.getLineNumber(importIndex))
85+
9486
9587 executeCouldRollBackAction(project) {
9688 editFile.insertString(insertIndex, " \n " + importClassLineString + " \n " )
Original file line number Diff line number Diff line change @@ -16,7 +16,6 @@ import wu.seal.jsontokotlin.feedback.sendActionInfo
1616import wu.seal.jsontokotlin.ui.JsonInputDialog
1717import wu.seal.jsontokotlin.utils.ClassCodeFilter
1818import wu.seal.jsontokotlin.utils.executeCouldRollBackAction
19- import java.awt.SystemColor.text
2019import java.net.URL
2120import java.util.*
2221
@@ -145,23 +144,6 @@ class MakeKotlinClassAction : AnAction("MakeKotlinClass") {
145144 if (offset == 0 ) {
146145 offset = document.textLength
147146 }
148- val lastPackageKeywordLineEndIndex = try {
149- " ^[\\ s]*package.+\n $" .toRegex(RegexOption .MULTILINE ).findAll(document.text).last().range.endInclusive
150- } catch (e: Exception ) {
151- - 1
152- }
153- val lastImportKeywordLineEndIndex = try {
154- " ^[\\ s]*import.+\n $" .toRegex(RegexOption .MULTILINE ).findAll(document.text).last().range.endInclusive
155- } catch (e: Exception ) {
156- - 1
157- }
158- if (offset < lastPackageKeywordLineEndIndex) {
159- offset = lastPackageKeywordLineEndIndex + 1
160- }
161- if (offset < lastImportKeywordLineEndIndex) {
162- offset = lastImportKeywordLineEndIndex + 1
163- }
164-
165147 } else {
166148 offset = document.textLength
167149 }
You can’t perform that action at this time.
0 commit comments