11/*
2- * Copyright 2022-2024 DiffPlug
2+ * Copyright 2022-2025 DiffPlug
33 *
44 * Licensed under the Apache License, Version 2.0 (the "License");
55 * you may not use this file except in compliance with the License.
@@ -28,8 +28,7 @@ public final class KtfmtFormatterFunc implements FormatterFunc {
2828 @ Nonnull
2929 private final KtfmtStyle style ;
3030
31- @ Nullable
32- private final KtfmtFormattingOptions ktfmtFormattingOptions ;
31+ @ Nullable private final KtfmtFormattingOptions ktfmtFormattingOptions ;
3332
3433 public KtfmtFormatterFunc () {
3534 this (KtfmtStyle .META , null );
@@ -55,29 +54,23 @@ public String apply(@Nonnull String input) throws Exception {
5554 }
5655
5756 private FormattingOptions createFormattingOptions () throws Exception {
58- FormattingOptions formattingOptions ;
59- switch (style ) {
60- case META :
61- formattingOptions = Formatter .META_FORMAT ;
62- break ;
63- case GOOGLE :
64- formattingOptions = Formatter .GOOGLE_FORMAT ;
65- break ;
66- case KOTLIN_LANG :
67- formattingOptions = Formatter .KOTLINLANG_FORMAT ;
68- break ;
69- default :
70- throw new IllegalStateException ("Unknown formatting option " + style );
71- }
57+ FormattingOptions formattingOptions = switch (style ) {
58+ case META -> Formatter .META_FORMAT ;
59+ case GOOGLE -> Formatter .GOOGLE_FORMAT ;
60+ case KOTLIN_LANG -> Formatter .KOTLINLANG_FORMAT ;
61+ default -> throw new IllegalStateException ("Unknown formatting option " + style );
62+ };
7263
7364 if (ktfmtFormattingOptions != null ) {
7465 formattingOptions = formattingOptions .copy (
75- ktfmtFormattingOptions .getMaxWidth ().orElse (formattingOptions .getMaxWidth ()),
76- ktfmtFormattingOptions .getBlockIndent ().orElse (formattingOptions .getBlockIndent ()),
77- ktfmtFormattingOptions .getContinuationIndent ().orElse (formattingOptions .getContinuationIndent ()),
78- ktfmtFormattingOptions .getManageTrailingCommas ().orElse (formattingOptions .getManageTrailingCommas ()),
79- ktfmtFormattingOptions .getRemoveUnusedImports ().orElse (formattingOptions .getRemoveUnusedImports ()),
80- formattingOptions .getDebuggingPrintOpsAfterFormatting ());
66+ ktfmtFormattingOptions .getMaxWidth ().orElse (formattingOptions .getMaxWidth ()),
67+ ktfmtFormattingOptions .getBlockIndent ().orElse (formattingOptions .getBlockIndent ()),
68+ ktfmtFormattingOptions .getContinuationIndent ().orElse (formattingOptions .getContinuationIndent ()),
69+ ktfmtFormattingOptions .getTrailingCommaManagementStrategy ()
70+ .map (KtfmtTrailingCommaManagementStrategy ::toFormatterTrailingCommaManagementStrategy )
71+ .orElse (formattingOptions .getTrailingCommaManagementStrategy ()),
72+ ktfmtFormattingOptions .getRemoveUnusedImports ().orElse (formattingOptions .getRemoveUnusedImports ()),
73+ formattingOptions .getDebuggingPrintOpsAfterFormatting ());
8174 }
8275
8376 return formattingOptions ;
0 commit comments