Skip to content

Commit

Permalink
Make UrlFormNameTrait hold name value
Browse files Browse the repository at this point in the history
Almost... the test is failing and I don't know why.
  • Loading branch information
dhpiggott committed Aug 9, 2023
1 parent a8fd2b5 commit 72a05ab
Showing 1 changed file with 70 additions and 11 deletions.
81 changes: 70 additions & 11 deletions modules/core/src/alloy/UrlFormNameTrait.java
Original file line number Diff line number Diff line change
Expand Up @@ -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<UrlFormNameTrait> {
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<UrlFormNameTrait, Builder> {
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<UrlFormNameTrait> {
public Provider() {
super(ID, (node) -> new UrlFormNameTrait());
}
}
}

0 comments on commit 72a05ab

Please sign in to comment.