Skip to content

Commit 7969d13

Browse files
committed
修复插件BUG:
1. 将Class To IDL更名为Class To Thrift IDL 2. 修复Class To Thrift IDL功能对BigDecimal类转换异常的问题
1 parent d836812 commit 7969d13

File tree

8 files changed

+36
-31
lines changed

8 files changed

+36
-31
lines changed

README.md

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,8 @@
11
# object-helper-plugin
2-
![](https://img.shields.io/badge/version-v1.2.0-blue)
2+
![](https://img.shields.io/badge/version-v1.2.1-blue)
33
![](https://img.shields.io/badge/license-Apache%202-red)
4-
![](https://img.shields.io/badge/size-36.43%20kB-yellowgreen)
5-
![](https://img.shields.io/badge/download-500%2B-green)
4+
![](https://img.shields.io/badge/size-36.54%20kB-yellowgreen)
5+
![](https://img.shields.io/badge/download-1.1k-green)
66

77
插件地址:[https://plugins.jetbrains.com/plugin/15788-objecthelper](https://plugins.jetbrains.com/plugin/15788-objecthelper)
88

@@ -16,14 +16,14 @@ JetBrains Intellij IDEA ObjectHelper插件,包含以下功能:
1616

1717
![](https://image.bigcoder.cn/20210227223302.gif)
1818

19-
- Java类转IDL
19+
- Java类转Thrift IDL
2020
![](https://image.bigcoder.cn/6eee7a02-8e4e-4f11-9b8c-81d661a920c5.gif)
2121

2222
## 未来功能支持计划
2323

2424
object-helper插件未来功能支持计划:
2525

26-
- [x] Class转IDL(Class To IDL)
26+
- [x] Class转IDL(Class To Thrift IDL)
2727
- [ ] Class转XML(Class To XML)
2828
- [ ] JSON转Class(JSON TO Class)
2929
- [ ] All Setter

object-helper.jar

118 Bytes
Binary file not shown.

resources/META-INF/plugin.xml

Lines changed: 8 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
<idea-plugin>
22
<id>cn.bigcoder.plugin.objecthelper</id>
33
<name>ObjectHelper</name>
4-
<version>1.2.0</version>
4+
<version>1.2.1</version>
55
<vendor email="[email protected]" url="https://github.com/bigcoder84/object-helper-plugin">HearingSmile</vendor>
66

77
<description><![CDATA[
@@ -15,7 +15,8 @@
1515
]]></description>
1616

1717
<change-notes><![CDATA[
18-
<li>New feature:Added the ability to quickly convert Java classes to IDL</li>
18+
<li>Fix:rename "Class To IDL" to "Class To Thrift IDL"</li>
19+
<li>Fix bug:fix "Class To Thrift IDL" BigDecimal conversion exception</li>
1920
]]>
2021
</change-notes>
2122

@@ -39,12 +40,13 @@
3940
class="cn.bigcoder.plugin.objecthelper.action.ClassToFormatJsonAction" text="Class To JSON"
4041
description="Converts the Java class to a JSON string">
4142
<add-to-group group-id="EditorPopupMenu" anchor="first"/>
42-
<keyboard-shortcut keymap="$default" first-keystroke="shift alt P"/>
43+
<keyboard-shortcut keymap="$default" first-keystroke="shift alt J"/>
4344
</action>
44-
<action id="cn.bigcoder.plugin.objecthelper.action.ClassToIDLAction"
45-
class="cn.bigcoder.plugin.objecthelper.action.ClassToIDLAction" text="Class To Thrift IDL"
46-
description="Converts the Java class to a IDL string">
45+
<action id="cn.bigcoder.plugin.objecthelper.action.ClassToThriftIDLAction"
46+
class="cn.bigcoder.plugin.objecthelper.action.ClassToThriftIDLAction" text="Class To Thrift IDL"
47+
description="Converts the Java class to a Thrift IDL string">
4748
<add-to-group group-id="EditorPopupMenu" anchor="first"/>
49+
<keyboard-shortcut keymap="$default" first-keystroke="shift alt I"/>
4850
</action>
4951
</actions>
5052

src/cn/bigcoder/plugin/objecthelper/action/ClassToIDLAction.java renamed to src/cn/bigcoder/plugin/objecthelper/action/ClassToThriftIDLAction.java

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
package cn.bigcoder.plugin.objecthelper.action;
22

33
import cn.bigcoder.plugin.objecthelper.common.util.NotificationUtils;
4-
import cn.bigcoder.plugin.objecthelper.generator.idl.IDLGenerator;
4+
import cn.bigcoder.plugin.objecthelper.generator.idl.ThriftIDLGenerator;
55
import com.intellij.openapi.actionSystem.AnAction;
66
import com.intellij.openapi.actionSystem.AnActionEvent;
77
import com.intellij.openapi.ide.CopyPasteManager;
@@ -17,14 +17,14 @@
1717
* @author: Jindong.Tian
1818
* @date: 2021-08-21
1919
**/
20-
public class ClassToIDLAction extends AnAction {
20+
public class ClassToThriftIDLAction extends AnAction {
2121
@Override
2222
public void actionPerformed(@NotNull AnActionEvent anActionEvent) {
2323
PsiClass psiClass = getOperatePsiClass(anActionEvent);
2424
if (psiClass == null) {
2525
return;
2626
}
27-
String idl = IDLGenerator.getInstance(psiClass).generate();
27+
String idl = ThriftIDLGenerator.getInstance(psiClass).generate();
2828
CopyPasteManager.getInstance().setContents(new StringSelection(idl));
2929
NotificationUtils.notifyInfo(anActionEvent.getProject(), "IDL代码成功置入剪贴板:<br>" + idl);
3030
}

src/cn/bigcoder/plugin/objecthelper/common/constant/JavaClassName.java

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@ public class JavaClassName {
1515
public static final String DATE_TYPE = "java.util.Date";
1616
public static final String LOCAL_DATE_TYPE = "java.time.LocalDate";
1717
public static final String LOCAL_DATE_TIME_TYPE = "java.time.LocalDateTime";
18+
public static final String BIG_DECIMAL = "java.math.BigDecimal";
1819

1920
public static final String COLLECTION_TYPE = "java.util.Collection";
2021
public static final String MAP_TYPE = "java.util.Map";

src/cn/bigcoder/plugin/objecthelper/common/util/IDLUtils.java

Lines changed: 8 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -20,25 +20,22 @@ public static String convertJavaTypeToIDLType(String canonicalText){
2020
}
2121
switch (canonicalText) {
2222
case STRING_TYPE:
23+
case BIG_DECIMAL:
2324
return STRING;
25+
case BYTE_TYPE:
26+
return BYTE;
27+
case SHORT_TYPE:
28+
return I16;
2429
case INTEGER_TYPE:
2530
return I32;
2631
case LONG_TYPE:
32+
case LOCAL_DATE_TYPE:
33+
case DATE_TYPE:
34+
case LOCAL_DATE_TIME_TYPE:
2735
return I64;
28-
case SHORT_TYPE:
29-
return I16;
30-
case BYTE_TYPE:
31-
return BYTE;
3236
case DOUBLE_TYPE:
33-
return DOUBLE;
3437
case FLOAT_TYPE:
3538
return DOUBLE;
36-
case DATE_TYPE:
37-
return I64;
38-
case LOCAL_DATE_TYPE:
39-
return I64;
40-
case LOCAL_DATE_TIME_TYPE:
41-
return I64;
4239
default:
4340
return null;
4441
}

src/cn/bigcoder/plugin/objecthelper/common/util/PsiTypeUtils.java

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -72,7 +72,8 @@ public static boolean isDataType(PsiType psiType) {
7272
|| FLOAT_TYPE.equals(canonicalName)
7373
|| DATE_TYPE.equals(canonicalName)
7474
|| LOCAL_DATE_TYPE.equals(canonicalName)
75-
|| LOCAL_DATE_TIME_TYPE.equals(canonicalName)) {
75+
|| LOCAL_DATE_TIME_TYPE.equals(canonicalName)
76+
|| BIG_DECIMAL.equals(canonicalName)) {
7677
return true;
7778
}
7879
return false;

src/cn/bigcoder/plugin/objecthelper/generator/idl/IDLGenerator.java renamed to src/cn/bigcoder/plugin/objecthelper/generator/idl/ThriftIDLGenerator.java

Lines changed: 9 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@
33
import cn.bigcoder.plugin.objecthelper.common.util.IDLUtils;
44
import cn.bigcoder.plugin.objecthelper.common.util.PsiTypeUtils;
55
import cn.bigcoder.plugin.objecthelper.common.util.PsiUtils;
6+
import cn.bigcoder.plugin.objecthelper.common.util.StringUtils;
67
import cn.bigcoder.plugin.objecthelper.generator.Generator;
78
import com.intellij.psi.PsiArrayType;
89
import com.intellij.psi.PsiClass;
@@ -20,7 +21,7 @@
2021
* @author: Jindong.Tian
2122
* @date: 2021-08-20
2223
**/
23-
public class IDLGenerator implements Generator {
24+
public class ThriftIDLGenerator implements Generator {
2425

2526
private PsiClass psiClass;
2627

@@ -29,7 +30,7 @@ public class IDLGenerator implements Generator {
2930
*/
3031
private Set<String> recursiveCache = Sets.newHashSet();
3132

32-
private IDLGenerator(PsiClass psiClass) {
33+
private ThriftIDLGenerator(PsiClass psiClass) {
3334
this.psiClass = psiClass;
3435
}
3536

@@ -54,7 +55,10 @@ private StringBuilder generateStructCode(PsiClass psiClass) {
5455
StringBuilder code = new StringBuilder();
5556
for (PsiField allPsiField : allPsiFields) {
5657
code = processAssociateClass(allPsiField.getType(), code);
57-
fields.add(processPsiField(allPsiField));
58+
String field = processPsiField(allPsiField);
59+
if (StringUtils.isNotEmpty(field)) {
60+
fields.add(field);
61+
}
5862
}
5963
return code.append(generateStructCode(psiClass.getName(), fields));
6064
}
@@ -179,7 +183,7 @@ private String processType(PsiType psiType) {
179183
return null;
180184
}
181185

182-
public static IDLGenerator getInstance(PsiClass psiClass) {
183-
return new IDLGenerator(psiClass);
186+
public static ThriftIDLGenerator getInstance(PsiClass psiClass) {
187+
return new ThriftIDLGenerator(psiClass);
184188
}
185189
}

0 commit comments

Comments
 (0)