Use CachedValuesManager.getCachedValue()

This commit is contained in:
Andrey Breslav
2013-03-14 15:19:08 +04:00
parent 7702274633
commit 48cd960eee
@@ -74,43 +74,40 @@ public final class AnalyzerFacadeWithCache {
@NotNull @NotNull
public static AnalyzeExhaust analyzeFileWithCache(@NotNull final JetFile file, public static AnalyzeExhaust analyzeFileWithCache(@NotNull final JetFile file,
@NotNull final Function<JetFile, Collection<JetFile>> declarationProvider) { @NotNull final Function<JetFile, Collection<JetFile>> declarationProvider) {
// Need lock for getValue(), because parallel threads can start evaluation of compute() simultaneously // Need lock, because parallel threads can start evaluation of compute() simultaneously
synchronized (lock) { synchronized (lock) {
CachedValue<AnalyzeExhaust> result = file.getUserData(ANALYZE_EXHAUST_FULL); return CachedValuesManager.getManager(file.getProject()).getCachedValue(
if (result == null) { file,
result = ANALYZE_EXHAUST_FULL,
CachedValuesManager.getManager(file.getProject()).createCachedValue(new CachedValueProvider<AnalyzeExhaust>() { new CachedValueProvider<AnalyzeExhaust>() {
@Override @Override
public Result<AnalyzeExhaust> compute() { public Result<AnalyzeExhaust> compute() {
try { try {
if (DumbService.isDumb(file.getProject())) { if (DumbService.isDumb(file.getProject())) {
return new Result<AnalyzeExhaust>( return new Result<AnalyzeExhaust>(
emptyExhaust(), emptyExhaust(),
PsiModificationTracker.MODIFICATION_COUNT); PsiModificationTracker.MODIFICATION_COUNT);
}
ApplicationUtils.warnTimeConsuming(LOG);
AnalyzeExhaust analyzeExhaustHeaders = analyzeHeadersWithCacheOnFile(file, declarationProvider);
AnalyzeExhaust exhaust = analyzeBodies(analyzeExhaustHeaders, file);
return new Result<AnalyzeExhaust>(exhaust, PsiModificationTracker.MODIFICATION_COUNT);
}
catch (ProcessCanceledException e) {
throw e;
}
catch (Throwable e) {
handleError(e);
return emptyExhaustWithDiagnosticOnFile(file, e);
}
} }
}, false);
file.putUserData(ANALYZE_EXHAUST_FULL, result); ApplicationUtils.warnTimeConsuming(LOG);
}
return result.getValue(); AnalyzeExhaust analyzeExhaustHeaders = analyzeHeadersWithCacheOnFile(file, declarationProvider);
AnalyzeExhaust exhaust = analyzeBodies(analyzeExhaustHeaders, file);
return new Result<AnalyzeExhaust>(exhaust, PsiModificationTracker.MODIFICATION_COUNT);
}
catch (ProcessCanceledException e) {
throw e;
}
catch (Throwable e) {
handleError(e);
return emptyExhaustWithDiagnosticOnFile(file, e);
}
}
},
false
);
} }
} }