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

Side by Side Diff: lib/strong_mode.dart

Issue 1401273002: Move DDC to analyzer-based checker (Closed) Base URL: git@github.com:dart-lang/dev_compiler.git@master
Patch Set: rebase Created 5 years, 2 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 unified diff | Download patch
« no previous file with comments | « lib/src/utils.dart ('k') | pubspec.yaml » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
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 10 show
(...skipping 13 matching lines...) Expand all
24 StaticTypeWarningCode; 24 StaticTypeWarningCode;
25 import 'package:analyzer/src/generated/source.dart' show Source; 25 import 'package:analyzer/src/generated/source.dart' show Source;
26 import 'package:args/args.dart'; 26 import 'package:args/args.dart';
27 27
28 import 'src/analysis_context.dart' show enableDevCompilerInference; 28 import 'src/analysis_context.dart' show enableDevCompilerInference;
29 import 'src/checker/checker.dart' show CodeChecker; 29 import 'src/checker/checker.dart' show CodeChecker;
30 import 'src/checker/rules.dart' show TypeRules; 30 import 'src/checker/rules.dart' show TypeRules;
31 31
32 /// 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
33 /// the ability to do local type inference in some situations. 33 /// the ability to do local type inference in some situations.
34 // TODO(jmesserly): remove this class.
34 class StrongChecker { 35 class StrongChecker {
35 final AnalysisContext _context; 36 final AnalysisContext _context;
36 final CodeChecker _checker; 37 final CodeChecker _checker;
37 final _ErrorCollector _reporter; 38 final _ErrorCollector _reporter;
38 39
39 StrongChecker._(this._context, this._checker, this._reporter); 40 StrongChecker._(this._context, this._checker, this._reporter);
40 41
41 factory StrongChecker(AnalysisContext context, StrongModeOptions options) { 42 factory StrongChecker(AnalysisContext context, StrongModeOptions options) {
42 // TODO(vsm): Remove this once analyzer_cli is completely switched to the 43 // TODO(vsm): Remove this once analyzer_cli is completely switched to the
43 // task model. 44 // task model.
44 if (!AnalysisEngine 45 if (!AnalysisEngine.instance.useTaskModel) {
45 .instance.useTaskModel) enableDevCompilerInference(context, options); 46 enableDevCompilerInference(context, options);
46 var rules = new TypeRules(context.typeProvider, options: options); 47 var rules = new TypeRules(context.typeProvider);
47 var reporter = new _ErrorCollector(options.hints); 48 var reporter = new _ErrorCollector(options.hints);
48 var checker = new CodeChecker(rules, reporter); 49 var checker = new CodeChecker(rules, reporter);
49 return new StrongChecker._(context, checker, reporter); 50 return new StrongChecker._(context, checker, reporter);
51 }
52 return new StrongChecker._(context, null, null);
50 } 53 }
51 54
52 /// Computes and returns DDC errors for the [source]. 55 /// Computes and returns DDC errors for the [source].
53 AnalysisErrorInfo computeErrors(Source source) { 56 AnalysisErrorInfo computeErrors(Source source) {
54 var errors = new List<AnalysisError>(); 57 var errors = new List<AnalysisError>();
55 _reporter.errors = errors; 58 if (_checker != null) {
59 _reporter.errors = errors;
56 60
57 for (Source librarySource in _context.getLibrariesContaining(source)) { 61 for (Source librarySource in _context.getLibrariesContaining(source)) {
58 var resolved = _context.resolveCompilationUnit2(source, librarySource); 62 var resolved = _context.resolveCompilationUnit2(source, librarySource);
59 _checker.visitCompilationUnit(resolved); 63 _checker.visitCompilationUnit(resolved);
64 }
65 _reporter.errors = null;
60 } 66 }
61 _reporter.errors = null;
62
63 return new AnalysisErrorInfoImpl(errors, _context.getLineInfo(source)); 67 return new AnalysisErrorInfoImpl(errors, _context.getLineInfo(source));
64 } 68 }
65 } 69 }
66 70
67 class _ErrorCollector implements AnalysisErrorListener { 71 class _ErrorCollector implements AnalysisErrorListener {
68 List<AnalysisError> errors; 72 List<AnalysisError> errors;
69 final bool hints; 73 final bool hints;
70 _ErrorCollector(this.hints); 74 _ErrorCollector(this.hints);
71 75
72 void onError(AnalysisError error) { 76 void onError(AnalysisError error) {
(...skipping 26 matching lines...) Expand all
99 defaultsTo: false, 103 defaultsTo: false,
100 hide: hide); 104 hide: hide);
101 } 105 }
102 106
103 bool operator ==(Object other) { 107 bool operator ==(Object other) {
104 if (other is! StrongModeOptions) return false; 108 if (other is! StrongModeOptions) return false;
105 StrongModeOptions s = other; 109 StrongModeOptions s = other;
106 return hints == s.hints; 110 return hints == s.hints;
107 } 111 }
108 } 112 }
OLDNEW
« no previous file with comments | « lib/src/utils.dart ('k') | pubspec.yaml » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698