[groovy] process DGM with other extensions
authorDaniil Ovchinnikov <daniil.ovchinnikov@jetbrains.com>
Tue, 8 Nov 2016 19:08:11 +0000 (22:08 +0300)
committerDaniil Ovchinnikov <daniil.ovchinnikov@jetbrains.com>
Tue, 8 Nov 2016 19:13:04 +0000 (22:13 +0300)
plugins/groovy/groovy-psi/resources/standardDsls/extensions.gdsl [deleted file]
plugins/groovy/groovy-psi/src/org/jetbrains/plugins/groovy/dgm/GroovyExtensionProvider.java
plugins/groovy/groovy-psi/src/org/jetbrains/plugins/groovy/lang/psi/util/GroovyCommonClassNames.java
plugins/groovy/groovy-psi/src/org/jetbrains/plugins/groovy/lang/psi/util/PsiUtil.java

diff --git a/plugins/groovy/groovy-psi/resources/standardDsls/extensions.gdsl b/plugins/groovy/groovy-psi/resources/standardDsls/extensions.gdsl
deleted file mode 100644 (file)
index 0d5f358..0000000
+++ /dev/null
@@ -1,38 +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 standardDsls
-
-/**
- * @author Maxim.Medvedev
- */
-
-contributor([:]) {
-  category "org.codehaus.groovy.runtime.DateGroovyMethods"
-  category "org.codehaus.groovy.runtime.DefaultGroovyMethods"
-  category "org.codehaus.groovy.runtime.DefaultGroovyStaticMethods", true
-  category "org.codehaus.groovy.runtime.EncodingGroovyMethods"
-  category "org.codehaus.groovy.runtime.IOGroovyMethods"
-  category "org.codehaus.groovy.runtime.ProcessGroovyMethods"
-  category "org.codehaus.groovy.runtime.ResourceGroovyMethods"
-  category "org.codehaus.groovy.runtime.SocketGroovyMethods"
-  category "org.codehaus.groovy.runtime.SqlGroovyMethods"
-  category "org.codehaus.groovy.runtime.StringGroovyMethods"
-  category "org.codehaus.groovy.runtime.SwingGroovyMethods"
-  category "org.codehaus.groovy.runtime.XmlGroovyMethods"
-  category "org.codehaus.groovy.vmplugin.v5.PluginDefaultGroovyMethods"
-}
index 340132abc13f774119ee1de0009192e2d4a12e3d..f1963f84f03c2bc55fe55b6e87b7df47418e9955 100644 (file)
@@ -28,11 +28,13 @@ 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.ArrayList;
-import java.util.Collections;
 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
  */
@@ -48,15 +50,17 @@ public class GroovyExtensionProvider {
     return ServiceManager.getService(project, GroovyExtensionProvider.class);
   }
 
-  public Couple<List<String>> collectExtensions(GlobalSearchScope resolveScope) {
-    PsiPackage aPackage = JavaPsiFacade.getInstance(myProject).findPackage("META-INF.services");
-    if (aPackage == null) {
-      return Couple.of(Collections.<String>emptyList(), Collections.<String>emptyList());
-    }
+  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;
 
-    List<String> instanceClasses = new ArrayList<>();
-    List<String> staticClasses = new ArrayList<>();
     for (PsiDirectory directory : aPackage.getDirectories(resolveScope)) {
       PsiFile file = directory.findFile(ORG_CODEHAUS_GROOVY_RUNTIME_EXTENSION_MODULE);
       if (file instanceof PropertiesFile) {
@@ -67,8 +71,6 @@ public class GroovyExtensionProvider {
         if (stat != null) collectClasses(stat, staticClasses);
       }
     }
-
-    return Couple.of(instanceClasses, staticClasses);
   }
 
   private static void collectClasses(IProperty pr, List<String> classes) {
@@ -78,7 +80,7 @@ public class GroovyExtensionProvider {
     String[] qnames = value.split("\\s*,\\s*");
     ContainerUtil.addAll(classes, qnames);
   }
-  
+
   public static class GroovyExtensionVetoSPI implements Condition<String> {
 
     @Override
index ac537ce11233fa346d5e5748565952cfbdd2b60b..9475db045e3173b8851042091f76cdf2ee91f647 100644 (file)
  */
 package org.jetbrains.plugins.groovy.lang.psi.util;
 
-import com.intellij.util.containers.ContainerUtil;
-
-import java.util.Collections;
 import java.util.Set;
 
+import static com.intellij.util.containers.ContainerUtil.newLinkedHashSet;
+import static java.util.Collections.unmodifiableSet;
+
 /**
  * @author Maxim.Medvedev
  */
@@ -68,10 +68,9 @@ public final class GroovyCommonClassNames {
   public static final String GROOVY_TRAIT = "groovy.transform.Trait";
   public static final String GROOVY_TRAIT_IMPLEMENTED = "org.codehaus.groovy.transform.trait.Traits.Implemented";
 
-  public static final Set<String> GROOVY_EXTENSION_CLASSES = Collections.unmodifiableSet(ContainerUtil.newLinkedHashSet(
+  public static final Set<String> DEFAULT_INSTANCE_EXTENSIONS = unmodifiableSet(newLinkedHashSet(
     "org.codehaus.groovy.runtime.DateGroovyMethods",
     "org.codehaus.groovy.runtime.DefaultGroovyMethods",
-    "org.codehaus.groovy.runtime.DefaultGroovyStaticMethods",
     "org.codehaus.groovy.runtime.EncodingGroovyMethods",
     "org.codehaus.groovy.runtime.IOGroovyMethods",
     "org.codehaus.groovy.runtime.ProcessGroovyMethods",
@@ -84,5 +83,9 @@ public final class GroovyCommonClassNames {
     "org.codehaus.groovy.vmplugin.v5.PluginDefaultGroovyMethods"
   ));
 
+  public static final Set<String> DEFAULT_STATIC_EXTENSIONS = unmodifiableSet(newLinkedHashSet(
+    "org.codehaus.groovy.runtime.DefaultGroovyStaticMethods"
+  ));
+
   private GroovyCommonClassNames() { }
 }
\ No newline at end of file
index aadfa60829b269ed1d17b3c6f9924c5901083053..2b95cb243e1b08d426e6f84cb090915abdeab2ab 100644 (file)
@@ -91,6 +91,9 @@ import org.jetbrains.plugins.groovy.lang.resolve.processors.MethodResolverProces
 
 import java.util.*;
 
+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 ven
  */
@@ -1387,7 +1390,7 @@ public class PsiUtil {
     if (aClass == null) return false;
 
     final String qname = aClass.getQualifiedName();
-    return GroovyCommonClassNames.GROOVY_EXTENSION_CLASSES.contains(qname);
+    return DEFAULT_INSTANCE_EXTENSIONS.contains(qname) || DEFAULT_STATIC_EXTENSIONS.contains(qname);
   }
 
   public static boolean isVoidMethodCall(@Nullable GrExpression expression) {