extract separate element finder for migrations
authorDmitry Jemerov <yole@jetbrains.com>
Mon, 3 Oct 2011 17:43:35 +0000 (19:43 +0200)
committerDmitry Jemerov <yole@jetbrains.com>
Tue, 4 Oct 2011 14:03:47 +0000 (16:03 +0200)
java/java-impl/src/com/intellij/psi/impl/JavaPsiFacadeImpl.java
java/java-impl/src/com/intellij/psi/impl/migration/MigrationElementFinder.java [new file with mode: 0644]
resources/src/META-INF/IdeaPlugin.xml

index 03897c4d328892d3e4fc0c355aa27154b51fecf0..849712a2fa7becae1bbbb46befc1e9cd654bae62 100644 (file)
@@ -33,7 +33,6 @@ import com.intellij.psi.*;
 import com.intellij.psi.impl.file.PsiPackageImpl;
 import com.intellij.psi.impl.file.impl.JavaFileManager;
 import com.intellij.psi.impl.file.impl.JavaFileManagerImpl;
-import com.intellij.psi.impl.migration.PsiMigrationManager;
 import com.intellij.psi.impl.source.DummyHolderFactory;
 import com.intellij.psi.impl.source.JavaDummyHolder;
 import com.intellij.psi.impl.source.JavaDummyHolderFactory;
@@ -52,7 +51,6 @@ import com.intellij.util.containers.ContainerUtil;
 import com.intellij.util.containers.HashMap;
 import com.intellij.util.messages.MessageBus;
 import org.jetbrains.annotations.NotNull;
-import org.jetbrains.annotations.Nullable;
 
 import java.util.*;
 import java.util.concurrent.ConcurrentMap;
@@ -283,42 +281,18 @@ public class JavaPsiFacadeImpl extends JavaPsiFacadeEx implements Disposable {
     return myFileManager;
   }
 
-  @Nullable
-  private PsiPackage findPackageDefault(String qualifiedName) {
-    final PsiPackage aPackage = myFileManager.findPackage(qualifiedName);
-    if (aPackage == null && PsiMigrationManager.getInstance(myProject).getCurrentMigration() != null) {
-      final PsiPackage migrationPackage = PsiMigrationManager.getInstance(myProject).getCurrentMigration().getMigrationPackage(qualifiedName);
-      if (migrationPackage != null) return migrationPackage;
-    }
-
-    return aPackage;
-  }
-
   private class PsiElementFinderImpl extends PsiElementFinder {
     public PsiClass findClass(@NotNull String qualifiedName, @NotNull GlobalSearchScope scope) {
-      PsiClass psiClass = myFileManager.findClass(qualifiedName, scope);
-
-      if (psiClass == null && PsiMigrationManager.getInstance(myProject).getCurrentMigration() != null) {
-        psiClass = PsiMigrationManager.getInstance(myProject).getCurrentMigration().getMigrationClass(qualifiedName);
-      }
-
-      return psiClass;
+      return myFileManager.findClass(qualifiedName, scope);
     }
 
     @NotNull
     public PsiClass[] findClasses(@NotNull String qualifiedName, @NotNull GlobalSearchScope scope) {
-      final PsiClass[] classes = myFileManager.findClasses(qualifiedName, scope);
-      if (classes.length == 0 && PsiMigrationManager.getInstance(myProject).getCurrentMigration() != null) {
-        final PsiClass migrationClass = PsiMigrationManager.getInstance(myProject).getCurrentMigration().getMigrationClass(qualifiedName);
-        if (migrationClass != null) {
-          return new PsiClass[]{migrationClass};
-        }
-      }
-      return classes;
+      return myFileManager.findClasses(qualifiedName, scope);
     }
 
     public PsiPackage findPackage(@NotNull String qualifiedName) {
-      return findPackageDefault(qualifiedName);
+      return myFileManager.findPackage(qualifiedName);
     }
 
     @NotNull
diff --git a/java/java-impl/src/com/intellij/psi/impl/migration/MigrationElementFinder.java b/java/java-impl/src/com/intellij/psi/impl/migration/MigrationElementFinder.java
new file mode 100644 (file)
index 0000000..f0d0967
--- /dev/null
@@ -0,0 +1,66 @@
+/*
+ * Copyright 2000-2011 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 com.intellij.psi.impl.migration;
+
+import com.intellij.openapi.project.DumbAware;
+import com.intellij.openapi.project.Project;
+import com.intellij.psi.PsiClass;
+import com.intellij.psi.PsiElementFinder;
+import com.intellij.psi.PsiPackage;
+import com.intellij.psi.search.GlobalSearchScope;
+import org.jetbrains.annotations.NotNull;
+
+/**
+ * @author yole
+ */
+public class MigrationElementFinder extends PsiElementFinder implements DumbAware {
+  private final Project myProject;
+
+  public MigrationElementFinder(Project project) {
+    myProject = project;
+  }
+
+  @Override
+  public PsiClass findClass(@NotNull String qualifiedName, @NotNull GlobalSearchScope scope) {
+    PsiMigrationImpl migration = PsiMigrationManager.getInstance(myProject).getCurrentMigration();
+    if (migration != null) {
+      return migration.getMigrationClass(qualifiedName);
+    }
+    return null;
+  }
+
+  @NotNull
+  @Override
+  public PsiClass[] findClasses(@NotNull String qualifiedName, @NotNull GlobalSearchScope scope) {
+    PsiMigrationImpl migration = PsiMigrationManager.getInstance(myProject).getCurrentMigration();
+    if (migration != null) {
+      final PsiClass migrationClass = migration.getMigrationClass(qualifiedName);
+      if (migrationClass != null) {
+        return new PsiClass[]{migrationClass};
+      }
+    }
+    return PsiClass.EMPTY_ARRAY;
+  }
+
+  @Override
+  public PsiPackage findPackage(@NotNull String qualifiedName) {
+    PsiMigrationImpl migration = PsiMigrationManager.getInstance(myProject).getCurrentMigration();
+    if (migration != null) {
+      return migration.getMigrationPackage(qualifiedName);
+    }
+    return null;
+  }
+}
index ce512b1cff345b857ffddb120ce0e8971366ddcf..be47d181f75da108a93f42309dd155e396e41b18 100644 (file)
     <treeGenerator implementation="com.intellij.psi.impl.source.tree.JavaTreeGenerator"/>
 
     <java.elementFinder implementation="com.intellij.psi.impl.PackagePrefixElementFinder"/>
+    <java.elementFinder implementation="com.intellij.psi.impl.migration.MigrationElementFinder"/>
 
     <projectService serviceImplementation="com.intellij.openapi.roots.ui.configuration.ProjectStructureConfigurable"/>
     <projectService serviceInterface="com.intellij.openapi.roots.ui.configuration.projectRoot.daemon.ProjectStructureProblemsSettings"