Skip to content

Commit

Permalink
Add Go Synthetic Trait equality methods (#423)
Browse files Browse the repository at this point in the history
When using smithy diff or trait comparisons for the Go `Synthetic`
trait, the following exception is thrown in the `createNode()`
implementation:

```text
"attempted to serialize runtime only trait"
```

This is due to inheriting from `AbstractTrait`'s equality methods which
use the `ToNode()` method which calls the `createNode()` method.

This change adds an `equals()` and `hashCode()` implementation for the
Go `Synthetic` trait that does not use `ToNode()` or `createNode()`.

`ToNode()` cannot be overriden since `AbstractTrait`'s implementation is
marked as `final`.
  • Loading branch information
syall committed Apr 12, 2023
1 parent 1521536 commit 7f8b3b9
Showing 1 changed file with 19 additions and 0 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -55,6 +55,25 @@ protected Node createNode() {
throw new CodegenException("attempted to serialize runtime only trait");
}

@Override
public boolean equals(Object other) {
if (other == this) {
return true;
} else if (!(other instanceof Synthetic)) {
return false;
} else {
Synthetic b = (Synthetic) other;
return toShapeId().equals(b.toShapeId()) && archetype.equals(b.getArchetype());
}
}

@Override
public int hashCode() {
return toShapeId().hashCode() * 17 + Node.objectNode()
.withOptionalMember(ARCHETYPE, archetype.map(ShapeId::toString).map(Node::from))
.hashCode();
}

@Override
public SmithyBuilder<Synthetic> toBuilder() {
Builder builder = builder();
Expand Down

0 comments on commit 7f8b3b9

Please sign in to comment.