Skip to content

Commit 9d68d0d

Browse files
committed
Revert casting terminal endpoint builder methods
I didn't realize the onBuild function was used to intercept terminal builder results and rewrite them to a different type. While this is extremely unintuitive, changing it now breaks existing usage of these builders.
1 parent 1f59ac9 commit 9d68d0d

File tree

3 files changed

+15
-15
lines changed

3 files changed

+15
-15
lines changed

smithy-rules-engine/src/main/java/software/amazon/smithy/rulesengine/language/syntax/rule/Rule.java

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -255,24 +255,24 @@ public Builder condition(ToCondition condition) {
255255
return this;
256256
}
257257

258-
public EndpointRule endpoint(Endpoint endpoint) {
259-
return (EndpointRule) this.onBuild.apply(new EndpointRule(this, endpoint));
258+
public Rule endpoint(Endpoint endpoint) {
259+
return this.onBuild.apply(new EndpointRule(this, endpoint));
260260
}
261261

262-
public ErrorRule error(Node error) {
262+
public Rule error(Node error) {
263263
return error(Expression.fromNode(error));
264264
}
265265

266-
public ErrorRule error(String error) {
266+
public Rule error(String error) {
267267
return error(Literal.of(error));
268268
}
269269

270-
public ErrorRule error(Expression error) {
271-
return (ErrorRule) this.onBuild.apply(new ErrorRule(this, error));
270+
public Rule error(Expression error) {
271+
return this.onBuild.apply(new ErrorRule(this, error));
272272
}
273273

274-
public TreeRule treeRule(Rule... rules) {
275-
return (TreeRule) this.treeRule(Arrays.asList(rules));
274+
public Rule treeRule(Rule... rules) {
275+
return this.treeRule(Arrays.asList(rules));
276276
}
277277

278278
@SafeVarargs

smithy-rules-engine/src/test/java/software/amazon/smithy/rulesengine/logic/cfg/CfgTest.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -50,7 +50,7 @@ void gettersReturnConstructorValues() {
5050

5151
@Test
5252
void fromCreatesSimpleCfg() {
53-
EndpointRule rule = EndpointRule.builder()
53+
EndpointRule rule = (EndpointRule) EndpointRule.builder()
5454
.endpoint(TestHelpers.endpoint("https://example.com"));
5555

5656
EndpointRuleSet ruleSet = EndpointRuleSet.builder()
@@ -75,7 +75,7 @@ void fromCreatesConditionNode() {
7575
.addParameter(Parameter.builder().name("region").type(ParameterType.STRING).build())
7676
.build();
7777

78-
EndpointRule rule = EndpointRule.builder()
78+
EndpointRule rule = (EndpointRule) EndpointRule.builder()
7979
.condition(Condition.builder().fn(TestHelpers.isSet("region")).build())
8080
.endpoint(TestHelpers.endpoint("https://example.com"));
8181

smithy-rules-engine/src/test/java/software/amazon/smithy/rulesengine/logic/cfg/SsaTransformTest.java

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -41,7 +41,7 @@ void testNoDisambiguationNeeded() {
4141
.result("bucketMatches")
4242
.build();
4343

44-
EndpointRule rule = EndpointRule.builder()
44+
EndpointRule rule = (EndpointRule) EndpointRule.builder()
4545
.conditions(Collections.singletonList(condition1))
4646
.endpoint(endpoint("https://example.com"));
4747

@@ -127,7 +127,7 @@ void testErrorRuleHandling() {
127127
.result("hasError")
128128
.build();
129129

130-
ErrorRule errorRule = ErrorRule.builder()
130+
ErrorRule errorRule = (ErrorRule) ErrorRule.builder()
131131
.conditions(Collections.singletonList(cond))
132132
.error(Expression.of("Error occurred"));
133133

@@ -161,7 +161,7 @@ void testTreeRuleHandling() {
161161
EndpointRule innerRule1 = createRuleWithBinding("Region", "us-east-1", "isEast", "https://east.com");
162162
EndpointRule innerRule2 = createRuleWithBinding("Region", "us-west-2", "isWest", "https://west.com");
163163

164-
TreeRule treeRule = TreeRule.builder()
164+
TreeRule treeRule = (TreeRule) TreeRule.builder()
165165
.conditions(Collections.singletonList(outerCond))
166166
.treeRule(innerRule1, innerRule2);
167167

@@ -193,7 +193,7 @@ void testParameterShadowingAttempt() {
193193
.result("Bucket_shadow")
194194
.build();
195195

196-
EndpointRule rule = EndpointRule.builder()
196+
EndpointRule rule = (EndpointRule) EndpointRule.builder()
197197
.conditions(Collections.singletonList(shadowingCond))
198198
.endpoint(endpoint("https://example.com"));
199199

@@ -216,7 +216,7 @@ private static EndpointRule createRuleWithBinding(String param, String value, St
216216
.result(resultVar)
217217
.build();
218218

219-
return EndpointRule.builder()
219+
return (EndpointRule) EndpointRule.builder()
220220
.conditions(Collections.singletonList(cond))
221221
.endpoint(endpoint(url));
222222
}

0 commit comments

Comments
 (0)