@Override
    public void modifyShape(
            AbstractShapeBuilder<?, ?> builder,
            Map<String, MemberShape.Builder> memberBuilders,
            Function<ShapeId, Map<ShapeId, Trait>> unclaimedTraits,
            Function<ShapeId, Shape> shapeMap
    ) {
        Shape mixinShape = shapeMap.apply(mixin);
        if (mixinShape == null) {
            throw new SourceException("Cannot apply mixin to " + builder.getId() + ": " + mixin + " not found",
                    builder);
        }

        for (MemberShape member : mixinShape.members()) {
            ShapeId targetId = builder.getId().withMember(member.getMemberName());
            // Claim traits from the trait maps that were applied to synthesized shapes.
            Map<ShapeId, Trait> introducedTraits = new LinkedHashMap<>(unclaimedTraits.apply(targetId));
            if (potentiallyIntroducedTraits != null && potentiallyIntroducedTraits.containsKey(targetId)) {
                introducedTraits.putAll(potentiallyIntroducedTraits.get(targetId));
            }
            String memberName = member.getMemberName();
            MemberShape introducedMember = null;
            Optional<MemberShape> previouslyAdded = builder.getMember(memberName);
            if (previouslyAdded.isPresent()) {
                // The member was previously introduced, check if it inherits from another mixin to
                // avoid overwriting it.
                MemberShape previous = previouslyAdded.get();
                if (!previous.getMixins().isEmpty()) {
                    MemberShape.Builder previouslyAddedBuilder = previous.toBuilder();
                    introducedMember = previouslyAddedBuilder
                            .addMixin(member)
                            .build();
                    if (!previous.getTarget().equals(member.getTarget())) {
                        mixinMemberConflict(previouslyAddedBuilder, member);
                    }
                }
            }

            if (introducedMember == null) {
                if (memberBuilders.containsKey(member.getMemberName())) {
                    MemberShape.Builder original = memberBuilders.get(member.getMemberName());
                    introducedMember = original.addMixin(member).build();
                    if (!introducedMember.getTarget().equals(member.getTarget())) {
                        mixinMemberConflict(original, member);
                    }
                } else if (!introducedTraits.isEmpty()) {
                    // Build local member copies before adding mixins if traits
                    // were introduced to inherited mixin members.
                    introducedMember = MemberShape.builder()
                            .id(targetId)
                            .target(member.getTarget())
                            .source(member.getSourceLocation())
                            .addTraits(introducedTraits.values())
                            .addMixin(member)
                            .build();
                }
            }

            if (introducedMember != null) {
                builder.addMember(introducedMember);
            }
        }

        builder.addMixin(mixinShape);
    }
Applies mixins to shapes after the mixins have been resolved.
smithy-model/src/main/java/software/amazon/smithy/model/loader/ApplyMixin.java