codegen-lite/src/main/java/software/amazon/awssdk/codegen/lite/emitters/JavaCodeFormatter.java [31:100]:
- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
@SuppressWarnings("unchecked")
public class JavaCodeFormatter implements CodeTransformer {

    private static final Map<String, Object> DEFAULT_FORMATTER_OPTIONS;
    private static final Object lock = new Object();

    static {
        DEFAULT_FORMATTER_OPTIONS = DefaultCodeFormatterConstants.getEclipseDefaultSettings();

        DEFAULT_FORMATTER_OPTIONS.put(JavaCore.COMPILER_COMPLIANCE, JavaCore.VERSION_1_8);
        DEFAULT_FORMATTER_OPTIONS.put(JavaCore.COMPILER_CODEGEN_TARGET_PLATFORM, JavaCore.VERSION_1_8);
        DEFAULT_FORMATTER_OPTIONS.put(JavaCore.COMPILER_SOURCE, JavaCore.VERSION_1_8);
        DEFAULT_FORMATTER_OPTIONS.put(DefaultCodeFormatterConstants.FORMATTER_TAB_CHAR,
                                      JavaCore.SPACE);
        DEFAULT_FORMATTER_OPTIONS.put(
                DefaultCodeFormatterConstants.FORMATTER_COMMENT_INDENT_PARAMETER_DESCRIPTION,
                DefaultCodeFormatterConstants.FALSE);
        DEFAULT_FORMATTER_OPTIONS.put(
                DefaultCodeFormatterConstants.FORMATTER_ALIGNMENT_FOR_ENUM_CONSTANTS,
                DefaultCodeFormatterConstants.createAlignmentValue(true,
                                                                   DefaultCodeFormatterConstants.WRAP_ONE_PER_LINE,
                                                                   DefaultCodeFormatterConstants.INDENT_ON_COLUMN));
        DEFAULT_FORMATTER_OPTIONS.put(
                DefaultCodeFormatterConstants.FORMATTER_ALIGNMENT_FOR_PARAMETERS_IN_CONSTRUCTOR_DECLARATION,
                DefaultCodeFormatterConstants.createAlignmentValue(false,
                                                                   DefaultCodeFormatterConstants.WRAP_COMPACT,
                                                                   DefaultCodeFormatterConstants.INDENT_DEFAULT));
        // Formats custom file headers if provided
        DEFAULT_FORMATTER_OPTIONS
                .put(DefaultCodeFormatterConstants.FORMATTER_COMMENT_FORMAT_HEADER,
                     DefaultCodeFormatterConstants.TRUE);
        DEFAULT_FORMATTER_OPTIONS.put(DefaultCodeFormatterConstants.FORMATTER_LINE_SPLIT, "130");
        DEFAULT_FORMATTER_OPTIONS.put(DefaultCodeFormatterConstants.FORMATTER_COMMENT_LINE_LENGTH, "120");
    }

    private final CodeFormatter codeFormatter;

    /**
     * Creates a JavaCodeFormatter using the default formatter options.
     */
    public JavaCodeFormatter() {
        this(new HashMap<>());
    }

    /**
     * Creates a JavaCodeFormatter using the default formatter options and
     * optionally applying user provided options on top.
     *
     * @param overrideOptions user provided options to apply on top of defaults
     */
    public JavaCodeFormatter(final Map<String, Object> overrideOptions) {
        Map<String, Object> formatterOptions = new HashMap<>(DEFAULT_FORMATTER_OPTIONS);
        if (overrideOptions != null) {
            formatterOptions.putAll(overrideOptions);
        }

        this.codeFormatter = ToolFactory.createCodeFormatter(formatterOptions,
                                                             ToolFactory.M_FORMAT_EXISTING);
    }

