@@ -42,7 +42,7 @@ class MakeKotlinClassAction : AnAction("MakeKotlinClass") {
4242 */
4343 var tempClassName = " "
4444 val couldGetAndReuseClassNameInCurrentEditFileForInsertCode =
45- couldGetAndReuseClassNameInCurrentEditFileForInsertCode(editorText)
45+ couldGetAndReuseClassNameInCurrentEditFileForInsertCode(editorText)
4646
4747 if (couldGetAndReuseClassNameInCurrentEditFileForInsertCode) {
4848 /* *
@@ -54,9 +54,9 @@ class MakeKotlinClassAction : AnAction("MakeKotlinClass") {
5454 inputDialog.show()
5555 val className = inputDialog.getClassName()
5656 val inputString = inputDialog.inputString
57- val json = if (inputString?.startsWith(" http" ) == true ) {
57+ val json = if (inputString?.startsWith(" http" ) == true ) {
5858 URL (inputString).readText()
59- } else inputString
59+ } else inputString
6060 if (json == null || json.isEmpty()) {
6161 return
6262 }
@@ -75,16 +75,18 @@ class MakeKotlinClassAction : AnAction("MakeKotlinClass") {
7575 }
7676
7777
78+ } catch (e: UnSupportJsonException ) {
79+ Messages .showInfoMessage(" No need converting, just use List<Any> is enough for your json string" , " Tip" )
7880 } catch (e: Throwable ) {
7981 dealWithException(jsonString, e)
8082 throw e
8183 }
8284 }
8385
8486 private fun reuseClassName (
85- couldGetAndReuseClassNameInCurrentEditFileForInserCode : Boolean ,
86- className : String ,
87- tempClassName : String
87+ couldGetAndReuseClassNameInCurrentEditFileForInserCode : Boolean ,
88+ className : String ,
89+ tempClassName : String
8890 ) = couldGetAndReuseClassNameInCurrentEditFileForInserCode && className == tempClassName
8991
9092 private fun couldNotInsertCode (editor : Editor ? ): Boolean {
@@ -108,11 +110,11 @@ class MakeKotlinClassAction : AnAction("MakeKotlinClass") {
108110 }
109111
110112 private fun insertKotlinCode (
111- project : Project ? ,
112- document : Document ,
113- className : String ,
114- jsonString : String ,
115- caret : Caret ?
113+ project : Project ? ,
114+ document : Document ,
115+ className : String ,
116+ jsonString : String ,
117+ caret : Caret ?
116118 ): Boolean {
117119 ImportClassWriter .insertImportClassCode(project, document)
118120
@@ -138,8 +140,8 @@ class MakeKotlinClassAction : AnAction("MakeKotlinClass") {
138140 offset = document.textLength
139141 }
140142 document.insertString(
141- Math .max(offset, 0 ),
142- ClassCodeFilter .removeDuplicateClassCode(codeMaker.makeKotlinDataClassCode())
143+ Math .max(offset, 0 ),
144+ ClassCodeFilter .removeDuplicateClassCode(codeMaker.makeKotlinDataClassCode())
143145 )
144146 }
145147 return true
@@ -153,12 +155,12 @@ class MakeKotlinClassAction : AnAction("MakeKotlinClass") {
153155 fun getCleanText (editorText : String ): String {
154156 val tempCleanText = editorText.substringBeforeLast(" class" )
155157 val cleanText =
156- if (tempCleanText.trim().endsWith(" data" )) tempCleanText.trim().removeSuffix(" data" ) else tempCleanText
158+ if (tempCleanText.trim().endsWith(" data" )) tempCleanText.trim().removeSuffix(" data" ) else tempCleanText
157159 return cleanText
158160 }
159161
160162 fun getCurrentEditFileTemClassName (editorText : String ) = editorText.substringAfterLast(" class" )
161- .substringBefore(" (" ).substringBefore(" {" ).trim()
163+ .substringBefore(" (" ).substringBefore(" {" ).trim()
162164
163165 /* *
164166 * whether we could reuse current class name declared in the edit file for inserting data class code
@@ -169,20 +171,20 @@ class MakeKotlinClassAction : AnAction("MakeKotlinClass") {
169171 var couldGetAndReuseClassNameInCurrentEditFileForInsertCode = false
170172 val removeDocComment = editorText.replace(Regex (" /\\ *\\ *(.|\n )*\\ */" , RegexOption .MULTILINE ), " " )
171173 val removeDocCommentAndPackageDeclareText = removeDocComment
172- .replace(Regex (" ^(?:\\ s*package |\\ s*import ).*$" , RegexOption .MULTILINE ), " " )
174+ .replace(Regex (" ^(?:\\ s*package |\\ s*import ).*$" , RegexOption .MULTILINE ), " " )
173175 if ((removeDocCommentAndPackageDeclareText.indexOf(" class" ) == removeDocCommentAndPackageDeclareText.lastIndexOf(
174- " class"
175- )
176- && removeDocCommentAndPackageDeclareText.indexOf(" class" ) != - 1
177- && removeDocCommentAndPackageDeclareText.substringAfter(" class" ).contains(" (" ).not ()
178- && removeDocCommentAndPackageDeclareText.substringAfter(" class" ).contains(" :" ).not ()
179- && removeDocCommentAndPackageDeclareText.substringAfter(" class" ).contains(" =" ).not ())
180- || (removeDocCommentAndPackageDeclareText.indexOf(" class" ) == removeDocCommentAndPackageDeclareText.lastIndexOf(
181- " class"
182- )
183- && removeDocCommentAndPackageDeclareText.indexOf(" class" ) != - 1
184- && removeDocCommentAndPackageDeclareText.substringAfter(" class" ).substringAfter(" (" )
185- .replace(Regex (" \\ s" ), " " ).let { it.equals(" )" ) || it.equals(" ){}" ) })
176+ " class"
177+ )
178+ && removeDocCommentAndPackageDeclareText.indexOf(" class" ) != - 1
179+ && removeDocCommentAndPackageDeclareText.substringAfter(" class" ).contains(" (" ).not ()
180+ && removeDocCommentAndPackageDeclareText.substringAfter(" class" ).contains(" :" ).not ()
181+ && removeDocCommentAndPackageDeclareText.substringAfter(" class" ).contains(" =" ).not ())
182+ || (removeDocCommentAndPackageDeclareText.indexOf(" class" ) == removeDocCommentAndPackageDeclareText.lastIndexOf(
183+ " class"
184+ )
185+ && removeDocCommentAndPackageDeclareText.indexOf(" class" ) != - 1
186+ && removeDocCommentAndPackageDeclareText.substringAfter(" class" ).substringAfter(" (" )
187+ .replace(Regex (" \\ s" ), " " ).let { it.equals(" )" ) || it.equals(" ){}" ) })
186188 ) {
187189 couldGetAndReuseClassNameInCurrentEditFileForInsertCode = true
188190 }
0 commit comments