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

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

Issue 195483004: Convert the command line dart analyzer to be async. (Closed) Base URL: https://dart.googlecode.com/svn/branches/bleeding_edge/dart
Patch Set: 2 nits Created 6 years, 9 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
« pkg/analyzer/bin/analyzer.dart ('K') | « pkg/analyzer/bin/analyzer.dart ('k') | no next file » | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: pkg/analyzer/lib/src/analyzer_impl.dart
diff --git a/pkg/analyzer/lib/src/analyzer_impl.dart b/pkg/analyzer/lib/src/analyzer_impl.dart
index a2b11514341e4fc7282f00c827562f2c5c8fe6f3..38baa94b9466ff12e1c0b521cbca08e904310972 100644
--- a/pkg/analyzer/lib/src/analyzer_impl.dart
+++ b/pkg/analyzer/lib/src/analyzer_impl.dart
@@ -4,8 +4,12 @@
library analyzer_impl;
+import 'dart:async';
+
import 'dart:io';
+import 'package:analyzer/src/error_formatter.dart';
+import 'package:analyzer/src/generated/java_core.dart' show JavaSystem;
import 'package:path/path.dart' as pathos;
import 'generated/java_io.dart';
@@ -14,16 +18,16 @@ import 'generated/error.dart';
import 'generated/source_io.dart';
import 'generated/sdk.dart';
import 'generated/sdk_io.dart';
-import 'generated/ast.dart';
import 'generated/element.dart';
import '../options.dart';
-
DartSdk sdk;
/// Analyzes single library [File].
class AnalyzerImpl {
+ final String sourcePath;
final CommandLineOptions options;
+ int startTime;
ContentCache contentCache = new ContentCache();
SourceFactory sourceFactory;
@@ -35,7 +39,7 @@ class AnalyzerImpl {
/// All [AnalysisErrorInfo]s in the analyzed library.
final List<AnalysisErrorInfo> errorInfos = new List<AnalysisErrorInfo>();
- AnalyzerImpl(CommandLineOptions this.options) {
+ AnalyzerImpl(String this.sourcePath, CommandLineOptions this.options, int this.startTime) {
Brian Wilkerson 2014/03/11 18:36:53 Don't include type annotations for field initializ
jwren 2014/03/11 21:53:04 Done.
if (sdk == null) {
sdk = new DirectoryBasedDartSdk(new JavaFile(options.dartSdkPath));
}
@@ -44,35 +48,80 @@ class AnalyzerImpl {
/**
* Treats the [sourcePath] as the top level library and analyzes it.
*/
- void analyze(String sourcePath) {
+ void analyze() {
sources.clear();
errorInfos.clear();
if (sourcePath == null) {
throw new ArgumentError("sourcePath cannot be null");
}
- var sourceFile = new JavaFile(sourcePath);
- var uriKind = getUriKind(sourceFile);
- var librarySource = new FileBasedSource.con2(sourceFile, uriKind);
+ JavaFile sourceFile = new JavaFile(sourcePath);
+ UriKind uriKind = getUriKind(sourceFile);
+ Source librarySource = new FileBasedSource.con2(sourceFile, uriKind);
+
// prepare context
- prepareAnalysisContext(sourceFile);
- // don't try to analyzer parts
- var unit = context.parseCompilationUnit(librarySource);
- var hasLibraryDirective = false;
- var hasPartOfDirective = false;
- for (var directive in unit.directives) {
- if (directive is LibraryDirective) hasLibraryDirective = true;
- if (directive is PartOfDirective) hasPartOfDirective = true;
- }
- if (hasPartOfDirective && !hasLibraryDirective) {
- print("Only libraries can be analyzed.");
- print("$sourceFile is a part and can not be analyzed.");
- return;
- }
- // resolve library
- var libraryElement = context.computeLibraryElement(librarySource);
- // prepare source and errors
- prepareSources(libraryElement);
- prepareErrors();
+ prepareAnalysisContext(sourceFile, librarySource);
+
+ // async perform all tasks in context
+ _analyze();
+ }
+
+ void _analyze() {
Bob Nystrom 2014/03/11 18:24:46 Drive-by code review! It's considered good style
jwren 2014/03/11 21:53:04 Bob- Thanks for the feedback. For now we are goin
+ new Future(context.performAnalysisTask).then((AnalysisResult result) {
+ List<ChangeNotice> notices = result.changeNotices;
Bob Nystrom 2014/03/11 18:24:46 Style nit: this function body should be indented +
jwren 2014/03/11 21:53:04 Done.
+ // TODO(jwren) change notices != null to result.isMoreWork after new
+ // dart translation is landed
+ if(notices != null) {
Bob Nystrom 2014/03/11 18:24:46 Space after "if".
Brian Wilkerson 2014/03/11 18:36:53 You're not making use of the utility method you de
jwren 2014/03/11 21:53:04 Done. Correct.
+ // There is more work, record the set of sources, and then call self
+ // again to perform next task
+ for(ChangeNotice notice in notices) {
Brian Wilkerson 2014/03/11 18:36:53 nit: space after "for"
jwren 2014/03/11 21:53:04 Done.
+ sources.add(notice.source);
+ }
+ return _analyze();
+ } else {
Bob Nystrom 2014/03/11 18:24:46 Friendly suggestion: Since the if case always retu
jwren 2014/03/11 21:53:04 Done.
+ //
+ // There are not any more tasks, set error code and print performance
+ // numbers.
+ //
+ // prepare errors
+ prepareErrors();
+
+ // compute max severity and set exitCode
+ ErrorSeverity status = maxErrorSeverity;
+ if (status == ErrorSeverity.WARNING && options.warningsAreFatal) {
+ status = ErrorSeverity.ERROR;
+ }
+ exitCode = status.ordinal;
+
+ // print errors
+ ErrorFormatter formatter = new ErrorFormatter(stdout, options);
+ formatter.formatErrors(errorInfos);
+
+ // print performance numbers
+ if (options.perf) {
+ int totalTime = JavaSystem.currentTimeMillis() - startTime;
+ int ioTime = PerformanceStatistics.io.result;
+ int scanTime = PerformanceStatistics.scan.result;
+ int parseTime = PerformanceStatistics.parse.result;
+ int resolveTime = PerformanceStatistics.resolve.result;
+ int errorsTime = PerformanceStatistics.errors.result;
+ int hintsTime = PerformanceStatistics.hints.result;
+ int angularTime = PerformanceStatistics.angular.result;
+ stdout.writeln("io:$ioTime");
+ stdout.writeln("scan:$scanTime");
+ stdout.writeln("parse:$parseTime");
+ stdout.writeln("resolve:$resolveTime");
+ stdout.writeln("errors:$errorsTime");
+ stdout.writeln("hints:$hintsTime");
+ stdout.writeln("angular:$angularTime");
+ stdout.writeln("other:${totalTime
+ - (ioTime + scanTime + parseTime + resolveTime + errorsTime + hintsTime
+ + angularTime)}");
+ stdout.writeln("total:$totalTime");
+ }
+ }
+ }).catchError((exception, stackTrace) {
+ AnalysisEngine.instance.logger.logError(exception);
Bob Nystrom 2014/03/11 18:24:46 This only needs to be indented +2.
jwren 2014/03/11 21:53:04 Done.
+ });
}
/// Returns the maximal [ErrorSeverity] of the recorded errors.
@@ -87,7 +136,7 @@ class AnalyzerImpl {
return status;
}
- void prepareAnalysisContext(JavaFile sourceFile) {
+ void prepareAnalysisContext(JavaFile sourceFile, Source source) {
List<UriResolver> resolvers = [new DartUriResolver(sdk), new FileUriResolver()];
// may be add package resolver
{
@@ -110,13 +159,11 @@ class AnalyzerImpl {
contextOptions.cacheSize = 256;
contextOptions.hint = !options.disableHints;
context.analysisOptions = contextOptions;
- }
- /// Fills [sources].
- void prepareSources(LibraryElement library) {
- var units = new Set<CompilationUnitElement>();
- var libraries = new Set<LibraryElement>();
- addLibrarySources(library, libraries, units);
+ // Create and add a ChangeSet
+ ChangeSet changeSet = new ChangeSet();
+ changeSet.addedSource(source);
+ context.applyChanges(changeSet);
}
void addCompilationUnitSource(CompilationUnitElement unit, Set<LibraryElement> libraries,
@@ -159,7 +206,7 @@ class AnalyzerImpl {
}
}
- /// Fills [errorInfos].
+ /// Fills [errorInfos] using [sources].
void prepareErrors() {
for (Source source in sources) {
context.computeErrors(source);
« pkg/analyzer/bin/analyzer.dart ('K') | « pkg/analyzer/bin/analyzer.dart ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698