diff --git a/gradle.properties b/gradle.properties index 8069eef..1dddd18 100644 --- a/gradle.properties +++ b/gradle.properties @@ -1,5 +1,5 @@ kotlin_version=1.3.61 -pluginVersion=3.1.1 +pluginVersion=3.1.2 #每次修改这里去打包 -ideaVersionPrefix=191 +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 c6ba237..91bcbec 100644 --- a/src/main/java/com/ruiyu/beanfactory/FlutterBeanFactoryAction.kt +++ b/src/main/java/com/ruiyu/beanfactory/FlutterBeanFactoryAction.kt @@ -24,6 +24,7 @@ class FlutterBeanFactoryAction : AnAction() { companion object { fun generateAllFile(project: Project) { + val pubSpecConfig = FileHelpers.getPubSpecConfig(project) val allClass = FileHelpers.getAllEntityFiles(project) //重新生成所有helper类 FileHelpers.generateAllDartEntityHelper(project, allClass) @@ -33,9 +34,9 @@ class FlutterBeanFactoryAction : AnAction() { content.append("// This file is automatically generated. DO NOT EDIT, all your changes would be lost.\n") //导包 allClass.forEach { - content.append("import 'package:${project.name}/${it.second.substringAfter("${project.name}/")}") + content.append("import 'package:${pubSpecConfig?.name}/${it.second.substringAfter("${pubSpecConfig?.name}/")}") content.append("\n") - content.append("import 'package:${project.name}/generated/json/${File(it.second).nameWithoutExtension}_helper.dart';") + content.append("import 'package:${pubSpecConfig?.name}/generated/json/${File(it.second).nameWithoutExtension}_helper.dart';") content.append("\n") } content.append("\n") diff --git a/src/main/java/com/ruiyu/file/FileHelpers.kt b/src/main/java/com/ruiyu/file/FileHelpers.kt index e8e7b6e..7989c6f 100644 --- a/src/main/java/com/ruiyu/file/FileHelpers.kt +++ b/src/main/java/com/ruiyu/file/FileHelpers.kt @@ -97,13 +97,13 @@ object FileHelpers { * 自动生成单个文件的辅助文件 */ private fun generateDartEntityHelper(project: Project, packageName: String, helperClassGeneratorInfos: MutableList?) { - + val pubSpecConfig = getPubSpecConfig(project) val content = StringBuilder() //导包 //辅助主类的包名 content.append(packageName) content.append("\n") - content.append("import 'package:${project.name}/generated/json/base/json_filed.dart';") + content.append("import 'package:${pubSpecConfig?.name}/generated/json/base/json_filed.dart';") content.append("\n") content.append(helperClassGeneratorInfos?.joinToString("\n")) //创建文件 @@ -125,6 +125,7 @@ object FileHelpers { * 获取所有符合生成的file */ fun getAllEntityFiles(project: Project): List, String>> { + val pubSpecConfig = getPubSpecConfig(project) val psiManager = PsiManager.getInstance(project) return FilenameIndex.getAllFilesByExt(project, "dart").filter { it.path.endsWith("_${ServiceManager.getService(Settings::class.java).state.modelSuffix.toLowerCase()}.dart") && it.path.contains("${project.name}/lib/") @@ -136,7 +137,7 @@ object FileHelpers { if (dartFileHelperClassGeneratorInfo == null) { null } else { - dartFileHelperClassGeneratorInfo to "import 'package:${project.name}/${packageName}';" + dartFileHelperClassGeneratorInfo to "import 'package:${pubSpecConfig?.name}/${packageName}';" } } @@ -307,6 +308,7 @@ fun PsiFileSystemItem.getParentLibEnd(): String { private const val PUBSPEC_KEY = "flutter_i18n" +private const val PROJECT_NAME = "name" private const val PUBSPEC_ENABLE_PLUGIN_KEY = "enable-flutter-i18n" private const val PUBSPEC_DART_ENABLED_KEY = "enable-for-dart" @@ -314,6 +316,8 @@ data class PubSpecConfig( val project: Project, val pubRoot: PubRoot, val map: Map, + //项目名称,导包需要 + val name: String = map[PROJECT_NAME]?.toString() ?: "", val i18nMap: Map<*, *>? = map[PUBSPEC_KEY] as? Map<*, *>, val isFlutterModule: Boolean = FlutterModuleUtils.hasFlutterModule(project), val isPluginConfigured: Boolean = i18nMap != null, diff --git a/src/main/java/com/ruiyu/jsontodart/ModelGenerator.kt b/src/main/java/com/ruiyu/jsontodart/ModelGenerator.kt index 5fb8807..e7fcbd0 100644 --- a/src/main/java/com/ruiyu/jsontodart/ModelGenerator.kt +++ b/src/main/java/com/ruiyu/jsontodart/ModelGenerator.kt @@ -3,6 +3,7 @@ package com.ruiyu.jsontodart import com.google.gson.GsonBuilder 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.utils.Inflector import com.ruiyu.utils.JsonUtils @@ -75,11 +76,12 @@ class ModelGenerator( val jsonRawData = gson.fromJson>(collectInfo.userInputJson, object : TypeToken>() {}.type) // val jsonRawData = gson.fromJson>(collectInfo.userInputJson, HashMap::class.java) JsonUtils.jsonMapMCompletion(jsonRawData) + val pubSpecConfig = FileHelpers.getPubSpecConfig(project) val stringBuilder = StringBuilder() //导包 - stringBuilder.append("import 'package:${project.name}/generated/json/base/json_convert_content.dart';") + stringBuilder.append("import 'package:${pubSpecConfig?.name}/generated/json/base/json_convert_content.dart';") stringBuilder.append("\n") - stringBuilder.append("import 'package:${project.name}/generated/json/base/json_filed.dart';") + stringBuilder.append("import 'package:${pubSpecConfig?.name}/generated/json/base/json_filed.dart';") stringBuilder.append("\n\n") stringBuilder.append(generateClassDefinition(collectInfo.firstClassName(), "", jsonRawData).joinToString("\n")) //生成helper类 diff --git a/src/main/resources/META-INF/plugin.xml b/src/main/resources/META-INF/plugin.xml index 86ca4e6..c88aef1 100644 --- a/src/main/resources/META-INF/plugin.xml +++ b/src/main/resources/META-INF/plugin.xml @@ -10,6 +10,7 @@
If you need generic conversions in your network requests, use the jsonconvert.fromjsonast method directly.
]]> Solve the guide package project name problem

Version 3.1 has been released,Provide JsonConvert.dart,EntityFactory is deprecated

fixed error occurred when try casting null to List

fixed new file bug