diff --git a/idea/src/META-INF/plugin.xml b/idea/src/META-INF/plugin.xml
index 7199d23c45c..9e37aaf1f41 100644
--- a/idea/src/META-INF/plugin.xml
+++ b/idea/src/META-INF/plugin.xml
@@ -17,9 +17,6 @@
org.jetbrains.jet.plugin.compiler.JetCompilerManager
-
- org.jetbrains.jet.plugin.caches.JetCacheManager
-
org.jetbrains.jet.plugin.references.BuiltInsReferenceResolver
diff --git a/idea/src/org/jetbrains/jet/plugin/caches/JetCacheManager.java b/idea/src/org/jetbrains/jet/plugin/caches/JetCacheManager.java
deleted file mode 100644
index 2eb8444ceec..00000000000
--- a/idea/src/org/jetbrains/jet/plugin/caches/JetCacheManager.java
+++ /dev/null
@@ -1,75 +0,0 @@
-/*
- * Copyright 2010-2012 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.jet.plugin.caches;
-
-import com.intellij.openapi.components.ProjectComponent;
-import com.intellij.openapi.project.Project;
-import com.intellij.psi.search.PsiShortNamesCache;
-import org.jetbrains.annotations.NotNull;
-import org.jetbrains.jet.lang.psi.JetFile;
-import org.jetbrains.jet.plugin.project.JsModuleDetector;
-
-public class JetCacheManager implements ProjectComponent {
- private Project myProject;
- private JetShortNamesCache myCache;
-
- public static JetCacheManager getInstance(Project project) {
- return project.getComponent(JetCacheManager.class);
- }
-
- public JetCacheManager(Project project) {
- myProject = project;
- }
-
- @Override
- public void projectOpened() {
-
- }
-
- @Override
- public void projectClosed() {
-
- }
-
- @Override
- @NotNull
- public String getComponentName() {
- return "Kotlin caches manager";
- }
-
- @Override
- public void initComponent() {
- myCache = new JetShortNamesCache(myProject);
- }
-
- @Override
- public void disposeComponent() {
-
- }
-
- public JetShortNamesCache getNamesCache() {
- return myCache;
- }
-
- public PsiShortNamesCache getShortNamesCache(@NotNull JetFile jetFile) {
- if (JsModuleDetector.isJsModule(jetFile)) {
- return myCache;
- }
-
- return PsiShortNamesCache.getInstance(myProject);
- }
-}
diff --git a/idea/src/org/jetbrains/jet/plugin/caches/JetGotoClassContributor.java b/idea/src/org/jetbrains/jet/plugin/caches/JetGotoClassContributor.java
index a1351ed3fd7..3b6735160a8 100644
--- a/idea/src/org/jetbrains/jet/plugin/caches/JetGotoClassContributor.java
+++ b/idea/src/org/jetbrains/jet/plugin/caches/JetGotoClassContributor.java
@@ -54,14 +54,14 @@ public class JetGotoClassContributor implements GotoClassContributor {
@NotNull
@Override
public String[] getNames(Project project, boolean includeNonProjectItems) {
- return JetCacheManager.getInstance(project).getNamesCache().getAllClassNames();
+ return JetShortNamesCache.getKotlinInstance(project).getAllClassNames();
}
@NotNull
@Override
public NavigationItem[] getItemsByName(String name, String pattern, Project project, boolean includeNonProjectItems) {
final GlobalSearchScope scope = GlobalSearchScope.allScope(project);
- PsiClass[] classes = JetCacheManager.getInstance(project).getNamesCache().getClassesByName(name, scope);
+ PsiClass[] classes = JetShortNamesCache.getKotlinInstance(project).getClassesByName(name, scope);
Collection javaQualifiedNames = new HashSet();
diff --git a/idea/src/org/jetbrains/jet/plugin/caches/JetShortNamesCache.java b/idea/src/org/jetbrains/jet/plugin/caches/JetShortNamesCache.java
index ec6b99f9457..2ed1bb3bfcd 100644
--- a/idea/src/org/jetbrains/jet/plugin/caches/JetShortNamesCache.java
+++ b/idea/src/org/jetbrains/jet/plugin/caches/JetShortNamesCache.java
@@ -19,6 +19,7 @@ package org.jetbrains.jet.plugin.caches;
import com.google.common.base.Function;
import com.google.common.collect.Collections2;
import com.google.common.collect.Sets;
+import com.intellij.openapi.extensions.Extensions;
import com.intellij.openapi.project.Project;
import com.intellij.openapi.util.Condition;
import com.intellij.psi.*;
@@ -55,6 +56,16 @@ import java.util.*;
*/
public class JetShortNamesCache extends PsiShortNamesCache {
+ public static JetShortNamesCache getKotlinInstance(@NotNull Project project) {
+ PsiShortNamesCache[] extensions = Extensions.getArea(project).getExtensionPoint(PsiShortNamesCache.EP_NAME).getExtensions();
+ for (PsiShortNamesCache extension : extensions) {
+ if (extension instanceof JetShortNamesCache) {
+ return (JetShortNamesCache) extension;
+ }
+ }
+ throw new IllegalStateException(JetShortNamesCache.class.getSimpleName() + " is not found for project " + project);
+ }
+
private static final PsiMethod[] NO_METHODS = new PsiMethod[0];
private static final PsiField[] NO_FIELDS = new PsiField[0];
private final Project project;
@@ -70,6 +81,7 @@ public class JetShortNamesCache extends PsiShortNamesCache {
@Override
public String[] getAllClassNames() {
Collection classNames = JetShortClassNameIndex.getInstance().getAllKeys(project);
+ // .namespace classes can not be indexed, since they have no explicit declarations
classNames.add(JvmAbi.PACKAGE_CLASS);
return ArrayUtil.toStringArray(classNames);
}
@@ -83,6 +95,7 @@ public class JetShortNamesCache extends PsiShortNamesCache {
List result = new ArrayList();
if (JvmAbi.PACKAGE_CLASS.equals(name)) {
+ // .namespace classes can not be indexed, since they have no explicit declarations
Collection allPackageFqNames = JetPackageDeclarationIndex.getInstance().getAllKeys(project);
for (String fqName : allPackageFqNames) {
PsiClass psiClass = JavaElementFinder.getInstance(project).findClass(fqName + "." + JvmAbi.PACKAGE_CLASS, scope);
diff --git a/idea/src/org/jetbrains/jet/plugin/completion/JetCompletionContributor.java b/idea/src/org/jetbrains/jet/plugin/completion/JetCompletionContributor.java
index 5ea38f2368e..8ee9e07d326 100644
--- a/idea/src/org/jetbrains/jet/plugin/completion/JetCompletionContributor.java
+++ b/idea/src/org/jetbrains/jet/plugin/completion/JetCompletionContributor.java
@@ -38,7 +38,6 @@ import org.jetbrains.jet.lang.resolve.lazy.ResolveSession;
import org.jetbrains.jet.lang.resolve.lazy.ResolveSessionUtils;
import org.jetbrains.jet.lang.resolve.scopes.JetScope;
import org.jetbrains.jet.lexer.JetTokens;
-import org.jetbrains.jet.plugin.caches.JetCacheManager;
import org.jetbrains.jet.plugin.caches.JetShortNamesCache;
import org.jetbrains.jet.plugin.completion.weigher.JetCompletionSorting;
import org.jetbrains.jet.plugin.project.WholeProjectAnalyzerFacade;
@@ -200,13 +199,14 @@ public class JetCompletionContributor extends CompletionContributor {
}
private void addJetExtensions() {
- JetShortNamesCache namesCache = JetCacheManager.getInstance(getPosition().getProject()).getNamesCache();
+ Project project = getPosition().getProject();
+ JetShortNamesCache namesCache = JetShortNamesCache.getKotlinInstance(project);
Collection jetCallableExtensions = namesCache.getJetCallableExtensions(
jetResult.getShortNameFilter(),
jetReference.getExpression(),
getResolveSession(),
- GlobalSearchScope.allScope(getPosition().getProject()));
+ GlobalSearchScope.allScope(project));
jetResult.addAllElements(jetCallableExtensions);
}
@@ -229,7 +229,7 @@ public class JetCompletionContributor extends CompletionContributor {
String actualPrefix = jetResult.getResult().getPrefixMatcher().getPrefix();
Project project = getPosition().getProject();
- JetShortNamesCache namesCache = JetCacheManager.getInstance(project).getNamesCache();
+ JetShortNamesCache namesCache = JetShortNamesCache.getKotlinInstance(project);
GlobalSearchScope scope = GlobalSearchScope.allScope(project);
Collection functionNames = namesCache.getAllTopLevelFunctionNames();
@@ -243,8 +243,9 @@ public class JetCompletionContributor extends CompletionContributor {
}
private void addJetTopLevelObjects() {
- JetShortNamesCache namesCache = JetCacheManager.getInstance(getPosition().getProject()).getNamesCache();
- GlobalSearchScope scope = GlobalSearchScope.allScope(getPosition().getProject());
+ Project project = getPosition().getProject();
+ JetShortNamesCache namesCache = JetShortNamesCache.getKotlinInstance(project);
+ GlobalSearchScope scope = GlobalSearchScope.allScope(project);
Collection objectNames = namesCache.getAllTopLevelObjectNames();
for (String name : objectNames) {
diff --git a/idea/src/org/jetbrains/jet/plugin/completion/JetTypesCompletionHelper.java b/idea/src/org/jetbrains/jet/plugin/completion/JetTypesCompletionHelper.java
index 206eafebbf1..9c16dd0d015 100644
--- a/idea/src/org/jetbrains/jet/plugin/completion/JetTypesCompletionHelper.java
+++ b/idea/src/org/jetbrains/jet/plugin/completion/JetTypesCompletionHelper.java
@@ -27,7 +27,6 @@ import org.jetbrains.jet.lang.psi.JetFile;
import org.jetbrains.jet.lang.resolve.lazy.ResolveSessionUtils;
import org.jetbrains.jet.lang.resolve.name.FqName;
import org.jetbrains.jet.lang.types.lang.KotlinBuiltIns;
-import org.jetbrains.jet.plugin.caches.JetCacheManager;
import org.jetbrains.jet.plugin.caches.JetShortNamesCache;
import org.jetbrains.jet.plugin.libraries.DecompiledDataFactory;
import org.jetbrains.jet.plugin.project.JsModuleDetector;
@@ -42,7 +41,7 @@ public class JetTypesCompletionHelper {
jetCompletionResult.addAllElements(KotlinBuiltIns.getInstance().getNonPhysicalClasses());
Project project = parameters.getOriginalFile().getProject();
- JetShortNamesCache namesCache = JetCacheManager.getInstance(project).getNamesCache();
+ JetShortNamesCache namesCache = JetShortNamesCache.getKotlinInstance(project);
jetCompletionResult.addAllElements(namesCache.getJetClassesDescriptors(
jetCompletionResult.getShortNameFilter(), jetCompletionResult.getResolveSession()));
diff --git a/idea/src/org/jetbrains/jet/plugin/quickfix/ImportClassAndFunFix.java b/idea/src/org/jetbrains/jet/plugin/quickfix/ImportClassAndFunFix.java
index 8e25671e4b4..9afe6645e71 100644
--- a/idea/src/org/jetbrains/jet/plugin/quickfix/ImportClassAndFunFix.java
+++ b/idea/src/org/jetbrains/jet/plugin/quickfix/ImportClassAndFunFix.java
@@ -55,7 +55,6 @@ import org.jetbrains.jet.lang.resolve.lazy.ResolveSession;
import org.jetbrains.jet.lang.resolve.name.FqName;
import org.jetbrains.jet.plugin.JetBundle;
import org.jetbrains.jet.plugin.actions.JetAddImportAction;
-import org.jetbrains.jet.plugin.caches.JetCacheManager;
import org.jetbrains.jet.plugin.caches.JetShortNamesCache;
import org.jetbrains.jet.plugin.project.JsModuleDetector;
import org.jetbrains.jet.plugin.project.WholeProjectAnalyzerFacade;
@@ -121,7 +120,7 @@ public class ImportClassAndFunFix extends JetHintAction
@NotNull ResolveSession resolveSession,
@NotNull Project project
) {
- JetShortNamesCache namesCache = JetCacheManager.getInstance(project).getNamesCache();
+ JetShortNamesCache namesCache = JetShortNamesCache.getKotlinInstance(project);
Collection topLevelFunctions = namesCache.getTopLevelFunctionDescriptorsByName(
referenceName, expression, resolveSession, GlobalSearchScope.allScope(project));
@@ -141,7 +140,7 @@ public class ImportClassAndFunFix extends JetHintAction
@NotNull ResolveSession resolveSession,
@NotNull Project project
) {
- JetShortNamesCache namesCache = JetCacheManager.getInstance(project).getNamesCache();
+ JetShortNamesCache namesCache = JetShortNamesCache.getKotlinInstance(project);
Collection jetCallableExtensions = namesCache.getJetCallableExtensions(
new Condition() {
@Override
@@ -180,7 +179,7 @@ public class ImportClassAndFunFix extends JetHintAction
}
private static Collection getClassesFromCache(@NotNull final String typeName, @NotNull JetFile file) {
- PsiShortNamesCache cache = JetCacheManager.getInstance(file.getProject()).getShortNamesCache(file);
+ PsiShortNamesCache cache = getShortNamesCache(file);
PsiClass[] classes = cache.getClassesByName(typeName, GlobalSearchScope.allScope(file.getProject()));
@@ -204,8 +203,16 @@ public class ImportClassAndFunFix extends JetHintAction
});
}
+ private static PsiShortNamesCache getShortNamesCache(@NotNull JetFile jetFile) {
+ if (JsModuleDetector.isJsModule(jetFile)) {
+ return JetShortNamesCache.getKotlinInstance(jetFile.getProject());
+ }
+
+ return PsiShortNamesCache.getInstance(jetFile.getProject());
+ }
+
private static Collection getJetClasses(@NotNull final String typeName, @NotNull Project project, @NotNull ResolveSession resolveSession) {
- JetShortNamesCache cache = JetCacheManager.getInstance(project).getNamesCache();
+ JetShortNamesCache cache = JetShortNamesCache.getKotlinInstance(project);
Collection descriptors = cache.getJetClassesDescriptors(new Condition() {
@Override
public boolean value(String s) {