Skip to content

Commit

Permalink
Merge pull request #18 from mars-men/dev-1.5.9
Browse files Browse the repository at this point in the history
Dev 1.5.9
  • Loading branch information
mars-men authored Mar 20, 2021
2 parents ba39835 + aa06dbd commit ce55e72
Show file tree
Hide file tree
Showing 5 changed files with 51 additions and 6 deletions.
15 changes: 13 additions & 2 deletions src/main/java/com/foxsteps/gsonformat/ConvertBridge.java
Original file line number Diff line number Diff line change
Expand Up @@ -550,8 +550,9 @@ private List<FieldEntity> createFields(JSONObject json, Map<String, FieldApiInfo
List<FieldEntity> fieldEntityList = new ArrayList<FieldEntity>();
List<FieldArrayEntity> listEntityList = new ArrayList<FieldArrayEntity>();
//是否添加注释
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);
Expand Down Expand Up @@ -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, "");

Expand Down
8 changes: 8 additions & 0 deletions src/main/java/com/foxsteps/gsonformat/common/StringUtils.java
Original file line number Diff line number Diff line change
Expand Up @@ -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) {

Expand Down
2 changes: 1 addition & 1 deletion src/main/java/com/foxsteps/gsonformat/config/Config.java
Original file line number Diff line number Diff line change
Expand Up @@ -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));
Expand Down
30 changes: 28 additions & 2 deletions src/main/java/com/foxsteps/gsonformat/ui/JsonDialog.java
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}
}
}
});

Expand Down
2 changes: 1 addition & 1 deletion src/main/resources/META-INF/plugin.xml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
<idea-plugin>
<name>GsonFormatPlus</name>
<version>1.5.8</version>
<version>1.5.9</version>
<description><![CDATA[
<!doctype html>
<html>
Expand Down

0 comments on commit ce55e72

Please sign in to comment.