• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /*
2  * Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved.
3  *
4  * Licensed under the Apache License, Version 2.0 (the "License").
5  * You may not use this file except in compliance with the License.
6  * A copy of the License is located at
7  *
8  *  http://aws.amazon.com/apache2.0
9  *
10  * or in the "license" file accompanying this file. This file is distributed
11  * on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either
12  * express or implied. See the License for the specific language governing
13  * permissions and limitations under the License.
14  */
15 
16 package software.amazon.awssdk.codegen.jmespath.component;
17 
18 
19 import software.amazon.awssdk.codegen.jmespath.parser.JmesPathVisitor;
20 import software.amazon.awssdk.utils.Validate;
21 
22 /**
23  * An argument to a {@link FunctionExpression}. Either a {@link Expression} that is evaluated and passed to the function or a
24  * {@link ExpressionType} that is passed to the function as-is and is evaluated by the function.
25  */
26 public class FunctionArg {
27     private Expression expression;
28     private ExpressionType expressionType;
29 
FunctionArg()30     private FunctionArg() {
31     }
32 
expression(Expression expression)33     public static FunctionArg expression(Expression expression) {
34         Validate.notNull(expression, "expression");
35         FunctionArg result = new FunctionArg();
36         result.expression = expression;
37         return result;
38     }
39 
expressionType(ExpressionType expressionType)40     public static FunctionArg expressionType(ExpressionType expressionType) {
41         Validate.notNull(expressionType, "expressionType");
42         FunctionArg result = new FunctionArg();
43         result.expressionType = expressionType;
44         return result;
45     }
46 
isExpression()47     public boolean isExpression() {
48         return expression != null;
49     }
50 
isExpressionType()51     public boolean isExpressionType() {
52         return expressionType != null;
53     }
54 
55 
asExpression()56     public Expression asExpression() {
57         Validate.validState(isExpression(), "Not a Expression");
58         return expression;
59     }
60 
asExpressionType()61     public ExpressionType asExpressionType() {
62         Validate.validState(isExpressionType(), "Not a ExpressionType");
63         return expressionType;
64     }
65 
visit(JmesPathVisitor visitor)66     public void visit(JmesPathVisitor visitor) {
67         if (isExpression()) {
68             visitor.visitExpression(asExpression());
69         } else if (isExpressionType()) {
70             visitor.visitExpressionType(asExpressionType());
71         } else {
72             throw new IllegalStateException();
73         }
74     }
75 }
76