UnreferencedShapes { public Set<Shape> compute(Model model) { Walker shapeWalker = new Walker(NeighborProviderIndex.of(model).getProvider()); Set<Shape> connected = model.shapes(ServiceShape.class) .flatMap(service -> shapeWalker.walkShapes(service).stream()) .collect(Collectors.toSet()); model.shapes() .filter(shape -> shape.hasTrait(TraitDefinition.class)) .flatMap(shape -> shapeWalker.walkShapes(shape).stream()) .forEach(connected::add); return model.shapes() .filter(FunctionalUtils.not(Shape::isMemberShape)) .filter(FunctionalUtils.not(connected::contains)) .filter(FunctionalUtils.not(Prelude::isPreludeShape)) .filter(keepFilter) .collect(Collectors.toSet()); } UnreferencedShapes();  UnreferencedShapes(Predicate<Shape> keepFilter); Set<Shape> compute(Model model);  }
@Test public void doesNotCheckPrelude() { Model model = Model.assembler().assemble().unwrap(); assertThat(new UnreferencedShapes().compute(model), empty()); }
@Test public void doesNotCheckShapesThatAreTraitShapes() { UnreferencedShapes unref = new UnreferencedShapes(); assertThat(unref.compute(model).stream().map(Shape::getId).collect(Collectors.toSet()), containsInAnyOrder( ShapeId.from("ns.foo#Exclude1"), ShapeId.from("ns.foo#Exclude2"))); }
@Test public void doesNotIgnorePrivateShapes() { ShapeId id = ShapeId.from("foo.baz#Bar"); Model model = createPrivateShapeModel(id); UnreferencedShapes unref = new UnreferencedShapes(); Set<ShapeId> ids = unref.compute(model).stream().map(Shape::getId).collect(Collectors.toSet()); assertTrue(ids.contains(id)); }