Skip to content

Commit

Permalink
Merge pull request #14 from mars-men/dev-1.5.8
Browse files Browse the repository at this point in the history
Dev 1.5.8
  • Loading branch information
mars-men authored Feb 1, 2021
2 parents 7311216 + a415a8a commit f94a2ba
Show file tree
Hide file tree
Showing 7 changed files with 37 additions and 31 deletions.
12 changes: 9 additions & 3 deletions src/main/java/com/foxsteps/gsonformat/ConvertBridge.java
Original file line number Diff line number Diff line change
Expand Up @@ -596,9 +596,15 @@ private List<FieldEntity> createFields(JSONObject json, Map<String, FieldApiInfo
private FieldEntity createField(ClassEntity parentClass, String key, Object type, Map<String, FieldApiInfo> fieldApiInfoMap) {
//过滤 不符合规则的key
String fieldName = CheckUtil.getInstant().handleArg(key);
//使用序列化名:转为驼峰
if (Config.getInstant().isUseSerializedName()) {
fieldName = StringUtils.captureStringLeaveUnderscore(convertSerializedName(fieldName));
if (Config.getInstant().isUseSerializedName() && fieldName.contains("_")) {
if (fieldName.endsWith("_")) {
fieldName = fieldName.substring(0, fieldName.lastIndexOf("_"));
}
fieldName = StringUtils.captureStringLeaveUnderscore(fieldName.toLowerCase());
} else {
if (Config.getInstant().isUseSerializedName() && StringUtils.isAcronym(fieldName)) {
fieldName = fieldName.toLowerCase();
}
}
fieldName = handleDeclareFieldName(fieldName, "");

Expand Down
11 changes: 11 additions & 0 deletions src/main/java/com/foxsteps/gsonformat/common/StringUtils.java
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,17 @@ public static String captureStringLeaveUnderscore(String text) {
return stringBuilder.toString();
}

public static boolean isAcronym(String word) {
for(int i = 0; i < word.length(); i++) {
char c = word.charAt(i);
if (Character.isLowerCase(c)) {
return false;
}
}
return true;
}


public static String captureName(String text) {

if (text.length() > 0) {
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 @@ -10,7 +10,7 @@ public class Config {
private static Config config;

private boolean fieldPrivateMode = true;
private boolean generateComments = true;
private boolean generateComments = false;
private boolean useSerializedName = false;
private boolean objectFromData = false;
private boolean objectFromData1 = false;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -141,7 +141,7 @@ protected void createGetAndSetMethod(PsiElementFactory factory, PsiClass cls, Fi
fieldName = temp;
}
}
if (typeStr.equals("boolean") || typeStr.equals("Boolean")) {
if (typeStr.equals("boolean")) {
String method = "public ".concat(typeStr).concat(" is").concat(
captureName(fieldName)).concat("() { return ").concat(
field.getGenerateFieldName()).concat(" ;} ");
Expand Down
33 changes: 11 additions & 22 deletions src/main/java/com/foxsteps/gsonformat/ui/SettingDialog.form
Original file line number Diff line number Diff line change
Expand Up @@ -374,28 +374,6 @@
<text value="General"/>
</properties>
</component>
<component id="6cc2" class="javax.swing.JCheckBox" binding="generateCommentsCB">
<constraints>
<grid row="7" column="1" row-span="1" col-span="1" vsize-policy="0" hsize-policy="3" anchor="8" fill="0" indent="0" use-parent-layout="false">
<minimum-size width="-1" height="30"/>
<preferred-size width="-1" height="30"/>
</grid>
</constraints>
<properties>
<text value="generate comments"/>
</properties>
</component>
<component id="61cbe" class="javax.swing.JCheckBox" binding="splitGenerateCB">
<constraints>
<grid row="7" column="2" row-span="1" col-span="1" vsize-policy="0" hsize-policy="3" anchor="8" fill="0" indent="0" use-parent-layout="false">
<minimum-size width="-1" height="30"/>
<preferred-size width="-1" height="30"/>
</grid>
</constraints>
<properties>
<text value="split generate"/>
</properties>
</component>
<component id="9eff9" class="javax.swing.JCheckBox" binding="virgoModelCB">
<constraints>
<grid row="7" column="0" row-span="1" col-span="1" vsize-policy="0" hsize-policy="3" anchor="8" fill="0" indent="0" use-parent-layout="false">
Expand Down Expand Up @@ -425,6 +403,17 @@
<text value="edit"/>
</properties>
</component>
<component id="61cbe" class="javax.swing.JCheckBox" binding="splitGenerateCB">
<constraints>
<grid row="7" column="1" row-span="1" col-span="1" vsize-policy="0" hsize-policy="3" anchor="8" fill="0" indent="0" use-parent-layout="false">
<minimum-size width="-1" height="30"/>
<preferred-size width="-1" height="30"/>
</grid>
</constraints>
<properties>
<text value="split generate"/>
</properties>
</component>
</children>
</grid>
</children>
Expand Down
6 changes: 3 additions & 3 deletions src/main/java/com/foxsteps/gsonformat/ui/SettingDialog.java
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ public class SettingDialog extends JFrame {
private JCheckBox filedPrefixCB;
private JTextField annotationTF;
private JCheckBox virgoModelCB;
private JCheckBox generateCommentsCB;
//private JCheckBox generateCommentsCB;
private JCheckBox useWrapperClassCB;
private JCheckBox useCommentCB;
private JCheckBox splitGenerateCB;
Expand Down Expand Up @@ -100,7 +100,7 @@ public void actionPerformed(ActionEvent e) {
//处女模式CheckBox
virgoModelCB.setSelected(Config.getInstant().isVirgoMode());
//生成注释
generateCommentsCB.setSelected(Config.getInstant().isGenerateComments());
//generateCommentsCB.setSelected(Config.getInstant().isGenerateComments());
//字段前缀checkbox
filedPrefixCB.setSelected(Config.getInstant().isUseFieldNamePrefix());
filedPrefixTF.setEnabled(Config.getInstant().isUseFieldNamePrefix());
Expand Down Expand Up @@ -376,7 +376,7 @@ private void onOK() {
Config.getInstant().setReuseEntity(reuseEntityCB.isSelected());
Config.getInstant().setSuffixStr(suffixEdit.getText());
Config.getInstant().setVirgoMode(virgoModelCB.isSelected());
Config.getInstant().setGenerateComments(generateCommentsCB.isSelected());
//Config.getInstant().setGenerateComments(generateCommentsCB.isSelected());
Config.getInstant().setFiledNamePreFixStr(filedPrefixTF.getText());
Config.getInstant().setAnnotationStr(annotationTF.getText());
Config.getInstant().setUseFieldNamePrefix(filedPrefixCB.isSelected());
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.7</version>
<version>1.5.8</version>
<description><![CDATA[
<!doctype html>
<html>
Expand Down

0 comments on commit f94a2ba

Please sign in to comment.