diff --git a/src/main/java/com/sjhy/plugin/actions/MainAction.java b/src/main/java/com/sjhy/plugin/actions/MainAction.java index 8c1c367..8ea9ceb 100644 --- a/src/main/java/com/sjhy/plugin/actions/MainAction.java +++ b/src/main/java/com/sjhy/plugin/actions/MainAction.java @@ -15,6 +15,7 @@ import com.sjhy.plugin.dict.GlobalDict; import com.sjhy.plugin.entity.TypeMapper; import com.sjhy.plugin.enums.MatchType; import com.sjhy.plugin.tool.CacheDataUtils; +import com.sjhy.plugin.tool.CompatibleUtils; import com.sjhy.plugin.tool.CurrGroupUtils; import com.sjhy.plugin.tool.StringUtils; import com.sjhy.plugin.ui.SelectSavePath; @@ -84,7 +85,7 @@ public class MainAction extends AnAction { FLAG: for (DasColumn column : columns) { - String typeName = column.getDataType().getSpecification(); + String typeName = CompatibleUtils.getDataType(column).getSpecification(); for (TypeMapper typeMapper : typeMapperList) { try { if (typeMapper.getMatchType() == MatchType.ORDINARY) { @@ -114,7 +115,7 @@ public class MainAction extends AnAction { public static class Dialog extends DialogWrapper { - private String typeName; + private final String typeName; private JPanel mainPanel; diff --git a/src/main/java/com/sjhy/plugin/actions/MainActionGroup.java b/src/main/java/com/sjhy/plugin/actions/MainActionGroup.java index 5a4fd06..63badd6 100644 --- a/src/main/java/com/sjhy/plugin/actions/MainActionGroup.java +++ b/src/main/java/com/sjhy/plugin/actions/MainActionGroup.java @@ -25,22 +25,7 @@ public class MainActionGroup extends ActionGroup { /** * 缓存数据工具类 */ - private CacheDataUtils cacheDataUtils = CacheDataUtils.getInstance(); - - /** - * 是否不存在子菜单 - */ - private boolean notExistsChildren; - - /** - * 是否分组按钮 - * - * @return 是否隐藏 - */ - @Override - public boolean hideIfNoVisibleChildren() { - return this.notExistsChildren; - } + private final CacheDataUtils cacheDataUtils = CacheDataUtils.getInstance(); /** @@ -87,7 +72,6 @@ public class MainActionGroup extends ActionGroup { //保存数据到缓存 cacheDataUtils.setDbTableList(dbTableList); cacheDataUtils.setSelectDbTable(selectDbTable); - this.notExistsChildren = false; return getMenuList(); } @@ -134,7 +118,6 @@ public class MainActionGroup extends ActionGroup { * @return 空菜单组 */ private AnAction[] getEmptyAnAction() { - this.notExistsChildren = true; return AnAction.EMPTY_ARRAY; } } diff --git a/src/main/java/com/sjhy/plugin/dto/ColumnInfoDTO.java b/src/main/java/com/sjhy/plugin/dto/ColumnInfoDTO.java index c2f9882..494d99e 100644 --- a/src/main/java/com/sjhy/plugin/dto/ColumnInfoDTO.java +++ b/src/main/java/com/sjhy/plugin/dto/ColumnInfoDTO.java @@ -4,14 +4,13 @@ import com.intellij.database.model.DasColumn; import com.intellij.psi.PsiField; import com.sjhy.plugin.entity.TypeMapper; import com.sjhy.plugin.enums.MatchType; +import com.sjhy.plugin.tool.CompatibleUtils; import com.sjhy.plugin.tool.CurrGroupUtils; import com.sjhy.plugin.tool.DocCommentUtils; import com.sjhy.plugin.tool.NameUtils; import lombok.Data; import lombok.NoArgsConstructor; -import java.util.HashMap; -import java.util.Map; import java.util.regex.Pattern; /** @@ -36,7 +35,7 @@ public class ColumnInfoDTO { public ColumnInfoDTO(DasColumn column) { this.name = NameUtils.getInstance().getJavaName(column.getName()); this.comment = column.getComment(); - this.type = getJavaType(column.getDataType().toString()); + this.type = getJavaType(CompatibleUtils.getDataType(column).toString()); this.custom = false; this.ext = "{}"; } diff --git a/src/main/java/com/sjhy/plugin/tool/CompatibleUtils.java b/src/main/java/com/sjhy/plugin/tool/CompatibleUtils.java new file mode 100644 index 0000000..15b6434 --- /dev/null +++ b/src/main/java/com/sjhy/plugin/tool/CompatibleUtils.java @@ -0,0 +1,34 @@ +package com.sjhy.plugin.tool; + +import com.intellij.database.model.DasColumn; +import com.intellij.database.model.DataType; + +import java.lang.reflect.InvocationTargetException; +import java.lang.reflect.Method; + +/** + * 兼容工具 + * + * @author makejava + * @date 2023/04/04 17:08 + */ +public class CompatibleUtils { + + public static DataType getDataType(DasColumn dasColumn) { + try { + // 兼容2022.3.3及以上版本 + Method getDasTypeMethod = dasColumn.getClass().getMethod("getDasType"); + Object dasType = getDasTypeMethod.invoke(dasColumn); + Method toDataTypeMethod = dasType.getClass().getMethod("toDataType"); + return (DataType) toDataTypeMethod.invoke(dasType); + } catch (NoSuchMethodException | InvocationTargetException | IllegalAccessException e) { + // 兼容2022.3.3以下版本 + try { + Method getDataTypeMethod = dasColumn.getClass().getMethod("getDataType"); + return (DataType) getDataTypeMethod.invoke(dasColumn); + } catch (NoSuchMethodException | InvocationTargetException | IllegalAccessException ex) { + throw new RuntimeException(ex); + } + } + } +}