Cleanup (service provider for JavaFileManager)
authorRoman Shevchenko <roman.shevchenko@jetbrains.com>
Thu, 22 Sep 2016 12:21:27 +0000 (15:21 +0300)
committerRoman Shevchenko <roman.shevchenko@jetbrains.com>
Thu, 22 Sep 2016 12:22:31 +0000 (15:22 +0300)
java/java-psi-impl/src/com/intellij/psi/impl/file/impl/JavaFileManager.java
java/java-psi-impl/src/com/intellij/psi/impl/source/PsiJavaModuleReference.java
java/java-tests/testSrc/com/intellij/codeInsight/daemon/ModuleRenameTest.kt

index 7002a95ddf042a6c6c95729bfc3a0e8937f9bc9c..9af3207fe0f181874a98b0b737eb59b89e036eec 100644 (file)
@@ -15,6 +15,8 @@
  */
 package com.intellij.psi.impl.file.impl;
 
+import com.intellij.openapi.components.ServiceManager;
+import com.intellij.openapi.project.Project;
 import com.intellij.psi.PsiClass;
 import com.intellij.psi.PsiJavaModule;
 import com.intellij.psi.PsiPackage;
@@ -28,6 +30,14 @@ import java.util.Collection;
  * @author max
  */
 public interface JavaFileManager {
+  class SERVICE {
+    private SERVICE() { }
+
+    public static JavaFileManager getInstance(@NotNull Project project) {
+      return ServiceManager.getService(project, JavaFileManager.class);
+    }
+  }
+
   @Nullable
   PsiPackage findPackage(@NotNull String packageName);
 
index 9ef22ee9e33db8da8abfa072f77f8497374312f9..a86860a8aa37c40b780a684cee3550be02176c53 100644 (file)
@@ -15,7 +15,6 @@
  */
 package com.intellij.psi.impl.source;
 
-import com.intellij.openapi.components.ServiceManager;
 import com.intellij.openapi.module.Module;
 import com.intellij.openapi.project.Project;
 import com.intellij.openapi.roots.FileIndexFacade;
@@ -89,7 +88,7 @@ public class PsiJavaModuleReference extends PsiReferenceBase.Poly<PsiJavaModuleR
       }
 
       if (scope != null) {
-        JavaFileManager service = ServiceManager.getService(project, JavaFileManager.class);
+        JavaFileManager service = JavaFileManager.SERVICE.getInstance(project);
         Collection<PsiJavaModule> modules = service.findModules(reference.getCanonicalText(), scope);
         if (!modules.isEmpty()) {
           ResolveResult[] result = new ResolveResult[modules.size()];
index f97b6e5a81d668b6a03801c9ee597c3ddad77660..8ac0bfc8c6d7af02f3288897b90b53bdb23d8dd7 100644 (file)
@@ -16,7 +16,6 @@
 package com.intellij.codeInsight.daemon
 
 import com.intellij.openapi.application.runWriteAction
-import com.intellij.openapi.components.ServiceManager
 import com.intellij.psi.PsiDocumentManager
 import com.intellij.psi.impl.file.impl.JavaFileManager
 import com.intellij.psi.search.GlobalSearchScope
@@ -45,8 +44,7 @@ class ModuleRenameTest  : LightCodeInsightFixtureTestCase() {
 
   @Test fun testRename() {
     myFixture.configureByText("module-info.java", "module M { requires M2; }")
-    val service = ServiceManager.getService(project, JavaFileManager::class.java)
-    val module = service.findModules("M2", GlobalSearchScope.allScope(project)).first()
+    val module = JavaFileManager.SERVICE.getInstance(project).findModules("M2", GlobalSearchScope.allScope(project)).first()
     runWriteAction {
       RenameProcessor(project, module, "M2.bis", false, false).run()
       PsiDocumentManager.getInstance(project).commitAllDocuments()