Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(39)

Unified Diff: pkg/analyzer_cli/lib/src/analyzer_impl.dart

Issue 2659463003: Make analyzer_cli batch mode asynchronous. (Closed)
Patch Set: Created 3 years, 11 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
« no previous file with comments | « no previous file | pkg/analyzer_cli/lib/src/build_mode.dart » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: pkg/analyzer_cli/lib/src/analyzer_impl.dart
diff --git a/pkg/analyzer_cli/lib/src/analyzer_impl.dart b/pkg/analyzer_cli/lib/src/analyzer_impl.dart
index f33706ca909a31c79c9a16ef59e2da544890cac8..22654ef5621b016c012f46d8e1ec994529fbf086 100644
--- a/pkg/analyzer_cli/lib/src/analyzer_impl.dart
+++ b/pkg/analyzer_cli/lib/src/analyzer_impl.dart
@@ -4,6 +4,7 @@
library analyzer_cli.src.analyzer_impl;
+import 'dart:async';
import 'dart:collection';
import 'dart:io';
@@ -37,6 +38,7 @@ class AnalyzerImpl {
final CommandLineOptions options;
final int startTime;
+ final AnalysisOptions analysisOptions;
final AnalysisContext context;
/// Accumulated analysis statistics.
@@ -61,8 +63,8 @@ class AnalyzerImpl {
/// specified the "--package-warnings" option.
String _selfPackageName;
- AnalyzerImpl(this.context, this.librarySource, this.options, this.stats,
- this.startTime);
+ AnalyzerImpl(this.analysisOptions, this.context, this.librarySource,
+ this.options, this.stats, this.startTime);
/// Returns the maximal [ErrorSeverity] of the recorded errors.
ErrorSeverity get maxErrorSeverity {
@@ -111,24 +113,27 @@ class AnalyzerImpl {
}
}
- /// Treats the [sourcePath] as the top level library and analyzes it using a
- /// synchronous algorithm over the analysis engine. If [printMode] is `0`,
- /// then no error or performance information is printed. If [printMode] is `1`,
- /// then both will be printed. If [printMode] is `2`, then only performance
- /// information will be printed, and it will be marked as being for a cold VM.
- ErrorSeverity analyzeSync({int printMode: 1}) {
+ /// Treats the [sourcePath] as the top level library and analyzes it using
+ /// the analysis engine. If [printMode] is `0`, then no error or performance
+ /// information is printed. If [printMode] is `1`, then both will be printed.
+ /// If [printMode] is `2`, then only performance information will be printed,
+ /// and it will be marked as being for a cold VM.
+ Future<ErrorSeverity> analyze({int printMode: 1}) async {
setupForAnalysis();
- return _analyzeSync(printMode);
+ return await _analyze(printMode);
}
/// Fills [errorInfos] using [sources].
- void prepareErrors() {
- return _prepareErrorsTag.makeCurrentWhile(() {
+ Future<Null> prepareErrors() async {
+ PerformanceTag previous = _prepareErrorsTag.makeCurrent();
+ try {
for (Source source in sources) {
context.computeErrors(source);
errorInfos.add(context.getErrors(source));
}
- });
+ } finally {
+ previous.makeCurrent();
+ }
}
/// Fills [sources].
@@ -148,8 +153,7 @@ class AnalyzerImpl {
}
}
- /// The sync version of analysis.
- ErrorSeverity _analyzeSync(int printMode) {
+ Future<ErrorSeverity> _analyze(int printMode) async {
// Don't try to analyze parts.
if (context.computeKindOf(librarySource) == SourceKind.PART) {
stderr.writeln("Only libraries can be analyzed.");
@@ -157,9 +161,9 @@ class AnalyzerImpl {
"${librarySource.fullName} is a part and can not be analyzed.");
return ErrorSeverity.ERROR;
}
- var libraryElement = _resolveLibrary();
+ LibraryElement libraryElement = await _resolveLibrary();
prepareSources(libraryElement);
- prepareErrors();
+ await prepareErrors();
// Print errors and performance numbers.
if (printMode == 1) {
@@ -240,12 +244,15 @@ class AnalyzerImpl {
}
ProcessedSeverity _processError(AnalysisError error) =>
- processError(error, options, context);
+ processError(error, options, analysisOptions);
- LibraryElement _resolveLibrary() {
- return _resolveLibraryTag.makeCurrentWhile(() {
+ Future<LibraryElement> _resolveLibrary() async {
+ PerformanceTag previous = _resolveLibraryTag.makeCurrent();
+ try {
return context.computeLibraryElement(librarySource);
- });
+ } finally {
+ previous.makeCurrent();
+ }
}
/// Compute the severity of the error; however:
@@ -255,10 +262,10 @@ class AnalyzerImpl {
/// * if [options.lintsAreFatal] is true, escalate lints to errors.
static ErrorSeverity computeSeverity(
AnalysisError error, CommandLineOptions options,
- [AnalysisContext context]) {
- if (context != null) {
+ [AnalysisOptions analysisOptions]) {
+ if (analysisOptions != null) {
ErrorProcessor processor =
- ErrorProcessor.getProcessor(context.analysisOptions, error);
+ ErrorProcessor.getProcessor(analysisOptions, error);
// If there is a processor for this error, defer to it.
if (processor != null) {
return processor.severity;
@@ -296,8 +303,8 @@ class AnalyzerImpl {
/// Check various configuration options to get a desired severity for this
/// [error] (or `null` if it's to be suppressed).
static ProcessedSeverity processError(AnalysisError error,
- CommandLineOptions options, AnalysisContext context) {
- ErrorSeverity severity = computeSeverity(error, options, context);
+ CommandLineOptions options, AnalysisOptions analysisOptions) {
+ ErrorSeverity severity = computeSeverity(error, options, analysisOptions);
bool isOverridden = false;
// Skip TODOs categorically (unless escalated to ERROR or HINT.)
« no previous file with comments | « no previous file | pkg/analyzer_cli/lib/src/build_mode.dart » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698