Skip to content

Commit

Permalink
Release 1.7.2
Browse files Browse the repository at this point in the history
Fix a stack overflow bug
  • Loading branch information
seal committed Mar 12, 2018
1 parent 088259d commit f5e28d8
Show file tree
Hide file tree
Showing 12 changed files with 193 additions and 38 deletions.
2 changes: 1 addition & 1 deletion .idea/misc.xml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion JsonToKotlinClass.iml
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
<sourceFolder url="file://$MODULE_DIR$/test" isTestSource="true" />
<sourceFolder url="file://$MODULE_DIR$/resources" type="java-resource" />
</content>
<orderEntry type="jdk" jdkName="IntelliJ IDEA IU-171.4694.70" jdkType="IDEA JDK" />
<orderEntry type="inheritedJdk" />
<orderEntry type="sourceFolder" forTests="false" />
<orderEntry type="library" scope="TEST" name="com.winterbe:expekt:0.5.0" level="project" />
</component>
Expand Down
6 changes: 3 additions & 3 deletions resources/META-INF/plugin.xml
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
<idea-plugin>
<id>wu.seal.tool.jsontokotlin</id>
<name>JsonToKotlinClass</name>
<version>1.7.1</version>
<name>JSON To Kotlin Class (JsonToKotlinClass)</name>
<version>1.7.2</version>
<vendor email="[email protected]" url="https://www.github.com/wuseal">Seal</vendor>

<description><![CDATA[
Expand All @@ -15,7 +15,7 @@
]]></description>

