Create composite exception tracker when delegating ModuleResolverProvider

Avoid dropping delegate caches when exception (i.e. ProcessCancelled) is thrown in delegating provider
This commit is contained in:
Pavel V. Talanov
2014-09-16 18:41:23 +04:00
parent 68201c3e86
commit 8d89ac897a
4 changed files with 46 additions and 3 deletions
@@ -20,7 +20,7 @@ import com.intellij.openapi.util.ModificationTracker
import java.util.concurrent.atomic.AtomicLong
import org.jetbrains.jet.utils.rethrow
public class ExceptionTracker : ModificationTracker, LockBasedStorageManager.ExceptionHandlingStrategy {
public open class ExceptionTracker : ModificationTracker, LockBasedStorageManager.ExceptionHandlingStrategy {
private val cancelledTracker: AtomicLong = AtomicLong()
override fun handleException(throwable: Throwable): RuntimeException {
@@ -421,4 +421,11 @@ public class LockBasedStorageManager implements StorageManager {
}
}
@NotNull
public static LockBasedStorageManager createDelegatingWithSameLock(
@NotNull LockBasedStorageManager base,
@NotNull ExceptionHandlingStrategy newStrategy
) {
return new LockBasedStorageManager(getPointOfConstruction(), newStrategy, base.lock);
}
}
@@ -34,6 +34,7 @@ import org.jetbrains.jet.lang.resolve.java.structure.JavaClass
import org.jetbrains.jet.analyzer.ResolverForProject
import org.jetbrains.jet.analyzer.ModuleContent
import org.jetbrains.jet.analyzer.EmptyResolverForProject
import org.jetbrains.jet.context.GlobalContextImpl
fun createModuleResolverProvider(
project: Project,
@@ -45,7 +46,9 @@ fun createModuleResolverProvider(
val allModuleInfos = collectAllModuleInfosFromIdeaModel(project).toHashSet()
val globalContext = (delegateProvider as? ModuleResolverProviderImpl)?.globalContext ?: GlobalContext()
val globalContext =
(delegateProvider as? ModuleResolverProviderImpl)?.globalContext?.withCompositeExceptionTrackerUnderSameLock()
?: GlobalContext()
val syntheticFilesByModule = syntheticFiles.groupBy { it.getModuleInfo() }
val syntheticFilesModules = syntheticFilesByModule.keySet()
@@ -131,7 +134,7 @@ object EmptyModuleResolverProvider: ModuleResolverProvider {
class ModuleResolverProviderImpl(
override val resolverForProject: ResolverForProject<IdeaModuleInfo, ResolverForModule>,
private val bodiesResolveByModule: Map<IdeaModuleInfo, ResolveSessionForBodies>,
val globalContext: GlobalContext,
val globalContext: GlobalContextImpl,
val delegateProvider: ModuleResolverProvider = EmptyModuleResolverProvider
): ModuleResolverProvider {
override val exceptionTracker: ExceptionTracker = globalContext.exceptionTracker
@@ -0,0 +1,33 @@
/*
* 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 org.jetbrains.jet.context.GlobalContextImpl
import org.jetbrains.jet.storage.LockBasedStorageManager
import org.jetbrains.jet.storage.ExceptionTracker
fun GlobalContextImpl.withCompositeExceptionTrackerUnderSameLock(): GlobalContextImpl {
val newExceptionTracker = CompositeExceptionTracker(this.exceptionTracker)
val newStorageManager = LockBasedStorageManager.createDelegatingWithSameLock(this.storageManager, newExceptionTracker)
return GlobalContextImpl(newStorageManager, newExceptionTracker)
}
private class CompositeExceptionTracker(val delegate: ExceptionTracker): ExceptionTracker() {
override fun getModificationCount(): Long {
return super<ExceptionTracker>.getModificationCount() + delegate.getModificationCount()
}
}