diff --git a/codegen/smithy-dafny-codegen/src/main/java/software/amazon/polymorph/utils/IOUtils.java b/codegen/smithy-dafny-codegen/src/main/java/software/amazon/polymorph/utils/IOUtils.java index 73d1b8f47..495b498a9 100644 --- a/codegen/smithy-dafny-codegen/src/main/java/software/amazon/polymorph/utils/IOUtils.java +++ b/codegen/smithy-dafny-codegen/src/main/java/software/amazon/polymorph/utils/IOUtils.java @@ -69,10 +69,9 @@ public static void writeTokenTreesIntoDir( /** * Evaluate a simple template as a resource under "/templates/" * and then write it to "/". - * The template output path is also evaluated as in {@link #safeEvalPathTemplate(String, Map)} + * The template output path is also evaluated as in {@link #evalTemplate(String, Map)} * so the path can be customized by parameter values as well. * - * @see #safeEvalPathTemplate(String, Map) * @see #evalTemplate(String, Map) */ public static void writeTemplatedFile( @@ -84,7 +83,7 @@ public static void writeTemplatedFile( ) { final String content = evalTemplate(klass, templatePath, parameters); final Path outputPath = rootPath.resolve( - safeEvalPathTemplate(templateOutputPath, parameters) + evalTemplate(templateOutputPath, parameters) ); try { @@ -98,37 +97,29 @@ public static void writeTemplatedFile( } /** - * Evaluate a template string representing a file path. - * Note that ':' can't be used in file paths on Windows, + * Evaluate a simple template from a resource file using a {@link SimpleCodeWriter}. + * See {@link software.amazon.smithy.utils.AbstractCodeWriter} for documentation + * on the templating syntax. + * + * Note that ':' can't be used in resource paths on Windows, * so we use ';' instead and replace it with ':' before evaluating the templated path. * We also explicitly reject ':' in paths in case someone accidentally * uses that and doesn't test on Windows (purely hypothetically :) */ - public static String safeEvalPathTemplate( - final String pathTemplate, - final Map parameters + public static String evalTemplate( + Class klass, + String templatePath, + Map context ) { - if (pathTemplate.contains(":")) { + if (templatePath.contains(":")) { throw new IllegalArgumentException( "':' cannot be used in template paths since they are not allowed on Windows. Use ';' instead." ); } - return evalTemplate(pathTemplate.replace(';', ':'), parameters); - } - /** - * Evaluate a simple template from a resource file using a {@link SimpleCodeWriter}. - * See {@link software.amazon.smithy.utils.AbstractCodeWriter} for documentation - * on the templating syntax. - */ - public static String evalTemplate( - Class klass, - String templatePath, - Map context - ) { final String template = IoUtils.readUtf8Resource( klass, - "/templates/" + templatePath + "/templates/" + templatePath.replace(';', ':') ); return evalTemplate(template, context); }