Skip to content

Commit

Permalink
Support removing unused mixins
Browse files Browse the repository at this point in the history
  • Loading branch information
iancaffey authored and mtdowling committed Aug 25, 2023
1 parent e10e6be commit aef7995
Show file tree
Hide file tree
Showing 2 changed files with 31 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ Model transform(ModelTransformer transformer, Model model) {
}
}

if (!updatedShapes.isEmpty()) {
if (!updatedShapes.isEmpty() || !toRemove.isEmpty()) {
Model.Builder builder = model.toBuilder();
updatedShapes.forEach(builder::addShape);
// Don't use the removeShapes transform because that would further mutate shapes and remove the things
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -145,6 +145,36 @@ public void canFilterAndRemoveMixinsWhenMixinsArePresent() {
Matchers.equalTo(concrete.toBuilder().flattenMixins().build()));
}

@Test
public void canFilterAndRemoveMixinsWhenUnusedMixinsArePresent() {
ModelTransformer transformer = ModelTransformer.create();
Model.Builder builder = Model.builder();
StringShape string = StringShape.builder().id("smithy.example#String").build();
StructureShape mixin1 = StructureShape.builder()
.id("smithy.example#Mixin1")
.addTrait(MixinTrait.builder().build())
.addMember("a", string.getId())
.build();
StructureShape mixin2 = StructureShape.builder()
.id("smithy.example#Mixin2")
.addMember("b", string.getId())
.addTrait(MixinTrait.builder().build())
.build();
StructureShape mixin3 = StructureShape.builder()
.id("smithy.example#Mixin3")
.addMember("c", string.getId())
.addTrait(MixinTrait.builder().build())
.addMixin(mixin2)
.build();
builder.addShapes(mixin1, mixin2, mixin3);
Model model = builder.build();
Model result = transformer.flattenAndRemoveMixins(model);

assertThat(result.toSet(), Matchers.not(Matchers.hasItem(mixin1)));
assertThat(result.toSet(), Matchers.not(Matchers.hasItem(mixin2)));
assertThat(result.toSet(), Matchers.not(Matchers.hasItem(mixin3)));
}

@ParameterizedTest
@MethodSource("flattenShapesData")
public void flattenShapes(String name) {
Expand Down

0 comments on commit aef7995

Please sign in to comment.