From 30f49f3c9a1d0a633df52621acff44289162e582 Mon Sep 17 00:00:00 2001 From: Andrey Breslav Date: Mon, 3 Feb 2014 18:40:06 +0400 Subject: [PATCH] Invalidate per-file cache on exceptions --- .../resolve/java/AnalyzerFacadeForJVM.java | 18 ++++++++++++- .../project/AnalyzerFacadeWithCache.java | 27 ++++++++++++------- 2 files changed, 35 insertions(+), 10 deletions(-) diff --git a/compiler/frontend.java/src/org/jetbrains/jet/lang/resolve/java/AnalyzerFacadeForJVM.java b/compiler/frontend.java/src/org/jetbrains/jet/lang/resolve/java/AnalyzerFacadeForJVM.java index aa88c64faf5..2246dc120f3 100644 --- a/compiler/frontend.java/src/org/jetbrains/jet/lang/resolve/java/AnalyzerFacadeForJVM.java +++ b/compiler/frontend.java/src/org/jetbrains/jet/lang/resolve/java/AnalyzerFacadeForJVM.java @@ -26,6 +26,7 @@ import org.jetbrains.jet.analyzer.AnalyzeExhaust; import org.jetbrains.jet.analyzer.AnalyzerFacade; import org.jetbrains.jet.analyzer.AnalyzerFacadeForEverything; import org.jetbrains.jet.context.ContextPackage; +import org.jetbrains.jet.context.GlobalContext; import org.jetbrains.jet.context.GlobalContextImpl; import org.jetbrains.jet.di.InjectorForJavaDescriptorResolver; import org.jetbrains.jet.di.InjectorForJavaDescriptorResolverUtil; @@ -204,7 +205,22 @@ public enum AnalyzerFacadeForJVM implements AnalyzerFacade { boolean storeContextForBodiesResolve, ModuleDescriptorImpl module ) { - GlobalContextImpl globalContext = ContextPackage.GlobalContext(); + GlobalContext globalContext = ContextPackage.GlobalContext(); + return analyzeFilesWithJavaIntegrationInGlobalContext(project, files, trace, scriptParameters, filesToAnalyzeCompletely, + storeContextForBodiesResolve, module, globalContext); + } + + @NotNull + public static AnalyzeExhaust analyzeFilesWithJavaIntegrationInGlobalContext( + Project project, + Collection files, + BindingTrace trace, + List scriptParameters, + Predicate filesToAnalyzeCompletely, + boolean storeContextForBodiesResolve, + ModuleDescriptorImpl module, + GlobalContext globalContext + ) { TopDownAnalysisParameters topDownAnalysisParameters = new TopDownAnalysisParameters( globalContext.getStorageManager(), globalContext.getExceptionTracker(), diff --git a/idea/src/org/jetbrains/jet/plugin/project/AnalyzerFacadeWithCache.java b/idea/src/org/jetbrains/jet/plugin/project/AnalyzerFacadeWithCache.java index a5b863cd329..608f372fa95 100644 --- a/idea/src/org/jetbrains/jet/plugin/project/AnalyzerFacadeWithCache.java +++ b/idea/src/org/jetbrains/jet/plugin/project/AnalyzerFacadeWithCache.java @@ -35,6 +35,8 @@ import org.jetbrains.annotations.NotNull; import org.jetbrains.annotations.Nullable; import org.jetbrains.jet.analyzer.AnalyzeExhaust; import org.jetbrains.jet.asJava.LightClassUtil; +import org.jetbrains.jet.context.ContextPackage; +import org.jetbrains.jet.context.GlobalContext; import org.jetbrains.jet.lang.diagnostics.DiagnosticUtils; import org.jetbrains.jet.lang.diagnostics.Errors; import org.jetbrains.jet.lang.psi.JetElement; @@ -149,6 +151,7 @@ public final class AnalyzerFacadeWithCache { @Nullable @Override public Result> compute() { + final GlobalContext globalContext = ContextPackage.GlobalContext(); SLRUCache cache = new SLRUCache(3, 8) { @NotNull @@ -161,7 +164,7 @@ public final class AnalyzerFacadeWithCache { ApplicationUtils.warnTimeConsuming(LOG); - AnalyzeExhaust analyzeExhaustHeaders = analyzeHeadersWithCacheOnFile(file); + AnalyzeExhaust analyzeExhaustHeaders = analyzeHeadersWithCacheOnFile(file, globalContext); return analyzeBodies(analyzeExhaustHeaders, file); } catch (ProcessCanceledException e) { @@ -177,10 +180,10 @@ public final class AnalyzerFacadeWithCache { } } }; - return Result.create(cache, PsiModificationTracker.MODIFICATION_COUNT); + return Result.create(cache, PsiModificationTracker.MODIFICATION_COUNT, globalContext.getExceptionTracker()); } - private static AnalyzeExhaust analyzeHeadersWithCacheOnFile(@NotNull JetFile fileToCache) { + private static AnalyzeExhaust analyzeHeadersWithCacheOnFile(@NotNull JetFile fileToCache, @NotNull GlobalContext globalContext) { VirtualFile virtualFile = fileToCache.getVirtualFile(); if (LightClassUtil.belongsToKotlinBuiltIns(fileToCache) || virtualFile != null && LibraryUtil.findLibraryEntry(virtualFile, fileToCache.getProject()) != null) { @@ -188,12 +191,18 @@ public final class AnalyzerFacadeWithCache { // Mark file to skip fileToCache.putUserData(LibrarySourceHacks.SKIP_TOP_LEVEL_MEMBERS, true); // Resolve this file, not only project files (as KotlinCacheManager do) - return AnalyzerFacadeForJVM.INSTANCE.analyzeFiles( - fileToCache.getProject(), - Collections.singleton(fileToCache), - Collections.emptyList(), - Predicates.alwaysFalse() - ); + + return AnalyzerFacadeForJVM + .analyzeFilesWithJavaIntegrationInGlobalContext( + fileToCache.getProject(), + Collections.singleton(fileToCache), + new BindingTraceContext(), + Collections.emptyList(), + Predicates.alwaysFalse(), + true, + AnalyzerFacadeForJVM.createJavaModule(""), + globalContext + ); } KotlinDeclarationsCache cache = KotlinCacheManagerUtil.getDeclarationsFromProject(fileToCache);