From 5b396ac713233abb68f10277c65a5bd7bd06f600 Mon Sep 17 00:00:00 2001 From: Chase Coalwell <782571+srchase@users.noreply.github.com> Date: Mon, 8 May 2023 09:47:40 -0600 Subject: [PATCH] Remove UnaryFunctionCall class --- .../codegen/validation/UnaryFunctionCall.java | 61 ------------------- .../validation/UnaryFunctionCallTest.java | 36 ----------- 2 files changed, 97 deletions(-) delete mode 100644 smithy-typescript-codegen/src/main/java/software/amazon/smithy/typescript/codegen/validation/UnaryFunctionCall.java delete mode 100644 smithy-typescript-codegen/src/test/java/software/amazon/smithy/typescript/codegen/validation/UnaryFunctionCallTest.java diff --git a/smithy-typescript-codegen/src/main/java/software/amazon/smithy/typescript/codegen/validation/UnaryFunctionCall.java b/smithy-typescript-codegen/src/main/java/software/amazon/smithy/typescript/codegen/validation/UnaryFunctionCall.java deleted file mode 100644 index 47e55f79982..00000000000 --- a/smithy-typescript-codegen/src/main/java/software/amazon/smithy/typescript/codegen/validation/UnaryFunctionCall.java +++ /dev/null @@ -1,61 +0,0 @@ -/* - * Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved. - * SPDX-License-Identifier: Apache-2.0 - */ - -package software.amazon.smithy.typescript.codegen.validation; - -/** - * For handling expressions that may be unary function calls. - */ -public abstract class UnaryFunctionCall { - /** - * @param expression - to be examined. - * @return whether the expression is a single-depth function call with a single parameter. - */ - public static boolean check(String expression) { - if (expression.equals("_")) { - // not a call per se, but this indicates a pass-through function. - return true; - } - return maxCallDepth(expression) == 1 - && expression.matches(".+\\(.*\\)$") - && !expression.contains("new ") - && !expression.contains(","); - } - - /** - * @param callExpression - the call expression to be converted. Check that - * the expression is a unary call first. - * @return the unary function call converted to a function reference. - */ - public static String toRef(String callExpression) { - return callExpression.replaceAll("(.*)\\(.*\\)$", "$1"); - } - - /** - * Estimates the call depth of a function call expression. - * - * @example - * call() == 1 - * call(call()) == 2 - */ - private static int maxCallDepth(String expression) { - int depth = 0; - int maxDepth = 0; - for (int i = 0; i < expression.length(); ++i) { - char c = expression.charAt(i); - if (c == '(') { - depth += 1; - if (depth > maxDepth) { - maxDepth = depth; - } - continue; - } - if (c == ')') { - depth -= 1; - } - } - return maxDepth; - } -} diff --git a/smithy-typescript-codegen/src/test/java/software/amazon/smithy/typescript/codegen/validation/UnaryFunctionCallTest.java b/smithy-typescript-codegen/src/test/java/software/amazon/smithy/typescript/codegen/validation/UnaryFunctionCallTest.java deleted file mode 100644 index 61d510e9ef4..00000000000 --- a/smithy-typescript-codegen/src/test/java/software/amazon/smithy/typescript/codegen/validation/UnaryFunctionCallTest.java +++ /dev/null @@ -1,36 +0,0 @@ -package software.amazon.smithy.typescript.codegen.validation; - -import static org.junit.jupiter.api.Assertions.assertEquals; - -import org.junit.jupiter.api.Test; - -class UnaryFunctionCallTest { - @Test - void check() { - assertEquals(false, UnaryFunctionCall.check("")); - assertEquals(false, UnaryFunctionCall.check("5")); - assertEquals(false, UnaryFunctionCall.check("(param)")); - assertEquals(false, UnaryFunctionCall.check("x[5]")); - assertEquals(false, UnaryFunctionCall.check("new Date(timestamp)")); - assertEquals(false, UnaryFunctionCall.check("x(y(_))")); - assertEquals(false, UnaryFunctionCall.check("call(param).prop")); - assertEquals(false, UnaryFunctionCall.check("call(param, param2)")); - - assertEquals(true, UnaryFunctionCall.check("_")); - assertEquals(true, UnaryFunctionCall.check("x()")); - assertEquals(true, UnaryFunctionCall.check("x(_)")); - assertEquals(true, UnaryFunctionCall.check("long_function_name(long_parameter_name)")); - assertEquals(true, UnaryFunctionCall.check("container.function(param)")); - assertEquals(true, UnaryFunctionCall.check("factory(param)(param2)")); - } - - @Test - void toRef() { - assertEquals("_", UnaryFunctionCall.toRef("_")); - assertEquals("x", UnaryFunctionCall.toRef("x()")); - assertEquals("x", UnaryFunctionCall.toRef("x(_)")); - assertEquals("long_function_name", UnaryFunctionCall.toRef("long_function_name(long_parameter_name)")); - assertEquals("container.function", UnaryFunctionCall.toRef("container.function(param)")); - assertEquals("factory(param)", UnaryFunctionCall.toRef("factory(param)(param2)")); - } -} \ No newline at end of file