diff --git a/CHANGELOG.md b/CHANGELOG.md index 0b8e55f..efe6f9f 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -3,6 +3,11 @@ # RestfulToolkitX Changelog ## [Unreleased] +## [2.1.3] - 2023-03-19 +### Removed +- 移除未成熟的代码生成器 +- Remove less maturity code generators. + ## [2.1.2] - 2023-01-24 ### Added diff --git a/README.md b/README.md index 79122d4..faeb5d1 100644 --- a/README.md +++ b/README.md @@ -25,7 +25,7 @@ This branch will continue to be compatible with the latest version of IDEA, and - [x] A simple http request tool. - [x] Generate&Copy Query Param, Generate&Copy URL on the request method. - [x] Convert java class to JSON; format json data ( Windows: Ctrl + Enter; Mac: Command + Enter ) . -- [x] [Code generator](codeGen.md). Based on [EasyCode] + Generate Code Preview ![code_gen_preview.png](img/code_gen_preview_1.gif) diff --git a/codeGen.md b/codeGen.md deleted file mode 100644 index ed32310..0000000 --- a/codeGen.md +++ /dev/null @@ -1,71 +0,0 @@ -[中文](codeGen_zh_CN.md) - -# Code generator - -## [Spring Boot][Spring Boot] + [MyBatis-Plus][MyBatis-Plus] Style -![](img/code_gen_preview_1.gif) - -Note that the following dependencies and annotations are added manually. -- project dependency -```xml - - - - org.springframework.boot - spring-boot-starter-web - - - - com.baomidou - mybatis-plus-boot-starter - 3.5.1 - - - com.baomidou - mybatis-plus - 3.5.1 - - - com.baomidou - mybatis-plus-extension - 3.3.2 - - - - org.projectlombok - lombok - 1.18.8 - - -``` -- MapperScan -```java -@SpringBootApplication -//Add MapperScan -@MapperScan("com.example.demo.mapper") -public class DemoApplication { - - public static void main(String[] args) { - SpringApplication.run(DemoApplication.class, args); - } - -} -``` - -## [Spring Boot][Spring Boot] + JPA Style - -TODO - -## [JHipster][JHipster] Style - -TODO - -## Generator refactoring enhancements to support more useful features. - -TODO - -[Spring Boot]: https://spring.io/projects/spring-boot - -[MyBatis-Plus]: https://github.com/baomidou/mybatis-plus - -[JHipster]: https://www.jhipster.tech/ diff --git a/codeGen_zh_CN.md b/codeGen_zh_CN.md deleted file mode 100644 index c2ad5b2..0000000 --- a/codeGen_zh_CN.md +++ /dev/null @@ -1,72 +0,0 @@ -[English](codeGen.md) - -# 代码生成器 - - -## [Spring Boot][Spring Boot] + [MyBatis-Plus][MyBatis-Plus] 风格 -![](img/code_gen_preview_1.gif) - -注意,手动添加以下依赖和注解 -- 项目依赖 -```xml - - - - org.springframework.boot - spring-boot-starter-web - - - - com.baomidou - mybatis-plus-boot-starter - 3.5.1 - - - com.baomidou - mybatis-plus - 3.5.1 - - - com.baomidou - mybatis-plus-extension - 3.3.2 - - - - org.projectlombok - lombok - 1.18.8 - - -``` -- MapperScan -```java -@SpringBootApplication -//Add MapperScan -@MapperScan("com.example.demo.mapper") -public class DemoApplication { - - public static void main(String[] args) { - SpringApplication.run(DemoApplication.class, args); - } - -} -``` - -## [Spring Boot][Spring Boot] + JPA 风格 - -TODO - -## [JHipster][JHipster] 风格 - -TODO - -## 生成器重构增强,支持更多实用特性 - -TODO - -[Spring Boot]: https://spring.io/projects/spring-boot - -[MyBatis-Plus]: https://github.com/baomidou/mybatis-plus - -[JHipster]: https://www.jhipster.tech/ diff --git a/gradle.properties b/gradle.properties index 55d4829..791bd47 100644 --- a/gradle.properties +++ b/gradle.properties @@ -2,7 +2,7 @@ # -> https://plugins.jetbrains.com/docs/intellij/intellij-artifacts.html pluginGroup=jiux.net.plugin.restfultoolkit pluginName=RestfulToolkitX -pluginVersion=2.1.2 +pluginVersion=2.1.3 # See https://plugins.jetbrains.com/docs/intellij/build-number-ranges.html # for insight into build numbers and IntelliJ Platform versions. pluginSinceBuild=202 diff --git a/src/main/java/jiux/net/plugin/restful/codegen/actions/ConfigAction.java b/src/main/java/jiux/net/plugin/restful/codegen/actions/ConfigAction.java deleted file mode 100644 index 7833c66..0000000 --- a/src/main/java/jiux/net/plugin/restful/codegen/actions/ConfigAction.java +++ /dev/null @@ -1,40 +0,0 @@ -package jiux.net.plugin.restful.codegen.actions; - -import jiux.net.plugin.restful.codegen.ui.ConfigTableDialog; -import com.intellij.openapi.actionSystem.AnAction; -import com.intellij.openapi.actionSystem.AnActionEvent; -import com.intellij.openapi.project.Project; -import org.jetbrains.annotations.NotNull; -import org.jetbrains.annotations.Nullable; - -/** - * 表配置菜单 - * - * @author makejava - * @version 1.0.0 - * @since 2018/07/17 13:10 - */ -public class ConfigAction extends AnAction { - /** - * 构造方法 - * - * @param text 菜单名称 - */ - ConfigAction(@Nullable String text) { - super(text); - } - - /** - * 处理方法 - * - * @param event 事件对象 - */ - @Override - public void actionPerformed(@NotNull AnActionEvent event) { - Project project = event.getProject(); - if (project == null) { - return; - } - new ConfigTableDialog().show(); - } -} diff --git a/src/main/java/jiux/net/plugin/restful/codegen/actions/MainAction.java b/src/main/java/jiux/net/plugin/restful/codegen/actions/MainAction.java deleted file mode 100644 index 2f3462e..0000000 --- a/src/main/java/jiux/net/plugin/restful/codegen/actions/MainAction.java +++ /dev/null @@ -1,170 +0,0 @@ -package jiux.net.plugin.restful.codegen.actions; - -import jiux.net.plugin.restful.codegen.dict.GlobalDict; -import jiux.net.plugin.restful.codegen.entity.TypeMapper; -import jiux.net.plugin.restful.codegen.enums.MatchType; -import jiux.net.plugin.restful.codegen.service.SettingsStorageService; -import jiux.net.plugin.restful.codegen.tool.CacheDataUtils; -import jiux.net.plugin.restful.codegen.tool.CurrGroupUtils; -import jiux.net.plugin.restful.codegen.tool.StringUtils; -import jiux.net.plugin.restful.codegen.ui.SelectSavePath; -import com.intellij.database.model.DasColumn; -import com.intellij.database.psi.DbTable; -import com.intellij.database.util.DasUtil; -import com.intellij.openapi.actionSystem.AnAction; -import com.intellij.openapi.actionSystem.AnActionEvent; -import com.intellij.openapi.project.Project; -import com.intellij.openapi.ui.ComboBox; -import com.intellij.openapi.ui.DialogWrapper; -import com.intellij.openapi.ui.Messages; -import com.intellij.util.containers.JBIterable; -import com.intellij.util.ui.JBUI; -import org.jetbrains.annotations.NotNull; -import org.jetbrains.annotations.Nullable; - -import javax.swing.*; -import java.awt.*; -import java.util.HashSet; -import java.util.List; -import java.util.Set; -import java.util.regex.Pattern; -import java.util.regex.PatternSyntaxException; - -/** - * 代码生成菜单 - * - * @author makejava - * @version 1.0.0 - * @since 2018/07/17 13:10 - */ -public class MainAction extends AnAction { - /** - * 构造方法 - * - * @param text 菜单名称 - */ - MainAction(@Nullable String text) { - super(text); - } - - /** - * 处理方法 - * - * @param event 事件对象 - */ - @Override - public void actionPerformed(@NotNull AnActionEvent event) { - Project project = event.getProject(); - if (project == null) { - return; - } - - // 校验类型映射 - if (!typeValidator(project, CacheDataUtils.getInstance().getSelectDbTable())) { - // 没通过不打开窗口 - return; - } - - // - - //FIXME 仅限本地调试,重置代码生成配置 -// SettingsStorageService.getSettingsStorage().getGlobalConfigGroupMap().clear(); -// SettingsStorageService.getSettingsStorage().getTemplateGroupMap().clear(); -// SettingsStorageService.getSettingsStorage().resetDefaultVal(); - - //开始处理 - new SelectSavePath(event.getProject()).show(); - } - - - /** - * 类型校验,如果存在未知类型则引导用于去条件类型 - * - * @param dbTable 原始表对象 - * @return 是否验证通过 - */ - private boolean typeValidator(Project project, DbTable dbTable) { - // 处理所有列 - JBIterable columns = DasUtil.getColumns(dbTable); - List typeMapperList = CurrGroupUtils.getCurrTypeMapperGroup().getElementList(); - - // 简单的记录报错弹窗次数,避免重复报错 - Set errorCount = new HashSet<>(); - - FLAG: - for (DasColumn column : columns) { - String typeName = column.getDataType().getSpecification(); - for (TypeMapper typeMapper : typeMapperList) { - try { - if (typeMapper.getMatchType() == MatchType.ORDINARY) { - if (typeName.equalsIgnoreCase(typeMapper.getColumnType())) { - continue FLAG; - } - } else { - // 不区分大小写的正则匹配模式 - if (Pattern.compile(typeMapper.getColumnType(), Pattern.CASE_INSENSITIVE).matcher(typeName).matches()) { - continue FLAG; - } - } - } catch (PatternSyntaxException e) { - if (!errorCount.contains(typeMapper.getColumnType())) { - Messages.showWarningDialog( - "Type mapping《" + typeMapper.getColumnType() + "》has some syntax error,please correct them in time. Error info:" + e.getMessage(), - GlobalDict.TITLE_INFO); - errorCount.add(typeMapper.getColumnType()); - } - } - } - // 没找到类型,提示用户选择输入类型 - new Dialog(project, typeName).showAndGet(); - } - return true; - } - - public static class Dialog extends DialogWrapper { - - private String typeName; - - private JPanel mainPanel; - - private ComboBox comboBox; - - protected Dialog(@Nullable Project project, String typeName) { - super(project); - this.typeName = typeName; - this.initPanel(); - } - - private void initPanel() { - setTitle(GlobalDict.TITLE_INFO); - String msg = String.format("Database type %s,no mapping found. Please enter type to convert?", typeName); - JLabel label = new JLabel(msg); - this.mainPanel = new JPanel(new BorderLayout()); - this.mainPanel.setBorder(JBUI.Borders.empty(5, 10, 7, 10)); - mainPanel.add(label, BorderLayout.NORTH); - this.comboBox = new ComboBox<>(GlobalDict.DEFAULT_JAVA_TYPE_LIST); - this.comboBox.setEditable(true); - this.mainPanel.add(this.comboBox, BorderLayout.CENTER); - init(); - } - - @Override - protected @Nullable JComponent createCenterPanel() { - return this.mainPanel; - } - - @Override - protected void doOKAction() { - super.doOKAction(); - String selectedItem = (String) this.comboBox.getSelectedItem(); - if (StringUtils.isEmpty(selectedItem)) { - return; - } - TypeMapper typeMapper = new TypeMapper(); - typeMapper.setMatchType(MatchType.ORDINARY); - typeMapper.setJavaType(selectedItem); - typeMapper.setColumnType(typeName); - CurrGroupUtils.getCurrTypeMapperGroup().getElementList().add(typeMapper); - } - } -} diff --git a/src/main/java/jiux/net/plugin/restful/codegen/actions/MainActionGroup.java b/src/main/java/jiux/net/plugin/restful/codegen/actions/MainActionGroup.java deleted file mode 100644 index 018d331..0000000 --- a/src/main/java/jiux/net/plugin/restful/codegen/actions/MainActionGroup.java +++ /dev/null @@ -1,140 +0,0 @@ -package jiux.net.plugin.restful.codegen.actions; - -import jiux.net.plugin.restful.codegen.dict.GlobalDict; -import jiux.net.plugin.restful.codegen.service.TableInfoSettingsService; -import jiux.net.plugin.restful.codegen.tool.CacheDataUtils; -import com.intellij.database.psi.DbTable; -import com.intellij.openapi.actionSystem.*; -import com.intellij.openapi.project.Project; -import com.intellij.openapi.ui.Messages; -import com.intellij.psi.PsiElement; -import org.jetbrains.annotations.NotNull; -import org.jetbrains.annotations.Nullable; - -import java.util.ArrayList; -import java.util.List; - -/** - * 操作按钮分组 - * - * @author makejava - * @version 1.0.0 - * @since 2018/07/17 13:10 - */ -public class MainActionGroup extends ActionGroup { - /** - * 缓存数据工具类 - */ - private CacheDataUtils cacheDataUtils = CacheDataUtils.getInstance(); - - /** - * 是否不存在子菜单 - */ - private boolean notExistsChildren; - - /** - * 是否分组按钮 - * - * @return 是否隐藏 - */ - @Override - public boolean hideIfNoVisibleChildren() { - return this.notExistsChildren; - } - - - /** - * 根据右键在不同的选项上展示不同的子菜单 - * - * @param event 事件对象 - * @return 动作组 - */ - @NotNull - @Override - public AnAction[] getChildren(@Nullable AnActionEvent event) { - // 获取当前项目 - Project project = getEventProject(event); - if (project == null) { - return getEmptyAnAction(); - } - - //获取选中的PSI元素 - PsiElement psiElement = event.getData(LangDataKeys.PSI_ELEMENT); - DbTable selectDbTable = null; - if (psiElement instanceof DbTable) { - selectDbTable = (DbTable) psiElement; - } - if (selectDbTable == null) { - return getEmptyAnAction(); - } - //获取选中的所有表 - PsiElement[] psiElements = event.getData(LangDataKeys.PSI_ELEMENT_ARRAY); - if (psiElements == null || psiElements.length == 0) { - return getEmptyAnAction(); - } - List dbTableList = new ArrayList<>(); - for (PsiElement element : psiElements) { - if (!(element instanceof DbTable)) { - continue; - } - DbTable dbTable = (DbTable) element; - dbTableList.add(dbTable); - } - if (dbTableList.isEmpty()) { - return getEmptyAnAction(); - } - - //保存数据到缓存 - cacheDataUtils.setDbTableList(dbTableList); - cacheDataUtils.setSelectDbTable(selectDbTable); - this.notExistsChildren = false; - return getMenuList(); - } - - /** - * 初始化注册子菜单项目 - * - * @return 子菜单数组 - */ - private AnAction[] getMenuList() { - String mainActionId = "jiux.net.plugin.restful.codegen.action.generate"; - String configActionId = "jiux.net.plugin.restful.codegen.action.config"; - ActionManager actionManager = ActionManager.getInstance(); - // 代码生成菜单 - AnAction mainAction = actionManager.getAction(mainActionId); - if (mainAction == null) { - mainAction = new MainAction("Generate Code"); - actionManager.registerAction(mainActionId, mainAction); - } - // 表配置菜单 - AnAction configAction = actionManager.getAction(configActionId); - if (configAction == null) { - configAction = new ConfigAction("Config Table"); - actionManager.registerAction(configActionId, configAction); - } - AnAction clearConfigAction = new AnAction("Clear Config") { - @Override - public void actionPerformed(@NotNull AnActionEvent e) { - DbTable dbTable = CacheDataUtils.getInstance().getSelectDbTable(); - if (dbTable == null) { - return; - } - TableInfoSettingsService.getInstance().resetTableInfo(dbTable); - Messages.showInfoMessage(dbTable.getName() + " config info rested.", GlobalDict.TITLE_INFO); - } - }; - // 返回所有菜单 - return new AnAction[]{mainAction, configAction, clearConfigAction}; - } - - - /** - * 获取空菜单组 - * - * @return 空菜单组 - */ - private AnAction[] getEmptyAnAction() { - this.notExistsChildren = true; - return AnAction.EMPTY_ARRAY; - } -} diff --git a/src/main/java/jiux/net/plugin/restful/codegen/actions/RestfulCodeEntityAction.java b/src/main/java/jiux/net/plugin/restful/codegen/actions/RestfulCodeEntityAction.java deleted file mode 100644 index c1d667d..0000000 --- a/src/main/java/jiux/net/plugin/restful/codegen/actions/RestfulCodeEntityAction.java +++ /dev/null @@ -1,74 +0,0 @@ -package jiux.net.plugin.restful.codegen.actions; - -import com.google.common.collect.Lists; -import com.intellij.openapi.actionSystem.AnAction; -import com.intellij.openapi.actionSystem.AnActionEvent; -import com.intellij.openapi.actionSystem.CommonDataKeys; -import com.intellij.openapi.project.Project; -import com.intellij.openapi.vfs.VirtualFile; -import com.intellij.psi.PsiClass; -import com.intellij.psi.PsiJavaFile; -import com.intellij.psi.PsiManager; -import com.intellij.psi.PsiModifier; -import jiux.net.plugin.restful.codegen.tool.CacheDataUtils; -import jiux.net.plugin.restful.codegen.ui.SelectSavePath; -import org.jetbrains.annotations.NotNull; - -import java.util.Arrays; -import java.util.List; -import java.util.stream.Collectors; - - -public class RestfulCodeEntityAction extends AnAction { - - private final CacheDataUtils cacheDataUtils = CacheDataUtils.getInstance(); - - @Override - public void actionPerformed(@NotNull AnActionEvent event) { - Project project = event.getProject(); - if (project == null) { - return; - } - - // 过滤选择Java文件 - VirtualFile[] psiFiles = event.getData(CommonDataKeys.VIRTUAL_FILE_ARRAY); - if (psiFiles == null) { - return; - } - PsiManager psiManager = PsiManager.getInstance(project); - List psiJavaFiles = Arrays.stream(psiFiles) - .map(psiManager::findFile) - .filter(f -> f instanceof PsiJavaFile) - .map(f -> (PsiJavaFile) f) - .collect(Collectors.toList()); - if (psiJavaFiles.size() == 0) { - return; - } - - // 获取选中的类 - List psiClassList = resolvePsiClassByFile(psiJavaFiles); - if (psiClassList.size() == 0) { - return; - } - - // 缓存选中值 - cacheDataUtils.setSelectPsiClass(psiClassList.get(0)); - cacheDataUtils.setPsiClassList(psiClassList); - new SelectSavePath(project, true).show(); - } - - /** - * 解析类 - */ - private List resolvePsiClassByFile(List psiJavaFiles) { - List psiClassList = Lists.newArrayListWithCapacity(psiJavaFiles.size()); - for (PsiJavaFile psiJavaFile : psiJavaFiles) { - Arrays.stream(psiJavaFile.getClasses()) - .filter(o -> o.getModifierList() != null && o.getModifierList().hasModifierProperty(PsiModifier.PUBLIC)) - .findFirst().ifPresent(psiClassList::add); - } - return psiClassList; - } - - -} diff --git a/src/main/java/jiux/net/plugin/restful/codegen/actions/package-info.java b/src/main/java/jiux/net/plugin/restful/codegen/actions/package-info.java deleted file mode 100644 index f5c78d0..0000000 --- a/src/main/java/jiux/net/plugin/restful/codegen/actions/package-info.java +++ /dev/null @@ -1,8 +0,0 @@ -/** - * 包含所有的动作事件 - * - * @author makejava - * @version 1.0.0 - * @since 2018/08/10 21:37 - */ -package jiux.net.plugin.restful.codegen.actions; diff --git a/src/main/java/jiux/net/plugin/restful/codegen/constants/StrState.java b/src/main/java/jiux/net/plugin/restful/codegen/constants/StrState.java deleted file mode 100644 index b0016d5..0000000 --- a/src/main/java/jiux/net/plugin/restful/codegen/constants/StrState.java +++ /dev/null @@ -1,15 +0,0 @@ -package jiux.net.plugin.restful.codegen.constants; - -/** - * 字符串常量 - * - * @author makejava - * @version 1.0.0 - * @since 2018/09/03 09:32 - */ -public class StrState { - /** - * 相对路径常量 - */ - public static final String RELATIVE_PATH = "./"; -} diff --git a/src/main/java/jiux/net/plugin/restful/codegen/dict/GlobalDict.java b/src/main/java/jiux/net/plugin/restful/codegen/dict/GlobalDict.java deleted file mode 100644 index 38e2939..0000000 --- a/src/main/java/jiux/net/plugin/restful/codegen/dict/GlobalDict.java +++ /dev/null @@ -1,52 +0,0 @@ -package jiux.net.plugin.restful.codegen.dict; - -/** - * 全局字典 - * - * @author makejava - * @version 1.0.0 - * @date 2021/08/07 11:41 - */ -public interface GlobalDict { - /** - * 提示信息 - */ - String TITLE_INFO = "RestfulToolkitX Title Info"; - /** - * 版本号 - */ - String VERSION = "1.2.4"; - /** - * 作者名称 - */ - String AUTHOR = "RestfulToolkitX-Code"; - /** - * 默认分组名称 - */ - String DEFAULT_GROUP_NAME = "Default"; - /** - * 默认的Java类型列表 - */ - String[] DEFAULT_JAVA_TYPE_LIST = new String[]{ - "java.lang.String", - "java.lang.Integer", - "java.lang.Long", - "java.util.Boolean", - "java.util.Date", - "java.time.LocalDateTime", - "java.time.LocalDate", - "java.time.LocalTime", - "java.lang.Short", - "java.lang.Byte", - "java.lang.Character", - "java.lang.Character", - "java.math.BigDecimal", - "java.math.BigInteger", - "java.lang.Double", - "java.lang.Float", - "java.lang.String[]", - "java.util.List", - "java.util.Set", - "java.util.Map", - }; -} diff --git a/src/main/java/jiux/net/plugin/restful/codegen/dto/ColumnInfoDTO.java b/src/main/java/jiux/net/plugin/restful/codegen/dto/ColumnInfoDTO.java deleted file mode 100644 index b115210..0000000 --- a/src/main/java/jiux/net/plugin/restful/codegen/dto/ColumnInfoDTO.java +++ /dev/null @@ -1,80 +0,0 @@ -package jiux.net.plugin.restful.codegen.dto; - -import jiux.net.plugin.restful.codegen.entity.TypeMapper; -import jiux.net.plugin.restful.codegen.enums.MatchType; -import jiux.net.plugin.restful.codegen.tool.CurrGroupUtils; -import jiux.net.plugin.restful.codegen.tool.DocCommentUtils; -import jiux.net.plugin.restful.codegen.tool.NameUtils; -import com.intellij.database.model.DasColumn; -import com.intellij.psi.PsiField; -import lombok.Data; -import lombok.NoArgsConstructor; - -import java.util.HashMap; -import java.util.Map; -import java.util.regex.Pattern; - -/** - * 列信息传输对象 - * - * @author makejava - * @version 1.0.0 - * @date 2021/08/14 17:29 - */ -@Data -@NoArgsConstructor -public class ColumnInfoDTO { - - public ColumnInfoDTO(PsiField field) { - this.name = field.getName(); - this.comment = DocCommentUtils.getComment(field.getDocComment()); - this.type = field.getType().getCanonicalText(); - this.custom = false; - this.ext = new HashMap<>(); - } - - public ColumnInfoDTO(DasColumn column) { - this.name = NameUtils.getInstance().getJavaName(column.getName()); - this.comment = column.getComment(); - this.type = getJavaType(column.getDataType().toString()); - this.custom = false; - this.ext = new HashMap<>(); - } - - private String getJavaType(String dbType) { - for (TypeMapper typeMapper : CurrGroupUtils.getCurrTypeMapperGroup().getElementList()) { - if (typeMapper.getMatchType() == MatchType.ORDINARY) { - if (dbType.equalsIgnoreCase(typeMapper.getColumnType())) { - return typeMapper.getJavaType(); - } - } else { - // 不区分大小写的正则匹配模式 - if (Pattern.compile(typeMapper.getColumnType(), Pattern.CASE_INSENSITIVE).matcher(dbType).matches()) { - return typeMapper.getJavaType(); - } - } - } - return "java.lang.Object"; - } - - /** - * 名称 - */ - private String name; - /** - * 注释 - */ - private String comment; - /** - * 全类型 - */ - private String type; - /** - * 标记是否为自定义附加列 - */ - private Boolean custom; - /** - * 扩展数据 - */ - private Map ext; -} diff --git a/src/main/java/jiux/net/plugin/restful/codegen/dto/GenerateOptions.java b/src/main/java/jiux/net/plugin/restful/codegen/dto/GenerateOptions.java deleted file mode 100644 index 829b995..0000000 --- a/src/main/java/jiux/net/plugin/restful/codegen/dto/GenerateOptions.java +++ /dev/null @@ -1,36 +0,0 @@ -package jiux.net.plugin.restful.codegen.dto; - -import lombok.Builder; -import lombok.Data; - -/** - * 生成选项 - * - * @author makejava - * @version 1.0.0 - * @date 2021/08/17 09:08 - */ -@Data -@Builder -public class GenerateOptions { - /** - * 实体类模式 - */ - private Boolean entityModel; - /** - * 统一配置 - */ - private Boolean unifiedConfig; - /** - * 重新格式化代码 - */ - private Boolean reFormat; - /** - * 提示选是 - */ - private Boolean titleSure; - /** - * 提示选否 - */ - private Boolean titleRefuse; -} diff --git a/src/main/java/jiux/net/plugin/restful/codegen/dto/SettingsStorageDTO.java b/src/main/java/jiux/net/plugin/restful/codegen/dto/SettingsStorageDTO.java deleted file mode 100644 index a650cd0..0000000 --- a/src/main/java/jiux/net/plugin/restful/codegen/dto/SettingsStorageDTO.java +++ /dev/null @@ -1,214 +0,0 @@ -package jiux.net.plugin.restful.codegen.dto; - -import jiux.net.plugin.restful.codegen.dict.GlobalDict; -import jiux.net.plugin.restful.codegen.entity.*; -import jiux.net.plugin.restful.codegen.enums.ColumnConfigType; -import jiux.net.plugin.restful.codegen.tool.CollectionUtil; -import jiux.net.plugin.restful.codegen.tool.JSON; -import jiux.net.plugin.restful.codegen.tool.StringUtils; -import com.fasterxml.jackson.annotation.JsonProperty; -import com.intellij.ide.fileTemplates.impl.UrlUtil; -import com.intellij.util.ExceptionUtil; -import lombok.Data; - -import java.util.Arrays; -import java.util.HashMap; -import java.util.Map; -import java.util.Objects; - -/** - * 设置储存传输对象 - * - * @author makejava - * @version 1.0.0 - * @date 2021/08/07 11:35 - */ -@Data -public class SettingsStorageDTO { - /** - * 返回默认值,不使用静态常量,防止默认值别篡改 - * - * @return 储存对象 - */ - public static SettingsStorageDTO defaultVal() { - try { - // 从配置文件中加载配置 - String json = UrlUtil.loadText(Objects.requireNonNull(SettingsStorageDTO.class.getResource("/defaultConfig.json"))); - return JSON.parse(json, SettingsStorageDTO.class); - } catch (Exception e) { - ExceptionUtil.rethrow(e); - } - // 配置文件加载失败,直接创建配置 - SettingsStorageDTO storage = new SettingsStorageDTO(); - storage.author = GlobalDict.AUTHOR; - storage.version = GlobalDict.VERSION; - storage.userSecure = ""; - // 默认分组名称 - storage.currTypeMapperGroupName = GlobalDict.DEFAULT_GROUP_NAME; - storage.currTemplateGroupName = GlobalDict.DEFAULT_GROUP_NAME; - storage.currColumnConfigGroupName = GlobalDict.DEFAULT_GROUP_NAME; - storage.currGlobalConfigGroupName = GlobalDict.DEFAULT_GROUP_NAME; - // 默认配置信息 - storage.typeMapperGroupMap = new HashMap<>(16); - TypeMapperGroup typeMapperGroup = new TypeMapperGroup(); - typeMapperGroup.setName(GlobalDict.DEFAULT_GROUP_NAME); - typeMapperGroup.setElementList(Arrays.asList(new TypeMapper("varchar", "java.lang.String"), new TypeMapper("varchar\\(\\)", "java.lang.String"))); - storage.typeMapperGroupMap.put(GlobalDict.DEFAULT_GROUP_NAME, typeMapperGroup); - - ColumnConfigGroup columnConfigGroup = new ColumnConfigGroup(); - columnConfigGroup.setName(GlobalDict.DEFAULT_GROUP_NAME); - columnConfigGroup.setElementList(Arrays.asList(new ColumnConfig("disable", ColumnConfigType.BOOLEAN), new ColumnConfig("operator", ColumnConfigType.SELECT, "insert,update,delete,select"))); - storage.columnConfigGroupMap = new HashMap<>(16); - storage.columnConfigGroupMap.put(GlobalDict.DEFAULT_GROUP_NAME, columnConfigGroup); - - TemplateGroup templateGroup = new TemplateGroup(); - templateGroup.setName(GlobalDict.DEFAULT_GROUP_NAME); - templateGroup.setElementList(Arrays.asList(new Template("demo", "template"), new Template("entity.java", "public"))); - storage.templateGroupMap = new HashMap<>(16); - storage.templateGroupMap.put(GlobalDict.DEFAULT_GROUP_NAME, templateGroup); - - GlobalConfigGroup globalConfigGroup = new GlobalConfigGroup(); - globalConfigGroup.setName(GlobalDict.DEFAULT_GROUP_NAME); - globalConfigGroup.setElementList(Arrays.asList(new GlobalConfig("test", "abc"), new GlobalConfig("demo", "value"))); - storage.globalConfigGroupMap = new HashMap<>(16); - storage.globalConfigGroupMap.put(GlobalDict.DEFAULT_GROUP_NAME, globalConfigGroup); - return storage; - } - - /** - * 重置为默认值 - */ - public void resetDefaultVal() { - SettingsStorageDTO defaultVal = defaultVal(); - this.setAuthor(defaultVal.getAuthor()); - this.setVersion(defaultVal.getVersion()); - this.setCurrColumnConfigGroupName(GlobalDict.DEFAULT_GROUP_NAME); - this.getColumnConfigGroupMap().put(GlobalDict.DEFAULT_GROUP_NAME, defaultVal.getColumnConfigGroupMap().get(GlobalDict.DEFAULT_GROUP_NAME)); - this.setCurrTemplateGroupName(GlobalDict.DEFAULT_GROUP_NAME); - this.getTemplateGroupMap().put(GlobalDict.DEFAULT_GROUP_NAME, defaultVal.getTemplateGroupMap().get(GlobalDict.DEFAULT_GROUP_NAME)); - this.setCurrGlobalConfigGroupName(GlobalDict.DEFAULT_GROUP_NAME); - this.getGlobalConfigGroupMap().put(GlobalDict.DEFAULT_GROUP_NAME, defaultVal.getGlobalConfigGroupMap().get(GlobalDict.DEFAULT_GROUP_NAME)); - this.setCurrTypeMapperGroupName(GlobalDict.DEFAULT_GROUP_NAME); - this.getTypeMapperGroupMap().put(GlobalDict.DEFAULT_GROUP_NAME, defaultVal.getTypeMapperGroupMap().get(GlobalDict.DEFAULT_GROUP_NAME)); - // 恢复已被删除的分组 - defaultVal.getTemplateGroupMap().forEach((k, v) -> { - if (!getTemplateGroupMap().containsKey(k)) { - getTemplateGroupMap().put(k,v ); - } - }); - defaultVal.getGlobalConfigGroupMap().forEach((k, v) -> { - if (!getGlobalConfigGroupMap().containsKey(k)) { - getGlobalConfigGroupMap().put(k,v ); - } - }); - defaultVal.getColumnConfigGroupMap().forEach((k, v) -> { - if (!getColumnConfigGroupMap().containsKey(k)) { - getColumnConfigGroupMap().put(k,v ); - } - }); - defaultVal.getTypeMapperGroupMap().forEach((k, v) -> { - if (!getTypeMapperGroupMap().containsKey(k)) { - getTypeMapperGroupMap().put(k,v ); - } - }); - } - - /** - * 作者 - */ - private String author; - /** - * 版本号 - */ - private String version; - /** - * 用户密钥 - */ - private String userSecure; - /** - * 当前类型映射组名 - */ - private String currTypeMapperGroupName; - /** - * 类型映射组 - */ - @JsonProperty("typeMapper") - private Map typeMapperGroupMap; - /** - * 当前模板组名 - */ - private String currTemplateGroupName; - /** - * 模板组 - */ - @JsonProperty("template") - private Map templateGroupMap; - /** - * 当前配置表组名 - */ - private String currColumnConfigGroupName; - /** - * 配置表组 - */ - @JsonProperty("columnConfig") - private Map columnConfigGroupMap; - /** - * 当前全局配置组名 - */ - private String currGlobalConfigGroupName; - /** - * 全局配置组 - */ - @JsonProperty("globalConfig") - private Map globalConfigGroupMap; - - public void fillDefaultVal() { - SettingsStorageDTO defaultVal = defaultVal(); - if (CollectionUtil.isEmpty(this.typeMapperGroupMap)) { - this.typeMapperGroupMap = defaultVal.getTypeMapperGroupMap(); - } - if (!this.typeMapperGroupMap.containsKey(GlobalDict.DEFAULT_GROUP_NAME)) { - this.typeMapperGroupMap.put(GlobalDict.DEFAULT_GROUP_NAME, defaultVal.getTypeMapperGroupMap().get(GlobalDict.DEFAULT_GROUP_NAME)); - } - if (StringUtils.isEmpty(this.currTypeMapperGroupName)) { - this.setCurrTypeMapperGroupName(GlobalDict.DEFAULT_GROUP_NAME); - } - - - if (CollectionUtil.isEmpty(this.templateGroupMap)) { - this.templateGroupMap = defaultVal.getTemplateGroupMap(); - } - if (!this.templateGroupMap.containsKey(GlobalDict.DEFAULT_GROUP_NAME)) { - this.templateGroupMap.put(GlobalDict.DEFAULT_GROUP_NAME, defaultVal.getTemplateGroupMap().get(GlobalDict.DEFAULT_GROUP_NAME)); - } - if (StringUtils.isEmpty(this.currTemplateGroupName)) { - this.setCurrTemplateGroupName(GlobalDict.DEFAULT_GROUP_NAME); - } - - - if (CollectionUtil.isEmpty(this.columnConfigGroupMap)) { - this.columnConfigGroupMap = defaultVal.getColumnConfigGroupMap(); - } - if (!this.columnConfigGroupMap.containsKey(GlobalDict.DEFAULT_GROUP_NAME)) { - this.columnConfigGroupMap.put(GlobalDict.DEFAULT_GROUP_NAME, defaultVal.getColumnConfigGroupMap().get(GlobalDict.DEFAULT_GROUP_NAME)); - } - if (StringUtils.isEmpty(this.currColumnConfigGroupName)) { - this.setCurrColumnConfigGroupName(GlobalDict.DEFAULT_GROUP_NAME); - } - - - if (CollectionUtil.isEmpty(this.globalConfigGroupMap)) { - this.globalConfigGroupMap = defaultVal.getGlobalConfigGroupMap(); - } - if (!this.globalConfigGroupMap.containsKey(GlobalDict.DEFAULT_GROUP_NAME)) { - this.globalConfigGroupMap.put(GlobalDict.DEFAULT_GROUP_NAME, defaultVal.getGlobalConfigGroupMap().get(GlobalDict.DEFAULT_GROUP_NAME)); - } - if (StringUtils.isEmpty(this.currGlobalConfigGroupName)) { - this.setCurrGlobalConfigGroupName(GlobalDict.DEFAULT_GROUP_NAME); - } - - if (StringUtils.isEmpty(this.version)) { - this.setVersion(defaultVal.getVersion()); - } - } -} diff --git a/src/main/java/jiux/net/plugin/restful/codegen/dto/TableInfoDTO.java b/src/main/java/jiux/net/plugin/restful/codegen/dto/TableInfoDTO.java deleted file mode 100644 index a0dab01..0000000 --- a/src/main/java/jiux/net/plugin/restful/codegen/dto/TableInfoDTO.java +++ /dev/null @@ -1,247 +0,0 @@ -package jiux.net.plugin.restful.codegen.dto; - -import jiux.net.plugin.restful.codegen.entity.ColumnInfo; -import jiux.net.plugin.restful.codegen.entity.TableInfo; -import jiux.net.plugin.restful.codegen.tool.*; -import com.intellij.database.model.DasColumn; -import com.intellij.database.psi.DbTable; -import com.intellij.database.util.DasUtil; -import com.intellij.psi.PsiClass; -import com.intellij.psi.PsiField; -import com.intellij.util.containers.JBIterable; -import lombok.Data; -import lombok.NoArgsConstructor; - -import java.util.ArrayList; -import java.util.HashMap; -import java.util.List; -import java.util.Map; -import java.util.stream.Collectors; - -/** - * 表格信息传输对象 - * - * @author makejava - * @version 1.0.0 - * @date 2021/08/14 17:28 - */ -@Data -@NoArgsConstructor -public class TableInfoDTO { - - public TableInfoDTO(TableInfoDTO dto, DbTable dbTable) { - this(dbTable); - merge(dto, this); - } - - public TableInfoDTO(TableInfoDTO dto, PsiClass psiClass) { - this(psiClass); - merge(dto, this); - } - - private TableInfoDTO(PsiClass psiClass) { - this.name = psiClass.getName(); - this.preName = ""; - this.comment = DocCommentUtils.getComment(psiClass.getDocComment()); - this.templateGroupName = ""; - this.savePackageName = ""; - this.savePath = ""; - this.saveModelName = ""; - this.fullColumn = new ArrayList<>(); - for (PsiField field : psiClass.getAllFields()) { - this.fullColumn.add(new ColumnInfoDTO(field)); - } - } - - private TableInfoDTO(DbTable dbTable) { - this.name = NameUtils.getInstance().getClassName(dbTable.getName()); - this.preName = ""; - this.comment = dbTable.getComment(); - this.templateGroupName = ""; - this.savePackageName = ""; - this.savePath = ""; - this.saveModelName = ""; - this.fullColumn = new ArrayList<>(); - // 处理所有列 - JBIterable columns = DasUtil.getColumns(dbTable); - for (DasColumn column : columns) { - this.fullColumn.add(new ColumnInfoDTO(column)); - } - } - - private static void merge(TableInfoDTO oldData, TableInfoDTO newData) { - if (oldData == null || CollectionUtil.isEmpty(oldData.getFullColumn())) { - return; - } - if (!StringUtils.isEmpty(oldData.getPreName())) { - newData.preName = oldData.getPreName(); - } - if (!StringUtils.isEmpty(oldData.getTemplateGroupName())) { - newData.templateGroupName = oldData.getTemplateGroupName(); - } - if (!StringUtils.isEmpty(oldData.getSavePackageName())) { - newData.savePackageName = oldData.getSavePackageName(); - } - if (!StringUtils.isEmpty(oldData.getSavePath())) { - newData.savePath = oldData.getSavePath(); - } - if (!StringUtils.isEmpty(oldData.getSaveModelName())) { - newData.saveModelName = oldData.getSaveModelName(); - } - // 补充自定义列 - for (ColumnInfoDTO oldColumn : oldData.getFullColumn()) { - if (!oldColumn.getCustom()) { - continue; - } - newData.getFullColumn().add(oldColumn); - } - // 保持旧列的顺序 - Map map = newData.getFullColumn().stream().collect(Collectors.toMap(ColumnInfoDTO::getName, val -> val)); - List tmpList = new ArrayList<>(); - for (ColumnInfoDTO columnInfo : oldData.getFullColumn()) { - ColumnInfoDTO newColumn = map.get(columnInfo.getName()); - if (newColumn != null) { - tmpList.add(newColumn); - } - } - // 补充剩余列 - for (ColumnInfoDTO columnInfoDTO : newData.getFullColumn()) { - if (!tmpList.contains(columnInfoDTO)) { - tmpList.add(columnInfoDTO); - } - } - // list数据替换 - newData.getFullColumn().clear(); - newData.getFullColumn().addAll(tmpList); - } - - - /** - * 表名(首字母大写) - */ - private String name; - /** - * 表名前缀 - */ - private String preName; - /** - * 注释 - */ - private String comment; - /** - * 模板组名称 - */ - private String templateGroupName; - /** - * 所有列 - */ - private List fullColumn; - /** - * 保存的包名称 - */ - private String savePackageName; - /** - * 保存路径 - */ - private String savePath; - /** - * 保存的model名称 - */ - private String saveModelName; - - public TableInfo toTableInfo(PsiClass psiClass) { - TableInfo tableInfo = new TableInfo(); - tableInfo.setPsiClassObj(psiClass); - tableInfo.setName(this.getName()); - tableInfo.setPreName(this.getPreName()); - tableInfo.setTemplateGroupName(this.getTemplateGroupName()); - tableInfo.setSavePackageName(this.getSavePackageName()); - tableInfo.setSavePath(this.getSavePath()); - tableInfo.setComment(this.getComment()); - tableInfo.setSaveModelName(this.getSaveModelName()); - tableInfo.setFullColumn(new ArrayList<>()); - tableInfo.setPkColumn(new ArrayList<>()); - tableInfo.setOtherColumn(new ArrayList<>()); - for (PsiField field : psiClass.getAllFields()) { - if (PsiClassGenerateUtils.isSkipField(field)) { - continue; - } - ColumnInfo columnInfo = new ColumnInfo(); - columnInfo.setName(field.getName()); - columnInfo.setShortType(field.getType().getPresentableText()); - columnInfo.setType(field.getType().getCanonicalText()); - columnInfo.setComment(DocCommentUtils.getComment(field.getDocComment())); - columnInfo.setCustom(false); - tableInfo.getFullColumn().add(columnInfo); - if (PsiClassGenerateUtils.isPkField(field)) { - tableInfo.getPkColumn().add(columnInfo); - } else { - tableInfo.getOtherColumn().add(columnInfo); - } - } - return tableInfo; - } - - public TableInfo toTableInfo(DbTable dbTable) { - TableInfo tableInfo = new TableInfo(); - tableInfo.setObj(dbTable); - tableInfo.setName(this.getName()); - tableInfo.setPreName(this.getPreName()); - tableInfo.setTemplateGroupName(this.getTemplateGroupName()); - tableInfo.setSavePackageName(this.getSavePackageName()); - tableInfo.setSavePath(this.getSavePath()); - tableInfo.setComment(this.getComment()); - tableInfo.setSaveModelName(this.getSaveModelName()); - tableInfo.setFullColumn(new ArrayList<>()); - tableInfo.setPkColumn(new ArrayList<>()); - tableInfo.setOtherColumn(new ArrayList<>()); - // 列 - JBIterable columns = DasUtil.getColumns(dbTable); - Map nameToObj = new HashMap<>(columns.size()); - for (DasColumn column : columns) { - nameToObj.put(NameUtils.getInstance().getJavaName(column.getName()), column); - } - for (ColumnInfoDTO dto : this.getFullColumn()) { - ColumnInfo columnInfo = new ColumnInfo(); - columnInfo.setObj(nameToObj.get(dto.getName())); - columnInfo.setName(dto.getName()); - columnInfo.setType(dto.getType()); - // 最后一节为短类型 - String[] split = dto.getType().split("\\."); - columnInfo.setShortType(split[split.length - 1]); - columnInfo.setComment(dto.getComment()); - columnInfo.setCustom(dto.getCustom()); - columnInfo.setExt(dto.getExt()); - tableInfo.getFullColumn().add(columnInfo); - if (columnInfo.getObj() != null && DasUtil.isPrimary(columnInfo.getObj())) { - tableInfo.getPkColumn().add(columnInfo); - } else { - tableInfo.getOtherColumn().add(columnInfo); - } - } - return tableInfo; - } - - public static TableInfoDTO valueOf(TableInfo tableInfo) { - TableInfoDTO dto = new TableInfoDTO(); - dto.setName(tableInfo.getName()); - dto.setTemplateGroupName(tableInfo.getTemplateGroupName()); - dto.setSavePath(tableInfo.getSavePath()); - dto.setPreName(tableInfo.getPreName()); - dto.setComment(tableInfo.getComment()); - dto.setSavePackageName(tableInfo.getSavePackageName()); - dto.setSaveModelName(tableInfo.getSaveModelName()); - dto.setFullColumn(new ArrayList<>()); - // 处理列 - for (ColumnInfo columnInfo : tableInfo.getFullColumn()) { - ColumnInfoDTO columnInfoDTO = new ColumnInfoDTO(); - columnInfoDTO.setName(columnInfo.getName()); - columnInfoDTO.setType(columnInfo.getType()); - columnInfoDTO.setExt(columnInfo.getExt()); - columnInfoDTO.setCustom(columnInfo.getCustom()); - columnInfoDTO.setComment(columnInfo.getComment()); - dto.getFullColumn().add(columnInfoDTO); - } - return dto; - } -} diff --git a/src/main/java/jiux/net/plugin/restful/codegen/dto/TableInfoSettingsDTO.java b/src/main/java/jiux/net/plugin/restful/codegen/dto/TableInfoSettingsDTO.java deleted file mode 100644 index c22822b..0000000 --- a/src/main/java/jiux/net/plugin/restful/codegen/dto/TableInfoSettingsDTO.java +++ /dev/null @@ -1,119 +0,0 @@ -package jiux.net.plugin.restful.codegen.dto; - -import jiux.net.plugin.restful.codegen.entity.TableInfo; -import com.intellij.database.model.DasNamespace; -import com.intellij.database.psi.DbElement; -import com.intellij.database.psi.DbTable; -import com.intellij.psi.PsiClass; -import lombok.Data; - -import java.lang.reflect.InvocationTargetException; -import java.lang.reflect.Method; -import java.util.HashMap; -import java.util.Map; - -/** - * 表格信息设置传输对象 - * - * @author makejava - * @version 1.0.0 - * @date 2021/08/14 17:40 - */ -@Data -public class TableInfoSettingsDTO { - private Map tableInfoMap; - - public TableInfoSettingsDTO() { - this.tableInfoMap = new HashMap<>(16); - } - - private String generateKey(DbTable dbTable) { - // 递归添加3层名称作为key,第一层为表名、第二层为名命空间名称、第三层为数据库名 - StringBuilder builder = new StringBuilder(); - DbElement element = dbTable; - for (int i = 0; i < 3; i++) { - String name = element.getName(); - if (builder.length() > 0) { - // 添加分割符 - builder.insert(0, "."); - } - builder.insert(0, name); - try { - Method method = element.getClass().getDeclaredMethod("getParent"); - element = (DbElement) method.invoke(element); - } catch (NoSuchMethodException | IllegalAccessException | InvocationTargetException e) { - break; - } - // 未必所有的数据库都是存在三层,例如MySQL就只有两层。如果上次层不是Namespace,则不再继续获取 - if (!(element instanceof DasNamespace)) { - break; - } - } - return builder.toString(); - } - - private String generateKey(PsiClass psiClass) { - return psiClass.getQualifiedName(); - } - /** - * 读表信息 - * - * @param psiClass psi类 - * @return {@link TableInfo} - */ - @SuppressWarnings("Duplicates") - public TableInfo readTableInfo(PsiClass psiClass) { - String key = generateKey(psiClass); - TableInfoDTO dto = this.tableInfoMap.get(key); - dto = new TableInfoDTO(dto, psiClass); - this.tableInfoMap.put(key, dto); - return dto.toTableInfo(psiClass); - } - - /** - * 读表信息 - * - * @param dbTable 数据库表 - * @return {@link TableInfo} - */ - @SuppressWarnings("Duplicates") - public TableInfo readTableInfo(DbTable dbTable) { - String key = generateKey(dbTable); - TableInfoDTO dto = this.tableInfoMap.get(key); - dto = new TableInfoDTO(dto, dbTable); - this.tableInfoMap.put(key, dto); - return dto.toTableInfo(dbTable); - } - - /** - * 保存表信息 - * - * @param tableInfo 表信息 - */ - public void saveTableInfo(TableInfo tableInfo) { - if (tableInfo == null) { - return; - } - DbTable dbTable = tableInfo.getObj(); - PsiClass psiClass = tableInfo.getPsiClassObj(); - String key; - if (dbTable != null) { - key = generateKey(dbTable); - } else if (psiClass != null) { - key = generateKey(psiClass); - } else { - return; - } - this.tableInfoMap.put(key, TableInfoDTO.valueOf(tableInfo)); - } - - /** - * 重置表信息 - * - * @param dbTable 数据库表 - */ - public void resetTableInfo(DbTable dbTable) { - String key = generateKey(dbTable); - this.tableInfoMap.put(key, new TableInfoDTO(null, dbTable)); - } -} diff --git a/src/main/java/jiux/net/plugin/restful/codegen/entity/AbstractEditorItem.java b/src/main/java/jiux/net/plugin/restful/codegen/entity/AbstractEditorItem.java deleted file mode 100644 index 461d3ab..0000000 --- a/src/main/java/jiux/net/plugin/restful/codegen/entity/AbstractEditorItem.java +++ /dev/null @@ -1,38 +0,0 @@ -package jiux.net.plugin.restful.codegen.entity; - -/** - * 抽象的可编辑元素 - * - * @author makejava - * @version 1.0.0 - * @date 2021/08/11 13:45 - */ -public interface AbstractEditorItem extends AbstractItem { - /** - * 更改文件名称 - * - * @param name 文件名称 - */ - void changeFileName(String name); - - /** - * 获取文件名称 - * - * @return {@link String} - */ - String fileName(); - - /** - * 改变文件内容 - * - * @param content 内容 - */ - void changeFileContent(String content); - - /** - * 获取文件内容 - * - * @return {@link String} - */ - String fileContent(); -} diff --git a/src/main/java/jiux/net/plugin/restful/codegen/entity/AbstractGroup.java b/src/main/java/jiux/net/plugin/restful/codegen/entity/AbstractGroup.java deleted file mode 100644 index 03573a7..0000000 --- a/src/main/java/jiux/net/plugin/restful/codegen/entity/AbstractGroup.java +++ /dev/null @@ -1,65 +0,0 @@ -package jiux.net.plugin.restful.codegen.entity; - -import jiux.net.plugin.restful.codegen.factory.AbstractItemFactory; -import jiux.net.plugin.restful.codegen.tool.CloneUtils; -import jiux.net.plugin.restful.codegen.tool.ReflectionUtils; - -import java.util.List; - -/** - * 抽象分组类 - * - * @author makejava - * @version 1.0.0 - * @since 2018/07/17 13:10 - */ -public interface AbstractGroup> { - /** - * 获取分组名称 - * - * @return 分组名称 - */ - String getName(); - - /** - * 设置分组名称 - * - * @param name 分组名称 - */ - void setName(String name); - - /** - * 获取元素集合 - * - * @return 元素集合 - */ - List getElementList(); - - /** - * 设置元素集合 - * - * @param elementList 元素集合 - */ - void setElementList(List elementList); - - /** - * 默认子元素 - * - * @return {@link E} - */ - @SuppressWarnings("unchecked") - default E defaultChild() { - Class cls = (Class) ReflectionUtils.getGenericClass(this, 1); - return AbstractItemFactory.createDefaultVal(cls); - } - - /** - * 克隆对象 - * - * @return {@link T} - */ - default T cloneObj() { - //noinspection unchecked - return (T) CloneUtils.cloneByJson(this); - } -} diff --git a/src/main/java/jiux/net/plugin/restful/codegen/entity/AbstractItem.java b/src/main/java/jiux/net/plugin/restful/codegen/entity/AbstractItem.java deleted file mode 100644 index 5b01ed4..0000000 --- a/src/main/java/jiux/net/plugin/restful/codegen/entity/AbstractItem.java +++ /dev/null @@ -1,29 +0,0 @@ -package jiux.net.plugin.restful.codegen.entity; - -import jiux.net.plugin.restful.codegen.tool.CloneUtils; - -/** - * 抽象的项 - * - * @author makejava - * @version 1.0.0 - * @date 2021/08/11 09:47 - */ -public interface AbstractItem { - /** - * 默认值 - * - * @return {@link T} - */ - T defaultVal(); - - /** - * 克隆对象 - * - * @return 克隆结果 - */ - @SuppressWarnings("unchecked") - default T cloneObj() { - return (T) CloneUtils.cloneByJson(this); - } -} diff --git a/src/main/java/jiux/net/plugin/restful/codegen/entity/Callback.java b/src/main/java/jiux/net/plugin/restful/codegen/entity/Callback.java deleted file mode 100644 index 7f0c371..0000000 --- a/src/main/java/jiux/net/plugin/restful/codegen/entity/Callback.java +++ /dev/null @@ -1,30 +0,0 @@ -package jiux.net.plugin.restful.codegen.entity; - -import lombok.Data; - -/** - * 回调实体类 - * - * @author makejava - * @version 1.0.0 - * @since 2018/07/17 13:10 - */ -@Data -public class Callback { - /** - * 文件名 - */ - private String fileName; - /** - * 保存路径 - */ - private String savePath; - /** - * 是否重新格式化代码 - */ - private Boolean reformat; - /** - * 是否写入文件,部分模块不需要写入文件。例如debug.json模板 - */ - private Boolean writeFile; -} diff --git a/src/main/java/jiux/net/plugin/restful/codegen/entity/ColumnConfig.java b/src/main/java/jiux/net/plugin/restful/codegen/entity/ColumnConfig.java deleted file mode 100644 index dd808c1..0000000 --- a/src/main/java/jiux/net/plugin/restful/codegen/entity/ColumnConfig.java +++ /dev/null @@ -1,45 +0,0 @@ -package jiux.net.plugin.restful.codegen.entity; - -import jiux.net.plugin.restful.codegen.enums.ColumnConfigType; -import lombok.Data; -import lombok.NoArgsConstructor; - -/** - * 列配置信息 - * - * @author makejava - * @version 1.0.0 - * @since 2018/07/17 13:10 - */ -@Data -@NoArgsConstructor -public class ColumnConfig implements AbstractItem { - /** - * 标题 - */ - private String title; - /** - * 类型 - */ - private ColumnConfigType type; - /** - * 可选值,逗号分割 - */ - private String selectValue; - - public ColumnConfig(String title, ColumnConfigType type) { - this.title = title; - this.type = type; - } - - public ColumnConfig(String title, ColumnConfigType type, String selectValue) { - this.title = title; - this.type = type; - this.selectValue = selectValue; - } - - @Override - public ColumnConfig defaultVal() { - return new ColumnConfig("demo", ColumnConfigType.TEXT); - } -} diff --git a/src/main/java/jiux/net/plugin/restful/codegen/entity/ColumnConfigGroup.java b/src/main/java/jiux/net/plugin/restful/codegen/entity/ColumnConfigGroup.java deleted file mode 100644 index cb1148d..0000000 --- a/src/main/java/jiux/net/plugin/restful/codegen/entity/ColumnConfigGroup.java +++ /dev/null @@ -1,24 +0,0 @@ -package jiux.net.plugin.restful.codegen.entity; - -import lombok.Data; - -import java.util.List; - -/** - * 列配置分组 - * - * @author makejava - * @version 1.0.0 - * @since 2018/07/18 09:33 - */ -@Data -public class ColumnConfigGroup implements AbstractGroup { - /** - * 分组名称 - */ - private String name; - /** - * 元素对象 - */ - private List elementList; -} diff --git a/src/main/java/jiux/net/plugin/restful/codegen/entity/ColumnInfo.java b/src/main/java/jiux/net/plugin/restful/codegen/entity/ColumnInfo.java deleted file mode 100644 index 4eb900a..0000000 --- a/src/main/java/jiux/net/plugin/restful/codegen/entity/ColumnInfo.java +++ /dev/null @@ -1,47 +0,0 @@ -package jiux.net.plugin.restful.codegen.entity; - -import com.fasterxml.jackson.annotation.JsonIgnore; -import com.intellij.database.model.DasColumn; -import lombok.Data; - -import java.util.Map; - -/** - * 列信息 - * - * @author makejava - * @version 1.0.0 - * @since 2018/07/17 13:10 - */ -@Data -public class ColumnInfo { - /** - * 原始对象 - */ - @JsonIgnore - private DasColumn obj; - /** - * 名称 - */ - private String name; - /** - * 注释 - */ - private String comment; - /** - * 全类型 - */ - private String type; - /** - * 短类型 - */ - private String shortType; - /** - * 标记是否为自定义附加列 - */ - private Boolean custom; - /** - * 扩展数据 - */ - private Map ext; -} diff --git a/src/main/java/jiux/net/plugin/restful/codegen/entity/DebugField.java b/src/main/java/jiux/net/plugin/restful/codegen/entity/DebugField.java deleted file mode 100644 index b291057..0000000 --- a/src/main/java/jiux/net/plugin/restful/codegen/entity/DebugField.java +++ /dev/null @@ -1,26 +0,0 @@ -package jiux.net.plugin.restful.codegen.entity; - -import lombok.Data; - -/** - * 调试字段实体类 - * - * @author makejava - * @version 1.0.0 - * @since 2018/09/03 11:09 - */ -@Data -public class DebugField { - /** - * 字段名 - */ - private String name; - /** - * 字段类型 - */ - private Class type; - /** - * 字段值 - */ - private String value; -} diff --git a/src/main/java/jiux/net/plugin/restful/codegen/entity/DebugMethod.java b/src/main/java/jiux/net/plugin/restful/codegen/entity/DebugMethod.java deleted file mode 100644 index 2d9950d..0000000 --- a/src/main/java/jiux/net/plugin/restful/codegen/entity/DebugMethod.java +++ /dev/null @@ -1,26 +0,0 @@ -package jiux.net.plugin.restful.codegen.entity; - -import lombok.Data; - -/** - * 调试方法实体类 - * - * @author makejava - * @version 1.0.0 - * @since 2018/09/03 11:10 - */ -@Data -public class DebugMethod { - /** - * 方法名 - */ - private String name; - /** - * 方法描述 - */ - private String desc; - /** - * 执行方法得到的值 - */ - private Object value; -} diff --git a/src/main/java/jiux/net/plugin/restful/codegen/entity/GlobalConfig.java b/src/main/java/jiux/net/plugin/restful/codegen/entity/GlobalConfig.java deleted file mode 100644 index 29c7374..0000000 --- a/src/main/java/jiux/net/plugin/restful/codegen/entity/GlobalConfig.java +++ /dev/null @@ -1,51 +0,0 @@ -package jiux.net.plugin.restful.codegen.entity; - -import lombok.AllArgsConstructor; -import lombok.Data; -import lombok.NoArgsConstructor; - -/** - * 全局配置实体类 - * - * @author makejava - * @version 1.0.0 - * @since 2018/07/27 13:07 - */ -@Data -@NoArgsConstructor -@AllArgsConstructor -public class GlobalConfig implements AbstractEditorItem { - /** - * 名称 - */ - private String name; - /** - * 值 - */ - private String value; - - @Override - public GlobalConfig defaultVal() { - return new GlobalConfig("demo", "value"); - } - - @Override - public void changeFileName(String name) { - this.name = name; - } - - @Override - public String fileName() { - return this.name; - } - - @Override - public void changeFileContent(String content) { - this.value = content; - } - - @Override - public String fileContent() { - return this.value; - } -} diff --git a/src/main/java/jiux/net/plugin/restful/codegen/entity/GlobalConfigGroup.java b/src/main/java/jiux/net/plugin/restful/codegen/entity/GlobalConfigGroup.java deleted file mode 100644 index 70ccc59..0000000 --- a/src/main/java/jiux/net/plugin/restful/codegen/entity/GlobalConfigGroup.java +++ /dev/null @@ -1,24 +0,0 @@ -package jiux.net.plugin.restful.codegen.entity; - -import lombok.Data; - -import java.util.List; - -/** - * 全局配置分组 - * - * @author makejava - * @version 1.0.0 - * @since 2018/07/27 13:10 - */ -@Data -public class GlobalConfigGroup implements AbstractGroup { - /** - * 分组名称 - */ - private String name; - /** - * 元素对象集合 - */ - private List elementList; -} diff --git a/src/main/java/jiux/net/plugin/restful/codegen/entity/SaveFile.java b/src/main/java/jiux/net/plugin/restful/codegen/entity/SaveFile.java deleted file mode 100644 index 6009156..0000000 --- a/src/main/java/jiux/net/plugin/restful/codegen/entity/SaveFile.java +++ /dev/null @@ -1,286 +0,0 @@ -package jiux.net.plugin.restful.codegen.entity; - -import jiux.net.plugin.restful.codegen.dto.GenerateOptions; -import jiux.net.plugin.restful.codegen.tool.CompareFileUtils; -import jiux.net.plugin.restful.codegen.tool.FileUtils; -import jiux.net.plugin.restful.codegen.tool.MessageDialogUtils; -import jiux.net.plugin.restful.codegen.tool.ProjectUtils; -import com.intellij.openapi.diagnostic.Logger; -import com.intellij.openapi.editor.Document; -import com.intellij.openapi.fileEditor.FileDocumentManager; -import com.intellij.openapi.fileTypes.FileType; -import com.intellij.openapi.fileTypes.FileTypeManager; -import com.intellij.openapi.project.Project; -import com.intellij.openapi.ui.Messages; -import com.intellij.openapi.vfs.VfsUtil; -import com.intellij.openapi.vfs.VirtualFile; -import com.intellij.psi.PsiDocumentManager; -import com.intellij.testFramework.LightVirtualFile; -import lombok.Data; -import lombok.NonNull; - -import java.io.File; - -/** - * 需要保存的文件 - *

