void (FileTemplate template, ModuleInfo moduleInfo) { if (moduleInfo.fileAlreadyExists()) { return; } Project project = moduleInfo.myRootDir.getProject(); Properties properties = FileTemplateManager.getInstance(project).getDefaultProperties(); FileTemplateUtil.fillDefaultProperties(properties, moduleInfo.myRootDir); properties.setProperty(FileTemplate.ATTRIBUTE_NAME, MODULE_INFO_CLASS); try { PsiJavaFile moduleInfoFile = // this is done to copy the file header to the output (PsiJavaFile)FileTemplateUtil.createFromTemplate(template, MODULE_INFO_FILE, properties, moduleInfo.myRootDir); PsiJavaModule javaModule = moduleInfoFile.getModuleDeclaration(); LOG.assertTrue(javaModule != null, "module-info file should contain module declaration"); CharSequence moduleText = moduleInfo.createModuleText(); PsiJavaFile dummyFile = (PsiJavaFile)PsiFileFactory.getInstance(project) .createFileFromText(MODULE_INFO_FILE, JavaLanguage.INSTANCE, moduleText); PsiJavaModule actualModule = dummyFile.getModuleDeclaration(); LOG.assertTrue(actualModule != null, "module declaration wasn't created"); javaModule.replace(actualModule); CodeStyleManager.getInstance(project).reformat(moduleInfoFile); } catch (Exception e) { LOG.error("Failed to create module-info.java in " + moduleInfo.myRootDir.getVirtualFile().getPath() + ": " + e.getMessage()); } }