Skip to content

Commit

Permalink
sorting
Browse files Browse the repository at this point in the history
  • Loading branch information
rishav-karanjit committed Jan 8, 2025
1 parent 27bd15a commit 97fb363
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 8 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,9 @@

import static software.amazon.polymorph.smithygo.codegen.SymbolUtils.POINTABLE;
import static software.amazon.polymorph.smithygo.utils.Constants.DAFNY_RUNTIME_GO_LIBRARY_MODULE;

import java.util.Comparator;
import java.util.LinkedHashSet;
import java.util.stream.Collectors;
import software.amazon.polymorph.smithygo.codegen.GenerationContext;
import software.amazon.polymorph.smithygo.codegen.GoDelegator;
import software.amazon.polymorph.smithygo.codegen.GoWriter;
Expand Down Expand Up @@ -623,7 +625,8 @@ void generateShim() {
}

void shimErrors(GoWriter writer) {
for (final var error : model.getShapesWithTrait(ErrorTrait.class)) {
for (final var error : model.getShapesWithTrait(ErrorTrait.class).stream()
.sorted(Comparator.comparing(shape -> shape.getId().getName())).collect(Collectors.toCollection(LinkedHashSet::new))) {
writer.write(
"""
case $L.$L:
Expand All @@ -641,7 +644,8 @@ void shimErrors(GoWriter writer) {
}

void resourceErrors(GoWriter writer) {
for (final var error : model.getShapesWithTrait(ErrorTrait.class)) {
for (final var error : model.getShapesWithTrait(ErrorTrait.class).stream()
.sorted(Comparator.comparing(shape -> shape.getId().getName())).collect(Collectors.toCollection(LinkedHashSet::new))) {
writer.write(
"""
case $L:
Expand Down Expand Up @@ -710,7 +714,8 @@ void generateUnmodelledErrors(GenerationContext context) {
}

void generateReferencedResources(final GenerationContext context) {
final var refResources = model.getShapesWithTrait(ReferenceTrait.class);
final var refResources = model.getShapesWithTrait(ReferenceTrait.class).stream()
.sorted(Comparator.comparing(shape -> shape.getId().getName())).collect(Collectors.toCollection(LinkedHashSet::new));
for (final var refResource : refResources) {
if (!refResource.expectTrait(ReferenceTrait.class).isService()) {
final var resource = refResource
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,9 @@
import static software.amazon.polymorph.smithygo.utils.Constants.DAFNY_RUNTIME_GO_LIBRARY_MODULE;

import java.util.Collection;
import java.util.Comparator;
import java.util.HashSet;
import java.util.LinkedHashSet;
import java.util.LinkedList;
import java.util.Set;
import java.util.stream.Collectors;
Expand Down Expand Up @@ -205,7 +207,8 @@ public void generateSerializers(final GenerationContext context) {

final var refResources = context
.model()
.getShapesWithTrait(ReferenceTrait.class);
.getShapesWithTrait(ReferenceTrait.class).stream()
.sorted(Comparator.comparing(shape -> shape.getId().getName())).collect(Collectors.toCollection(LinkedHashSet::new));
for (final var refResource : refResources) {
final var resource = refResource
.expectTrait(ReferenceTrait.class)
Expand Down Expand Up @@ -584,7 +587,8 @@ public void generateDeserializers(final GenerationContext context) {

final var refResources = context
.model()
.getShapesWithTrait(ReferenceTrait.class);
.getShapesWithTrait(ReferenceTrait.class).stream()
.sorted(Comparator.comparing(shape -> shape.getId().getName())).collect(Collectors.toCollection(LinkedHashSet::new));
for (final var refResource : refResources) {
final var resource = refResource
.expectTrait(ReferenceTrait.class)
Expand Down Expand Up @@ -984,7 +988,8 @@ private void generateErrorSerializer(final GenerationContext context) {
final var serviceShape = context.settings().getService(context.model());
final var errorShapes = context
.model()
.getShapesWithTrait(ErrorTrait.class);
.getShapesWithTrait(ErrorTrait.class).stream()
.sorted(Comparator.comparing(shape -> shape.getId().getName())).collect(Collectors.toCollection(LinkedHashSet::new));

for (final var errorShape : errorShapes) {
if (
Expand Down Expand Up @@ -1340,7 +1345,8 @@ private void generateErrorDeserializer(final GenerationContext context) {
final var serviceShape = context.settings().getService(context.model());
final var errorShapes = context
.model()
.getShapesWithTrait(ErrorTrait.class);
.getShapesWithTrait(ErrorTrait.class).stream()
.sorted(Comparator.comparing(shape -> shape.getId().getName())).collect(Collectors.toCollection(LinkedHashSet::new));
for (final var errorShape : errorShapes) {
if (
!errorShape
Expand Down

0 comments on commit 97fb363

Please sign in to comment.