Skip to content

Commit 943dfaf

Browse files
committed
PR feedback
1 parent 9c0198e commit 943dfaf

File tree

5 files changed

+68
-4
lines changed

5 files changed

+68
-4
lines changed

smithy-jmespath/src/main/java/software/amazon/smithy/jmespath/JmespathExceptionType.java

Lines changed: 30 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -4,20 +4,47 @@
44
*/
55
package software.amazon.smithy.jmespath;
66

7+
/**
8+
* Defines categories of JMESPath errors.
9+
* A superset of the types defined in <a href="https://jmespath.org/specification.html#errors">the specification.
10+
*/
711
public enum JmespathExceptionType {
12+
/**
13+
* The "syntax" class of JMESPath errors.
14+
* <p>
15+
* "syntax" is not listed in the specification, but it is used
16+
* in <a href="https://github.com/jmespath/jmespath.test">the compliance tests</a> to indicate invalid expressions.
17+
*/
818
SYNTAX,
19+
20+
/**
21+
* The "invalid-type" class of JMESPath errors.
22+
*/
923
INVALID_TYPE,
24+
25+
/**
26+
* The "invalid-value" class of JMESPath errors.
27+
*/
1028
INVALID_VALUE,
29+
30+
/**
31+
* The "unknown-function" class of JMESPath errors.
32+
*/
1133
UNKNOWN_FUNCTION,
34+
35+
/**
36+
* The "invalid-arity" class of JMESPath errors.
37+
*/
1238
INVALID_ARITY,
39+
40+
/**
41+
* Any other error cause.
42+
*/
1343
OTHER;
1444

1545
/**
1646
* Returns the corresponding enum value for one of the identifiers used in
1747
* <a href="https://jmespath.org/specification.html#errors">the JMESPath specification</a>.
18-
* <p>
19-
* "syntax" is not listed in the specification, but it is used
20-
* in <a href="https://github.com/jmespath/jmespath.test">the compliance tests</a> to indicate invalid expressions.
2148
*/
2249
public static JmespathExceptionType fromID(String id) {
2350
return valueOf(id.toUpperCase().replace('-', '_'));

smithy-jmespath/src/main/java/software/amazon/smithy/jmespath/JmespathExpression.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -116,7 +116,7 @@ public LinterResult lint(LiteralExpression currentNode) {
116116
* @return Returns the result of evaluating the expression.
117117
*/
118118
public LiteralExpression evaluate(LiteralExpression currentNode) {
119-
return evaluate(currentNode, new LiteralExpressionJmespathRuntime());
119+
return evaluate(currentNode, LiteralExpressionJmespathRuntime.INSTANCE);
120120
}
121121

122122
/**

smithy-jmespath/src/main/java/software/amazon/smithy/jmespath/LiteralExpressionJmespathRuntime.java

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,12 @@
1414
import software.amazon.smithy.jmespath.evaluation.MappingIterable;
1515
import software.amazon.smithy.jmespath.evaluation.NumberType;
1616

17+
/**
18+
* A singleton implementation of the JmespathRuntime interface based on instances of the LiteralExpression class.
19+
* <p>
20+
* Does not use values of the additional LiteralExpression.EXPREF or LiteralExpression.ANY types
21+
* as they aren't necessary.
22+
*/
1723
public final class LiteralExpressionJmespathRuntime implements JmespathRuntime<LiteralExpression> {
1824

1925
public static final LiteralExpressionJmespathRuntime INSTANCE = new LiteralExpressionJmespathRuntime();

smithy-jmespath/src/main/java/software/amazon/smithy/jmespath/evaluation/EvaluationUtils.java

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,9 @@
1010
import java.util.Objects;
1111
import software.amazon.smithy.jmespath.RuntimeType;
1212

13+
/**
14+
* Functions that make evaluating JmespathExpressions or implementing the JmespathRuntime interface easier.
15+
*/
1316
public final class EvaluationUtils {
1417

1518
private static final InheritingClassMap<NumberType> numberTypeForClass = InheritingClassMap.<NumberType>builder()

smithy-jmespath/src/main/java/software/amazon/smithy/jmespath/evaluation/JmespathRuntime.java

Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -116,6 +116,7 @@ default String toString(T value) {
116116
if (first) {
117117
first = false;
118118
} else {
119+
// The compliance tests actually require ',' rather than ", " :P
119120
arrayStringBuilder.append(',');
120121
}
121122
arrayStringBuilder.append(toString(element));
@@ -158,6 +159,9 @@ default String toString(T value) {
158159
// BOOLEANs
159160
///////////////////////////////
160161

162+
/**
163+
* Creates a BOOLEAN value.
164+
*/
161165
T createBoolean(boolean b);
162166

163167
/**
@@ -170,6 +174,9 @@ default String toString(T value) {
170174
// STRINGs
171175
///////////////////////////////
172176

177+
/**
178+
* Creates a STRING value.
179+
*/
173180
T createString(String string);
174181

175182
/**
@@ -185,6 +192,9 @@ default String toString(T value) {
185192
// NUMBERs
186193
///////////////////////////////
187194

195+
/**
196+
* Creates a NUMBER value.
197+
*/
188198
T createNumber(Number value);
189199

190200
/**
@@ -203,8 +213,14 @@ default String toString(T value) {
203213
// ARRAYs
204214
///////////////////////////////
205215

216+
/**
217+
* Creates a new ArrayBuilder.
218+
*/
206219
ArrayBuilder<T> arrayBuilder();
207220

221+
/**
222+
* A builder interface for new ARRAY values.
223+
*/
208224
interface ArrayBuilder<T> {
209225

210226
/**
@@ -219,6 +235,9 @@ interface ArrayBuilder<T> {
219235
*/
220236
void addAll(T collection);
221237

238+
/**
239+
* Builds the new ARRAY value being built.
240+
*/
222241
T build();
223242
}
224243

@@ -264,8 +283,14 @@ default T slice(T array, int start, int stop, int step) {
264283
// OBJECTs
265284
///////////////////////////////
266285

286+
/**
287+
* Creates a new ObjectBuilder.
288+
*/
267289
ObjectBuilder<T> objectBuilder();
268290

291+
/**
292+
* A builder interface for new OBJECT values.
293+
*/
269294
interface ObjectBuilder<T> {
270295

271296
/**
@@ -279,6 +304,9 @@ interface ObjectBuilder<T> {
279304
*/
280305
void putAll(T object);
281306

307+
/**
308+
* Builds the new OBJECT value being built.
309+
*/
282310
T build();
283311
}
284312

0 commit comments

Comments
 (0)