Skip to content

Commit 0183cc2

Browse files
committed
fix #1679
1 parent e0c0120 commit 0183cc2

File tree

1 file changed

+7
-3
lines changed

1 file changed

+7
-3
lines changed

lib/src/googleJavaFormat/java/com/diffplug/spotless/glue/java/GoogleJavaFormatFormatterFunc.java

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,7 @@
2323
import com.google.googlejavaformat.java.FormatterException;
2424
import com.google.googlejavaformat.java.ImportOrderer;
2525
import com.google.googlejavaformat.java.JavaFormatterOptions;
26+
import com.google.googlejavaformat.java.JavaFormatterOptions.Style;
2627
import com.google.googlejavaformat.java.RemoveUnusedImports;
2728
import com.google.googlejavaformat.java.StringWrapper;
2829

@@ -37,13 +38,13 @@ public class GoogleJavaFormatFormatterFunc implements FormatterFunc {
3738
private final String version;
3839

3940
@Nonnull
40-
private final JavaFormatterOptions.Style formatterStyle;
41+
private final Style formatterStyle;
4142

4243
private final boolean reflowStrings;
4344

4445
public GoogleJavaFormatFormatterFunc(@Nonnull String version, @Nonnull String style, boolean reflowStrings) {
4546
this.version = Objects.requireNonNull(version);
46-
this.formatterStyle = JavaFormatterOptions.Style.valueOf(Objects.requireNonNull(style));
47+
this.formatterStyle = Style.valueOf(Objects.requireNonNull(style));
4748
this.reflowStrings = reflowStrings;
4849

4950
this.formatter = new Formatter(JavaFormatterOptions.builder()
@@ -56,7 +57,10 @@ public GoogleJavaFormatFormatterFunc(@Nonnull String version, @Nonnull String st
5657
public String apply(@Nonnull String input) throws Exception {
5758
String formatted = formatter.formatSource(input);
5859
String removedUnused = RemoveUnusedImports.removeUnusedImports(formatted);
59-
String sortedImports = ImportOrderer.reorderImports(removedUnused, formatterStyle);
60+
// Issue #1679: we used to call ImportOrderer.reorderImports(String) here, but that is deprecated.
61+
// Replacing the call with (the correct) reorderImports(String, Style) causes issues for Style.AOSP,
62+
// so we force the style to GOOGLE for now (which is what the deprecated method did)
63+
String sortedImports = ImportOrderer.reorderImports(removedUnused, Style.GOOGLE);
6064
return reflowLongStrings(sortedImports);
6165
}
6266

0 commit comments

Comments
 (0)