@@ -126,17 +126,22 @@ public static class KtfmtFormattingOptions implements Serializable {
126
126
@ Nullable
127
127
private Boolean removeUnusedImports = null ;
128
128
129
+ @ Nullable
130
+ private Boolean manageTrailingCommas = null ;
131
+
129
132
public KtfmtFormattingOptions () {}
130
133
131
134
public KtfmtFormattingOptions (
132
135
@ Nullable Integer maxWidth ,
133
136
@ Nullable Integer blockIndent ,
134
137
@ Nullable Integer continuationIndent ,
135
- @ Nullable Boolean removeUnusedImports ) {
138
+ @ Nullable Boolean removeUnusedImports ,
139
+ @ Nullable Boolean manageTrailingCommas ) {
136
140
this .maxWidth = maxWidth ;
137
141
this .blockIndent = blockIndent ;
138
142
this .continuationIndent = continuationIndent ;
139
143
this .removeUnusedImports = removeUnusedImports ;
144
+ this .manageTrailingCommas = manageTrailingCommas ;
140
145
}
141
146
142
147
public void setMaxWidth (int maxWidth ) {
@@ -154,6 +159,10 @@ public void setContinuationIndent(int continuationIndent) {
154
159
public void setRemoveUnusedImports (boolean removeUnusedImports ) {
155
160
this .removeUnusedImports = removeUnusedImports ;
156
161
}
162
+
163
+ public void setManageTrailingCommas (boolean manageTrailingCommas ) {
164
+ this .manageTrailingCommas = manageTrailingCommas ;
165
+ }
157
166
}
158
167
159
168
/** Creates a step which formats everything - code, import order, and unused imports. */
@@ -228,9 +237,9 @@ FormatterFunc createFormat() throws Exception {
228
237
}
229
238
230
239
final Constructor <?> optionsConstructor = ktfmtFormattingOptionsClass .getConstructor (
231
- Integer .class , Integer .class , Integer .class , Boolean .class );
240
+ Integer .class , Integer .class , Integer .class , Boolean .class , Boolean . class );
232
241
final Object ktfmtFormattingOptions = optionsConstructor .newInstance (
233
- options .maxWidth , options .blockIndent , options .continuationIndent , options .removeUnusedImports );
242
+ options .maxWidth , options .blockIndent , options .continuationIndent , options .removeUnusedImports , options . manageTrailingCommas );
234
243
if (style == null ) {
235
244
final Constructor <?> constructor = formatterFuncClass .getConstructor (ktfmtFormattingOptionsClass );
236
245
return (FormatterFunc ) constructor .newInstance (ktfmtFormattingOptions );
@@ -365,7 +374,7 @@ private Object getCustomFormattingOptions(Class<?> formatterClass) throws Except
365
374
/* continuationIndent = */ Optional .ofNullable (options .continuationIndent ).orElse ((Integer ) formattingOptionsClass .getMethod ("getContinuationIndent" ).invoke (formattingOptions )),
366
375
/* removeUnusedImports = */ Optional .ofNullable (options .removeUnusedImports ).orElse ((Boolean ) formattingOptionsClass .getMethod ("getRemoveUnusedImports" ).invoke (formattingOptions )),
367
376
/* 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 ) ));
369
378
}
370
379
}
371
380
0 commit comments