private Set<Shape> getTraitClosure(Model model) {
        // Get a map of existing providers, so we do not generate any trait definitions
        // for traits we have already manually defined a provider for.
        Set<ShapeId> existingProviders = new HashSet<>();
        ServiceLoader.load(TraitService.class, TraitCodegen.class.getClassLoader())
                .forEach(service -> existingProviders.add(service.getShapeId()));

        // Get all trait shapes within the specified namespace, but filter out
        // any trait shapes for which a provider is already defined or which have
        // excluded tags
        Set<Shape> traitClosure = traitSelector.select(model)
                .stream()
                .filter(pluginContext::isSourceShape)
                .filter(shape -> !existingProviders.contains(shape.getId()))
                .filter(shape -> !this.hasExcludeTag(shape))
                .collect(Collectors.toSet());

        if (traitClosure.isEmpty()) {
            LOGGER.warning("Could not find any trait definitions to generate.");
            return traitClosure;
        }

        // Find all shapes connected to trait shapes and therefore within generation closure.
        // These shapes must all be within the same namespace. Note: we do not need to add members
        // to the closure
        Set<Shape> nested = new HashSet<>();
        Walker walker = new Walker(model);
        for (Shape traitShape : traitClosure) {
            nested.addAll(walker.walkShapes(traitShape)
                    .stream()
                    .filter(shape -> !shape.isMemberShape())
                    .filter(shape -> !Prelude.isPreludeShape(shape))
                    .collect(Collectors.toSet()));
        }

        // If any nested shapes are not in the specified namespace, throw an error.
        Set<Shape> invalidNested = nested.stream()
                .filter(shape -> !shape.getId().getNamespace().startsWith(settings.smithyNamespace()))
                .collect(Collectors.toSet());
        if (!invalidNested.isEmpty()) {
            throw new RuntimeException("Shapes: " + invalidNested + " are within the trait closure but are not within "
                    + "the specified namespace `" + settings.smithyNamespace() + "`.");
        }
        traitClosure.addAll(nested);

        return traitClosure;
    }
Applies standard transforms to the model.
<dl>
    <dt>changeStringEnumsToEnumShapes</dt>
    <dd>Changes string enums to enum shapes for compatibility</dd>
    <dt>flattenAndRemoveMixins</dt>
    <dd>Ensures mixins are flattened into any generated traits or nested structures</dd>
</dl>
smithy-trait-codegen/src/main/java/software/amazon/smithy/traitcodegen/TraitCodegen.java