@Override
    public String toString() {
        String result = currentState.toString();

        // Trim excessive blank lines.
        if (trimBlankLines > -1) {
            StringBuilder builder = new StringBuilder(result.length());
            String[] lines = LINES.split(result);
            int blankCount = 0;

            for (String line : lines) {
                if (!StringUtils.isBlank(line)) {
                    builder.append(line).append(currentState.newline);
                    blankCount = 0;
                } else if (blankCount++ < trimBlankLines) {
                    builder.append(line).append(currentState.newline);
                }
            }

            result = builder.toString();
        }

        if (result.isEmpty()) {
            return trailingNewline ? currentState.newline : "";
        }

        // This accounts for cases where the only write on the AbstractCodeWriter was
        // an inline write, but the write ended with spaces.
        if (currentState.trimTrailingSpaces) {
            result = StringUtils.stripEnd(result, " ");
        }

        if (trailingNewline) {
            // Add a trailing newline if needed.
            return result.endsWith(currentState.newline) ? result : result + currentState.newline;
        } else if (result.endsWith(currentState.newline)) {
            // Strip the trailing newline if present.
            return result.substring(0, result.length() - currentState.newline.length());
        } else {
            return result;
        }
    }
Gets the contents of the generated code.

<p>The result will have an appended newline if the AbstractCodeWriter is
configured to always append a newline. A newline is only appended
in these cases if the result does not already end with a newline.

@return Returns the generated code.
smithy-utils/src/main/java/software/amazon/smithy/utils/AbstractCodeWriter.java