Skip to content

Commit

Permalink
chore(codegen): remove redundant checks for ifPresent
Browse files Browse the repository at this point in the history
  • Loading branch information
trivikr committed Nov 25, 2024
1 parent 2e46d06 commit 16c1fce
Showing 1 changed file with 9 additions and 7 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@
import software.amazon.smithy.codegen.core.SymbolProvider;
import software.amazon.smithy.model.Model;
import software.amazon.smithy.model.knowledge.TopDownIndex;
import software.amazon.smithy.model.shapes.MemberShape;
import software.amazon.smithy.model.shapes.OperationShape;
import software.amazon.smithy.model.shapes.ServiceShape;
import software.amazon.smithy.model.shapes.StructureShape;
Expand Down Expand Up @@ -203,13 +204,14 @@ private static Map<String, Object> getPluginFunctionParams(
params.put("requestChecksumRequired", httpChecksumTrait.isRequestChecksumRequired());
httpChecksumTrait.getRequestAlgorithmMember().ifPresent(requestAlgorithmMember -> {
params.put("requestAlgorithmMember", requestAlgorithmMember);
operation.getInput().ifPresent(inputShapeId -> {
StructureShape inputShape = model.expectShape(inputShapeId, StructureShape.class);
inputShape.getMember(requestAlgorithmMember).ifPresent(requestAlgorithmMemberShape -> {
requestAlgorithmMemberShape.getTrait(HttpHeaderTrait.class).ifPresent(httpHeaderTrait -> {
params.put("requestAlgorithmMemberHttpHeader", httpHeaderTrait.getValue());
});
});

// We know that input shape is structure, and contains requestAlgorithmMember.
StructureShape inputShape = model.expectShape(operation.getInput().get(), StructureShape.class);
MemberShape requestAlgorithmMemberShape = inputShape.getAllMembers().get(requestAlgorithmMember);

// Set requestAlgorithmMemberHttpHeader if HttpHeaderTrait is present.
requestAlgorithmMemberShape.getTrait(HttpHeaderTrait.class).ifPresent(httpHeaderTrait -> {
params.put("requestAlgorithmMemberHttpHeader", httpHeaderTrait.getValue());
});
});
httpChecksumTrait.getRequestValidationModeMember().ifPresent(requestValidationModeMember -> {
Expand Down

0 comments on commit 16c1fce

Please sign in to comment.