From 3662d104f434e75455ede136d8dfdb3746f8e054 Mon Sep 17 00:00:00 2001 From: makejava <1353036300@qq.com> Date: Mon, 3 Sep 2018 11:06:53 +0800 Subject: [PATCH] =?UTF-8?q?=E4=BC=98=E5=8C=96=E7=94=A8=E6=88=B7=E4=BD=93?= =?UTF-8?q?=E9=AA=8C=EF=BC=8C=E5=B0=86=E7=A9=BAmodule=E5=BE=80=E5=90=8E?= =?UTF-8?q?=E7=A7=BB?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/main/java/com/sjhy/plugin/Test.java | 16 ---------------- .../java/com/sjhy/plugin/tool/ModuleUtils.java | 10 ++++++++++ .../java/com/sjhy/plugin/ui/SelectSavePath.java | 17 ++++++++++++++++- 3 files changed, 26 insertions(+), 17 deletions(-) delete mode 100644 src/main/java/com/sjhy/plugin/Test.java diff --git a/src/main/java/com/sjhy/plugin/Test.java b/src/main/java/com/sjhy/plugin/Test.java deleted file mode 100644 index 91615fd..0000000 --- a/src/main/java/com/sjhy/plugin/Test.java +++ /dev/null @@ -1,16 +0,0 @@ -package com.sjhy.plugin; - -import java.io.IOException; - -/** - * 临时测试类 - * - * @author makejava - * @version 1.0.0 - * @since 2018/07/17 13:10 - */ -public class Test { - public static void main(String[] args) throws IOException { - - } -} diff --git a/src/main/java/com/sjhy/plugin/tool/ModuleUtils.java b/src/main/java/com/sjhy/plugin/tool/ModuleUtils.java index 0813f52..c9c1947 100644 --- a/src/main/java/com/sjhy/plugin/tool/ModuleUtils.java +++ b/src/main/java/com/sjhy/plugin/tool/ModuleUtils.java @@ -38,4 +38,14 @@ public final class ModuleUtils { } return virtualFileList.get(0); } + + /** + * 判断模块是否存在源代码文件夹 + * + * @param module 模块对象 + * @return 是否存在 + */ + public static boolean existsSourcePath(Module module) { + return !CollectionUtil.isEmpty(ModuleRootManager.getInstance(module).getSourceRoots(JavaSourceRootType.SOURCE)); + } } diff --git a/src/main/java/com/sjhy/plugin/ui/SelectSavePath.java b/src/main/java/com/sjhy/plugin/ui/SelectSavePath.java index 04af93f..66de65b 100644 --- a/src/main/java/com/sjhy/plugin/ui/SelectSavePath.java +++ b/src/main/java/com/sjhy/plugin/ui/SelectSavePath.java @@ -25,6 +25,7 @@ import javax.swing.*; import java.awt.*; import java.awt.event.*; import java.util.ArrayList; +import java.util.LinkedList; import java.util.List; /** @@ -103,6 +104,10 @@ public class SelectSavePath extends JDialog { * 代码生成服务 */ private CodeGenerateService codeGenerateService; + /** + * 当前项目中的module + */ + private List moduleList; /** * 构造方法 @@ -112,6 +117,16 @@ public class SelectSavePath extends JDialog { this.tableInfoService = TableInfoService.getInstance(project); this.codeGenerateService = CodeGenerateService.getInstance(project); this.templateGroup = CurrGroupUtils.getCurrTemplateGroup(); + // 初始化module,存在资源路径的排前面 + this.moduleList = new LinkedList<>(); + for (Module module : ModuleManager.getInstance(project).getModules()) { + // 存在源代码文件夹放前面,否则放后面 + if (ModuleUtils.existsSourcePath(module)) { + this.moduleList.add(0, module); + } else { + this.moduleList.add(module); + } + } init(); setContentPane(contentPane); setModal(true); @@ -222,7 +237,7 @@ public class SelectSavePath extends JDialog { allCheckBox.addActionListener(e -> checkBoxList.forEach(jCheckBox -> jCheckBox.setSelected(allCheckBox.isSelected()))); //初始化Module选择 - for (Module module : ModuleManager.getInstance(project).getModules()) { + for (Module module : this.moduleList) { moduleComboBox.addItem(module.getName()); }