diff --git a/idea_plugin/src/main/java/com/google/googlejavaformat/intellij/GoogleJavaFormatConfigurable.form b/idea_plugin/src/main/java/com/google/googlejavaformat/intellij/GoogleJavaFormatConfigurable.form index 1db1d7920..cae5a5db0 100644 --- a/idea_plugin/src/main/java/com/google/googlejavaformat/intellij/GoogleJavaFormatConfigurable.form +++ b/idea_plugin/src/main/java/com/google/googlejavaformat/intellij/GoogleJavaFormatConfigurable.form @@ -1,6 +1,6 @@
diff --git a/idea_plugin/src/main/java/com/google/googlejavaformat/intellij/GoogleJavaFormatConfigurable.java b/idea_plugin/src/main/java/com/google/googlejavaformat/intellij/GoogleJavaFormatConfigurable.java index 759decc0f..7b73d0638 100644 --- a/idea_plugin/src/main/java/com/google/googlejavaformat/intellij/GoogleJavaFormatConfigurable.java +++ b/idea_plugin/src/main/java/com/google/googlejavaformat/intellij/GoogleJavaFormatConfigurable.java @@ -40,6 +40,7 @@ class GoogleJavaFormatConfigurable extends BaseConfigurable implements Searchabl private final Project project; private JPanel panel; private JCheckBox enable; + private JCheckBox optimizeImports; private JComboBox styleComboBox; public GoogleJavaFormatConfigurable(Project project) { @@ -80,6 +81,7 @@ public JComponent createComponent() { public void apply() throws ConfigurationException { GoogleJavaFormatSettings settings = GoogleJavaFormatSettings.getInstance(project); settings.setEnabled(enable.isSelected() ? EnabledState.ENABLED : getDisabledState()); + settings.setOptimizeImports(optimizeImports.isSelected()); settings.setStyle(((UiFormatterStyle) styleComboBox.getSelectedItem()).convert()); } @@ -94,6 +96,7 @@ private EnabledState getDisabledState() { public void reset() { GoogleJavaFormatSettings settings = GoogleJavaFormatSettings.getInstance(project); enable.setSelected(settings.isEnabled()); + optimizeImports.setSelected(settings.shouldOptimizeImports()); styleComboBox.setSelectedItem(UiFormatterStyle.convert(settings.getStyle())); } @@ -101,6 +104,7 @@ public void reset() { public boolean isModified() { GoogleJavaFormatSettings settings = GoogleJavaFormatSettings.getInstance(project); return enable.isSelected() != settings.isEnabled() + || optimizeImports.isSelected() != settings.shouldOptimizeImports() || !styleComboBox.getSelectedItem().equals(UiFormatterStyle.convert(settings.getStyle())); } diff --git a/idea_plugin/src/main/java/com/google/googlejavaformat/intellij/GoogleJavaFormatFormattingService.java b/idea_plugin/src/main/java/com/google/googlejavaformat/intellij/GoogleJavaFormatFormattingService.java index 9d2d7a595..6db650877 100644 --- a/idea_plugin/src/main/java/com/google/googlejavaformat/intellij/GoogleJavaFormatFormattingService.java +++ b/idea_plugin/src/main/java/com/google/googlejavaformat/intellij/GoogleJavaFormatFormattingService.java @@ -27,6 +27,7 @@ import com.intellij.formatting.service.AsyncFormattingRequest; import com.intellij.ide.highlighter.JavaFileType; import com.intellij.lang.ImportOptimizer; +import com.intellij.lang.java.JavaImportOptimizer; import com.intellij.openapi.project.Project; import com.intellij.openapi.util.TextRange; import com.intellij.psi.PsiFile; @@ -41,6 +42,9 @@ public class GoogleJavaFormatFormattingService extends AsyncDocumentFormattingSe public static final ImmutableSet