From 5d06440e8545486add61672ac639f9d112cd7baa Mon Sep 17 00:00:00 2001 From: wangzejun Date: Sat, 13 Mar 2021 11:53:55 +0800 Subject: [PATCH 1/2] =?UTF-8?q?gsonFormatPlus:=20=E4=BF=AE=E5=A4=8D#11?= =?UTF-8?q?=E9=97=AE=E9=A2=98=E5=8F=8A#16=E9=97=AE=E9=A2=98?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../com/foxsteps/gsonformat/ConvertBridge.java | 15 +++++++++++++-- .../foxsteps/gsonformat/common/StringUtils.java | 8 ++++++++ .../com/foxsteps/gsonformat/config/Config.java | 2 +- src/main/resources/META-INF/plugin.xml | 2 +- 4 files changed, 23 insertions(+), 4 deletions(-) diff --git a/src/main/java/com/foxsteps/gsonformat/ConvertBridge.java b/src/main/java/com/foxsteps/gsonformat/ConvertBridge.java index e7a42bd..e6b3b01 100644 --- a/src/main/java/com/foxsteps/gsonformat/ConvertBridge.java +++ b/src/main/java/com/foxsteps/gsonformat/ConvertBridge.java @@ -550,8 +550,9 @@ private List createFields(JSONObject json, Map fieldEntityList = new ArrayList(); List listEntityList = new ArrayList(); //是否添加注释 - boolean writeExtra = Config.getInstant().isGenerateComments(); - + //boolean writeExtra = Config.getInstant().isGenerateComments(); + //去掉构造函数注释 + boolean writeExtra=false; for (int i = 0; i < fieldList.size(); i++) { String key = fieldList.get(i); Object value = json.get(key); @@ -602,9 +603,19 @@ private FieldEntity createField(ClassEntity parentClass, String key, Object type } fieldName = StringUtils.captureStringLeaveUnderscore(fieldName.toLowerCase()); } else { + //fieldName是全部大写 if (Config.getInstant().isUseSerializedName() && StringUtils.isAcronym(fieldName)) { fieldName = fieldName.toLowerCase(); } + //首字母是大写,存在其他字母是小写 + if (StringUtils.isFirsrtUpper(fieldName)) { + if (fieldName.length() == 1) { + fieldName = fieldName.toLowerCase(); + }else{ + fieldName = fieldName.substring(0,1).toLowerCase()+ fieldName.substring(1); + } + } + } fieldName = handleDeclareFieldName(fieldName, ""); diff --git a/src/main/java/com/foxsteps/gsonformat/common/StringUtils.java b/src/main/java/com/foxsteps/gsonformat/common/StringUtils.java index 4e7f4af..9e98bc3 100644 --- a/src/main/java/com/foxsteps/gsonformat/common/StringUtils.java +++ b/src/main/java/com/foxsteps/gsonformat/common/StringUtils.java @@ -41,6 +41,14 @@ public static boolean isAcronym(String word) { return true; } + public static boolean isFirsrtUpper(String word) { + char c = word.charAt(0); + if(Character.isUpperCase(c)){ + return true; + } + return false; + } + public static String captureName(String text) { diff --git a/src/main/java/com/foxsteps/gsonformat/config/Config.java b/src/main/java/com/foxsteps/gsonformat/config/Config.java index d81be37..b1b47af 100644 --- a/src/main/java/com/foxsteps/gsonformat/config/Config.java +++ b/src/main/java/com/foxsteps/gsonformat/config/Config.java @@ -122,7 +122,7 @@ public static Config getInstant() { config.setErrorCount(PropertiesComponent.getInstance().getOrInitInt("errorCount", 0)); config.setVirgoMode(PropertiesComponent.getInstance().getBoolean("virgoMode", true)); config.setUseFieldNamePrefix(PropertiesComponent.getInstance().getBoolean("useFieldNamePrefix", false)); - config.setGenerateComments(PropertiesComponent.getInstance().getBoolean("generateComments", true)); + config.setGenerateComments(PropertiesComponent.getInstance().getBoolean("generateComments", false)); config.setSplitGenerate(PropertiesComponent.getInstance().getBoolean("splitGenerate", false)); config.setUseWrapperClass(PropertiesComponent.getInstance().getBoolean("useWrapperClass", true)); config.setUseComment(PropertiesComponent.getInstance().getBoolean("useComment", false)); diff --git a/src/main/resources/META-INF/plugin.xml b/src/main/resources/META-INF/plugin.xml index 81ea660..6c94996 100644 --- a/src/main/resources/META-INF/plugin.xml +++ b/src/main/resources/META-INF/plugin.xml @@ -1,6 +1,6 @@ GsonFormatPlus - 1.5.8 + 1.5.9 From aa06dbdacc86b45e143196598c3de1e63d872bf2 Mon Sep 17 00:00:00 2001 From: wangzejun Date: Thu, 18 Mar 2021 00:18:12 +0800 Subject: [PATCH 2/2] =?UTF-8?q?gsonFormatPlus:=20=E4=BF=AE=E5=A4=8D#11?= =?UTF-8?q?=E9=97=AE=E9=A2=98#16=E9=97=AE=E9=A2=98#17=E9=97=AE=E9=A2=98?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../foxsteps/gsonformat/ui/JsonDialog.java | 30 +++++++++++++++++-- 1 file changed, 28 insertions(+), 2 deletions(-) diff --git a/src/main/java/com/foxsteps/gsonformat/ui/JsonDialog.java b/src/main/java/com/foxsteps/gsonformat/ui/JsonDialog.java index de18262..ee67ce6 100644 --- a/src/main/java/com/foxsteps/gsonformat/ui/JsonDialog.java +++ b/src/main/java/com/foxsteps/gsonformat/ui/JsonDialog.java @@ -208,8 +208,34 @@ public void actionPerformed(ActionEvent e) { if (!StringUtils.isNotBlank(json)) { return; } - SystemUtils.copyToClipboard(json); - NotificationCenter.sendNotificationForProject(" Copy json success !",NotificationType.INFORMATION,project); + String formatJson=""; + try { + if (json.startsWith("{")) { + JSONObject jsonObject = new JSONObject(json); + formatJson = jsonObject.toString(4); + editTP.setText(formatJson); + } else if (json.startsWith("[")) { + JSONArray jsonArray = new JSONArray(json); + formatJson = jsonArray.toString(4); + editTP.setText(formatJson); + } + SystemUtils.copyToClipboard(formatJson); + NotificationCenter.sendNotificationForProject(" Copy json success !",NotificationType.INFORMATION,project); + } catch (JSONException jsonException) { + try { + String goodJson = JsonUtils.removeComment(json); + formatJson = JsonUtils.formatJson(goodJson); + editTP.setText(formatJson); + commentAR.setText(JsonUtils.getJsonComment(json, formatJson)); + SystemUtils.copyToClipboard(formatJson); + NotificationCenter.sendNotificationForProject(" Copy json success !",NotificationType.INFORMATION,project); + } catch (Exception exception) { + formatJson=""; + exception.printStackTrace(); + NotificationCenter.sendNotificationForProject("json格式不正确,格式需要标准的json或者json5",NotificationType.ERROR,project); + return; + } + } } });