cache groovy inner classes, more correctly cache groovy class methods (IDEA-52183)
authorpeter <peter.gromov@jetbrains.com>
Sat, 27 Feb 2010 11:35:44 +0000 (11:35 +0000)
committerpeter <peter.gromov@jetbrains.com>
Sat, 27 Feb 2010 11:40:35 +0000 (11:40 +0000)
plugins/groovy/src/META-INF/plugin.xml
plugins/groovy/src/org/jetbrains/plugins/groovy/config/GroovyLibraryListener.java [deleted file]
plugins/groovy/src/org/jetbrains/plugins/groovy/lang/psi/impl/statements/typedef/GrTypeDefinitionImpl.java

index bb0bc525d1317216845d6a0511a29be568fafb7c..7fc4b6ba10df895147d9d60cd589c7db9eec78b9 100644 (file)
     <component>
       <implementation-class>org.jetbrains.plugins.groovy.codeInspection.local.GroovyUnusedImportsPassFactory</implementation-class>
     </component>
-    <!--<component>
-      <implementation-class>org.jetbrains.plugins.groovy.config.GroovyLibraryListener</implementation-class>
-    </component>-->
     <component>
       <interface-class>org.jetbrains.plugins.groovy.annotator.intentions.dynamic.DynamicManager</interface-class>
       <implementation-class>org.jetbrains.plugins.groovy.annotator.intentions.dynamic.DynamicManagerImpl</implementation-class>
