@Test public void shouldReportDefinitionsForTraitsThatAreNotUsed() { Model model = Model.assembler() .addImport(UnreferencedTraitDefinitionsTest.class.getResource("unreferenced-test.json")) .assemble() .unwrap(); UnreferencedTraitDefinitions unreferencedTraitDefinitions = new UnreferencedTraitDefinitions(); assertThat(unreferencedTraitDefinitions.compute(model), contains(model.expectShape(ShapeId.from("ns.foo#quux")))); }
public Set<Shape> compute(Model model) { Walker walker = new Walker(NeighborProviderIndex.of(model).getProvider()); Set<Shape> unused = model.getShapesWithTrait(TraitDefinition.class).stream() .filter(FunctionalUtils.not(Prelude::isPreludeShape)) .collect(Collectors.toSet()); model.shapes(ServiceShape.class) .flatMap(service -> walker.walkShapes(service).stream()) .distinct() .map(Shape::getAllTraits) .flatMap(traits -> traits.keySet().stream()) .distinct() .flatMap(traitId -> OptionalUtils.stream(model.getShape(traitId))) .filter(keepFilter) .forEach(unused::remove); return unused; }
UnreferencedTraitDefinitions { public Set<Shape> compute(Model model) { Walker walker = new Walker(NeighborProviderIndex.of(model).getProvider()); Set<Shape> unused = model.getShapesWithTrait(TraitDefinition.class).stream() .filter(FunctionalUtils.not(Prelude::isPreludeShape)) .collect(Collectors.toSet()); model.shapes(ServiceShape.class) .flatMap(service -> walker.walkShapes(service).stream()) .distinct() .map(Shape::getAllTraits) .flatMap(traits -> traits.keySet().stream()) .distinct() .flatMap(traitId -> OptionalUtils.stream(model.getShape(traitId))) .filter(keepFilter) .forEach(unused::remove); return unused; } }
UnreferencedTraitDefinitions { public Set<Shape> compute(Model model) { Walker walker = new Walker(NeighborProviderIndex.of(model).getProvider()); Set<Shape> unused = model.getShapesWithTrait(TraitDefinition.class).stream() .filter(FunctionalUtils.not(Prelude::isPreludeShape)) .collect(Collectors.toSet()); model.shapes(ServiceShape.class) .flatMap(service -> walker.walkShapes(service).stream()) .distinct() .map(Shape::getAllTraits) .flatMap(traits -> traits.keySet().stream()) .distinct() .flatMap(traitId -> OptionalUtils.stream(model.getShape(traitId))) .filter(keepFilter) .forEach(unused::remove); return unused; } UnreferencedTraitDefinitions();  UnreferencedTraitDefinitions(Predicate<Shape> keepFilter); }
UnreferencedTraitDefinitions { public Set<Shape> compute(Model model) { Walker walker = new Walker(NeighborProviderIndex.of(model).getProvider()); Set<Shape> unused = model.getShapesWithTrait(TraitDefinition.class).stream() .filter(FunctionalUtils.not(Prelude::isPreludeShape)) .collect(Collectors.toSet()); model.shapes(ServiceShape.class) .flatMap(service -> walker.walkShapes(service).stream()) .distinct() .map(Shape::getAllTraits) .flatMap(traits -> traits.keySet().stream()) .distinct() .flatMap(traitId -> OptionalUtils.stream(model.getShape(traitId))) .filter(keepFilter) .forEach(unused::remove); return unused; } UnreferencedTraitDefinitions();  UnreferencedTraitDefinitions(Predicate<Shape> keepFilter); Set<Shape> compute(Model model); }
UnreferencedTraitDefinitions { public Set<Shape> compute(Model model) { Walker walker = new Walker(NeighborProviderIndex.of(model).getProvider()); Set<Shape> unused = model.getShapesWithTrait(TraitDefinition.class).stream() .filter(FunctionalUtils.not(Prelude::isPreludeShape)) .collect(Collectors.toSet()); model.shapes(ServiceShape.class) .flatMap(service -> walker.walkShapes(service).stream()) .distinct() .map(Shape::getAllTraits) .flatMap(traits -> traits.keySet().stream()) .distinct() .flatMap(traitId -> OptionalUtils.stream(model.getShape(traitId))) .filter(keepFilter) .forEach(unused::remove); return unused; } UnreferencedTraitDefinitions();  UnreferencedTraitDefinitions(Predicate<Shape> keepFilter); Set<Shape> compute(Model model);  }