NeighborVisitor extends ShapeVisitor.Default<List<Relationship>> implements NeighborProvider { @Override public List<Relationship> operationShape(OperationShape shape) { List<Relationship> result = new ArrayList<>(); shape.getInput().ifPresent(id -> result.add(relationship(shape, RelationshipType.INPUT, id))); shape.getOutput().ifPresent(id -> result.add(relationship(shape, RelationshipType.OUTPUT, id))); result.addAll(shape.getErrors().stream() .map(errorId -> relationship(shape, RelationshipType.ERROR, errorId)) .collect(Collectors.toList())); return result; } NeighborVisitor(Model model); @Override List<Relationship> getNeighbors(Shape shape); @Override List<Relationship> getDefault(Shape shape); @Override List<Relationship> serviceShape(ServiceShape shape); @Override List<Relationship> resourceShape(ResourceShape shape); @Override List<Relationship> operationShape(OperationShape shape); @Override List<Relationship> memberShape(MemberShape shape); @Override List<Relationship> listShape(ListShape shape); @Override List<Relationship> setShape(SetShape shape); @Override List<Relationship> mapShape(MapShape shape); @Override List<Relationship> structureShape(StructureShape shape); @Override List<Relationship> unionShape(UnionShape shape);  }
@Test public void operationShape() { StructureShape error = StructureShape.builder().id("ns.foo#Error").build(); StructureShape input = StructureShape.builder().id("ns.foo#Input").build(); StructureShape output = StructureShape.builder().id("ns.foo#Output").build(); OperationShape method = OperationShape.builder() .id("ns.foo#Foo") .input(input.getId()) .output(output.getId()) .addError(error.getId()) .build(); Model model = Model.builder().addShapes(method, input, output, error).build(); NeighborVisitor neighborVisitor = new NeighborVisitor(model); List<Relationship> relationships = method.accept(neighborVisitor); assertThat(relationships, containsInAnyOrder( Relationship.create(method, RelationshipType.INPUT, input), Relationship.create(method, RelationshipType.OUTPUT, output), Relationship.create(method, RelationshipType.ERROR, error))); }