Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

number类型的id强制声明为long #140

Open
wants to merge 3 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 8 additions & 0 deletions local.properties
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
## This file must *NOT* be checked into Version Control Systems,
# as it contains information specific to your local configuration.
#
# Location of the SDK. This is only used by Gradle.
# For customization when using a Version Control System, please read the
# header note.
#Mon Dec 30 14:07:00 CST 2019
sdk.dir=/Users/hss/Library/Android/sdk
40 changes: 38 additions & 2 deletions src/main/java/org/gsonformat/intellij/entity/FieldEntity.java
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
package org.gsonformat.intellij.entity;


import org.apache.http.util.TextUtils;
import org.gsonformat.intellij.common.CheckUtil;
import org.jdesktop.swingx.ux.CellProvider;
Expand Down Expand Up @@ -65,6 +66,9 @@ public String getRealType() {
if (targetClass != null) {
return targetClass.getClassName();
}
if(nameContainsId() && isTypeInt()){
type = "long";
}
return type;
}

Expand All @@ -76,18 +80,50 @@ public String getBriefType() {
if (i > 0) {
return type.substring(i);
}
if(nameContainsId() && isTypeInt()){
type = "long";
}
return type;
}

private boolean nameContainsId(){
if(TextUtils.isEmpty(fieldName)){
return false;
}
String filedName = getGenerateFieldName();
return filedName.contains("id") || filedName.contains("Id");
}

private boolean isTypeInt(){
return "int".equals(type) || "Integer".equals(type);
}

public String getFullNameType() {

String filedName = getGenerateFieldName();

String filedType = type;
if (targetClass != null) {
return targetClass.getQualifiedName();
filedType = targetClass.getQualifiedName();
}
return type;

//如果key里带id/Id,且将被指定为int,Integer,那么自动将其指定为long
if("int".equals(filedType) || "Integer".equals(filedType)){
if(filedName.contains("id") || filedName.contains("Id")){
filedType = "long";
}
}
type = "long";

return filedType;
}

public void setType(String type) {
this.type = type;
if(nameContainsId() && isTypeInt()){
this.type = "long";
}

}

public void checkAndSetType(String text) {
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
Expand Up @@ -6,7 +6,7 @@
</html>
]]>
</description>
<version>1.5.0</version>
<version>1.5.1</version>
<vendor email="[email protected]">zzz40500</vendor>
<idea-version since-build="107.121"/>
<change-notes><![CDATA[
Expand Down
8 changes: 6 additions & 2 deletions 测试用例. txt
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,9 @@
{
"name": "王五",
"gender": "man",
"age": 15,
"uid": 15,
"cntId": 33,
"cnt": 33,
"height": "140cm"
}
测试2: 多种模型测试
Expand All @@ -12,11 +14,13 @@
"name": "王五",
"gender": "man",
"age": 15,
"uid": 15,
"height": "140cm",
"addr": {
"province": "fujian",
"city": "quanzhou",
"code": "300000"
"code": "300000",
"cityId":87
},
"hobby": [
{
Expand Down