String (String templateContent, final VelocityContext context, boolean useSystemLineSeparators, @Nullable Consumer<? super VelocityException> exceptionHandler) { final StringWriter stringWriter = new StringWriter(); try { Project project; final Object projectName = context.get(FileTemplateManager.PROJECT_NAME_VARIABLE); if (projectName instanceof String) { Project[] projects = ProjectManager.getInstance().getOpenProjects(); project = ContainerUtil.find(projects, project1 -> projectName.equals(project1.getName())); } else { project = null; } VelocityTemplateContext.withContext(project, () -> VelocityWrapper.evaluate(project, context, stringWriter, templateContent)); } catch (final VelocityException e) { if (ApplicationManager.getApplication().isUnitTestMode()) { LOG.error(e); } LOG.info("Error evaluating template:\n" + templateContent, e); if (exceptionHandler == null) { ApplicationManager.getApplication() .invokeLater(() -> Messages.showErrorDialog(IdeBundle.message("error.parsing.file.template", e.getMessage()), IdeBundle.message("title.velocity.error"))); } else { exceptionHandler.accept(e); } } final String result = stringWriter.toString(); if (useSystemLineSeparators) { final String newSeparator = CodeStyle.getDefaultSettings().getLineSeparator(); if (!"\n".equals(newSeparator)) { return StringUtil.convertLineSeparators(result, newSeparator); } } return result; }