diff --git a/modules/core/src/alloy/UrlFormNameTrait.java b/modules/core/src/alloy/UrlFormNameTrait.java index 71f0eaa..96654d2 100644 --- a/modules/core/src/alloy/UrlFormNameTrait.java +++ b/modules/core/src/alloy/UrlFormNameTrait.java @@ -16,19 +16,78 @@ package alloy; import software.amazon.smithy.model.node.Node; +import software.amazon.smithy.model.node.ObjectNode; import software.amazon.smithy.model.shapes.ShapeId; -import software.amazon.smithy.model.traits.AnnotationTrait; +import software.amazon.smithy.model.traits.AbstractTrait; +import software.amazon.smithy.model.traits.AbstractTraitBuilder; +import software.amazon.smithy.model.traits.TraitService; +import software.amazon.smithy.utils.ToSmithyBuilder; -public final class UrlFormNameTrait extends AnnotationTrait { - public static ShapeId ID = ShapeId.from("alloy#urlFormName"); +public final class UrlFormNameTrait extends AbstractTrait implements ToSmithyBuilder { + public static final ShapeId ID = ShapeId.from("alloy#urlFormName"); + private final String name; - public UrlFormNameTrait() { - super(ID, Node.objectNode()); - } + private UrlFormNameTrait(Builder builder) { + super(ID, builder.getSourceLocation()); + this.name = builder.getName(); + } + + public String getName() { + return this.name; + } + + @Override + protected Node createNode() { + return ObjectNode.builder().withMember("name", name).build(); + } + + @Override + public Builder toBuilder() { + Builder builder = new Builder().sourceLocation(getSourceLocation()); + builder.setName(name); + return builder; + } + + /** + * @return Returns a builder used to create an examples trait. + */ + public static Builder builder() { + return new Builder(); + } + + public static final class Builder extends AbstractTraitBuilder { + private String name; + + public Builder setName(String name) { + this.name = name; + return this; + } + + public String getName() { + return name; + } + + @Override + public UrlFormNameTrait build() { + return new UrlFormNameTrait(this); + } + } + + public static final class Provider implements TraitService { + @Override + public ShapeId getShapeId() { + return ID; + } + + public UrlFormNameTrait createTrait(ShapeId target, Node value) { + Builder builder = builder().sourceLocation(value); + ObjectNode on = value.expectObjectNode(); + String name = on.expectStringMember("name").getValue(); + builder.setName(name); + UrlFormNameTrait result = builder.build(); + result.setNodeCache(value); + return result; + } + } - public static final class Provider extends AnnotationTrait.Provider { - public Provider() { - super(ID, (node) -> new UrlFormNameTrait()); - } - } }