mirror of https://gitee.com/makejava/EasyCode.git
利用反射对2022.3.3及以上版本进行兼容性支持
This commit is contained in:
parent
ba3ccba5a8
commit
0651597b65
|
@ -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;
|
||||
|
||||
|
|
|
@ -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;
|
||||
}
|
||||
}
|
||||
|
|
|
@ -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 = "{}";
|
||||
}
|
||||
|
|
|
@ -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);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
Loading…
Reference in New Issue