void () { ModifiableModuleModel moduleModel = ModuleManager.getInstance(myProject).getModifiableModel(); moduleModel.setModuleGroupPath(myModule, new String[]{"Group"}); WriteAction.runAndWait(() -> moduleModel.commit()); final VirtualFile srcFile = getSrcDirectory().getVirtualFile(); if (srcFile.findChild("empty") == null){ ApplicationManager.getApplication().runWriteAction(new Runnable() { @Override public void run() { try { srcFile.createChildDirectory(this, "empty"); } catch (IOException e) { fail(e.getLocalizedMessage()); } } }); } doTest(true, true, """ -Project -Module -PsiPackage: com.package1 Class1.java Class2.java Class4.java emptyClassFile.class Form1.form Form1.java Form2.form PsiPackage: empty -PsiPackage: java Class1.java -PsiPackage: javax.servlet Class1.java -Libraries -PsiPackage: java +PsiPackage: awt +PsiPackage: beans.beancontext +PsiPackage: io +PsiPackage: lang +PsiPackage: net +PsiPackage: rmi +PsiPackage: security +PsiPackage: sql +PsiPackage: util -PsiPackage: javax.swing +PsiPackage: table AbstractButton.class Icon.class JButton.class JComponent.class JDialog.class JFrame.class JLabel.class JPanel.class JScrollPane.class JTable.class SwingConstants.class SwingUtilities.class -PsiPackage: META-INF MANIFEST.MF LICENSE """ , 4); doTest(false, true, """ -Project -PsiPackage: com.package1 Class1.java Class2.java Class4.java emptyClassFile.class Form1.form Form1.java Form2.form PsiPackage: empty -PsiPackage: java Class1.java -PsiPackage: javax.servlet Class1.java -Libraries -PsiPackage: java +PsiPackage: awt +PsiPackage: beans.beancontext +PsiPackage: io +PsiPackage: lang +PsiPackage: net +PsiPackage: rmi +PsiPackage: security +PsiPackage: sql +PsiPackage: util -PsiPackage: javax.swing +PsiPackage: table AbstractButton.class Icon.class JButton.class JComponent.class JDialog.class JFrame.class JLabel.class JPanel.class JScrollPane.class JTable.class SwingConstants.class SwingUtilities.class -PsiPackage: META-INF MANIFEST.MF LICENSE """ , 3); doTest(true, false, """ -Project -Module -PsiPackage: com.package1 Class1.java Class2.java Class4.java emptyClassFile.class Form1.form Form1.java Form2.form PsiPackage: empty -PsiPackage: java Class1.java -PsiPackage: javax.servlet Class1.java """, 3); doTest(false, false, true, true, """ -Project -PsiPackage: com.package1 Class1.java Class2.java Class4.java emptyClassFile.class Form1.form Form1.java Form2.form PsiPackage: empty -PsiPackage: java Class1.java -PsiPackage: j.servlet Class1.java """, 3); doTest(false, false, """ -Project -PsiPackage: com.package1 Class1.java Class2.java Class4.java emptyClassFile.class Form1.form Form1.java Form2.form PsiPackage: empty -PsiPackage: java Class1.java -PsiPackage: javax.servlet Class1.java """, 3); }