- * 如果文件保存在项目路径下,则使用idea提供的psi对象操作。如果文件保存在非项目路径下,则使用java原始IO流操作。 - * - * @author makejava - * @version 1.0.0 - * @since 2020/04/20 22:54 - */ -@Data -public class SaveFile { - private static final Logger LOG = Logger.getInstance(SaveFile.class); - /** - * 所属项目 - */ - private Project project; - /** - * 文件内容 - */ - private String content; - /** - * 文件工具类 - */ - private FileUtils fileUtils = FileUtils.getInstance(); - /** - * 回调对象 - */ - private Callback callback; - /** - * 生成配置 - */ - private GenerateOptions generateOptions; - - /** - * 保存文件 - * - * @param project 项目 - * @param content 内容 - * @param callback 回调 - * @param generateOptions 生成选项 - */ - public SaveFile(@NonNull Project project, @NonNull String content, @NonNull Callback callback, @NonNull GenerateOptions generateOptions) { - this.project = project; - this.callback = callback; - this.content = content.replace("\r", ""); - this.generateOptions = generateOptions; - } - - /** - * 文件是否为项目文件 - * - * @return 是否为项目文件 - */ - private boolean isProjectFile() { - VirtualFile baseDir = ProjectUtils.getBaseDir(project); - // 无法获取到项目基本目录,可能是Default项目,直接返回非项目文件 - if (baseDir == null) { - return false; - } - // 路径对比,判断项目路径是否为文件保存路径的子路径 - String projectPath = handlerPath(baseDir.getPath()); - String tmpFilePath = handlerPath(callback.getSavePath()); - if (tmpFilePath.length() > projectPath.length()) { - if (!"/".equals(tmpFilePath.substring(projectPath.length(), projectPath.length() + 1))) { - return false; - } - } - return tmpFilePath.indexOf(projectPath) == 0; - } - - /** - * 处理路径,统一分割符并转小写 - * - * @param path 路径 - * @return 处理后的路径 - */ - private String handlerPath(String path) { - return handlerPath(path, true); - } - - /** - * 处理路径,统一分割符并转小写 - * - * @param path 路径 - * @param lowerCase 是否转小写 - * @return 处理后的路径 - */ - private String handlerPath(String path, boolean lowerCase) { - // 统一分割符 - path = path.replace("\\", "/"); - // 避免重复分割符 - path = path.replace("//", "/"); - // 统一小写 - return lowerCase ? path.toLowerCase() : path; - } - - /** - * 通过IDEA自带的Psi文件方式写入 - */ - public void write() { - if (!Boolean.TRUE.equals(callback.getWriteFile())) { - return; - } - // 判断目录是否存在 - VirtualFile baseDir = ProjectUtils.getBaseDir(project); - if (baseDir == null) { - throw new IllegalStateException("项目基本路径不存在"); - } - // 处理保存路径 - String savePath = handlerPath(callback.getSavePath(), false); - if (isProjectFile()) { - // 删除保存路径的前面部分 - savePath = savePath.substring(handlerPath(baseDir.getPath()).length()); - } else { - baseDir = null; - } - // 删除开头与结尾的/符号 - while (savePath.startsWith("/")) { - savePath = savePath.substring(1); - } - while (savePath.endsWith("/")) { - savePath = savePath.substring(0, savePath.length() - 1); - } - // 查找保存目录是否存在 - VirtualFile saveDir; - if (baseDir == null) { - saveDir = VfsUtil.findFileByIoFile(new File(savePath), false); - } else { - saveDir = VfsUtil.findRelativeFile(baseDir, savePath.split("/")); - } - // 提示创建目录 - VirtualFile directory = titleCreateDir(saveDir, baseDir, savePath); - if (directory == null) { - return; - } - VirtualFile psiFile = directory.findChild(callback.getFileName()); - // 保存或覆盖 - saveOrReplaceFile(psiFile, directory); - } - - /** - * 提示创建目录 - * - * @param saveDir 保存路径 - * @return 是否放弃执行 - */ - private VirtualFile titleCreateDir(VirtualFile saveDir, VirtualFile baseDir, String savePath) { - if (saveDir != null) { - return saveDir; - } - // 尝试创建目录 - String msg = String.format("Directory %s Not Found, Confirm Create?", callback.getSavePath()); - if (generateOptions.getTitleSure()) { - saveDir = fileUtils.createChildDirectory(project, baseDir, savePath); - return saveDir; - } else if (generateOptions.getTitleRefuse()) { - return null; - } else { - if (MessageDialogUtils.yesNo(project, msg)) { - saveDir = fileUtils.createChildDirectory(project, baseDir, savePath); - return saveDir; - } - } - return null; - } - - /** - * 保存或替换文件 - * - * @param file 文件 - * @param directory 目录 - */ - private void saveOrReplaceFile(VirtualFile file, VirtualFile directory) { - PsiDocumentManager psiDocumentManager = PsiDocumentManager.getInstance(project); - Document document; - // 文件不存在直接创建 - if (file == null) { - file = fileUtils.createChildFile(project, directory, callback.getFileName()); - if (file == null) { - return; - } - document = coverFile(file); - } else { - // 提示覆盖文件 - if (generateOptions.getTitleSure()) { - // 默认选是 - document = coverFile(file); - } else if (generateOptions.getTitleRefuse()) { - // 默认选否 - return; - } else { - String msg = String.format("File %s Exists, Select Operate Mode?", file.getPath()); - int result = MessageDialogUtils.yesNoCancel(project, msg, "Convert", "Compare", "Cancel"); - switch (result) { - case Messages.YES: - // 覆盖文件 - document = coverFile(file); - break; - case Messages.NO: - // 对比代码时也格式化代码 - String newText = content; - if (Boolean.TRUE.equals(callback.getReformat())) { - // 保留旧文件内容,用新文件覆盖旧文件执行格式化,然后再还原旧文件内容 - String oldText = getFileText(file); - Document tmpDoc = coverFile(file); - // 格式化代码 - FileUtils.getInstance().reformatFile(project, file); - // 提交文档改动,并非VCS中的提交文件 - psiDocumentManager.commitDocument(tmpDoc); - // 获取新的文件内容 - newText = getFileText(file); - // 还原旧文件 - coverFile(file, oldText); - } - FileType fileType = FileTypeManager.getInstance().getFileTypeByFileName(callback.getFileName()); - CompareFileUtils.showCompareWindow(project, file, new LightVirtualFile(callback.getFileName(), fileType, newText)); - return; - case Messages.CANCEL: - default: - return; - } - } - } - // 执行代码格式化操作 - if (Boolean.TRUE.equals(callback.getReformat())) { - FileUtils.getInstance().reformatFile(project, file); - } - // 提交文档改动,并非VCS中的提交文件 - if (document != null) { - psiDocumentManager.commitDocument(document); - } - } - - private String getFileText(VirtualFile file) { - FileDocumentManager fileDocumentManager = FileDocumentManager.getInstance(); - Document document = fileDocumentManager.getDocument(file); - if (document == null) { - throw new IllegalStateException("virtual file to document failure"); - } - return document.getText(); - } - - /** - * 覆盖文件 - * - * @param file 文件 - * @return 覆盖后的文档对象 - */ - private Document coverFile(VirtualFile file) { - return coverFile(file, content); - } - - /** - * 覆盖文件 - * - * @param file 文件 - * @param text 文件内容 - * @return 覆盖后的文档对象 - */ - private Document coverFile(VirtualFile file, String text) { - return FileUtils.getInstance().writeFileContent(project, file, callback.getFileName(), text); - } -} diff --git a/src/main/java/jiux/net/plugin/restful/codegen/entity/TableInfo.java b/src/main/java/jiux/net/plugin/restful/codegen/entity/TableInfo.java deleted file mode 100644 index 80d3deb..0000000 --- a/src/main/java/jiux/net/plugin/restful/codegen/entity/TableInfo.java +++ /dev/null @@ -1,71 +0,0 @@ -package jiux.net.plugin.restful.codegen.entity; - -import com.fasterxml.jackson.annotation.JsonIgnore; -import com.intellij.database.psi.DbTable; -import com.intellij.psi.PsiClass; -import lombok.Data; - -import java.util.List; - -/** - * 表信息 - * - * @author makejava - * @version 1.0.0 - * @since 2018/07/17 13:10 - */ -@Data -public class TableInfo { - /** - * 原始对象 - */ - @JsonIgnore - private DbTable obj; - - /** - * 原始对象(从实体生成) - */ - @JsonIgnore - private PsiClass psiClassObj; - - /** - * 表名(首字母大写) - */ - private String name; - /** - * 表名前缀 - */ - private String preName; - /** - * 注释 - */ - private String comment; - /** - * 模板组名称 - */ - private String templateGroupName; - /** - * 所有列 - */ - private List fullColumn; - /** - * 主键列 - */ - private List pkColumn; - /** - * 其他列 - */ - private List otherColumn; - /** - * 保存的包名称 - */ - private String savePackageName; - /** - * 保存路径 - */ - private String savePath; - /** - * 保存的model名称 - */ - private String saveModelName; -} diff --git a/src/main/java/jiux/net/plugin/restful/codegen/entity/Template.java b/src/main/java/jiux/net/plugin/restful/codegen/entity/Template.java deleted file mode 100644 index af12068..0000000 --- a/src/main/java/jiux/net/plugin/restful/codegen/entity/Template.java +++ /dev/null @@ -1,51 +0,0 @@ -package jiux.net.plugin.restful.codegen.entity; - -import lombok.AllArgsConstructor; -import lombok.Data; -import lombok.NoArgsConstructor; - -/** - * 模板信息类 - * - * @author makejava - * @version 1.0.0 - * @since 2018/07/17 13:10 - */ -@Data -@NoArgsConstructor -@AllArgsConstructor -public class Template implements AbstractEditorItem