OLD | NEW |
1 // Copyright (c) 2015, the Dart project authors. Please see the AUTHORS file | 1 // Copyright (c) 2015, the Dart project authors. Please see the AUTHORS file |
2 // for details. All rights reserved. Use of this source code is governed by a | 2 // for details. All rights reserved. Use of this source code is governed by a |
3 // BSD-style license that can be found in the LICENSE file. | 3 // BSD-style license that can be found in the LICENSE file. |
4 | 4 |
5 /// Command line tool to run the checker on a Dart program. | 5 /// Command line tool to run the checker on a Dart program. |
6 library dev_compiler.devc; | 6 library dev_compiler.devc; |
7 | 7 |
8 import 'dart:async'; | 8 import 'dart:async'; |
9 import 'dart:convert'; | 9 import 'dart:convert'; |
10 import 'dart:io'; | 10 import 'dart:io'; |
11 | 11 |
12 import 'package:analyzer/src/generated/error.dart' as analyzer; | 12 import 'package:analyzer/src/generated/error.dart' as analyzer; |
13 import 'package:analyzer/src/generated/engine.dart' | 13 import 'package:analyzer/src/generated/engine.dart' |
14 show AnalysisContext, ChangeSet; | 14 show AnalysisContext, ChangeSet; |
15 import 'package:analyzer/src/generated/source.dart' show Source; | 15 import 'package:analyzer/src/generated/source.dart' show Source; |
16 import 'package:logging/logging.dart' show Level, Logger, LogRecord; | 16 import 'package:logging/logging.dart' show Level, Logger, LogRecord; |
17 import 'package:path/path.dart' as path; | 17 import 'package:path/path.dart' as path; |
18 import 'package:shelf/shelf.dart' as shelf; | 18 import 'package:shelf/shelf.dart' as shelf; |
19 import 'package:shelf/shelf_io.dart' as shelf; | 19 import 'package:shelf/shelf_io.dart' as shelf; |
20 import 'package:shelf_static/shelf_static.dart' as shelf_static; | 20 import 'package:shelf_static/shelf_static.dart' as shelf_static; |
21 | 21 |
| 22 |
| 23 import 'src/analysis_context.dart'; |
22 import 'src/checker/checker.dart'; | 24 import 'src/checker/checker.dart'; |
23 import 'src/checker/dart_sdk.dart' show mockSdkSources; | |
24 import 'src/checker/resolver.dart'; | |
25 import 'src/checker/rules.dart'; | 25 import 'src/checker/rules.dart'; |
26 import 'src/codegen/code_generator.dart' show CodeGenerator; | 26 import 'src/codegen/code_generator.dart' show CodeGenerator; |
27 import 'src/codegen/dart_codegen.dart'; | 27 import 'src/codegen/dart_codegen.dart'; |
28 import 'src/codegen/html_codegen.dart'; | 28 import 'src/codegen/html_codegen.dart'; |
29 import 'src/codegen/js_codegen.dart'; | 29 import 'src/codegen/js_codegen.dart'; |
30 import 'src/dependency_graph.dart'; | 30 import 'src/dependency_graph.dart'; |
31 import 'src/info.dart' | 31 import 'src/info.dart' |
32 show AnalyzerError, CheckerResults, LibraryInfo, LibraryUnit; | 32 show AnalyzerError, CheckerResults, LibraryInfo, LibraryUnit; |
33 import 'src/options.dart'; | 33 import 'src/options.dart'; |
34 import 'src/report.dart'; | 34 import 'src/report.dart'; |
(...skipping 23 matching lines...) Expand all Loading... |
58 final CheckerReporter _reporter; | 58 final CheckerReporter _reporter; |
59 final TypeRules rules; | 59 final TypeRules rules; |
60 final CodeChecker _checker; | 60 final CodeChecker _checker; |
61 final SourceNode _entryNode; | 61 final SourceNode _entryNode; |
62 List<LibraryInfo> _libraries = <LibraryInfo>[]; | 62 List<LibraryInfo> _libraries = <LibraryInfo>[]; |
63 final _generators = <CodeGenerator>[]; | 63 final _generators = <CodeGenerator>[]; |
64 bool _hashing; | 64 bool _hashing; |
65 bool _failure = false; | 65 bool _failure = false; |
66 | 66 |
67 factory Compiler(CompilerOptions options, | 67 factory Compiler(CompilerOptions options, |
68 {TypeResolver resolver, CheckerReporter reporter}) { | 68 {AnalysisContext context, CheckerReporter reporter}) { |
69 if (resolver == null) { | 69 |
70 resolver = options.useMockSdk | 70 if (context == null) context = createAnalysisContext(options); |
71 ? new TypeResolver.fromMock(mockSdkSources, options) | |
72 : new TypeResolver.fromDir(options.dartSdkPath, options); | |
73 } | |
74 var context = resolver.context; | |
75 | 71 |
76 if (reporter == null) { | 72 if (reporter == null) { |
77 reporter = options.dumpInfo | 73 reporter = options.dumpInfo |
78 ? new SummaryReporter(context, options.logLevel) | 74 ? new SummaryReporter(context, options.logLevel) |
79 : new LogReporter(context, useColors: options.useColors); | 75 : new LogReporter(context, useColors: options.useColors); |
80 } | 76 } |
81 var graph = new SourceGraph(context, reporter, options); | 77 var graph = new SourceGraph(context, reporter, options); |
82 var rules = new RestrictedRules(context.typeProvider, options: options); | 78 var rules = new RestrictedRules(context.typeProvider, options: options); |
83 var checker = new CodeChecker(rules, reporter, options); | 79 var checker = new CodeChecker(rules, reporter, options); |
84 | 80 |
(...skipping 248 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
333 // Note: the cache-control header should be enough, but this doesn't hurt | 329 // Note: the cache-control header should be enough, but this doesn't hurt |
334 // and can help renew the policy after it expires. | 330 // and can help renew the policy after it expires. |
335 headers['ETag'] = hash; | 331 headers['ETag'] = hash; |
336 } | 332 } |
337 return response.change(headers: headers); | 333 return response.change(headers: headers); |
338 }; | 334 }; |
339 } | 335 } |
340 | 336 |
341 final _log = new Logger('dev_compiler'); | 337 final _log = new Logger('dev_compiler'); |
342 final _earlyErrorResult = new CheckerResults(const [], null, true); | 338 final _earlyErrorResult = new CheckerResults(const [], null, true); |
OLD | NEW |