[groovy] get rid of GroovyExtensionProvider service
authorDaniil Ovchinnikov <daniil.ovchinnikov@jetbrains.com>
Wed, 9 Nov 2016 13:46:08 +0000 (16:46 +0300)
committerDaniil Ovchinnikov <daniil.ovchinnikov@jetbrains.com>
Wed, 9 Nov 2016 15:45:27 +0000 (18:45 +0300)
plugins/groovy/groovy-psi/src/org/jetbrains/plugins/groovy/dgm/DGMMemberContributor.java
plugins/groovy/groovy-psi/src/org/jetbrains/plugins/groovy/dgm/DGMUtil.java
plugins/groovy/groovy-psi/src/org/jetbrains/plugins/groovy/dgm/GroovyExtensionProvider.java [deleted file]
plugins/groovy/groovy-psi/src/org/jetbrains/plugins/groovy/dgm/GroovyExtensionVetoSPI.java [new file with mode: 0644]
plugins/groovy/groovy-psi/src/org/jetbrains/plugins/groovy/lang/GroovyCoreEnvironment.java
plugins/groovy/src/META-INF/plugin.xml
plugins/groovy/src/org/jetbrains/plugins/groovy/dgm/DGMFileTypeFactory.java

index 696ef2f66fb22d0b17ce071c3e5c36c1dc348729..0143c83caa1bfdcab6054bc6cae45c072bbec8f1 100644 (file)
@@ -15,6 +15,8 @@
  */
 package org.jetbrains.plugins.groovy.dgm;
 
+import com.intellij.lang.properties.IProperty;
+import com.intellij.lang.properties.psi.PropertiesFile;
 import com.intellij.openapi.project.Project;
 import com.intellij.openapi.util.Couple;
 import com.intellij.psi.*;
@@ -26,13 +28,15 @@ import com.intellij.psi.util.CachedValuesManager;
 import com.intellij.psi.util.PsiModificationTracker;
 import com.intellij.util.containers.ContainerUtil;
 import org.jetbrains.annotations.NotNull;
-import org.jetbrains.annotations.Nullable;
 import org.jetbrains.plugins.groovy.lang.resolve.NonCodeMembersContributor;
 import org.jetbrains.plugins.groovy.lang.resolve.ResolveUtil;
 
 import java.util.List;
 import java.util.concurrent.ConcurrentMap;
 
+import static org.jetbrains.plugins.groovy.lang.psi.util.GroovyCommonClassNames.DEFAULT_INSTANCE_EXTENSIONS;
+import static org.jetbrains.plugins.groovy.lang.psi.util.GroovyCommonClassNames.DEFAULT_STATIC_EXTENSIONS;
+
 /**
  * Provides members from extension classes referenced in {@code META-INF/services/org.codehaus.groovy.runtime.ExtensionModule}.
  */
