JetCacheManager removed
This commit is contained in:
@@ -17,9 +17,6 @@
|
||||
<component>
|
||||
<implementation-class>org.jetbrains.jet.plugin.compiler.JetCompilerManager</implementation-class>
|
||||
</component>
|
||||
<component>
|
||||
<implementation-class>org.jetbrains.jet.plugin.caches.JetCacheManager</implementation-class>
|
||||
</component>
|
||||
<component>
|
||||
<implementation-class>org.jetbrains.jet.plugin.references.BuiltInsReferenceResolver</implementation-class>
|
||||
</component>
|
||||
|
||||
@@ -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);
|
||||
}
|
||||
}
|
||||
@@ -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<String> javaQualifiedNames = new HashSet<String>();
|
||||
|
||||
|
||||
@@ -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<String> 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<PsiClass> result = new ArrayList<PsiClass>();
|
||||
|
||||
if (JvmAbi.PACKAGE_CLASS.equals(name)) {
|
||||
// .namespace classes can not be indexed, since they have no explicit declarations
|
||||
Collection<String> allPackageFqNames = JetPackageDeclarationIndex.getInstance().getAllKeys(project);
|
||||
for (String fqName : allPackageFqNames) {
|
||||
PsiClass psiClass = JavaElementFinder.getInstance(project).findClass(fqName + "." + JvmAbi.PACKAGE_CLASS, scope);
|
||||
|
||||
@@ -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<DeclarationDescriptor> 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<String> 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<String> objectNames = namesCache.getAllTopLevelObjectNames();
|
||||
|
||||
for (String name : objectNames) {
|
||||
|
||||
@@ -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()));
|
||||
|
||||
|
||||
@@ -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<JetSimpleNameExpression>
|
||||
@NotNull ResolveSession resolveSession,
|
||||
@NotNull Project project
|
||||
) {
|
||||
JetShortNamesCache namesCache = JetCacheManager.getInstance(project).getNamesCache();
|
||||
JetShortNamesCache namesCache = JetShortNamesCache.getKotlinInstance(project);
|
||||
|
||||
Collection<FunctionDescriptor> topLevelFunctions = namesCache.getTopLevelFunctionDescriptorsByName(
|
||||
referenceName, expression, resolveSession, GlobalSearchScope.allScope(project));
|
||||
@@ -141,7 +140,7 @@ public class ImportClassAndFunFix extends JetHintAction<JetSimpleNameExpression>
|
||||
@NotNull ResolveSession resolveSession,
|
||||
@NotNull Project project
|
||||
) {
|
||||
JetShortNamesCache namesCache = JetCacheManager.getInstance(project).getNamesCache();
|
||||
JetShortNamesCache namesCache = JetShortNamesCache.getKotlinInstance(project);
|
||||
Collection<DeclarationDescriptor> jetCallableExtensions = namesCache.getJetCallableExtensions(
|
||||
new Condition<String>() {
|
||||
@Override
|
||||
@@ -180,7 +179,7 @@ public class ImportClassAndFunFix extends JetHintAction<JetSimpleNameExpression>
|
||||
}
|
||||
|
||||
private static Collection<FqName> 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<JetSimpleNameExpression>
|
||||
});
|
||||
}
|
||||
|
||||
private static PsiShortNamesCache getShortNamesCache(@NotNull JetFile jetFile) {
|
||||
if (JsModuleDetector.isJsModule(jetFile)) {
|
||||
return JetShortNamesCache.getKotlinInstance(jetFile.getProject());
|
||||
}
|
||||
|
||||
return PsiShortNamesCache.getInstance(jetFile.getProject());
|
||||
}
|
||||
|
||||
private static Collection<FqName> getJetClasses(@NotNull final String typeName, @NotNull Project project, @NotNull ResolveSession resolveSession) {
|
||||
JetShortNamesCache cache = JetCacheManager.getInstance(project).getNamesCache();
|
||||
JetShortNamesCache cache = JetShortNamesCache.getKotlinInstance(project);
|
||||
Collection<ClassDescriptor> descriptors = cache.getJetClassesDescriptors(new Condition<String>() {
|
||||
@Override
|
||||
public boolean value(String s) {
|
||||
|
||||
Reference in New Issue
Block a user