private Set<Shape> getAffectedStructures(Model model, Shape resource) {
        Set<Shape> result = new HashSet<>();

        for (StructureShape struct : model.getStructureShapesWithTrait(ReferencesTrait.class)) {
            // References can also be on strings, but we only care about structs.
            ReferencesTrait trait = struct.expectTrait(ReferencesTrait.class);
            // Get the reference to a particular shape.
            List<ReferencesTrait.Reference> references = trait.getResourceReferences(resource.getId());

            if (!references.isEmpty()) {
                // If the trait contains a reference to the resource, then create a new version of the
                // trait and shape that no longer reference the resource.
                ReferencesTrait.Builder traitBuilder = trait.toBuilder();
                traitBuilder.clearReferences();

                for (ReferencesTrait.Reference ref : trait.getReferences()) {
                    if (!references.contains(ref)) {
                        traitBuilder.addReference(ref);
                    }
                }

                result.add(struct.toBuilder().addTrait(traitBuilder.build()).build());
            }
        }

        return result;
    }
Removes references to resources that are removed from
{@link ReferencesTrait}s.
smithy-model/src/main/java/software/amazon/smithy/model/transform/plugins/CleanResourceReferences.java