@@ -72,7 +76,7 @@ public class DGMMemberContributor extends NonCodeMembersContributor {
     List<GdkMethodHolder> gdkMethods = ContainerUtil.newArrayList();
 
     JavaPsiFacade facade = JavaPsiFacade.getInstance(project);
-    Couple<List<String>> extensions = GroovyExtensionProvider.getInstance(project).collectExtensions(resolveScope);
+    Couple<List<String>> extensions = collectExtensions(project, resolveScope);
     for (String category : extensions.getFirst()) {
       PsiClass clazz = facade.findClass(category, resolveScope);
       if (clazz != null) {
@@ -87,4 +91,39 @@ public class DGMMemberContributor extends NonCodeMembersContributor {
     }
     return gdkMethods;
   }
+
+  @NotNull
+  private static Couple<List<String>> collectExtensions(@NotNull Project project, @NotNull GlobalSearchScope resolveScope) {
+    List<String> instanceClasses = ContainerUtil.newArrayList(DEFAULT_INSTANCE_EXTENSIONS);
+    List<String> staticClasses = ContainerUtil.newArrayList(DEFAULT_STATIC_EXTENSIONS);
+    doCollectExtensions(project, resolveScope, instanceClasses, staticClasses);
+    return Couple.of(instanceClasses, staticClasses);
+  }
+
+  private static void doCollectExtensions(@NotNull Project project,
+                                          @NotNull GlobalSearchScope resolveScope,
+                                          List<String> instanceClasses,
+                                          List<String> staticClasses) {
+    PsiPackage aPackage = JavaPsiFacade.getInstance(project).findPackage("META-INF.services");
+    if (aPackage == null) return;
+
+    for (PsiDirectory directory : aPackage.getDirectories(resolveScope)) {
+      PsiFile file = directory.findFile(DGMUtil.ORG_CODEHAUS_GROOVY_RUNTIME_EXTENSION_MODULE);
+      if (file instanceof PropertiesFile) {
+        IProperty inst = ((PropertiesFile)file).findPropertyByKey("extensionClasses");
+        IProperty stat = ((PropertiesFile)file).findPropertyByKey("staticExtensionClasses");
+
+        if (inst != null) collectClasses(inst, instanceClasses);
+        if (stat != null) collectClasses(stat, staticClasses);
+      }
+    }
+  }
+
+  private static void collectClasses(IProperty pr, List<String> classes) {
+    String value = pr.getUnescapedValue();
+    if (value == null) return;
+    value = value.trim();
+    String[] qnames = value.split("\\s*,\\s*");
+    ContainerUtil.addAll(classes, qnames);
+  }
 }
index 09c00afbfd4a5eb6017efd53866770a142db017b..faf605c098f247899d55987965db9bf1d2b0c3be 100644 (file)
@@ -25,12 +25,13 @@ import com.intellij.psi.PsiFile;
  * @author Max Medvedev
  */
 public class DGMUtil {
+  public static final String ORG_CODEHAUS_GROOVY_RUNTIME_EXTENSION_MODULE = "org.codehaus.groovy.runtime.ExtensionModule";
   public static final String[] KEYS = new String[]{"moduleName", "moduleVersion", "extensionClasses", "staticExtensionClasses",};
 
   public static boolean isInDGMFile(PsiElement e) {
     PsiFile file = e.getContainingFile();
     return file instanceof PropertiesFile &&
-           Comparing.equal(file.getName(), GroovyExtensionProvider.ORG_CODEHAUS_GROOVY_RUNTIME_EXTENSION_MODULE,
+           Comparing.equal(file.getName(), ORG_CODEHAUS_GROOVY_RUNTIME_EXTENSION_MODULE,
                            SystemInfo.isFileSystemCaseSensitive);
   }
 }
diff --git a/plugins/groovy/groovy-psi/src/org/jetbrains/plugins/groovy/dgm/GroovyExtensionProvider.java b/plugins/groovy/groovy-psi/src/org/jetbrains/plugins/groovy/dgm/GroovyExtensionProvider.java
deleted file mode 100644 (file)
index f1963f8..0000000
+++ /dev/null
@@ -1,91 +0,0 @@
-/*
- * Copyright 2000-2014 JetBrains s.r.o.
- *
- * Licensed under the Apache License, Version 2.0 (the "License");
- * you may not use this file except in compliance with the License.
- * You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-package org.jetbrains.plugins.groovy.dgm;
-
-import com.intellij.lang.properties.IProperty;
-import com.intellij.lang.properties.psi.PropertiesFile;
-import com.intellij.openapi.components.ServiceManager;
-import com.intellij.openapi.project.Project;
-import com.intellij.openapi.util.Condition;
-import com.intellij.openapi.util.Couple;
-import com.intellij.psi.JavaPsiFacade;
-import com.intellij.psi.PsiDirectory;
-import com.intellij.psi.PsiFile;
-import com.intellij.psi.PsiPackage;
-import com.intellij.psi.search.GlobalSearchScope;
-import com.intellij.util.containers.ContainerUtil;
-import org.jetbrains.annotations.NonNls;
-import org.jetbrains.annotations.NotNull;
-
-import java.util.List;
-
-import static org.jetbrains.plugins.groovy.lang.psi.util.GroovyCommonClassNames.DEFAULT_INSTANCE_EXTENSIONS;
-import static org.jetbrains.plugins.groovy.lang.psi.util.GroovyCommonClassNames.DEFAULT_STATIC_EXTENSIONS;
-
-/**
- * @author Max Medvedev
- */
-public class GroovyExtensionProvider {
-  @NonNls public static final String ORG_CODEHAUS_GROOVY_RUNTIME_EXTENSION_MODULE = "org.codehaus.groovy.runtime.ExtensionModule";
-  private final Project myProject;
-
-  public GroovyExtensionProvider(Project project) {
-    myProject = project;
-  }
-
-  public static GroovyExtensionProvider getInstance(Project project) {
-    return ServiceManager.getService(project, GroovyExtensionProvider.class);
-  }
-
-  public Couple<List<String>> collectExtensions(@NotNull GlobalSearchScope resolveScope) {
-    List<String> instanceClasses = ContainerUtil.newArrayList(DEFAULT_INSTANCE_EXTENSIONS);
-    List<String> staticClasses = ContainerUtil.newArrayList(DEFAULT_STATIC_EXTENSIONS);
-    doCollectExtensions(resolveScope, instanceClasses, staticClasses);
-    return Couple.of(instanceClasses, staticClasses);
-  }
-
-  private void doCollectExtensions(@NotNull GlobalSearchScope resolveScope, List<String> instanceClasses, List<String> staticClasses) {
-    PsiPackage aPackage = JavaPsiFacade.getInstance(myProject).findPackage("META-INF.services");
-    if (aPackage == null) return;
-
-    for (PsiDirectory directory : aPackage.getDirectories(resolveScope)) {
-      PsiFile file = directory.findFile(ORG_CODEHAUS_GROOVY_RUNTIME_EXTENSION_MODULE);
-      if (file instanceof PropertiesFile) {
-        IProperty inst = ((PropertiesFile)file).findPropertyByKey("extensionClasses");
-        IProperty stat = ((PropertiesFile)file).findPropertyByKey("staticExtensionClasses");
-
-        if (inst != null) collectClasses(inst, instanceClasses);
-        if (stat != null) collectClasses(stat, staticClasses);
-      }
-    }
-  }
-
-  private static void collectClasses(IProperty pr, List<String> classes) {
-    String value = pr.getUnescapedValue();
-    if (value == null) return;
-    value = value.trim();
-    String[] qnames = value.split("\\s*,\\s*");
-    ContainerUtil.addAll(classes, qnames);
-  }
-
-  public static class GroovyExtensionVetoSPI implements Condition<String> {
-
-    @Override
-    public boolean value(String s) {
-      return ORG_CODEHAUS_GROOVY_RUNTIME_EXTENSION_MODULE.equals(s);
-    }
-  }
-}
diff --git a/plugins/groovy/groovy-psi/src/org/jetbrains/plugins/groovy/dgm/GroovyExtensionVetoSPI.java b/plugins/groovy/groovy-psi/src/org/jetbrains/plugins/groovy/dgm/GroovyExtensionVetoSPI.java
new file mode 100644 (file)
index 0000000..1c99743
--- /dev/null
@@ -0,0 +1,26 @@
+/*
+ * Copyright 2000-2016 JetBrains s.r.o.
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package org.jetbrains.plugins.groovy.dgm;
+
+import com.intellij.openapi.util.Condition;
+
+public class GroovyExtensionVetoSPI implements Condition<String> {
+
+  @Override
+  public boolean value(String s) {
+    return DGMUtil.ORG_CODEHAUS_GROOVY_RUNTIME_EXTENSION_MODULE.equals(s);
+  }
+}
index 3a90f63ba3594cf70f6228d62bceae1ad9601a1c..585c6321d66bec914df96f7d3a25dd0036468acd 100644 (file)
@@ -66,7 +66,6 @@ import org.jetbrains.plugins.groovy.configSlurper.ConfigSlurperMapContentProvide
 import org.jetbrains.plugins.groovy.configSlurper.GroovyMapValueTypeEnhancer;
 import org.jetbrains.plugins.groovy.dgm.DGMImplicitPropertyUsageProvider;
 import org.jetbrains.plugins.groovy.dgm.DGMMemberContributor;
-import org.jetbrains.plugins.groovy.dgm.GroovyExtensionProvider;
 import org.jetbrains.plugins.groovy.dsl.DslActivationStatus;
 import org.jetbrains.plugins.groovy.dsl.GroovyDslAnnotator;
 import org.jetbrains.plugins.groovy.dsl.GroovyDslFileIndex;
@@ -359,7 +358,6 @@ public class GroovyCoreEnvironment {
       project.registerService(GroovyPsiManager.class, GroovyPsiManager.class);
       project.registerService(GroovyCodeStyleManager.class, CoreGroovyCodeStyleManager.class);
       project.registerService(GroovyCodeStyleSettingsFacade.class, CoreGroovyCodeStyleSettingsFacade.class);
-      project.registerService(GroovyExtensionProvider.class, GroovyExtensionProvider.class);
       projectEnvironment.addProjectExtension(PsiShortNamesCache.EP_NAME, new GroovyShortNamesCache(project));
       projectEnvironment.addProjectExtension(PsiElementFinder.EP_NAME, new GroovyClassFinder(project));
       TextEditorHighlightingPassRegistrar registrar = TextEditorHighlightingPassRegistrar.getInstance(project);
index 9ac4d73c13f1d9c2831a86710b9cfea0fbd1a2cd..a1d2009df337c79b0d5a8a362ae5f85607b475e2 100644 (file)
     <projectService serviceImplementation="org.jetbrains.plugins.groovy.compiler.GreclipseIdeaCompilerSettings"/>
     <buildProcess.parametersProvider implementation="org.jetbrains.plugins.groovy.compiler.GrBuildProcessParametersProvider"/>
 
-    <vetoSPICondition implementation="org.jetbrains.plugins.groovy.dgm.GroovyExtensionProvider$GroovyExtensionVetoSPI"/>
+    <vetoSPICondition implementation="org.jetbrains.plugins.groovy.dgm.GroovyExtensionVetoSPI"/>
 
     <stubElementTypeHolder class="org.jetbrains.plugins.groovy.lang.parser.GroovyElementTypes"/>
     <!--Stubs index-->
     <projectService serviceInterface="org.jetbrains.plugins.groovy.lang.psi.impl.GroovyCodeStyleSettingsFacade"
                     serviceImplementation="org.jetbrains.plugins.groovy.codeStyle.GroovyCodeStyleSettingsFacadeImpl"/>
 
-    <projectService
-        serviceImplementation="org.jetbrains.plugins.groovy.dgm.GroovyExtensionProvider"/>
-
     <problemFileHighlightFilter implementation="org.jetbrains.plugins.groovy.GroovyProblemFileHighlightFilter"/>
 
     <renameInputValidator implementation="org.jetbrains.plugins.groovy.GroovyRenameInputValidator"/>
index e82c560e457182e146f61c9a60f7d6cb6a9161fc..d3cbd33d66ff223bded72514cb06888cb7e1ce11 100644 (file)
@@ -29,7 +29,7 @@ public class DGMFileTypeFactory extends FileTypeFactory {
 
   @Override
   public void createFileTypes(@NotNull FileTypeConsumer consumer) {
-    ExactFileNameMatcher matcher = new ExactFileNameMatcher(GroovyExtensionProvider.ORG_CODEHAUS_GROOVY_RUNTIME_EXTENSION_MODULE,
+    ExactFileNameMatcher matcher = new ExactFileNameMatcher(DGMUtil.ORG_CODEHAUS_GROOVY_RUNTIME_EXTENSION_MODULE,
                                                             !SystemInfo.isFileSystemCaseSensitive);
     consumer.consume(PropertiesFileType.INSTANCE, matcher);
   }