Chromium Code Reviews| OLD | NEW |
|---|---|
| 1 #!/usr/bin/env dart | 1 #!/usr/bin/env dart |
| 2 | 2 |
| 3 // Copyright (c) 2013, the Dart project authors. Please see the AUTHORS file | 3 // Copyright (c) 2013, the Dart project authors. Please see the AUTHORS file |
| 4 // for details. All rights reserved. Use of this source code is governed by a | 4 // for details. All rights reserved. Use of this source code is governed by a |
| 5 // BSD-style license that can be found in the LICENSE file. | 5 // BSD-style license that can be found in the LICENSE file. |
| 6 | 6 |
| 7 /** The entry point for the analyzer. */ | 7 /** The entry point for the analyzer. */ |
| 8 library analyzer; | 8 library analyzer; |
| 9 | 9 |
| 10 import 'dart:async'; | 10 import 'dart:async'; |
| 11 import 'dart:convert'; | 11 import 'dart:convert'; |
| 12 import 'dart:io'; | 12 import 'dart:io'; |
| 13 | 13 |
| 14 import 'package:analyzer/src/analyzer_impl.dart'; | |
| 14 import 'package:analyzer/src/generated/engine.dart'; | 15 import 'package:analyzer/src/generated/engine.dart'; |
| 15 import 'package:analyzer/src/generated/error.dart'; | 16 import 'package:analyzer/src/generated/error.dart'; |
| 16 import 'package:analyzer/src/generated/java_core.dart' show JavaSystem, instance OfTimer; | 17 import 'package:analyzer/src/generated/java_core.dart' show JavaSystem; |
| 17 import 'package:analyzer/options.dart'; | 18 import 'package:analyzer/options.dart'; |
| 18 | 19 |
| 19 import 'package:analyzer/src/analyzer_impl.dart'; | |
| 20 import 'package:analyzer/src/error_formatter.dart'; | |
| 21 | |
| 22 void main(args) { | 20 void main(args) { |
| 23 var options = CommandLineOptions.parse(args); | 21 var options = CommandLineOptions.parse(args); |
| 24 if (options.shouldBatch) { | 22 if (options.shouldBatch) { |
| 25 BatchRunner.runAsBatch(args, (List<String> args) { | 23 BatchRunner.runAsBatch(args, (List<String> args) { |
| 26 var options = CommandLineOptions.parse(args); | 24 var options = CommandLineOptions.parse(args); |
| 27 return _runAnalyzer(options); | 25 return _runAnalyzer(options); |
| 28 }); | 26 }); |
| 29 } else { | 27 } else { |
| 30 int startTime = JavaSystem.currentTimeMillis(); | 28 _runAnalyzer(options); |
| 31 | |
| 32 ErrorSeverity result = _runAnalyzer(options); | |
| 33 | |
| 34 if (options.perf) { | |
| 35 int totalTime = JavaSystem.currentTimeMillis() - startTime; | |
| 36 int ioTime = PerformanceStatistics.io.result; | |
| 37 int scanTime = PerformanceStatistics.scan.result; | |
| 38 int parseTime = PerformanceStatistics.parse.result; | |
| 39 int resolveTime = PerformanceStatistics.resolve.result; | |
| 40 int errorsTime = PerformanceStatistics.errors.result; | |
| 41 int hintsTime = PerformanceStatistics.hints.result; | |
| 42 int angularTime = PerformanceStatistics.angular.result; | |
| 43 print("io:$ioTime"); | |
| 44 print("scan:$scanTime"); | |
| 45 print("parse:$parseTime"); | |
| 46 print("resolve:$resolveTime"); | |
| 47 print("errors:$errorsTime"); | |
| 48 print("hints:$hintsTime"); | |
| 49 print("angular:$angularTime"); | |
| 50 print("other:${totalTime | |
| 51 - (ioTime + scanTime + parseTime + resolveTime + errorsTime + hintsTime | |
| 52 + angularTime)}"); | |
| 53 print("total:$totalTime"); | |
| 54 } | |
| 55 exitCode = result.ordinal; | |
| 56 } | 29 } |
| 57 } | 30 } |
| 58 | 31 |
| 59 ErrorSeverity _runAnalyzer(CommandLineOptions options) { | 32 void _runAnalyzer(var options) { |
|
Brian Wilkerson
2014/03/11 18:36:53
Please provide a type annotation for the parameter
jwren
2014/03/11 21:53:04
Done.
| |
| 33 int startTime = JavaSystem.currentTimeMillis(); | |
| 60 if (!options.machineFormat) { | 34 if (!options.machineFormat) { |
| 61 stdout.writeln("Analyzing ${options.sourceFiles}..."); | 35 stdout.writeln("Analyzing ${options.sourceFiles}..."); |
| 62 } | 36 } |
| 63 ErrorSeverity allResult = ErrorSeverity.NONE; | 37 ErrorSeverity allResult = ErrorSeverity.NONE; |
| 64 String sourcePath = options.sourceFiles[0]; | 38 String sourcePath = options.sourceFiles[0]; |
| 65 sourcePath = sourcePath.trim(); | 39 sourcePath = sourcePath.trim(); |
| 66 // check that file exists | 40 // check that file exists |
| 67 if (!new File(sourcePath).existsSync()) { | 41 if (!new File(sourcePath).existsSync()) { |
| 68 print('File not found: $sourcePath'); | 42 print('File not found: $sourcePath'); |
| 69 return ErrorSeverity.ERROR; | 43 exitCode = ErrorSeverity.ERROR.ordinal; |
| 70 } | 44 } |
| 71 // check that file is Dart file | 45 // check that file is Dart file |
| 72 if (!AnalysisEngine.isDartFileName(sourcePath)) { | 46 if (!AnalysisEngine.isDartFileName(sourcePath)) { |
| 73 print('$sourcePath is not a Dart file'); | 47 print('$sourcePath is not a Dart file'); |
| 74 return ErrorSeverity.ERROR; | 48 exitCode = ErrorSeverity.ERROR.ordinal; |
| 75 } | 49 } |
| 76 // do analyze | 50 // do analyze |
| 77 ErrorFormatter formatter = new ErrorFormatter(options.machineFormat ? stderr : stdout, options); | 51 AnalyzerImpl analyzer = new AnalyzerImpl(sourcePath, options, startTime); |
| 78 AnalyzerImpl analyzer = new AnalyzerImpl(options); | 52 analyzer.analyze(); |
| 79 analyzer.analyze(sourcePath); | |
| 80 // print errors | |
| 81 formatter.formatErrors(analyzer.errorInfos); | |
| 82 // prepare status | |
| 83 ErrorSeverity status = analyzer.maxErrorSeverity; | |
| 84 if (status == ErrorSeverity.WARNING && options.warningsAreFatal) { | |
| 85 status = ErrorSeverity.ERROR; | |
| 86 } | |
| 87 return status; | |
| 88 } | 53 } |
| 89 | 54 |
| 90 typedef ErrorSeverity BatchRunnerHandler(List<String> args); | 55 typedef ErrorSeverity BatchRunnerHandler(List<String> args); |
| 91 | 56 |
| 92 /// Provides a framework to read command line options from stdin and feed them t o a callback. | 57 /// Provides a framework to read command line options from stdin and feed them t o a callback. |
| 93 class BatchRunner { | 58 class BatchRunner { |
| 94 /** | 59 /** |
| 95 * Run the tool in 'batch' mode, receiving command lines through stdin and ret urning pass/fail | 60 * Run the tool in 'batch' mode, receiving command lines through stdin and ret urning pass/fail |
| 96 * status through stdout. This feature is intended for use in unit testing. | 61 * status through stdout. This feature is intended for use in unit testing. |
| 97 */ | 62 */ |
| (...skipping 42 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 140 stdout.writeln('>>> TEST $resultPassString ${stopwatch.elapsedMillisecon ds}ms'); | 105 stdout.writeln('>>> TEST $resultPassString ${stopwatch.elapsedMillisecon ds}ms'); |
| 141 } catch (e, stackTrace) { | 106 } catch (e, stackTrace) { |
| 142 stderr.writeln(e); | 107 stderr.writeln(e); |
| 143 stderr.writeln(stackTrace); | 108 stderr.writeln(stackTrace); |
| 144 stderr.writeln('>>> EOF STDERR'); | 109 stderr.writeln('>>> EOF STDERR'); |
| 145 stdout.writeln('>>> TEST CRASH'); | 110 stdout.writeln('>>> TEST CRASH'); |
| 146 } | 111 } |
| 147 }); | 112 }); |
| 148 } | 113 } |
| 149 } | 114 } |
| OLD | NEW |