From c6310d0bc822bc3c1dbf55f7d7749aa9f33ccaa9 Mon Sep 17 00:00:00 2001 From: Lucas McDonald Date: Tue, 30 Jul 2024 12:30:09 -0700 Subject: [PATCH] cleanup --- .../localservice/ConstraintUtils.java | 16 ++++---- .../customize/ErrorsFileWriter.java | 6 +-- .../customize/ReferencesFileWriter.java | 2 +- .../DafnyClientCodegenPluginSettings.java | 40 +++++++++---------- 4 files changed, 31 insertions(+), 33 deletions(-) diff --git a/codegen/smithy-dafny-codegen/src/main/java/software/amazon/polymorph/smithypython/localservice/ConstraintUtils.java b/codegen/smithy-dafny-codegen/src/main/java/software/amazon/polymorph/smithypython/localservice/ConstraintUtils.java index 6f00ca884..688e765b6 100644 --- a/codegen/smithy-dafny-codegen/src/main/java/software/amazon/polymorph/smithypython/localservice/ConstraintUtils.java +++ b/codegen/smithy-dafny-codegen/src/main/java/software/amazon/polymorph/smithypython/localservice/ConstraintUtils.java @@ -52,8 +52,8 @@ protected static void writeLengthTraitMinCheckForMember( () -> { writer.write( """ - raise ValueError("The size of $1L must be greater than or equal to $2L") - """, + raise ValueError("The size of $1L must be greater than or equal to $2L") + """, memberName, min); }); @@ -76,8 +76,8 @@ protected static void writeLengthTraitMaxCheckForMember( () -> { writer.write( """ - raise ValueError("The size of $1L must be less than or equal to $2L") - """, + raise ValueError("The size of $1L must be less than or equal to $2L") + """, memberName, max); }); @@ -107,8 +107,8 @@ protected static void writeRangeTraitMinCheckForMember( () -> { writer.write( """ - raise ValueError("$1L must be greater than or equal to $2L") - """, + raise ValueError("$1L must be greater than or equal to $2L") + """, memberName, min); }); @@ -138,8 +138,8 @@ protected static void writeRangeTraitMaxCheckForMember( () -> { writer.write( """ - raise ValueError("$1L must be less than or equal to $2L") - """, + raise ValueError("$1L must be less than or equal to $2L") + """, memberName, max); }); diff --git a/codegen/smithy-dafny-codegen/src/main/java/software/amazon/polymorph/smithypython/localservice/customize/ErrorsFileWriter.java b/codegen/smithy-dafny-codegen/src/main/java/software/amazon/polymorph/smithypython/localservice/customize/ErrorsFileWriter.java index 1397d4989..d355ac35d 100644 --- a/codegen/smithy-dafny-codegen/src/main/java/software/amazon/polymorph/smithypython/localservice/customize/ErrorsFileWriter.java +++ b/codegen/smithy-dafny-codegen/src/main/java/software/amazon/polymorph/smithypython/localservice/customize/ErrorsFileWriter.java @@ -346,9 +346,9 @@ private void generateSmithyErrorToDafnyErrorBlock( // Nothing found, we know nothing about this error. Cast as opaque writer.write( """ - else: - return $L.Error_Opaque(obj=e) - """, + else: + return $L.Error_Opaque(obj=e) + """, DafnyNameResolver.getDafnyPythonTypesModuleNameForShape(serviceShape.getId(), codegenContext)); writer.addStdlibImport(DafnyNameResolver.getDafnyGeneratedPathForSmithyNamespace(serviceShape.getId().getNamespace())); } diff --git a/codegen/smithy-dafny-codegen/src/main/java/software/amazon/polymorph/smithypython/localservice/customize/ReferencesFileWriter.java b/codegen/smithy-dafny-codegen/src/main/java/software/amazon/polymorph/smithypython/localservice/customize/ReferencesFileWriter.java index edd1428e3..a490f1346 100644 --- a/codegen/smithy-dafny-codegen/src/main/java/software/amazon/polymorph/smithypython/localservice/customize/ReferencesFileWriter.java +++ b/codegen/smithy-dafny-codegen/src/main/java/software/amazon/polymorph/smithypython/localservice/customize/ReferencesFileWriter.java @@ -275,7 +275,7 @@ private void generateNativeWrapperFunctionDefinitionForResource( writer.addStdlibImport(SmithyNameResolver.getPythonModuleSmithygeneratedPathForSmithyNamespace( serviceShape.getId().getNamespace(), codegenContext.settings()) + ".errors", - "_smithy_error_to_dafny_error" + "_smithy_error_to_dafny_error" ); writer.openBlock( diff --git a/codegen/smithy-dafny-codegen/src/main/java/software/amazon/smithy/dafny/codegen/DafnyClientCodegenPluginSettings.java b/codegen/smithy-dafny-codegen/src/main/java/software/amazon/smithy/dafny/codegen/DafnyClientCodegenPluginSettings.java index 95d3d5332..b33521766 100644 --- a/codegen/smithy-dafny-codegen/src/main/java/software/amazon/smithy/dafny/codegen/DafnyClientCodegenPluginSettings.java +++ b/codegen/smithy-dafny-codegen/src/main/java/software/amazon/smithy/dafny/codegen/DafnyClientCodegenPluginSettings.java @@ -164,26 +164,24 @@ static Optional fromObject( ); } - /** - * Traverses up from the given start path, - * searching for a "smithy-build.json" file and returning its path if found. - */ - private static Optional findSmithyBuildJson(final Path start) { - if (start == null || !start.isAbsolute()) { - throw new IllegalArgumentException( - "Start path must be non-null and absolute" - ); - } - Path cursor = start.normalize(); - final Path root = cursor.getRoot(); - // Shouldn't need to traverse more than 100 levels... but don't hang forever - for (int i = 0; !root.equals(cursor) && i < 100; i++) { - final Path config = cursor.resolve("smithy-build.json"); - if (Files.exists(config)) { - return Optional.of(config); - } - cursor = cursor.getParent(); - } - return Optional.empty(); + /** + * Traverses up from the given start path, + * searching for a "smithy-build.json" file and returning its path if found. + */ + private static Optional findSmithyBuildJson(final Path start) { + if (start == null || !start.isAbsolute()) { + throw new IllegalArgumentException("Start path must be non-null and absolute"); + } + Path cursor = start.normalize(); + final Path root = cursor.getRoot(); + // Shouldn't need to traverse more than 100 levels... but don't hang forever + for (int i = 0; !root.equals(cursor) && i < 100; i++) { + final Path config = cursor.resolve("smithy-build.json"); + if (Files.exists(config)) { + return Optional.of(config); + } + cursor = cursor.getParent(); + } + return Optional.empty(); } }