Skip to content

Commit f5e28d8

Browse files
author
seal
committed
Release 1.7.2
Fix a stack overflow bug
1 parent 088259d commit f5e28d8

File tree

12 files changed

+193
-38
lines changed

12 files changed

+193
-38
lines changed

.idea/misc.xml

Lines changed: 1 addition & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

JsonToKotlinClass.iml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@
88
<sourceFolder url="file://$MODULE_DIR$/test" isTestSource="true" />
99
<sourceFolder url="file://$MODULE_DIR$/resources" type="java-resource" />
1010
</content>
11-
<orderEntry type="jdk" jdkName="IntelliJ IDEA IU-171.4694.70" jdkType="IDEA JDK" />
11+
<orderEntry type="inheritedJdk" />
1212
<orderEntry type="sourceFolder" forTests="false" />
1313
<orderEntry type="library" scope="TEST" name="com.winterbe:expekt:0.5.0" level="project" />
1414
</component>

resources/META-INF/plugin.xml

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
<idea-plugin>
22
<id>wu.seal.tool.jsontokotlin</id>
3-
<name>JsonToKotlinClass</name>
4-
<version>1.7.1</version>
3+
<name>JSON To Kotlin Class (JsonToKotlinClass)</name>
4+
<version>1.7.2</version>
55
<vendor email="[email protected]" url="https://www.github.com/wuseal">Seal</vendor>
66

77
<description><![CDATA[
@@ -15,7 +15,7 @@
1515
]]></description>
1616

1717
<change-notes><![CDATA[
18-
Rename back to JsonToKotlinClass for an Unknow exception cause the plugin unable to use on Android Studio.</br>
18+
Fix a stack overflow bug</br>
1919
1.Custom Annotation support multiple annotations on class and multiple annotations on property
2020
,With this function you could add extract annotation on class like `@Parcelize`
2121
,and also you could custom the annotation format to make it support `kotlinx.serializable`

src/wu/seal/jsontokotlin/JsonToKotlinApplication.kt

Lines changed: 12 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,26 +1,31 @@
11
package wu.seal.jsontokotlin
22

33
import com.intellij.openapi.components.ApplicationComponent
4+
import wu.seal.jsontokotlin.feedback.PLUGIN_VERSION
45
import wu.seal.jsontokotlin.feedback.sendConfigInfo
5-
import wu.seal.jsontokotlin.feedback.sendHistoryExceptionInfo
66
import wu.seal.jsontokotlin.feedback.sendHistoryActionInfo
7+
import wu.seal.jsontokotlin.feedback.sendHistoryExceptionInfo
8+
import wu.seal.jsontokotlin.utils.LogUtil
79

810
/**
911
*
1012
* Created by Seal.wu on 2017/8/21.
1113
*/
1214

13-
const val PLUGIN_VERSION = "1.7"
14-
1515
class JsonToKotlinApplication : ApplicationComponent {
1616

1717
override fun initComponent() {
1818

19-
println("init json to kotlin ")
19+
LogUtil.i("init JSON To Kotlin Class version ==$PLUGIN_VERSION")
20+
2021
Thread() {
21-
sendConfigInfo()
22-
sendHistoryExceptionInfo()
23-
sendHistoryActionInfo()
22+
try {
23+
sendConfigInfo()
24+
sendHistoryExceptionInfo()
25+
sendHistoryActionInfo()
26+
} catch (e: Exception) {
27+
LogUtil.e(e.message.toString(),e)
28+
}
2429
}.start()
2530
}
2631

src/wu/seal/jsontokotlin/MakeKotlinClassAction.kt

Lines changed: 24 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -9,11 +9,9 @@ import com.intellij.openapi.editor.Document
99
import com.intellij.openapi.editor.Editor
1010
import com.intellij.openapi.project.Project
1111
import 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.*
1613
import wu.seal.jsontokotlin.ui.JsonInputDialog
14+
import wu.seal.jsontokotlin.utils.LogUtil
1715
import wu.seal.jsontokotlin.utils.executeCouldRollBackAction
1816

1917
import 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.\nAgree 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
}

src/wu/seal/jsontokotlin/feedback/Actions.kt

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,5 @@
11
package wu.seal.jsontokotlin.feedback
22

3-
import wu.seal.jsontokotlin.PLUGIN_VERSION
43
import java.text.SimpleDateFormat
54
import java.util.*
65

src/wu/seal/jsontokotlin/feedback/Datas.kt

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,6 @@
11
package wu.seal.jsontokotlin.feedback
22

33
import wu.seal.jsontokotlin.ConfigManager
4-
import wu.seal.jsontokotlin.PLUGIN_VERSION
54
import java.text.SimpleDateFormat
65
import java.util.*
76

src/wu/seal/jsontokotlin/feedback/ExceptionHandler.kt

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,5 @@
11
package wu.seal.jsontokotlin.feedback
22

3-
import wu.seal.jsontokotlin.PLUGIN_VERSION
43
import java.io.PrintWriter
54
import java.io.StringWriter
65
import java.text.SimpleDateFormat
Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,15 +1,24 @@
11
package wu.seal.jsontokotlin.feedback
22

3+
import com.intellij.ide.plugins.PluginManager
4+
import com.intellij.openapi.extensions.PluginId
35
import wu.seal.jsontokotlin.ConfigManager
6+
import wu.seal.jsontokotlin.test.TestConfig
47

58
/**
69
* Flag relative
710
* Created by Seal.Wu on 2017/9/25.
811
*/
912

13+
val PLUGIN_VERSION = if (TestConfig.isTestModel.not()){
14+
PluginManager.getPlugin(PluginId.getId("wu.seal.tool.jsontokotlin"))?.version.toString()
15+
} else "1.X"
1016

1117
val UUID = if (ConfigManager.userUUID.isEmpty()) {
1218
val uuid = java.util.UUID.randomUUID().toString()
1319
ConfigManager.userUUID = uuid
1420
uuid
15-
} else ConfigManager.userUUID
21+
} else ConfigManager.userUUID
22+
23+
24+
val PLUGIN_NAME = "JSON To Kotlin Class"
Lines changed: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,36 @@
1+
package wu.seal.jsontokotlin.utils
2+
3+
import com.intellij.openapi.diagnostic.LoggerRt
4+
import wu.seal.jsontokotlin.feedback.PLUGIN_NAME
5+
import wu.seal.jsontokotlin.test.TestConfig
6+
import java.util.logging.Logger
7+
8+
/**
9+
* Created by Seal.Wu on 2018/3/12.
10+
*/
11+
internal object LogUtil {
12+
13+
fun i(info: String) {
14+
if (TestConfig.isTestModel) {
15+
Logger.getLogger(PLUGIN_NAME).info(info)
16+
} else {
17+
LoggerRt.getInstance(PLUGIN_NAME).info(info)
18+
}
19+
}
20+
21+
fun w(warning: String) {
22+
if (TestConfig.isTestModel) {
23+
Logger.getLogger(PLUGIN_NAME).warning(warning)
24+
} else {
25+
LoggerRt.getInstance(PLUGIN_NAME).warn(warning)
26+
}
27+
}
28+
29+
fun e(message: String, e: Throwable) {
30+
if (TestConfig.isTestModel) {
31+
e.printStackTrace()
32+
} else {
33+
LoggerRt.getInstance(PLUGIN_NAME).error(message,e)
34+
}
35+
}
36+
}

0 commit comments

Comments
 (0)