Skip to content

Commit

Permalink
Revert "Fix bug #83"
Browse files Browse the repository at this point in the history
This reverts commit 79b22d7
  • Loading branch information
sealkingking committed Dec 23, 2018
1 parent 3e69d41 commit cb6c303
Show file tree
Hide file tree
Showing 2 changed files with 4 additions and 30 deletions.
16 changes: 4 additions & 12 deletions src/main/kotlin/wu/seal/jsontokotlin/ImportClassWriter.kt
Original file line number Diff line number Diff line change
Expand Up @@ -78,19 +78,11 @@ object ImportClassWriter : IImportClassWriter {

if (importClassLineString !in text) {

val packageIndex = try {
"^[\\s]*package".toRegex(RegexOption.MULTILINE).find(text)!!.range.endInclusive
} catch (e: Exception) {
-1
}
val lastImportKeywordIndex = try {
"^[\\s]*import".toRegex(RegexOption.MULTILINE).findAll(text).last().range.endInclusive
} catch (e: Exception) {
-1
}
val index = Math.max(lastImportKeywordIndex, packageIndex)
val packageIndex = text.indexOf("package ")
val importIndex = Math.max(text.lastIndexOf("import"), packageIndex)
val insertIndex =
if (index == -1) 0 else editFile.getLineEndOffset(editFile.getLineNumber(index))
if (importIndex == -1) 0 else editFile.getLineEndOffset(editFile.getLineNumber(importIndex))


executeCouldRollBackAction(project) {
editFile.insertString(insertIndex, "\n" + importClassLineString + "\n")
Expand Down
18 changes: 0 additions & 18 deletions src/main/kotlin/wu/seal/jsontokotlin/MakeKotlinClassAction.kt
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,6 @@ import wu.seal.jsontokotlin.feedback.sendActionInfo
import wu.seal.jsontokotlin.ui.JsonInputDialog
import wu.seal.jsontokotlin.utils.ClassCodeFilter
import wu.seal.jsontokotlin.utils.executeCouldRollBackAction
import java.awt.SystemColor.text
import java.net.URL
import java.util.*

Expand Down Expand Up @@ -145,23 +144,6 @@ class MakeKotlinClassAction : AnAction("MakeKotlinClass") {
if (offset == 0) {
offset = document.textLength
}
val lastPackageKeywordLineEndIndex = try {
"^[\\s]*package.+\n$".toRegex(RegexOption.MULTILINE).findAll(document.text).last().range.endInclusive
} catch (e: Exception) {
-1
}
val lastImportKeywordLineEndIndex = try {
"^[\\s]*import.+\n$".toRegex(RegexOption.MULTILINE).findAll(document.text).last().range.endInclusive
} catch (e: Exception) {
-1
}
if (offset < lastPackageKeywordLineEndIndex) {
offset = lastPackageKeywordLineEndIndex + 1
}
if (offset < lastImportKeywordLineEndIndex) {
offset = lastImportKeywordLineEndIndex + 1
}

} else {
offset = document.textLength
}
Expand Down

0 comments on commit cb6c303

Please sign in to comment.