| OLD | NEW |
| 1 // Copyright (c) 2014, the Dart project authors. Please see the AUTHORS file | 1 // Copyright (c) 2014, 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 library engine.resolver; | 5 library engine.resolver; |
| 6 | 6 |
| 7 import "dart:math" as math; | 7 import "dart:math" as math; |
| 8 import 'dart:collection'; | 8 import 'dart:collection'; |
| 9 | 9 |
| 10 import 'package:analyzer/src/generated/utilities_collection.dart'; | 10 import 'package:analyzer/src/generated/utilities_collection.dart'; |
| 11 import 'package:analyzer/src/generated/visitors.dart'; | |
| 12 | 11 |
| 13 import 'ast.dart'; | 12 import 'ast.dart'; |
| 14 import 'constant.dart'; | 13 import 'constant.dart'; |
| 15 import 'element.dart'; | 14 import 'element.dart'; |
| 16 import 'element_resolver.dart'; | 15 import 'element_resolver.dart'; |
| 17 import 'engine.dart'; | 16 import 'engine.dart'; |
| 18 import 'error.dart'; | 17 import 'error.dart'; |
| 19 import 'error_verifier.dart'; | 18 import 'error_verifier.dart'; |
| 20 import 'html.dart' as ht; | 19 import 'html.dart' as ht; |
| 21 import 'java_core.dart'; | 20 import 'java_core.dart'; |
| (...skipping 9173 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 9195 for (PrefixElement prefix in definingLibrary.prefixes) { | 9194 for (PrefixElement prefix in definingLibrary.prefixes) { |
| 9196 define(prefix); | 9195 define(prefix); |
| 9197 } | 9196 } |
| 9198 _defineLocalNames(definingLibrary.definingCompilationUnit); | 9197 _defineLocalNames(definingLibrary.definingCompilationUnit); |
| 9199 for (CompilationUnitElement compilationUnit in definingLibrary.parts) { | 9198 for (CompilationUnitElement compilationUnit in definingLibrary.parts) { |
| 9200 _defineLocalNames(compilationUnit); | 9199 _defineLocalNames(compilationUnit); |
| 9201 } | 9200 } |
| 9202 } | 9201 } |
| 9203 } | 9202 } |
| 9204 | 9203 |
| 9205 /// Implementers contribute lint warnings via the provided error [reporter]. | |
| 9206 abstract class Linter { | |
| 9207 /// Used to report lint warnings. | |
| 9208 /// NOTE: this is set by the framework before visit begins. | |
| 9209 ErrorReporter reporter; | |
| 9210 | |
| 9211 /// Return a visitor to be passed to compilation units to perform lint | |
| 9212 /// analysis. | |
| 9213 /// Lint errors are reported via this [Linter]'s error [reporter]. | |
| 9214 AstVisitor getVisitor(); | |
| 9215 } | |
| 9216 | |
| 9217 /// Traverses a library's worth of dart code at a time to generate lint warnings | |
| 9218 /// over the set of sources. | |
| 9219 /// | |
| 9220 /// See [LintCode]. | |
| 9221 class LintGenerator { | |
| 9222 | |
| 9223 /// A global container for contributed linters. | |
| 9224 static final List<Linter> LINTERS = <Linter>[]; | |
| 9225 | |
| 9226 final Iterable<CompilationUnit> _compilationUnits; | |
| 9227 final AnalysisErrorListener _errorListener; | |
| 9228 final Iterable<Linter> _linters; | |
| 9229 | |
| 9230 LintGenerator(this._compilationUnits, this._errorListener, | |
| 9231 [Iterable<Linter> linters]) | |
| 9232 : _linters = linters != null ? linters : LINTERS; | |
| 9233 | |
| 9234 void generate() { | |
| 9235 TimeCounter_TimeCounterHandle timeCounter = | |
| 9236 PerformanceStatistics.lint.start(); | |
| 9237 try { | |
| 9238 _compilationUnits.forEach((cu) { | |
| 9239 if (cu.element != null) { | |
| 9240 _generate(cu, cu.element.source); | |
| 9241 } | |
| 9242 }); | |
| 9243 } finally { | |
| 9244 timeCounter.stop(); | |
| 9245 } | |
| 9246 } | |
| 9247 | |
| 9248 void _generate(CompilationUnit unit, Source source) { | |
| 9249 ErrorReporter errorReporter = new ErrorReporter(_errorListener, source); | |
| 9250 _linters.forEach((l) => l.reporter = errorReporter); | |
| 9251 Iterable<AstVisitor> visitors = _linters.map((l) => l.getVisitor()); | |
| 9252 unit.accept(new DelegatingAstVisitor(visitors.where((v) => v != null))); | |
| 9253 } | |
| 9254 } | |
| 9255 | 9204 |
| 9256 /** | 9205 /** |
| 9257 * This class is used to replace uses of `HashMap<String, ExecutableElement>` wh
ich are not as | 9206 * This class is used to replace uses of `HashMap<String, ExecutableElement>` wh
ich are not as |
| 9258 * performant as this class. | 9207 * performant as this class. |
| 9259 */ | 9208 */ |
| 9260 class MemberMap { | 9209 class MemberMap { |
| 9261 /** | 9210 /** |
| 9262 * The current size of this map. | 9211 * The current size of this map. |
| 9263 */ | 9212 */ |
| 9264 int _size = 0; | 9213 int _size = 0; |
| (...skipping 6244 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 15509 * library. | 15458 * library. |
| 15510 */ | 15459 */ |
| 15511 final HashSet<String> members = new HashSet<String>(); | 15460 final HashSet<String> members = new HashSet<String>(); |
| 15512 | 15461 |
| 15513 /** | 15462 /** |
| 15514 * Names of resolved or unresolved class members that are read in the | 15463 * Names of resolved or unresolved class members that are read in the |
| 15515 * library. | 15464 * library. |
| 15516 */ | 15465 */ |
| 15517 final HashSet<String> readMembers = new HashSet<String>(); | 15466 final HashSet<String> readMembers = new HashSet<String>(); |
| 15518 } | 15467 } |
| OLD | NEW |