<change-notes><![CDATA[
Rename back to JsonToKotlinClass for an Unknow exception cause the plugin unable to use on Android Studio.</br>
Fix a stack overflow bug</br>
1.Custom Annotation support multiple annotations on class and multiple annotations on property
,With this function you could add extract annotation on class like `@Parcelize`
,and also you could custom the annotation format to make it support `kotlinx.serializable`
Expand Down
19 changes: 12 additions & 7 deletions src/wu/seal/jsontokotlin/JsonToKotlinApplication.kt
Original file line number Diff line number Diff line change
@@ -1,26 +1,31 @@
package wu.seal.jsontokotlin

import com.intellij.openapi.components.ApplicationComponent
import wu.seal.jsontokotlin.feedback.PLUGIN_VERSION
import wu.seal.jsontokotlin.feedback.sendConfigInfo
import wu.seal.jsontokotlin.feedback.sendHistoryExceptionInfo
import wu.seal.jsontokotlin.feedback.sendHistoryActionInfo
import wu.seal.jsontokotlin.feedback.sendHistoryExceptionInfo
import wu.seal.jsontokotlin.utils.LogUtil

/**
*
* Created by Seal.wu on 2017/8/21.
*/

const val PLUGIN_VERSION = "1.7"

class JsonToKotlinApplication : ApplicationComponent {

override fun initComponent() {

println("init json to kotlin ")
LogUtil.i("init JSON To Kotlin Class version ==$PLUGIN_VERSION")

Thread() {
sendConfigInfo()
sendHistoryExceptionInfo()
sendHistoryActionInfo()
try {
sendConfigInfo()
sendHistoryExceptionInfo()
sendHistoryActionInfo()
} catch (e: Exception) {
LogUtil.e(e.message.toString(),e)
}
}.start()
}

Expand Down
44 changes: 24 additions & 20 deletions src/wu/seal/jsontokotlin/MakeKotlinClassAction.kt
Original file line number Diff line number Diff line change
Expand Up @@ -9,11 +9,9 @@ import com.intellij.openapi.editor.Document
import com.intellij.openapi.editor.Editor
import com.intellij.openapi.project.Project
import com.intellij.openapi.ui.Messages
import wu.seal.jsontokotlin.feedback.StartAction
import wu.seal.jsontokotlin.feedback.SuccessCompleteAction
import wu.seal.jsontokotlin.feedback.getUncaughtExceptionHandler
import wu.seal.jsontokotlin.feedback.sendActionInfo
import wu.seal.jsontokotlin.feedback.*
import wu.seal.jsontokotlin.ui.JsonInputDialog
import wu.seal.jsontokotlin.utils.LogUtil
import wu.seal.jsontokotlin.utils.executeCouldRollBackAction

import java.util.IllegalFormatFlagsException
Expand Down Expand Up @@ -70,7 +68,7 @@ class MakeKotlinClassAction : AnAction("MakeKotlinClass") {
}


} catch (e: Exception) {
} catch (e: Throwable) {
dealWithException(jsonString, e)
throw e
}
Expand Down Expand Up @@ -98,7 +96,7 @@ class MakeKotlinClassAction : AnAction("MakeKotlinClass") {
}.start()
}

private fun dealWithException(jsonString: String, e: Exception) {
private fun dealWithException(jsonString: String, e: Throwable) {
var jsonString1 = jsonString
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())
if (yes != Messages.YES) {
Expand Down Expand Up @@ -157,20 +155,26 @@ class MakeKotlinClassAction : AnAction("MakeKotlinClass") {
* if we could use it,then we would clean the kotlin file as it was new file without any class code .
*/
internal fun couldGetAndReuseClassNameInCurrentEditFileForInsertCode(editorText: String): Boolean {
var couldGetAndReuseClassNameInCurrentEditFileForInsertCode = false
val removeCommentEditorText = editorText.replace(Regex("/*\\*(.|\n)*\\*/"),"")
.replace(Regex("^(?:\\s*package |\\s*import ).*$",RegexOption.MULTILINE),"")
if ((removeCommentEditorText.indexOf("class") == removeCommentEditorText.lastIndexOf("class")
&& removeCommentEditorText.indexOf("class") != -1
&& removeCommentEditorText.substringAfter("class").contains("(").not()
&& removeCommentEditorText.substringAfter("class").contains(":").not()
&& removeCommentEditorText.substringAfter("class").contains("=").not())
||(removeCommentEditorText.indexOf("class") == removeCommentEditorText.lastIndexOf("class")
&& removeCommentEditorText.indexOf("class") != -1
&&removeCommentEditorText.substringAfter("class").substringAfter("(")
.replace(Regex("\\s"),"").let { it.equals(")")||it.equals("){}") })) {
couldGetAndReuseClassNameInCurrentEditFileForInsertCode = true
try {
var couldGetAndReuseClassNameInCurrentEditFileForInsertCode = false
val removeDocComment = editorText.replace(Regex("/\\*\\*(.|\n)*\\*/",RegexOption.MULTILINE), "")
val removeDocCommentAndPackageDeclareText = removeDocComment
.replace(Regex("^(?:\\s*package |\\s*import ).*$", RegexOption.MULTILINE), "")
if ((removeDocCommentAndPackageDeclareText.indexOf("class") == removeDocCommentAndPackageDeclareText.lastIndexOf("class")
&& removeDocCommentAndPackageDeclareText.indexOf("class") != -1
&& removeDocCommentAndPackageDeclareText.substringAfter("class").contains("(").not()
&& removeDocCommentAndPackageDeclareText.substringAfter("class").contains(":").not()
&& removeDocCommentAndPackageDeclareText.substringAfter("class").contains("=").not())
|| (removeDocCommentAndPackageDeclareText.indexOf("class") == removeDocCommentAndPackageDeclareText.lastIndexOf("class")
&& removeDocCommentAndPackageDeclareText.indexOf("class") != -1
&& removeDocCommentAndPackageDeclareText.substringAfter("class").substringAfter("(")
.replace(Regex("\\s"), "").let { it.equals(")") || it.equals("){}") })) {
couldGetAndReuseClassNameInCurrentEditFileForInsertCode = true
}
return couldGetAndReuseClassNameInCurrentEditFileForInsertCode
} catch (e:Throwable) {
LogUtil.e(e.message.toString(), e)
return false
}
return couldGetAndReuseClassNameInCurrentEditFileForInsertCode
}
}
1 change: 0 additions & 1 deletion src/wu/seal/jsontokotlin/feedback/Actions.kt
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
package wu.seal.jsontokotlin.feedback

import wu.seal.jsontokotlin.PLUGIN_VERSION
import java.text.SimpleDateFormat
import java.util.*

Expand Down
1 change: 0 additions & 1 deletion src/wu/seal/jsontokotlin/feedback/Datas.kt
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
package wu.seal.jsontokotlin.feedback

import wu.seal.jsontokotlin.ConfigManager
import wu.seal.jsontokotlin.PLUGIN_VERSION
import java.text.SimpleDateFormat
import java.util.*

Expand Down
1 change: 0 additions & 1 deletion src/wu/seal/jsontokotlin/feedback/ExceptionHandler.kt
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
package wu.seal.jsontokotlin.feedback

import wu.seal.jsontokotlin.PLUGIN_VERSION
import java.io.PrintWriter
import java.io.StringWriter
import java.text.SimpleDateFormat
Expand Down
11 changes: 10 additions & 1 deletion src/wu/seal/jsontokotlin/feedback/Flag.kt
Original file line number Diff line number Diff line change
@@ -1,15 +1,24 @@
package wu.seal.jsontokotlin.feedback

import com.intellij.ide.plugins.PluginManager
import com.intellij.openapi.extensions.PluginId
import wu.seal.jsontokotlin.ConfigManager
import wu.seal.jsontokotlin.test.TestConfig

/**
* Flag relative
* Created by Seal.Wu on 2017/9/25.
*/

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

val UUID = if (ConfigManager.userUUID.isEmpty()) {
val uuid = java.util.UUID.randomUUID().toString()
ConfigManager.userUUID = uuid
uuid
} else ConfigManager.userUUID
} else ConfigManager.userUUID


val PLUGIN_NAME = "JSON To Kotlin Class"
36 changes: 36 additions & 0 deletions src/wu/seal/jsontokotlin/utils/LogUtil.kt
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
package wu.seal.jsontokotlin.utils

import com.intellij.openapi.diagnostic.LoggerRt
import wu.seal.jsontokotlin.feedback.PLUGIN_NAME
import wu.seal.jsontokotlin.test.TestConfig
import java.util.logging.Logger

/**
* Created by Seal.Wu on 2018/3/12.
*/
internal object LogUtil {

fun i(info: String) {
if (TestConfig.isTestModel) {
Logger.getLogger(PLUGIN_NAME).info(info)
} else {
LoggerRt.getInstance(PLUGIN_NAME).info(info)
}
}

fun w(warning: String) {
if (TestConfig.isTestModel) {
Logger.getLogger(PLUGIN_NAME).warning(warning)
} else {
LoggerRt.getInstance(PLUGIN_NAME).warn(warning)
}
}

fun e(message: String, e: Throwable) {
if (TestConfig.isTestModel) {
e.printStackTrace()
} else {
LoggerRt.getInstance(PLUGIN_NAME).error(message,e)
}
}
}
1 change: 1 addition & 0 deletions test/wu/seal/jsontokotlin/KPropertyTest.kt
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,7 @@ class KPropertyTest {
}

println("getPropertyStringBlock:\n$propertyStringBlock")

}

}
Expand Down
107 changes: 105 additions & 2 deletions test/wu/seal/jsontokotlin/MakeKotlinClassActionTest.kt
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ class MakeKotlinClassActionTest {

@Test
fun before() {
TestConfig.isTestModel = true
TestConfig.setToTestInitState()
}

@Test
Expand All @@ -19,6 +19,15 @@ class MakeKotlinClassActionTest {

}

@Test
fun couldGetAndReuseClassNameInCurrentEditFileForInsertCodeForSpecialString() {
TestConfig.setToTestInitState()
val action = MakeKotlinClassAction()

action.couldGetAndReuseClassNameInCurrentEditFileForInsertCode(specialString).should.be.`false`

}

@Test
fun couldGetAndReuseClassNameInCurrentEditFileForInsertCodeForOnlyPackageNameDeclare() {
val action = MakeKotlinClassAction()
Expand Down Expand Up @@ -232,6 +241,7 @@ class MakeKotlinClassActionTest {
class Test(){ }"""
action.getCleanText(emptyString).trim().should.be.equal("package wu.seal.jsontokotlin.supporter")
}

@Test
fun getCleanTextForPackageAndOnlyOneClassNameWithCommentContainsClassStringDeclare() {
val action = MakeKotlinClassAction()
Expand All @@ -244,7 +254,7 @@ class MakeKotlinClassActionTest {
class Test
"""
action.getCleanText(emptyString).trim().should.be.equal(
"""
"""
package wu.seal.jsontokotlin.supporter
/**
*
Expand Down Expand Up @@ -291,4 +301,97 @@ class MakeKotlinClassActionTest {
*/
import wu.seal.jsontokotlinclass.test.TestConfig.isTestModel""".trim())
}

private val specialString = """package cn.com.iresearch.phonemonitor;
import android.app.Activity;
import android.os.Bundle;
import android.support.annotation.Nullable;
import android.support.v4.app.DialogFragment;
import android.support.v4.app.FragmentActivity;
import android.support.v4.app.FragmentManager;
import android.support.v4.app.FragmentTransaction;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.AdapterView;
import android.widget.Button;
import android.widget.FrameLayout;
import android.widget.ImageView;
import android.widget.LinearLayout;
import android.widget.ListAdapter;
import android.widget.ListView;
import android.widget.TextView;
import com.dh.foundation.utils.StringUtils;
import butterknife.Bind;
import butterknife.ButterKnife;
import butterknife.OnClick;
import cn.com.iresearch.phonemonitor.diaoyantong.R;
/**
* 对话框碎片
* Created By: Seal.Wu
* Date: 2016/4/8
* Time: 14:32
*/
public class ViewDialogFragment extends DialogFragment {
@Bind(R.id.tv_tips)
TextView tvTips;
@Bind(R.id.btn_left)
Button btnLeft;
@Bind(R.id.btn_right)
Button btnRight;
@Bind(R.id.listView)
ListView listView;
@Bind(R.id.spacer)
View spacer;
@Bind(R.id.ll_btn_layout)
LinearLayout llBtnLayout;
@Bind(R.id.line_bt_btn)
ImageView line;
@Bind(R.id.fl_tips)
LinearLayout flTips;
private Runnable runnable;
private View customView;
@Nullable
@Override
public View onCreateView(LayoutInflater inflater, @Nullable ViewGroup container, @Nullable Bundle savedInstanceState) {
if (customView != null) {
return customView;
}
View view = inflater.inflate(R.layout.fragment_dialog, container, false);
ButterKnife.bind(this, view);
if (runnable != null) {
runnable.run();
}
return view;
}
@Override
public void onDestroyView() {
super.onDestroyView();
ButterKnife.unbind(this);
}
@OnClick({R.id.btn_left, R.id.btn_right})
public void onClick(View view) {
switch (view.getId()) {
case R.id.btn_left:
break;
case R.id.btn_right:
break;
}
}
}
"""
}

0 comments on commit f5e28d8

Please sign in to comment.