    @Override
    public String apply(String contents) {
        TextEdit edit;
        // There is a race condition in the org.eclipse.jdt.internal.formatter.DefaultCodeFormatter in version 3.10.0.
        // The static PROBING_SCANNER can have its state changed by multiple threads.
        // Synchronize our usage of that class to ensure we don't hit this.
        synchronized (lock) {
            edit = codeFormatter.format(
                CodeFormatter.K_COMPILATION_UNIT
                | CodeFormatter.F_INCLUDE_COMMENTS, contents, 0,
- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -



codegen/src/main/java/software/amazon/awssdk/codegen/emitters/JavaCodeFormatter.java [32:101]:
- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
@SuppressWarnings("unchecked")
public class JavaCodeFormatter implements CodeTransformer {

    private static final Map<String, Object> DEFAULT_FORMATTER_OPTIONS;
    private static final Object lock = new Object();

    static {
        DEFAULT_FORMATTER_OPTIONS = DefaultCodeFormatterConstants.getEclipseDefaultSettings();

        DEFAULT_FORMATTER_OPTIONS.put(JavaCore.COMPILER_COMPLIANCE, JavaCore.VERSION_1_8);
        DEFAULT_FORMATTER_OPTIONS.put(JavaCore.COMPILER_CODEGEN_TARGET_PLATFORM, JavaCore.VERSION_1_8);
        DEFAULT_FORMATTER_OPTIONS.put(JavaCore.COMPILER_SOURCE, JavaCore.VERSION_1_8);
        DEFAULT_FORMATTER_OPTIONS.put(DefaultCodeFormatterConstants.FORMATTER_TAB_CHAR,
                                      JavaCore.SPACE);
        DEFAULT_FORMATTER_OPTIONS.put(
                DefaultCodeFormatterConstants.FORMATTER_COMMENT_INDENT_PARAMETER_DESCRIPTION,
                DefaultCodeFormatterConstants.FALSE);
        DEFAULT_FORMATTER_OPTIONS.put(
                DefaultCodeFormatterConstants.FORMATTER_ALIGNMENT_FOR_ENUM_CONSTANTS,
                DefaultCodeFormatterConstants.createAlignmentValue(true,
                                                                   DefaultCodeFormatterConstants.WRAP_ONE_PER_LINE,
                                                                   DefaultCodeFormatterConstants.INDENT_ON_COLUMN));
        DEFAULT_FORMATTER_OPTIONS.put(
                DefaultCodeFormatterConstants.FORMATTER_ALIGNMENT_FOR_PARAMETERS_IN_CONSTRUCTOR_DECLARATION,
                DefaultCodeFormatterConstants.createAlignmentValue(false,
                                                                   DefaultCodeFormatterConstants.WRAP_COMPACT,
                                                                   DefaultCodeFormatterConstants.INDENT_DEFAULT));
        // Formats custom file headers if provided
        DEFAULT_FORMATTER_OPTIONS
                .put(DefaultCodeFormatterConstants.FORMATTER_COMMENT_FORMAT_HEADER,
                     DefaultCodeFormatterConstants.TRUE);
        DEFAULT_FORMATTER_OPTIONS.put(DefaultCodeFormatterConstants.FORMATTER_LINE_SPLIT, "130");
        DEFAULT_FORMATTER_OPTIONS.put(DefaultCodeFormatterConstants.FORMATTER_COMMENT_LINE_LENGTH, "120");
    }

    private final CodeFormatter codeFormatter;

    /**
     * Creates a JavaCodeFormatter using the default formatter options.
     */
    public JavaCodeFormatter() {
        this(new HashMap<>());
    }

    /**
     * Creates a JavaCodeFormatter using the default formatter options and
     * optionally applying user provided options on top.
     *
     * @param overrideOptions user provided options to apply on top of defaults
     */
    public JavaCodeFormatter(final Map<String, Object> overrideOptions) {
        Map<String, Object> formatterOptions = new HashMap<>(DEFAULT_FORMATTER_OPTIONS);
        if (overrideOptions != null) {
            formatterOptions.putAll(overrideOptions);
        }

        this.codeFormatter = ToolFactory.createCodeFormatter(formatterOptions,
                                                             ToolFactory.M_FORMAT_EXISTING);
    }

    @Override
    public String apply(String contents) {
        TextEdit edit;
        // There is a race condition in the org.eclipse.jdt.internal.formatter.DefaultCodeFormatter in version 3.10.0.
        // The static PROBING_SCANNER can have its state changed by multiple threads.
        // Synchronize our usage of that class to ensure we don't hit this.
        synchronized (lock) {
            edit = codeFormatter.format(
                CodeFormatter.K_COMPILATION_UNIT
                | CodeFormatter.F_INCLUDE_COMMENTS, contents, 0,
- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -



