Methods extracted/reordered

This commit is contained in:
Andrey Breslav
2012-12-17 14:42:33 +04:00
parent f1e31341ef
commit 6b9c6e3d95
@@ -85,27 +85,15 @@ public final class AnalyzerFacadeWithCache {
try { try {
if (DumbService.isDumb(file.getProject())) { if (DumbService.isDumb(file.getProject())) {
return new Result<AnalyzeExhaust>( return new Result<AnalyzeExhaust>(
AnalyzeExhaust.success(BindingContext.EMPTY, ModuleConfiguration.EMPTY), emptyExhaust(),
PsiModificationTracker.MODIFICATION_COUNT); PsiModificationTracker.MODIFICATION_COUNT);
} }
ApplicationUtils.warnTimeConsuming(LOG); ApplicationUtils.warnTimeConsuming(LOG);
// Collect context for headers first
AnalyzeExhaust analyzeExhaustHeaders = analyzeHeadersWithCacheOnFile(file, declarationProvider); AnalyzeExhaust analyzeExhaustHeaders = analyzeHeadersWithCacheOnFile(file, declarationProvider);
BodiesResolveContext context = analyzeExhaustHeaders.getBodiesResolveContext(); AnalyzeExhaust exhaust = analyzeBodies(analyzeExhaustHeaders, file);
ModuleConfiguration moduleConfiguration = analyzeExhaustHeaders.getModuleConfiguration();
assert context != null : "Headers resolver should prepare and stored information for bodies resolve";
// Need to resolve bodies in given file and all in the same package
AnalyzeExhaust exhaust = AnalyzerFacadeProvider.getAnalyzerFacadeForFile(file).analyzeBodiesInFiles(
file.getProject(),
Collections.<AnalyzerScriptParameter>emptyList(),
new JetFilesProvider.SameJetFilePredicate(file),
new DelegatingBindingTrace(analyzeExhaustHeaders.getBindingContext(), "trace to resolve bodies in file", file.getName()),
context,
moduleConfiguration);
return new Result<AnalyzeExhaust>(exhaust, PsiModificationTracker.MODIFICATION_COUNT); return new Result<AnalyzeExhaust>(exhaust, PsiModificationTracker.MODIFICATION_COUNT);
} }
@@ -114,25 +102,9 @@ public final class AnalyzerFacadeWithCache {
} }
catch (Throwable e) { catch (Throwable e) {
handleError(e); handleError(e);
return emptyExhaustWithDiagnosticOnFile(e); return emptyExhaustWithDiagnosticOnFile(file, e);
} }
} }
@NotNull
private Result<AnalyzeExhaust> emptyExhaustWithDiagnosticOnFile(Throwable e) {
BindingTraceContext bindingTraceContext = new BindingTraceContext();
bindingTraceContext.report(Errors.EXCEPTION_WHILE_ANALYZING.on(file, e));
AnalyzeExhaust analyzeExhaust = AnalyzeExhaust.error(bindingTraceContext.getBindingContext(), e);
CachedValue<AnalyzeExhaust> bindingContextCachedValue = file.getUserData(ANALYZE_EXHAUST_HEADERS);
if (bindingContextCachedValue != null && bindingContextCachedValue.hasUpToDateValue()) {
// Force invalidating of headers cache - temp decision for monitoring rewrite slice bug
PsiModificationTracker tracker = PsiManager.getInstance(file.getProject()).getModificationTracker();
((PsiModificationTrackerImpl) tracker).incOutOfCodeBlockModificationCounter();
}
return new Result<AnalyzeExhaust>(analyzeExhaust, PsiModificationTracker.MODIFICATION_COUNT);
}
}, false); }, false);
file.putUserData(ANALYZE_EXHAUST_FULL, bindingContextCachedValue); file.putUserData(ANALYZE_EXHAUST_FULL, bindingContextCachedValue);
@@ -142,6 +114,10 @@ public final class AnalyzerFacadeWithCache {
} }
} }
private static AnalyzeExhaust emptyExhaust() {
return AnalyzeExhaust.success(BindingContext.EMPTY, ModuleConfiguration.EMPTY);
}
private static AnalyzeExhaust analyzeHeadersWithCacheOnFile( private static AnalyzeExhaust analyzeHeadersWithCacheOnFile(
@NotNull final JetFile fileToCache, @NotNull final JetFile fileToCache,
@NotNull final Function<JetFile, Collection<JetFile>> declarationProvider @NotNull final Function<JetFile, Collection<JetFile>> declarationProvider
@@ -154,9 +130,9 @@ public final class AnalyzerFacadeWithCache {
public Result<AnalyzeExhaust> compute() { public Result<AnalyzeExhaust> compute() {
AnalyzeExhaust exhaust = AnalyzerFacadeProvider.getAnalyzerFacadeForFile(fileToCache) AnalyzeExhaust exhaust = AnalyzerFacadeProvider.getAnalyzerFacadeForFile(fileToCache)
.analyzeFiles(fileToCache.getProject(), .analyzeFiles(fileToCache.getProject(),
declarationProvider.fun(fileToCache), declarationProvider.fun(fileToCache),
Collections.<AnalyzerScriptParameter>emptyList(), Collections.<AnalyzerScriptParameter>emptyList(),
Predicates.<PsiFile>alwaysFalse()); Predicates.<PsiFile>alwaysFalse());
return new Result<AnalyzeExhaust>(exhaust, PsiModificationTracker.OUT_OF_CODE_BLOCK_MODIFICATION_COUNT); return new Result<AnalyzeExhaust>(exhaust, PsiModificationTracker.OUT_OF_CODE_BLOCK_MODIFICATION_COUNT);
} }
@@ -167,6 +143,38 @@ public final class AnalyzerFacadeWithCache {
return bindingContextCachedValue.getValue(); return bindingContextCachedValue.getValue();
} }
private static AnalyzeExhaust analyzeBodies(AnalyzeExhaust analyzeExhaustHeaders, JetFile file) {
BodiesResolveContext context = analyzeExhaustHeaders.getBodiesResolveContext();
ModuleConfiguration moduleConfiguration = analyzeExhaustHeaders.getModuleConfiguration();
assert context != null : "Headers resolver should prepare and stored information for bodies resolve";
// Need to resolve bodies in given file and all in the same package
return AnalyzerFacadeProvider.getAnalyzerFacadeForFile(file).analyzeBodiesInFiles(
file.getProject(),
Collections.<AnalyzerScriptParameter>emptyList(),
new JetFilesProvider.SameJetFilePredicate(file),
new DelegatingBindingTrace(analyzeExhaustHeaders.getBindingContext(),
"trace to resolve bodies in file", file.getName()),
context,
moduleConfiguration);
}
@NotNull
private static CachedValueProvider.Result<AnalyzeExhaust> emptyExhaustWithDiagnosticOnFile(JetFile file, Throwable e) {
BindingTraceContext bindingTraceContext = new BindingTraceContext();
bindingTraceContext.report(Errors.EXCEPTION_WHILE_ANALYZING.on(file, e));
AnalyzeExhaust analyzeExhaust = AnalyzeExhaust.error(bindingTraceContext.getBindingContext(), e);
CachedValue<AnalyzeExhaust> bindingContextCachedValue = file.getUserData(ANALYZE_EXHAUST_HEADERS);
if (bindingContextCachedValue != null && bindingContextCachedValue.hasUpToDateValue()) {
// Force invalidating of headers cache - temp decision for monitoring rewrite slice bug
PsiModificationTracker tracker = PsiManager.getInstance(file.getProject()).getModificationTracker();
((PsiModificationTrackerImpl) tracker).incOutOfCodeBlockModificationCounter();
}
return new CachedValueProvider.Result<AnalyzeExhaust>(analyzeExhaust, PsiModificationTracker.MODIFICATION_COUNT);
}
private static void handleError(@NotNull Throwable e) { private static void handleError(@NotNull Throwable e) {
DiagnosticUtils.throwIfRunningOnServer(e); DiagnosticUtils.throwIfRunningOnServer(e);
LOG.error(e); LOG.error(e);