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 /// Types needed to implement "strong" checking in the Dart analyzer. This is | 5 /// Types needed to implement "strong" checking in the Dart analyzer. This is |
6 /// intended to be used by `analyzer_cli` and `analysis_server` packages. | 6 /// intended to be used by `analyzer_cli` and `analysis_server` packages. |
7 library dev_compiler.strong_mode; | 7 library dev_compiler.strong_mode; |
8 | 8 |
9 import 'package:analyzer/src/generated/engine.dart' | 9 import 'package:analyzer/src/generated/engine.dart' |
10 show AnalysisContextImpl, AnalysisErrorInfo, AnalysisErrorInfoImpl; | 10 show |
| 11 AnalysisContext, |
| 12 AnalysisContextImpl, |
| 13 AnalysisEngine, |
| 14 AnalysisErrorInfo, |
| 15 AnalysisErrorInfoImpl; |
11 import 'package:analyzer/src/generated/error.dart' | 16 import 'package:analyzer/src/generated/error.dart' |
12 show | 17 show |
13 AnalysisError, | 18 AnalysisError, |
14 AnalysisErrorListener, | 19 AnalysisErrorListener, |
15 CompileTimeErrorCode, | 20 CompileTimeErrorCode, |
16 ErrorCode, | 21 ErrorCode, |
17 ErrorSeverity, | 22 ErrorSeverity, |
18 HintCode, | 23 HintCode, |
19 StaticTypeWarningCode; | 24 StaticTypeWarningCode; |
20 import 'package:analyzer/src/generated/source.dart' show Source; | 25 import 'package:analyzer/src/generated/source.dart' show Source; |
21 import 'package:args/args.dart'; | 26 import 'package:args/args.dart'; |
22 | 27 |
23 import 'src/analysis_context.dart' show enableDevCompilerInference; | 28 import 'src/analysis_context.dart' show enableDevCompilerInference; |
24 import 'src/checker/checker.dart' show CodeChecker; | 29 import 'src/checker/checker.dart' show CodeChecker; |
25 import 'src/checker/rules.dart' show RestrictedRules; | 30 import 'src/checker/rules.dart' show RestrictedRules; |
26 | 31 |
27 /// A type checker for Dart code that operates under stronger rules, and has | 32 /// A type checker for Dart code that operates under stronger rules, and has |
28 /// the ability to do local type inference in some situations. | 33 /// the ability to do local type inference in some situations. |
29 class StrongChecker { | 34 class StrongChecker { |
30 final AnalysisContextImpl _context; | 35 final AnalysisContext _context; |
31 final CodeChecker _checker; | 36 final CodeChecker _checker; |
32 final _ErrorCollector _reporter; | 37 final _ErrorCollector _reporter; |
33 | 38 |
34 StrongChecker._(this._context, this._checker, this._reporter); | 39 StrongChecker._(this._context, this._checker, this._reporter); |
35 | 40 |
36 factory StrongChecker( | 41 factory StrongChecker(AnalysisContext context, StrongModeOptions options) { |
37 AnalysisContextImpl context, StrongModeOptions options) { | 42 // TODO(vsm): Remove this once analyzer_cli is completely switched to the |
38 enableDevCompilerInference(context, options); | 43 // task model. |
| 44 if (!AnalysisEngine |
| 45 .instance.useTaskModel) enableDevCompilerInference(context, options); |
39 var rules = new RestrictedRules(context.typeProvider, options: options); | 46 var rules = new RestrictedRules(context.typeProvider, options: options); |
40 var reporter = new _ErrorCollector(options.hints); | 47 var reporter = new _ErrorCollector(options.hints); |
41 var checker = new CodeChecker(rules, reporter, options); | 48 var checker = new CodeChecker(rules, reporter, options); |
42 return new StrongChecker._(context, checker, reporter); | 49 return new StrongChecker._(context, checker, reporter); |
43 } | 50 } |
44 | 51 |
45 /// Computes and returns DDC errors for the [source]. | 52 /// Computes and returns DDC errors for the [source]. |
46 AnalysisErrorInfo computeErrors(Source source) { | 53 AnalysisErrorInfo computeErrors(Source source) { |
47 var errors = new List<AnalysisError>(); | 54 var errors = new List<AnalysisError>(); |
48 _reporter.errors = errors; | 55 _reporter.errors = errors; |
(...skipping 135 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
184 List<String> _optionsToList(String option, | 191 List<String> _optionsToList(String option, |
185 {List<String> defaultValue: const <String>[]}) { | 192 {List<String> defaultValue: const <String>[]}) { |
186 if (option == null) { | 193 if (option == null) { |
187 return defaultValue; | 194 return defaultValue; |
188 } else if (option.isEmpty) { | 195 } else if (option.isEmpty) { |
189 return <String>[]; | 196 return <String>[]; |
190 } else { | 197 } else { |
191 return option.split(','); | 198 return option.split(','); |
192 } | 199 } |
193 } | 200 } |
OLD | NEW |