@@ -126,17 +126,22 @@ public static class KtfmtFormattingOptions implements Serializable {
126126@ Nullable
127127private Boolean removeUnusedImports = null ;
128128
129+ @ Nullable
130+ private Boolean manageTrailingCommas = null ;
131+
129132public KtfmtFormattingOptions () {}
130133
131134public KtfmtFormattingOptions (
132135@ Nullable Integer maxWidth ,
133136@ Nullable Integer blockIndent ,
134137@ Nullable Integer continuationIndent ,
135- @ Nullable Boolean removeUnusedImports ) {
138+ @ Nullable Boolean removeUnusedImports ,
139+ @ Nullable Boolean manageTrailingCommas ) {
136140this .maxWidth = maxWidth ;
137141this .blockIndent = blockIndent ;
138142this .continuationIndent = continuationIndent ;
139143this .removeUnusedImports = removeUnusedImports ;
144+ this .manageTrailingCommas = manageTrailingCommas ;
140145}
141146
142147public void setMaxWidth (int maxWidth ) {
@@ -154,6 +159,10 @@ public void setContinuationIndent(int continuationIndent) {
154159public void setRemoveUnusedImports (boolean removeUnusedImports ) {
155160this .removeUnusedImports = removeUnusedImports ;
156161}
162+
163+ public void setManageTrailingCommas (boolean manageTrailingCommas ) {
164+ this .manageTrailingCommas = manageTrailingCommas ;
165+ }
157166}
158167
159168/** Creates a step which formats everything - code, import order, and unused imports. */
@@ -228,9 +237,9 @@ FormatterFunc createFormat() throws Exception {
228237}
229238
230239final Constructor <?> optionsConstructor = ktfmtFormattingOptionsClass .getConstructor (
231- Integer .class , Integer .class , Integer .class , Boolean .class );
240+ Integer .class , Integer .class , Integer .class , Boolean .class , Boolean . class );
232241final Object ktfmtFormattingOptions = optionsConstructor .newInstance (
233- options .maxWidth , options .blockIndent , options .continuationIndent , options .removeUnusedImports );
242+ options .maxWidth , options .blockIndent , options .continuationIndent , options .removeUnusedImports , options . manageTrailingCommas );
234243if (style == null ) {
235244final Constructor <?> constructor = formatterFuncClass .getConstructor (ktfmtFormattingOptionsClass );
236245return (FormatterFunc ) constructor .newInstance (ktfmtFormattingOptions );
@@ -365,7 +374,7 @@ private Object getCustomFormattingOptions(Class<?> formatterClass) throws Except
365374/* continuationIndent = */ Optional .ofNullable (options .continuationIndent ).orElse ((Integer ) formattingOptionsClass .getMethod ("getContinuationIndent" ).invoke (formattingOptions )),
366375/* removeUnusedImports = */ Optional .ofNullable (options .removeUnusedImports ).orElse ((Boolean ) formattingOptionsClass .getMethod ("getRemoveUnusedImports" ).invoke (formattingOptions )),
367376/* debuggingPrintOpsAfterFormatting = */ (Boolean ) formattingOptionsClass .getMethod ("getDebuggingPrintOpsAfterFormatting" ).invoke (formattingOptions ),
368- /* manageTrailingCommas */ ( Boolean ) formattingOptionsClass .getMethod ("getManageTrailingCommas" ).invoke (formattingOptions ));
377+ /* manageTrailingCommas */ Optional . ofNullable ( options . manageTrailingCommas ). orElse (( Boolean ) formattingOptionsClass .getMethod ("getManageTrailingCommas" ).invoke (formattingOptions ) ));
369378}
370379}
371380
0 commit comments