@@ -9,11 +9,9 @@ import com.intellij.openapi.editor.Document
99import com.intellij.openapi.editor.Editor
1010import com.intellij.openapi.project.Project
1111import com.intellij.openapi.ui.Messages
12- import wu.seal.jsontokotlin.feedback.StartAction
13- import wu.seal.jsontokotlin.feedback.SuccessCompleteAction
14- import wu.seal.jsontokotlin.feedback.getUncaughtExceptionHandler
15- import wu.seal.jsontokotlin.feedback.sendActionInfo
12+ import wu.seal.jsontokotlin.feedback.*
1613import wu.seal.jsontokotlin.ui.JsonInputDialog
14+ import wu.seal.jsontokotlin.utils.LogUtil
1715import wu.seal.jsontokotlin.utils.executeCouldRollBackAction
1816
1917import java.util.IllegalFormatFlagsException
@@ -70,7 +68,7 @@ class MakeKotlinClassAction : AnAction("MakeKotlinClass") {
7068 }
7169
7270
73- } catch (e: Exception ) {
71+ } catch (e: Throwable ) {
7472 dealWithException(jsonString, e)
7573 throw e
7674 }
@@ -98,7 +96,7 @@ class MakeKotlinClassAction : AnAction("MakeKotlinClass") {
9896 }.start()
9997 }
10098
101- private fun dealWithException (jsonString : String , e : Exception ) {
99+ private fun dealWithException (jsonString : String , e : Throwable ) {
102100 var jsonString1 = jsonString
103101 val yes = Messages .showYesNoDialog(" Some thing execute wrong.\n Agree with publishing your JSON text to help us to solve the problem?" , " Excuse me" , Messages .getQuestionIcon())
104102 if (yes != Messages .YES ) {
@@ -157,20 +155,26 @@ class MakeKotlinClassAction : AnAction("MakeKotlinClass") {
157155 * if we could use it,then we would clean the kotlin file as it was new file without any class code .
158156 */
159157 internal fun couldGetAndReuseClassNameInCurrentEditFileForInsertCode (editorText : String ): Boolean {
160- var couldGetAndReuseClassNameInCurrentEditFileForInsertCode = false
161- val removeCommentEditorText = editorText.replace(Regex (" /*\\ *(.|\n )*\\ */" )," " )
162- .replace(Regex (" ^(?:\\ s*package |\\ s*import ).*$" ,RegexOption .MULTILINE )," " )
163- if ((removeCommentEditorText.indexOf(" class" ) == removeCommentEditorText.lastIndexOf(" class" )
164- && removeCommentEditorText.indexOf(" class" ) != - 1
165- && removeCommentEditorText.substringAfter(" class" ).contains(" (" ).not ()
166- && removeCommentEditorText.substringAfter(" class" ).contains(" :" ).not ()
167- && removeCommentEditorText.substringAfter(" class" ).contains(" =" ).not ())
168- || (removeCommentEditorText.indexOf(" class" ) == removeCommentEditorText.lastIndexOf(" class" )
169- && removeCommentEditorText.indexOf(" class" ) != - 1
170- && removeCommentEditorText.substringAfter(" class" ).substringAfter(" (" )
171- .replace(Regex (" \\ s" )," " ).let { it.equals(" )" )|| it.equals(" ){}" ) })) {
172- couldGetAndReuseClassNameInCurrentEditFileForInsertCode = true
158+ try {
159+ var couldGetAndReuseClassNameInCurrentEditFileForInsertCode = false
160+ val removeDocComment = editorText.replace(Regex (" /\\ *\\ *(.|\n )*\\ */" ,RegexOption .MULTILINE ), " " )
161+ val removeDocCommentAndPackageDeclareText = removeDocComment
162+ .replace(Regex (" ^(?:\\ s*package |\\ s*import ).*$" , RegexOption .MULTILINE ), " " )
163+ if ((removeDocCommentAndPackageDeclareText.indexOf(" class" ) == removeDocCommentAndPackageDeclareText.lastIndexOf(" class" )
164+ && removeDocCommentAndPackageDeclareText.indexOf(" class" ) != - 1
165+ && removeDocCommentAndPackageDeclareText.substringAfter(" class" ).contains(" (" ).not ()
166+ && removeDocCommentAndPackageDeclareText.substringAfter(" class" ).contains(" :" ).not ()
167+ && removeDocCommentAndPackageDeclareText.substringAfter(" class" ).contains(" =" ).not ())
168+ || (removeDocCommentAndPackageDeclareText.indexOf(" class" ) == removeDocCommentAndPackageDeclareText.lastIndexOf(" class" )
169+ && removeDocCommentAndPackageDeclareText.indexOf(" class" ) != - 1
170+ && removeDocCommentAndPackageDeclareText.substringAfter(" class" ).substringAfter(" (" )
171+ .replace(Regex (" \\ s" ), " " ).let { it.equals(" )" ) || it.equals(" ){}" ) })) {
172+ couldGetAndReuseClassNameInCurrentEditFileForInsertCode = true
173+ }
174+ return couldGetAndReuseClassNameInCurrentEditFileForInsertCode
175+ } catch (e: Throwable ) {
176+ LogUtil .e(e.message.toString(), e)
177+ return false
173178 }
174- return couldGetAndReuseClassNameInCurrentEditFileForInsertCode
175179 }
176180}
0 commit comments