23
23
import com .google .googlejavaformat .java .FormatterException ;
24
24
import com .google .googlejavaformat .java .ImportOrderer ;
25
25
import com .google .googlejavaformat .java .JavaFormatterOptions ;
26
+ import com .google .googlejavaformat .java .JavaFormatterOptions .Style ;
26
27
import com .google .googlejavaformat .java .RemoveUnusedImports ;
27
28
import com .google .googlejavaformat .java .StringWrapper ;
28
29
@@ -37,13 +38,13 @@ public class GoogleJavaFormatFormatterFunc implements FormatterFunc {
37
38
private final String version ;
38
39
39
40
@ Nonnull
40
- private final JavaFormatterOptions . Style formatterStyle ;
41
+ private final Style formatterStyle ;
41
42
42
43
private final boolean reflowStrings ;
43
44
44
45
public GoogleJavaFormatFormatterFunc (@ Nonnull String version , @ Nonnull String style , boolean reflowStrings ) {
45
46
this .version = Objects .requireNonNull (version );
46
- this .formatterStyle = JavaFormatterOptions . Style .valueOf (Objects .requireNonNull (style ));
47
+ this .formatterStyle = Style .valueOf (Objects .requireNonNull (style ));
47
48
this .reflowStrings = reflowStrings ;
48
49
49
50
this .formatter = new Formatter (JavaFormatterOptions .builder ()
@@ -56,7 +57,10 @@ public GoogleJavaFormatFormatterFunc(@Nonnull String version, @Nonnull String st
56
57
public String apply (@ Nonnull String input ) throws Exception {
57
58
String formatted = formatter .formatSource (input );
58
59
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 );
60
64
return reflowLongStrings (sortedImports );
61
65
}
62
66
0 commit comments