From 9b01eb15ce2878ba11a2b13fd4364718b69b5a58 Mon Sep 17 00:00:00 2001 From: Andrey Breslav Date: Tue, 22 Apr 2014 19:41:31 +0400 Subject: [PATCH] KotlinCacheManager removed in favor of KotlinCacheService --- idea/src/META-INF/plugin.xml | 3 - .../resolve/DeclarationsCacheProvider.java | 80 ---------------- .../resolve/JSDeclarationsCacheProvider.java | 84 ----------------- .../resolve/JvmDeclarationsCacheProvider.java | 94 ------------------- .../caches/resolve/KotlinCacheManager.java | 57 ----------- 5 files changed, 318 deletions(-) delete mode 100644 idea/src/org/jetbrains/jet/plugin/caches/resolve/DeclarationsCacheProvider.java delete mode 100644 idea/src/org/jetbrains/jet/plugin/caches/resolve/JSDeclarationsCacheProvider.java delete mode 100644 idea/src/org/jetbrains/jet/plugin/caches/resolve/JvmDeclarationsCacheProvider.java delete mode 100644 idea/src/org/jetbrains/jet/plugin/caches/resolve/KotlinCacheManager.java diff --git a/idea/src/META-INF/plugin.xml b/idea/src/META-INF/plugin.xml index 230773b9caf..6a5db683de9 100644 --- a/idea/src/META-INF/plugin.xml +++ b/idea/src/META-INF/plugin.xml @@ -114,9 +114,6 @@ - - diff --git a/idea/src/org/jetbrains/jet/plugin/caches/resolve/DeclarationsCacheProvider.java b/idea/src/org/jetbrains/jet/plugin/caches/resolve/DeclarationsCacheProvider.java deleted file mode 100644 index 9eb38ef1b5d..00000000000 --- a/idea/src/org/jetbrains/jet/plugin/caches/resolve/DeclarationsCacheProvider.java +++ /dev/null @@ -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 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 { - 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 compute() { - Collection 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); - } - } -} diff --git a/idea/src/org/jetbrains/jet/plugin/caches/resolve/JSDeclarationsCacheProvider.java b/idea/src/org/jetbrains/jet/plugin/caches/resolve/JSDeclarationsCacheProvider.java deleted file mode 100644 index 2071cd0b103..00000000000 --- a/idea/src/org/jetbrains/jet/plugin/caches/resolve/JSDeclarationsCacheProvider.java +++ /dev/null @@ -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 declarationsProvider; - private final Key> 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() { - @Nullable - @Override - public Result 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.alwaysFalse(), - config, - true); - - return Result.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 - ); - } - } -} diff --git a/idea/src/org/jetbrains/jet/plugin/caches/resolve/JvmDeclarationsCacheProvider.java b/idea/src/org/jetbrains/jet/plugin/caches/resolve/JvmDeclarationsCacheProvider.java deleted file mode 100644 index 009ac88cd8d..00000000000 --- a/idea/src/org/jetbrains/jet/plugin/caches/resolve/JvmDeclarationsCacheProvider.java +++ /dev/null @@ -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 declarationsProvider; - private final Key> 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() { - @Nullable - @Override - public Result 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.alwaysFalse(), - true); - } - finally { - incompleteTrace = null; - } - - return Result.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 - ); - } - } -} diff --git a/idea/src/org/jetbrains/jet/plugin/caches/resolve/KotlinCacheManager.java b/idea/src/org/jetbrains/jet/plugin/caches/resolve/KotlinCacheManager.java deleted file mode 100644 index 43d642a4e0a..00000000000 --- a/idea/src/org/jetbrains/jet/plugin/caches/resolve/KotlinCacheManager.java +++ /dev/null @@ -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 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; - } -}