From fbb3788e55dacb324cc69011d3e55ef33029104d Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E5=BC=A0=E7=91=9E=E5=AE=87?= <15201231801@163.com> Date: Sun, 29 Dec 2019 16:15:19 +0800 Subject: [PATCH] 3.1.5 release --- README.md | 2 +- gradle.properties | 2 +- .../com/ruiyu/beanfactory/FlutterBeanFactoryAction.kt | 10 +++++----- src/main/java/com/ruiyu/jsontodart/ModelGenerator.kt | 6 ++++-- src/main/java/com/ruiyu/jsontodart/utils/Helper.kt | 6 ++++-- src/main/resources/META-INF/plugin.xml | 10 ++++------ 6 files changed, 19 insertions(+), 17 deletions(-) diff --git a/README.md b/README.md index 10170fc..e45eed8 100644 --- a/README.md +++ b/README.md @@ -13,7 +13,7 @@ What I do is generate dart beans based on json, as well as generics parameters a * Search 'FlutterJsonBeanFactory' in Intellij Idea Plugin Repositroy Or AndroidStudio Plugin Repository And Install it.
File --> Settings --> Plugins --> Browse Repositories -->Search FlutterJsonBean * Restart your Develop tools -* Press shortcut key `command` + `"` for mac , right click on package -> `New`->`Dart bean clas file from JSON` And Then you will know how to use +* Press shortcut key `alt ` + `j` for mac , right click on package -> `New`->`Dart bean clas file from JSON` And Then you will know how to use * If you change the fields in the class, just press the shortcut command + "to regenerate the tojson and fromjson methods. The generated method regenerates all helper classes and JsonConvert classes (the same as the shortcut command +") each time an entity file is created in the generated/json directory. * If you need generic conversions in your network requests, use the jsonconvert.fromjsonast method directly. * [中文移步](https://www.jianshu.com/p/14cbcbaa74b7) diff --git a/gradle.properties b/gradle.properties index 30518fb..3c9a2d8 100644 --- a/gradle.properties +++ b/gradle.properties @@ -1,5 +1,5 @@ kotlin_version=1.3.61 -pluginVersion=3.1.4 +pluginVersion=3.1.5 #每次修改这里去打包 ideaVersionPrefix=193 ideaVersion= \ No newline at end of file diff --git a/src/main/java/com/ruiyu/beanfactory/FlutterBeanFactoryAction.kt b/src/main/java/com/ruiyu/beanfactory/FlutterBeanFactoryAction.kt index ecc3cb6..65fa1e2 100644 --- a/src/main/java/com/ruiyu/beanfactory/FlutterBeanFactoryAction.kt +++ b/src/main/java/com/ruiyu/beanfactory/FlutterBeanFactoryAction.kt @@ -28,8 +28,8 @@ class FlutterBeanFactoryAction : AnAction() { fun generateAllFile(project: Project) { val pubSpecConfig = FileHelpers.getPubSpecConfig(project) - //是flutter项目 - if (FileHelpers.shouldActivateFor(project)) { + //判断是否是flutter项目 +// if (FileHelpers.shouldActivateFor(project)) { FileHelpers.getGeneratedFileRun(project) { //上次生成的老旧老文件 val oldHelperChildren = it.children.filterIsInstance().toMutableList() @@ -118,9 +118,9 @@ class FlutterBeanFactoryAction : AnAction() { project.showNotify("convert factory is generated") } - } else { - project.showNotify("This project is not flutter") - } +// } else { +// project.showNotify("This project is not flutter") +// } } diff --git a/src/main/java/com/ruiyu/jsontodart/ModelGenerator.kt b/src/main/java/com/ruiyu/jsontodart/ModelGenerator.kt index ee3eb77..aeef1b3 100644 --- a/src/main/java/com/ruiyu/jsontodart/ModelGenerator.kt +++ b/src/main/java/com/ruiyu/jsontodart/ModelGenerator.kt @@ -5,6 +5,8 @@ import com.google.gson.reflect.TypeToken import com.intellij.openapi.project.Project import com.ruiyu.file.FileHelpers import com.ruiyu.json.GsonUtil.MapTypeAdapter +import com.ruiyu.jsontodart.utils.camelCase +import com.ruiyu.jsontodart.utils.fixFieldName import com.ruiyu.utils.Inflector import com.ruiyu.utils.JsonUtils import com.ruiyu.utils.toUpperCaseFirstOne @@ -42,10 +44,10 @@ class ModelGenerator( keys.forEach { key -> val typeDef = TypeDefinition.fromDynamic(jsonRawData[key]) if (typeDef.name == "Class") { - typeDef.name = preName + (key as String).toUpperCaseFirstOne() + typeDef.name = preName + camelCase(key as String) } if (typeDef.subtype != null && typeDef.subtype == "Class") { - typeDef.subtype = preName + (key as String).toUpperCaseFirstOne() + typeDef.subtype = preName + camelCase(key as String) } classDefinition.addField(key as String, typeDef) } diff --git a/src/main/java/com/ruiyu/jsontodart/utils/Helper.kt b/src/main/java/com/ruiyu/jsontodart/utils/Helper.kt index bcd52c6..226cbd9 100644 --- a/src/main/java/com/ruiyu/jsontodart/utils/Helper.kt +++ b/src/main/java/com/ruiyu/jsontodart/utils/Helper.kt @@ -70,10 +70,12 @@ fun isPrimitiveType(typeName: String): Boolean { fun camelCase(init: String): String { + if (init.contains("_").not()) { + return init.toUpperCaseFirstOne() + } val ret = StringBuilder(init.length) - for (word in init.split("_".toRegex()).dropLastWhile { it.isEmpty() }.toTypedArray()) { - if (!word.isEmpty()) { + if (word.isNotEmpty()) { ret.append(word.substring(0, 1).toUpperCase()) ret.append(word.substring(1).toLowerCase()) } diff --git a/src/main/resources/META-INF/plugin.xml b/src/main/resources/META-INF/plugin.xml index 83d5801..093a152 100644 --- a/src/main/resources/META-INF/plugin.xml +++ b/src/main/resources/META-INF/plugin.xml @@ -6,10 +6,11 @@ Json to dart beans are provided, and dart files ending in entity are provided to generate dart bean factory for use.

right click on package -> `New`->`Dart bean clas file from JSON` And Then you will know how to use
-
If you change the fields in the class, just press the shortcut command + "to regenerate the tojson and fromjson methods. The generated method regenerates all helper classes and JsonConvert classes (the same as the shortcut command +") each time an entity file is created in the generated/json directory.
+
If you change the fields in the class, just press the shortcut alt + j to regenerate the tojson and fromjson methods. The generated method regenerates all helper classes and JsonConvert classes (the same as the shortcut alt + j) each time an entity file is created in the generated/json directory.

If you need generic conversions in your network requests, use the jsonconvert.fromjsonast method directly.
]]>
shortcut key is changed to Alt + j

if the first jsonobject in the jsonarray is not perfect, the data will not be complete

rebuild will delete redundant files

version 3.1 has been released,Provide JsonConvert.dart,EntityFactory is deprecated
@@ -21,10 +22,7 @@
fixed field forEach method when not converted to list

fixed the bug of plural to singular

fixed import bug under Windows
-
fixed the dart keyword problem, fixed the second-level class name problem, and the int automatic double problem
-
incomplete support for the first data of the list results in missing fields in the generated dart file
-
supports custom scan file names, and factory class customizations
-
support for custom model suffix names
+
fixed the dart keyword prob
support for custom model suffix names

support android studio

Json to dart beans are provided
]]> @@ -45,7 +43,7 @@ text="FlutterBeanFactory" description="Dart files ending in entity generate dart bean factory for use"> - +