diff --git a/flutter-idea/src/io/flutter/FlutterUtils.java b/flutter-idea/src/io/flutter/FlutterUtils.java index 3827db4aea..a345593157 100644 --- a/flutter-idea/src/io/flutter/FlutterUtils.java +++ b/flutter-idea/src/io/flutter/FlutterUtils.java @@ -550,7 +550,12 @@ public static EmbeddedBrowser embeddedBrowser(Project project) { return null; } - return FlutterSettings.getInstance().isEnableJcefBrowser() + FlutterSettings settings = FlutterSettings.getInstance(); + if (settings == null) { + return null; + } + + return settings.isEnableJcefBrowser() ? EmbeddedJcefBrowser.getInstance(project) : EmbeddedJxBrowser.getInstance(project); } diff --git a/flutter-idea/src/io/flutter/jxbrowser/EmbeddedBrowserEngine.java b/flutter-idea/src/io/flutter/jxbrowser/EmbeddedBrowserEngine.java index f43e74e18e..9a5da87bec 100644 --- a/flutter-idea/src/io/flutter/jxbrowser/EmbeddedBrowserEngine.java +++ b/flutter-idea/src/io/flutter/jxbrowser/EmbeddedBrowserEngine.java @@ -25,7 +25,7 @@ public class EmbeddedBrowserEngine { private final Engine engine; public static EmbeddedBrowserEngine getInstance() { - return ServiceManager.getService(EmbeddedBrowserEngine.class); + return ApplicationManager.getApplication().getService(EmbeddedBrowserEngine.class); } public EmbeddedBrowserEngine() { diff --git a/flutter-idea/src/io/flutter/module/settings/SettingsHelpForm.java b/flutter-idea/src/io/flutter/module/settings/SettingsHelpForm.java index edce19edab..be232c05f2 100644 --- a/flutter-idea/src/io/flutter/module/settings/SettingsHelpForm.java +++ b/flutter-idea/src/io/flutter/module/settings/SettingsHelpForm.java @@ -6,7 +6,6 @@ package io.flutter.module.settings; import com.intellij.ide.browsers.BrowserLauncher; -import com.intellij.openapi.components.ServiceManager; import com.intellij.ui.components.labels.LinkLabel; import io.flutter.FlutterBundle; import io.flutter.FlutterConstants; @@ -36,10 +35,6 @@ public class SettingsHelpForm { @SuppressWarnings("rawtypes") private LinkLabel gettingStartedUrl; - public static SettingsHelpForm getInstance() { - return ServiceManager.getService(SettingsHelpForm.class); - } - public SettingsHelpForm() { projectTypeLabel.setText(FlutterBundle.message("flutter.module.create.settings.help.project_type.label")); projectTypeDescriptionForApp.setText(FlutterBundle.message("flutter.module.create.settings.help.project_type.description.app")); diff --git a/flutter-idea/src/io/flutter/settings/FlutterSettings.java b/flutter-idea/src/io/flutter/settings/FlutterSettings.java index 2f20c8e1d5..bac36fa780 100644 --- a/flutter-idea/src/io/flutter/settings/FlutterSettings.java +++ b/flutter-idea/src/io/flutter/settings/FlutterSettings.java @@ -7,12 +7,14 @@ import com.google.common.annotations.VisibleForTesting; import com.intellij.ide.util.PropertiesComponent; +import com.intellij.openapi.application.ApplicationManager; import com.intellij.openapi.components.ServiceManager; import com.intellij.openapi.util.registry.Registry; import com.intellij.util.EventDispatcher; import com.jetbrains.lang.dart.analyzer.DartClosingLabelManager; import java.util.EventListener; +import java.util.Objects; public class FlutterSettings { private static final String reloadOnSaveKey = "io.flutter.reloadOnSave"; @@ -62,7 +64,7 @@ public static FlutterSettings getInstance() { return testInstance; } - return ServiceManager.getService(FlutterSettings.class); + return Objects.requireNonNull(ApplicationManager.getApplication()).getService(FlutterSettings.class); } protected static PropertiesComponent getPropertiesComponent() { diff --git a/flutter-idea/src/io/flutter/view/EmbeddedJcefBrowser.java b/flutter-idea/src/io/flutter/view/EmbeddedJcefBrowser.java index cec31775c2..d3aa2c3119 100644 --- a/flutter-idea/src/io/flutter/view/EmbeddedJcefBrowser.java +++ b/flutter-idea/src/io/flutter/view/EmbeddedJcefBrowser.java @@ -15,6 +15,7 @@ import javax.swing.*; import java.awt.Dimension; +import java.util.Objects; class EmbeddedJcefBrowserTab implements EmbeddedTab { private JBCefBrowser browser; @@ -48,8 +49,8 @@ public EmbeddedJcefBrowser(Project project) { } @NotNull - public static EmbeddedJcefBrowser getInstance(Project project) { - return ServiceManager.getService(project, EmbeddedJcefBrowser.class); + public static EmbeddedJcefBrowser getInstance(@NotNull Project project) { + return Objects.requireNonNull(project.getService(EmbeddedJcefBrowser.class)); } public Logger logger() { diff --git a/flutter-studio/src/io/flutter/android/AndroidModuleLibraryManager.java b/flutter-studio/src/io/flutter/android/AndroidModuleLibraryManager.java index dd9a698b14..8d819fc1df 100644 --- a/flutter-studio/src/io/flutter/android/AndroidModuleLibraryManager.java +++ b/flutter-studio/src/io/flutter/android/AndroidModuleLibraryManager.java @@ -61,10 +61,7 @@ import java.lang.reflect.Method; import java.nio.file.Path; import java.nio.file.Paths; -import java.util.Arrays; -import java.util.HashSet; -import java.util.List; -import java.util.Set; +import java.util.*; import java.util.concurrent.atomic.AtomicBoolean; import java.util.function.Function; import java.util.stream.Collectors; @@ -263,7 +260,7 @@ private static boolean shouldIncludeRoot(String path) { @NotNull public static AndroidModuleLibraryManager getInstance(@NotNull final Project project) { - return ServiceManager.getService(project, AndroidModuleLibraryManager.class); + return Objects.requireNonNull(project.getService(AndroidModuleLibraryManager.class)); } public static void startWatching(@NotNull Project project) {