KotlinCacheManager removed in favor of KotlinCacheService
This commit is contained in:
@@ -114,9 +114,6 @@
|
||||
<projectService serviceInterface="org.jetbrains.jet.lang.resolve.java.JetFilesProvider"
|
||||
serviceImplementation="org.jetbrains.jet.plugin.project.PluginJetFilesProvider"/>
|
||||
|
||||
<projectService serviceInterface="org.jetbrains.jet.plugin.caches.resolve.KotlinCacheManager"
|
||||
serviceImplementation="org.jetbrains.jet.plugin.caches.resolve.KotlinCacheManager"/>
|
||||
|
||||
<projectService serviceInterface="org.jetbrains.jet.plugin.caches.resolve.KotlinCacheService"
|
||||
serviceImplementation="org.jetbrains.jet.plugin.caches.resolve.KotlinCacheService"/>
|
||||
|
||||
|
||||
@@ -1,80 +0,0 @@
|
||||
/*
|
||||
* Copyright 2010-2013 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.resolve;
|
||||
|
||||
import com.intellij.openapi.project.Project;
|
||||
import com.intellij.psi.search.GlobalSearchScope;
|
||||
import com.intellij.psi.util.CachedValue;
|
||||
import com.intellij.psi.util.CachedValueProvider;
|
||||
import com.intellij.psi.util.CachedValuesManager;
|
||||
import com.intellij.psi.util.PsiModificationTracker;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
import org.jetbrains.annotations.Nullable;
|
||||
import org.jetbrains.jet.analyzer.AnalyzerFacade;
|
||||
import org.jetbrains.jet.lang.psi.JetFile;
|
||||
import org.jetbrains.jet.lang.resolve.java.JetFilesProvider;
|
||||
import org.jetbrains.jet.lang.resolve.lazy.ResolveSession;
|
||||
import org.jetbrains.jet.plugin.project.AnalyzerFacadeProvider;
|
||||
import org.jetbrains.jet.plugin.project.ResolveSessionForBodies;
|
||||
import org.jetbrains.jet.plugin.project.TargetPlatform;
|
||||
|
||||
import java.util.Collection;
|
||||
|
||||
public abstract class DeclarationsCacheProvider {
|
||||
private final CachedValue<ResolveSessionForBodies> lazyResolveCache;
|
||||
|
||||
protected final TargetPlatform platform;
|
||||
protected final Project project;
|
||||
|
||||
DeclarationsCacheProvider(Project project, TargetPlatform platform) {
|
||||
this.platform = platform;
|
||||
this.project = project;
|
||||
|
||||
this.lazyResolveCache = CachedValuesManager.getManager(project).createCachedValue(
|
||||
new CancelableResolveSessionValueProvider(project, platform), true);
|
||||
}
|
||||
|
||||
public abstract KotlinDeclarationsCache getDeclarations();
|
||||
|
||||
@NotNull
|
||||
public ResolveSessionForBodies getLazyResolveSession() {
|
||||
return lazyResolveCache.getValue();
|
||||
}
|
||||
|
||||
public boolean areDeclarationsAvailable(@NotNull JetFile jetFile) {
|
||||
return JetFilesProvider.getInstance(project).isFileInScope(jetFile, GlobalSearchScope.allScope(project));
|
||||
}
|
||||
|
||||
private static class CancelableResolveSessionValueProvider implements CachedValueProvider<ResolveSessionForBodies> {
|
||||
private final Project project;
|
||||
private final TargetPlatform platform;
|
||||
|
||||
private CancelableResolveSessionValueProvider(Project project, TargetPlatform platform) {
|
||||
this.project = project;
|
||||
this.platform = platform;
|
||||
}
|
||||
|
||||
@Nullable
|
||||
@Override
|
||||
public synchronized Result<ResolveSessionForBodies> compute() {
|
||||
Collection<JetFile> files = JetFilesProvider.getInstance(project).allInScope(GlobalSearchScope.allScope(project));
|
||||
AnalyzerFacade facade = AnalyzerFacadeProvider.getAnalyzerFacade(platform);
|
||||
ResolveSession resolveSession = facade.createSetup(project, files).getLazyResolveSession();
|
||||
return Result.create(new ResolveSessionForBodies(project, resolveSession), PsiModificationTracker.OUT_OF_CODE_BLOCK_MODIFICATION_COUNT);
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -1,84 +0,0 @@
|
||||
/*
|
||||
* Copyright 2010-2013 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.resolve;
|
||||
|
||||
import com.google.common.base.Predicates;
|
||||
import com.intellij.openapi.project.Project;
|
||||
import com.intellij.openapi.util.Key;
|
||||
import com.intellij.psi.PsiFile;
|
||||
import com.intellij.psi.search.GlobalSearchScope;
|
||||
import com.intellij.psi.util.CachedValue;
|
||||
import com.intellij.psi.util.CachedValueProvider;
|
||||
import com.intellij.psi.util.CachedValuesManager;
|
||||
import com.intellij.psi.util.PsiModificationTracker;
|
||||
import org.jetbrains.annotations.Nullable;
|
||||
import org.jetbrains.jet.analyzer.AnalyzeExhaust;
|
||||
import org.jetbrains.jet.lang.resolve.java.JetFilesProvider;
|
||||
import org.jetbrains.jet.plugin.project.ProjectStructureUtil;
|
||||
import org.jetbrains.jet.plugin.project.TargetPlatform;
|
||||
import org.jetbrains.k2js.analyze.AnalyzerFacadeForJS;
|
||||
import org.jetbrains.k2js.config.EcmaVersion;
|
||||
import org.jetbrains.k2js.config.LibrarySourcesConfig;
|
||||
|
||||
class JSDeclarationsCacheProvider extends DeclarationsCacheProvider {
|
||||
private final CachedValueProvider<KotlinDeclarationsCache> declarationsProvider;
|
||||
private final Key<CachedValue<KotlinDeclarationsCache>> cachedKey;
|
||||
private final Object declarationAnalysisLock = new Object();
|
||||
|
||||
JSDeclarationsCacheProvider(final Project project) {
|
||||
super(project, TargetPlatform.JS);
|
||||
|
||||
cachedKey = Key.create("KOTLIN_JS_DECLARATIONS_CACHE");
|
||||
|
||||
declarationsProvider = new CachedValueProvider<KotlinDeclarationsCache>() {
|
||||
@Nullable
|
||||
@Override
|
||||
public Result<KotlinDeclarationsCache> compute() {
|
||||
synchronized (declarationAnalysisLock) {
|
||||
LibrarySourcesConfig config = new LibrarySourcesConfig(
|
||||
project, "default",
|
||||
ProjectStructureUtil.getLibLocationForProject(project),
|
||||
EcmaVersion.defaultVersion(), false);
|
||||
|
||||
AnalyzeExhaust analyzeExhaust = AnalyzerFacadeForJS.analyzeFiles(
|
||||
JetFilesProvider.getInstance(project).allInScope(GlobalSearchScope.allScope(project)),
|
||||
Predicates.<PsiFile>alwaysFalse(),
|
||||
config,
|
||||
true);
|
||||
|
||||
return Result.<KotlinDeclarationsCache>create(
|
||||
new KotlinDeclarationsCacheImpl(analyzeExhaust),
|
||||
PsiModificationTracker.OUT_OF_CODE_BLOCK_MODIFICATION_COUNT,
|
||||
KotlinCacheManager.getInstance(project).getDeclarationsTracker()
|
||||
);
|
||||
}
|
||||
}
|
||||
};
|
||||
}
|
||||
|
||||
@Override
|
||||
public KotlinDeclarationsCache getDeclarations() {
|
||||
synchronized (declarationAnalysisLock) {
|
||||
return CachedValuesManager.getManager(project).getCachedValue(
|
||||
project,
|
||||
cachedKey,
|
||||
declarationsProvider,
|
||||
true
|
||||
);
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -1,94 +0,0 @@
|
||||
/*
|
||||
* Copyright 2010-2013 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.resolve;
|
||||
|
||||
import com.google.common.base.Predicates;
|
||||
import com.intellij.openapi.project.Project;
|
||||
import com.intellij.openapi.util.Key;
|
||||
import com.intellij.psi.PsiFile;
|
||||
import com.intellij.psi.search.GlobalSearchScope;
|
||||
import com.intellij.psi.util.CachedValue;
|
||||
import com.intellij.psi.util.CachedValueProvider;
|
||||
import com.intellij.psi.util.CachedValuesManager;
|
||||
import com.intellij.psi.util.PsiModificationTracker;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
import org.jetbrains.annotations.Nullable;
|
||||
import org.jetbrains.jet.analyzer.AnalyzeExhaust;
|
||||
import org.jetbrains.jet.lang.resolve.BindingContext;
|
||||
import org.jetbrains.jet.lang.resolve.BindingTrace;
|
||||
import org.jetbrains.jet.lang.resolve.BindingTraceContext;
|
||||
import org.jetbrains.jet.lang.resolve.java.AnalyzerFacadeForJVM;
|
||||
import org.jetbrains.jet.lang.resolve.java.JetFilesProvider;
|
||||
import org.jetbrains.jet.plugin.project.TargetPlatform;
|
||||
|
||||
class JvmDeclarationsCacheProvider extends DeclarationsCacheProvider {
|
||||
private final CachedValueProvider<KotlinDeclarationsCache> declarationsProvider;
|
||||
private final Key<CachedValue<KotlinDeclarationsCache>> cachedKey;
|
||||
private final Object declarationAnalysisLock = new Object();
|
||||
|
||||
private BindingTrace incompleteTrace;
|
||||
|
||||
JvmDeclarationsCacheProvider(final Project project) {
|
||||
super(project, TargetPlatform.JVM);
|
||||
|
||||
cachedKey = Key.create("KOTLIN_JVM_DECLARATIONS_CACHE");
|
||||
|
||||
declarationsProvider = new CachedValueProvider<KotlinDeclarationsCache>() {
|
||||
@Nullable
|
||||
@Override
|
||||
public Result<KotlinDeclarationsCache> compute() {
|
||||
// This lock is already acquired by the calling method,
|
||||
// but we put it here to guard for the case of further modifications
|
||||
synchronized (declarationAnalysisLock) {
|
||||
incompleteTrace = new BindingTraceContext();
|
||||
|
||||
AnalyzeExhaust analyzeExhaust;
|
||||
try {
|
||||
analyzeExhaust = AnalyzerFacadeForJVM.analyzeFilesWithJavaIntegration(
|
||||
project,
|
||||
JetFilesProvider.getInstance(project).allInScope(GlobalSearchScope.allScope(project)),
|
||||
incompleteTrace,
|
||||
Predicates.<PsiFile>alwaysFalse(),
|
||||
true);
|
||||
}
|
||||
finally {
|
||||
incompleteTrace = null;
|
||||
}
|
||||
|
||||
return Result.<KotlinDeclarationsCache>create(
|
||||
new KotlinDeclarationsCacheImpl(analyzeExhaust),
|
||||
PsiModificationTracker.OUT_OF_CODE_BLOCK_MODIFICATION_COUNT,
|
||||
KotlinCacheManager.getInstance(project).getDeclarationsTracker()
|
||||
);
|
||||
}
|
||||
}
|
||||
};
|
||||
}
|
||||
|
||||
@Override
|
||||
@NotNull
|
||||
public KotlinDeclarationsCache getDeclarations() {
|
||||
synchronized (declarationAnalysisLock) {
|
||||
return CachedValuesManager.getManager(project).getCachedValue(
|
||||
project,
|
||||
cachedKey,
|
||||
declarationsProvider,
|
||||
true
|
||||
);
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -1,57 +0,0 @@
|
||||
/*
|
||||
* Copyright 2010-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 org.jetbrains.jet.plugin.caches.resolve;
|
||||
|
||||
import com.google.common.collect.Maps;
|
||||
import com.intellij.openapi.components.ServiceManager;
|
||||
import com.intellij.openapi.project.Project;
|
||||
import com.intellij.openapi.util.DefaultModificationTracker;
|
||||
import com.intellij.openapi.util.ModificationTracker;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
import org.jetbrains.jet.plugin.project.TargetPlatform;
|
||||
|
||||
import java.util.Map;
|
||||
|
||||
public class KotlinCacheManager {
|
||||
@NotNull
|
||||
public static KotlinCacheManager getInstance(@NotNull Project project) {
|
||||
return ServiceManager.getService(project, KotlinCacheManager.class);
|
||||
}
|
||||
|
||||
private final Map<TargetPlatform, DeclarationsCacheProvider> cacheProviders = Maps.newHashMap();
|
||||
|
||||
private final DefaultModificationTracker kotlinDeclarationsTracker = new DefaultModificationTracker();
|
||||
|
||||
public KotlinCacheManager(@NotNull Project project) {
|
||||
cacheProviders.put(TargetPlatform.JVM, new JvmDeclarationsCacheProvider(project));
|
||||
cacheProviders.put(TargetPlatform.JS, new JSDeclarationsCacheProvider(project));
|
||||
}
|
||||
|
||||
@NotNull
|
||||
public DeclarationsCacheProvider getRegisteredProvider(@NotNull TargetPlatform platform) {
|
||||
DeclarationsCacheProvider provider = cacheProviders.get(platform);
|
||||
if (provider == null) {
|
||||
throw new IllegalStateException("Provider isn't registered for platform: " + platform);
|
||||
}
|
||||
|
||||
return provider;
|
||||
}
|
||||
|
||||
public ModificationTracker getDeclarationsTracker() {
|
||||
return kotlinDeclarationsTracker;
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user