diff --git a/plugins/groovy/src/org/jetbrains/plugins/groovy/config/GroovyLibraryListener.java b/plugins/groovy/src/org/jetbrains/plugins/groovy/config/GroovyLibraryListener.java
deleted file mode 100644 (file)
index e5c6571..0000000
+++ /dev/null
@@ -1,99 +0,0 @@
-/*
- * Copyright 2000-2010 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.config;
-
-import com.intellij.ProjectTopics;
-import com.intellij.openapi.application.Application;
-import com.intellij.openapi.application.ApplicationManager;
-import com.intellij.openapi.application.ApplicationNamesInfo;
-import com.intellij.openapi.components.AbstractProjectComponent;
-import com.intellij.openapi.module.Module;
-import com.intellij.openapi.module.ModuleManager;
-import com.intellij.openapi.project.Project;
-import com.intellij.openapi.roots.ModuleRootEvent;
-import com.intellij.openapi.roots.ModuleRootListener;
-import com.intellij.openapi.roots.libraries.Library;
-import com.intellij.openapi.ui.Messages;
-import com.intellij.openapi.vfs.newvfs.persistent.FSRecords;
-import com.intellij.util.containers.hash.HashSet;
-import com.intellij.util.messages.MessageBusConnection;
-import org.jetbrains.plugins.groovy.util.LibrariesUtil;
-
-import java.util.Set;
-
-/**
- * @author Maxim.Medvedev
- */
-public class GroovyLibraryListener extends AbstractProjectComponent implements ModuleRootListener {
-  private final Set<Module> groovyModules = new HashSet<Module>();
-
-  public GroovyLibraryListener(Project project) {
-    super(project);
-  }
-
-  @Override
-  public void projectOpened() {
-    final MessageBusConnection connection = myProject.getMessageBus().connect(myProject);
-    connection.subscribe(ProjectTopics.PROJECT_ROOTS, this);
-
-    final Module[] modules = ModuleManager.getInstance(myProject).getModules();
-    for (Module module : modules) {
-      if (module.isDisposed()) continue;
-      if (LibrariesUtil.hasGroovySdk(module)) {
-        groovyModules.add(module);
-      }
-    }
-  }
-
-  public void beforeRootsChange(ModuleRootEvent event) {
-  }
-
-  public void rootsChanged(ModuleRootEvent event) {
-    final Module[] modules = ModuleManager.getInstance(myProject).getModules();
-    for (Module module : modules) {
-      if (module.isDisposed()) continue;
-      final Library[] libraries = GroovyConfigUtils.getInstance().getSDKLibrariesByModule(module);
-      if ((libraries.length > 0 && !groovyModules.contains(module))) {
-        final Application app = ApplicationManager.getApplication();
-        if (app.isRestartCapable()) {
-          if (Messages.showYesNoDialog(myProject, "You have added Groovy SDK library '" +
-                                                  libraries[0].getName() +
-                                                  "' to module '" +
-                                                  module.getName() +
-                                                  "'. To add Groovy support " +
-                                                  ApplicationNamesInfo.getInstance().getFullProductName() +
-                                                  " must be restarted. Would you like to add Groovy support and restart now?",
-                                       "Add Groovy support", Messages.getInformationIcon()) == 0) {
-            FSRecords.invalidateCaches();
-            app.restart();
-          }
-        }
-        else {
-          Messages.showMessageDialog(myProject, "You have added Groovy SDK library '" +
-                                                libraries[0].getName() +
-                                                "' to module '" +
-                                                module.getName() +
-                                                "'. To add Groovy support you need to restart " +
-                                                ApplicationNamesInfo.getInstance().getFullProductName() +
-                                                ".", "Add Groovy support", Messages.getInformationIcon());
-        }
-      }
-      else if ((libraries.length == 0 && groovyModules.contains(module))) {
-        groovyModules.remove(module);
-      }
-    }
-  }
-}
index 2e2f43ec0bea31a7259b2cf1146b2075cfc239c3..1c08b2cec925e0c7d8155ca8f53e7b59844977c9 100644 (file)
@@ -78,9 +78,10 @@ import java.util.List;
  */
 public abstract class GrTypeDefinitionImpl extends GroovyBaseElementImpl<GrTypeDefinitionStub> implements GrTypeDefinition {
 
-  private PsiMethod[] myMethods;
-  private GrMethod[] myGroovyMethods;
-  private GrMethod[] myConstructors;
+  private volatile PsiClass[] myInnerClasses;
+  private volatile List<PsiMethod> myMethods;
+  private volatile GrMethod[] myGroovyMethods;
+  private volatile GrMethod[] myConstructors;
 
   public GrTypeDefinitionImpl(@NotNull ASTNode node) {
     super(node);
@@ -327,15 +328,18 @@ public abstract class GrTypeDefinitionImpl extends GroovyBaseElementImpl<GrTypeD
   @NotNull
   public PsiMethod[] getMethods() {
     if (myMethods == null) {
-      List<PsiMethod> result = new ArrayList<PsiMethod>();
+      List<PsiMethod> methods = new ArrayList<PsiMethod>();
       GrTypeDefinitionBody body = getBody();
       if (body != null) {
-        result.addAll(body.getMethods());
+        methods.addAll(body.getMethods());
       }
-      GrClassImplUtil.addGroovyObjectMethods(this, result);
-      myMethods = result.toArray(new PsiMethod[result.size()]);
+
+      myMethods = methods;
     }
-    return myMethods;
+
+    List<PsiMethod> result = new ArrayList<PsiMethod>(myMethods);
+    GrClassImplUtil.addGroovyObjectMethods(this, result);
+    return result.toArray(new PsiMethod[result.size()]);
   }
 
   @NotNull
@@ -354,6 +358,7 @@ public abstract class GrTypeDefinitionImpl extends GroovyBaseElementImpl<GrTypeD
 
   public void subtreeChanged() {
     myMethods = null;
+    myInnerClasses = null;
     myConstructors = null;
     myGroovyMethods = null;
     super.subtreeChanged();
@@ -377,12 +382,12 @@ public abstract class GrTypeDefinitionImpl extends GroovyBaseElementImpl<GrTypeD
 
   @NotNull
   public PsiClass[] getInnerClasses() {
-    final GrTypeDefinitionBody body = getBody();
-    if (body != null) {
-      return body.getInnerClasses();
+    if (myInnerClasses == null) {
+      final GrTypeDefinitionBody body = getBody();
+      myInnerClasses = body != null ? body.getInnerClasses() : PsiClass.EMPTY_ARRAY;
     }
 
-    return PsiClass.EMPTY_ARRAY;
+    return myInnerClasses;
   }
 
   @NotNull