@SuppressWarnings("unchecked")
    String applyFormatter(char identifier, Object value) {
        BiFunction<Object, String, String> f = resolveFormatter(identifier);
        if (f != null) {
            return f.apply(value, getIndentText());
        } else if (identifier == 'C') {
            // The default C formatter is evaluated dynamically to prevent cyclic references in CodeFormatter.
            CodeSection section = new AnonymousCodeSection("__C_formatter_" + states.size());
            // A single trailing newline is stripped from the result, if present. This is because the $C formatter
            // is often used on the same line as other text like:
            //
            //     w.write("Hi, $C.", w.consumer(writer -> writer.write("name");
            //     // Results in "Hi, name.\n" and not "Hi, name\n.\n"
            //
            // In these cases, the trailing newline introduced in the $C formatter by writer.write() is removed
            // since it's up to the surrounding text to dictate newlines. Use an explicit newline in the text to
            // inject a newline.
            if (value instanceof Runnable) {
                Runnable runnable = (Runnable) value;
                return removeTrailingNewline(expandSection(section, "", ignore -> runnable.run()));
            } else if (value instanceof Consumer) {
                Consumer<T> consumer = (Consumer<T>) value;
                return removeTrailingNewline(expandSection(section, "", ignore -> consumer.accept((T) this)));
            } else {
                throw new ClassCastException(String.format(
                        "Expected value for 'C' formatter to be an instance of %s or %s, but found %s %s",
                        Runnable.class.getName(),
                        Consumer.class.getName(),
                        value == null ? "null" : value.getClass().getName(),
                        getDebugInfo()));
            }
        } else {
            // Return null if no formatter was found.
            return null;
        }
    }
Enable or disable writing stack trace comments before each call to
{@link #write}, {@link #writeWithNoFormatting}, {@link #writeInline},
and {@link #writeInlineWithNoFormatting}.

<p>It's sometimes useful to know where in a code generator a line of code
generated text came from. Enabling stack trace comments will output
the last relevant stack trace information caused text to appear in the
code writer's output.

@param enableStackTraceComments Set to true to enable stack trace comments.
@return Returns self.
smithy-utils/src/main/java/software/amazon/smithy/utils/AbstractCodeWriter.java