Skip to content

Commit f9b5473

Browse files
soumya92cushon
authored andcommitted
Add aosp option to IntelliJ plugin
MOE_MIGRATED_REVID=133885010
1 parent cf0597f commit f9b5473

File tree

2 files changed

+19
-4
lines changed

2 files changed

+19
-4
lines changed

idea_plugin/src/com/google/googlejavaformat/intellij/GoogleJavaFormatCodeStyleManager.java

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,7 @@
2121
import com.google.common.collect.Range;
2222
import com.google.googlejavaformat.java.Formatter;
2323
import com.google.googlejavaformat.java.FormatterException;
24+
import com.google.googlejavaformat.java.JavaFormatterOptions;
2425
import com.google.googlejavaformat.java.Replacement;
2526
import com.intellij.openapi.application.ApplicationManager;
2627
import com.intellij.openapi.command.WriteCommandAction;
@@ -45,10 +46,16 @@
4546
*/
4647
public class GoogleJavaFormatCodeStyleManager extends CodeStyleManagerDecorator {
4748

48-
private final Formatter formatter = new Formatter();
49+
private final Formatter formatter;
4950

5051
public GoogleJavaFormatCodeStyleManager(@NotNull CodeStyleManager original) {
52+
this(original, JavaFormatterOptions.defaultOptions());
53+
}
54+
55+
public GoogleJavaFormatCodeStyleManager(
56+
@NotNull CodeStyleManager original, @NotNull JavaFormatterOptions formatterOptions) {
5157
super(original);
58+
formatter = new Formatter(formatterOptions);
5259
}
5360

5461
@Override

idea_plugin/src/com/google/googlejavaformat/intellij/GoogleJavaFormatInstaller.java

Lines changed: 11 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@
1616

1717
package com.google.googlejavaformat.intellij;
1818

19+
import com.google.googlejavaformat.java.JavaFormatterOptions;
1920
import com.intellij.openapi.project.Project;
2021
import com.intellij.psi.codeStyle.CodeStyleManager;
2122
import org.picocontainer.MutablePicoContainer;
@@ -30,14 +31,17 @@ public final class GoogleJavaFormatInstaller {
3031

3132
private GoogleJavaFormatInstaller() {}
3233

33-
public static void installFormatter(Project project, boolean useGoogleFormatter) {
34+
public static void installFormatter(
35+
Project project, boolean useGoogleFormatter, JavaFormatterOptions javaFormatterOptions) {
3436
CodeStyleManager currentManager = CodeStyleManager.getInstance(project);
3537
CodeStyleManager newManager = null;
3638

3739
if (useGoogleFormatter) {
38-
if (!(currentManager instanceof GoogleJavaFormatCodeStyleManager)) {
39-
newManager = new GoogleJavaFormatCodeStyleManager(currentManager);
40+
if (currentManager instanceof GoogleJavaFormatCodeStyleManager) {
41+
// Recreate from delegate, updating the javaFormatterOptions as needed.
42+
currentManager = ((GoogleJavaFormatCodeStyleManager) currentManager).getDelegate();
4043
}
44+
newManager = new GoogleJavaFormatCodeStyleManager(currentManager, javaFormatterOptions);
4145
} else {
4246
if (currentManager instanceof GoogleJavaFormatCodeStyleManager) {
4347
newManager = ((GoogleJavaFormatCodeStyleManager) currentManager).getDelegate();
@@ -50,4 +54,8 @@ public static void installFormatter(Project project, boolean useGoogleFormatter)
5054
container.registerComponentInstance(CODE_STYLE_MANAGER_KEY, newManager);
5155
}
5256
}
57+
58+
public static void installFormatter(Project project, boolean useGoogleFormatter) {
59+
installFormatter(project, useGoogleFormatter, JavaFormatterOptions.defaultOptions());
60+
}
5361
}

0 commit comments

Comments
 (0)