String (@Nullable PsiFile file, @Nullable Project project, @Nullable Module module, @NotNull String template, @Nullable String oldComment) { VelocityEngine engine = getEngine(); VelocityContext vc = new VelocityContext(); vc.put("today", new DateInfo()); if (file != null) vc.put("file", new FileInfo(file)); if (project != null) vc.put("project", new ProjectInfo(project)); if (module != null) vc.put("module", new ModuleInfo(module)); vc.put("username", System.getProperty("user.name")); vc.put("originalComment", new CommentInfo(oldComment)); if (file != null) { final VirtualFile virtualFile = PsiUtilCore.getVirtualFile(file); if (virtualFile != null) { final CopyrightVariablesProvider variablesProvider = CopyrightVariablesProviders.INSTANCE.forFileType(virtualFile.getFileType()); if (variablesProvider != null) { final Map<String, Object> context = new HashMap<>(); variablesProvider.collectVariables(context, project, module, file); for (Map.Entry<String, Object> entry : context.entrySet()) { vc.put(entry.getKey(), entry.getValue()); } } } } try { StringWriter sw = new StringWriter(); boolean stripLineBreak = false; if (template.endsWith("$")) { template += getVelocitySuffix(); stripLineBreak = true; } engine.evaluate(vc, sw, CopyrightManager.class.getName(), template); final String result = sw.getBuffer().toString(); return stripLineBreak ? StringUtil.trimEnd(result, getVelocitySuffix()) : result; } catch (Exception e) { return ""; } }