Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Ensure SourceLocations are on all StringListTrait traits #564

Merged
merged 1 commit into from
Sep 15, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -48,9 +48,7 @@ public Provider() {

@Override
public Builder toBuilder() {
ConditionKeysTrait.Builder builder = builder().sourceLocation(getSourceLocation());
getValues().forEach(builder::addValue);
return builder;
return builder().sourceLocation(getSourceLocation()).values(getValues());
}

public static final class Builder extends StringListTrait.Builder<ConditionKeysTrait, Builder> {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -45,9 +45,7 @@ public static Builder builder() {

@Override
public Builder toBuilder() {
Builder builder = builder().sourceLocation(getSourceLocation());
getValues().forEach(builder::addValue);
return builder;
return builder().sourceLocation(getSourceLocation()).values(getValues());
}

public static final class Builder extends StringListTrait.Builder<RequiredActionsTrait, Builder> {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,11 @@ public StringListTrait(ShapeId id, List<String> values, FromSourceLocation sourc

@Override
protected final Node createNode() {
return ArrayNode.fromStrings(values);
List<Node> nodes = new ArrayList<>(values.size());
for (String value : values) {
nodes.add(Node.from(value));
}
return new ArrayNode(nodes, getSourceLocation());
}

/**
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ public Provider() {

@Override
public Builder toBuilder() {
return builder().values(getValues());
return builder().sourceLocation(getSourceLocation()).values(getValues());
}

public static Builder builder() {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,8 +23,12 @@

import java.util.Optional;
import org.junit.jupiter.api.Test;
import software.amazon.smithy.model.SourceLocation;
import software.amazon.smithy.model.node.ArrayNode;
import software.amazon.smithy.model.node.Node;
import software.amazon.smithy.model.node.StringNode;
import software.amazon.smithy.model.shapes.ShapeId;
import software.amazon.smithy.utils.ListUtils;

public class TagsTraitTest {
@Test
Expand All @@ -40,4 +44,18 @@ public void loadsTrait() {
assertThat(tagsTrait.getValues(), contains("experimental"));
assertThat(tagsTrait.toNode(), equalTo(node));
}

@Test
public void hasSourceLocation() {
SourceLocation location1 = new SourceLocation("/foo.smithy", 1, 1);
SourceLocation location2 = new SourceLocation("/foo.smithy", 1, 2);
ArrayNode node = new ArrayNode(ListUtils.of(new StringNode("a", location1)), location2);
ShapeId id = ShapeId.from("ns.qux#foo");
TraitFactory provider = TraitFactory.createServiceFactory();
Optional<Trait> trait = provider.createTrait(ShapeId.from("smithy.api#tags"), id, node);

assertTrue(trait.isPresent());
assertThat(trait.get().getSourceLocation(), equalTo(location2));
assertThat(trait.get().toNode().getSourceLocation(), equalTo(location2));
}
}