From 3d0ceeda81cc34393afbea00fe5369f08d1dc8ca Mon Sep 17 00:00:00 2001 From: siddsriv Date: Mon, 9 Dec 2024 17:56:33 +0000 Subject: [PATCH] chore(codegen): reorder methods --- .../codegen/TypeScriptJmesPathVisitor.java | 136 +++++++++--------- 1 file changed, 68 insertions(+), 68 deletions(-) diff --git a/smithy-typescript-codegen/src/main/java/software/amazon/smithy/typescript/codegen/TypeScriptJmesPathVisitor.java b/smithy-typescript-codegen/src/main/java/software/amazon/smithy/typescript/codegen/TypeScriptJmesPathVisitor.java index 224a2ddc610..ad73bd1dd46 100644 --- a/smithy-typescript-codegen/src/main/java/software/amazon/smithy/typescript/codegen/TypeScriptJmesPathVisitor.java +++ b/smithy-typescript-codegen/src/main/java/software/amazon/smithy/typescript/codegen/TypeScriptJmesPathVisitor.java @@ -62,36 +62,6 @@ class TypeScriptJmesPathVisitor implements ExpressionVisitor { scopeCount = 0; } - private String serializeObject(Map obj) { - return "{" + obj.entrySet().stream() - .map(entry -> "\"" + entry.getKey() + "\":" + serializeValue(entry.getValue())) - .collect(Collectors.joining(",")) - + "}"; - } - - private String serializeArray(List array) { - return "[" + array.stream() - .map(this::serializeValue) - .collect(Collectors.joining(",")) - + "]"; - } - - @SuppressWarnings("unchecked") - private String serializeValue(Object value) { - if (value == null) { - return "null"; - } else if (value instanceof String) { - return "\"" + value + "\""; - } else if (value instanceof Number || value instanceof Boolean) { - return value.toString(); - } else if (value instanceof Map) { - return serializeObject((Map) value); - } else if (value instanceof ArrayList) { - return serializeArray((List) value); - } - throw new CodegenException("Unsupported literal type: " + value.getClass()); - } - public void run() { writer.openBlock("let returnComparator = () => {", "}", () -> { executionContext = accessor; @@ -101,44 +71,6 @@ public void run() { executionContext = "returnComparator()"; } - private String makeNewScope(String prefix) { - scopeCount += 1; - return prefix + scopeCount; - } - - void writeBooleanExpectation(String expectedValue, String returnValue) { - writer.openBlock("if ($L == $L) {", "}", executionContext, expectedValue, () -> { - writer.write("return $L;", returnValue); - }); - } - - void writeAnyStringEqualsExpectation(String expectedValue, String returnValue) { - String element = makeNewScope("anyStringEq_"); - writer.openBlock("for (let $L of $L) {", "}", element, executionContext, () -> { - writer.openBlock("if ($L == $S) {", "}", element, expectedValue, () -> { - writer.write("return $L;", returnValue); - }); - }); - } - - void writeAllStringEqualsExpectation(String expectedValue, String returnValue) { - String element = makeNewScope("element_"); - String result = makeNewScope("allStringEq_"); - writer.write("let $L = ($L.length > 0);", result, executionContext); - writer.openBlock("for (let $L of $L) {", "}", element, executionContext, () -> { - writer.write("$L = $L && ($L == $S)", result, result, element, expectedValue); - }); - writer.openBlock("if ($L) {", "}", result, () -> { - writer.write("return $L;", returnValue); - }); - } - - void writeStringExpectation(String expectedValue, String returnValue) { - writer.openBlock("if ($L === $S) {", "}", executionContext, expectedValue, () -> { - writer.write("return $L;", returnValue); - }); - } - @Override public Void visitComparator(ComparatorExpression expression) { @@ -374,4 +306,72 @@ public Void visitSubexpression(Subexpression expression) { expression.getRight().accept(this); return null; } + + void writeBooleanExpectation(String expectedValue, String returnValue) { + writer.openBlock("if ($L == $L) {", "}", executionContext, expectedValue, () -> { + writer.write("return $L;", returnValue); + }); + } + + void writeAnyStringEqualsExpectation(String expectedValue, String returnValue) { + String element = makeNewScope("anyStringEq_"); + writer.openBlock("for (let $L of $L) {", "}", element, executionContext, () -> { + writer.openBlock("if ($L == $S) {", "}", element, expectedValue, () -> { + writer.write("return $L;", returnValue); + }); + }); + } + + void writeAllStringEqualsExpectation(String expectedValue, String returnValue) { + String element = makeNewScope("element_"); + String result = makeNewScope("allStringEq_"); + writer.write("let $L = ($L.length > 0);", result, executionContext); + writer.openBlock("for (let $L of $L) {", "}", element, executionContext, () -> { + writer.write("$L = $L && ($L == $S)", result, result, element, expectedValue); + }); + writer.openBlock("if ($L) {", "}", result, () -> { + writer.write("return $L;", returnValue); + }); + } + + void writeStringExpectation(String expectedValue, String returnValue) { + writer.openBlock("if ($L === $S) {", "}", executionContext, expectedValue, () -> { + writer.write("return $L;", returnValue); + }); + } + + private String makeNewScope(String prefix) { + scopeCount += 1; + return prefix + scopeCount; + } + + private String serializeObject(Map obj) { + return "{" + obj.entrySet().stream() + .map(entry -> "\"" + entry.getKey() + "\":" + serializeValue(entry.getValue())) + .collect(Collectors.joining(",")) + + "}"; + } + + private String serializeArray(List array) { + return "[" + array.stream() + .map(this::serializeValue) + .collect(Collectors.joining(",")) + + "]"; + } + + @SuppressWarnings("unchecked") + private String serializeValue(Object value) { + if (value == null) { + return "null"; + } else if (value instanceof String) { + return "\"" + value + "\""; + } else if (value instanceof Number || value instanceof Boolean) { + return value.toString(); + } else if (value instanceof Map) { + return serializeObject((Map) value); + } else if (value instanceof ArrayList) { + return serializeArray((List) value); + } + throw new CodegenException("Unsupported literal type: " + value.getClass()); + } }