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

Side by Side Diff: pkg/analyzer/lib/src/services/lint.dart

Issue 1392143002: Add context to OptionsProcessor callback API. (Closed) Base URL: git@github.com:dart-lang/sdk.git@master
Patch Set: Arg reordering. 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 | « pkg/analyzer/lib/src/plugin/plugin_configuration.dart ('k') | pkg/analyzer/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 library lint; 5 library lint;
6 6
7 import 'package:analyzer/src/generated/ast.dart'; 7 import 'package:analyzer/src/generated/ast.dart';
8 import 'package:analyzer/src/generated/engine.dart'; 8 import 'package:analyzer/src/generated/engine.dart';
9 import 'package:analyzer/src/generated/error.dart'; 9 import 'package:analyzer/src/generated/error.dart';
10 import 'package:analyzer/src/generated/source.dart'; 10 import 'package:analyzer/src/generated/source.dart';
11 import 'package:analyzer/src/generated/visitors.dart'; 11 import 'package:analyzer/src/generated/visitors.dart';
12 12
13 /// A registry containing mappings of contexts to their associated configured
14 /// lints.
15 final Map<AnalysisContext, List<Linter>> lintRegistry =
16 <AnalysisContext, List<Linter>>{};
17
13 /// Implementers contribute lint warnings via the provided error [reporter]. 18 /// Implementers contribute lint warnings via the provided error [reporter].
14 abstract class Linter { 19 abstract class Linter {
15 /// Used to report lint warnings. 20 /// Used to report lint warnings.
16 /// NOTE: this is set by the framework before visit begins. 21 /// NOTE: this is set by the framework before visit begins.
17 ErrorReporter reporter; 22 ErrorReporter reporter;
18 23
19 /// Return a visitor to be passed to compilation units to perform lint 24 /// Return a visitor to be passed to compilation units to perform lint
20 /// analysis. 25 /// analysis.
21 /// Lint errors are reported via this [Linter]'s error [reporter]. 26 /// Lint errors are reported via this [Linter]'s error [reporter].
22 AstVisitor getVisitor(); 27 AstVisitor getVisitor();
23 } 28 }
24 29
25 /// Traverses a library's worth of dart code at a time to generate lint warnings 30 /// Traverses a library's worth of dart code at a time to generate lint warnings
26 /// over the set of sources. 31 /// over the set of sources.
27 /// 32 ///
28 /// See [LintCode]. 33 /// See [LintCode].
29 class LintGenerator { 34 class LintGenerator {
30 /// A global container for contributed linters. 35 /// A global container for contributed linters.
36 @deprecated // Use lintRegistry.
31 static final List<Linter> LINTERS = <Linter>[]; 37 static final List<Linter> LINTERS = <Linter>[];
32 38
33 final Iterable<CompilationUnit> _compilationUnits; 39 final Iterable<CompilationUnit> _compilationUnits;
34 final AnalysisErrorListener _errorListener; 40 final AnalysisErrorListener _errorListener;
35 final Iterable<Linter> _linters; 41 final Iterable<Linter> _linters;
36 42
37 LintGenerator(this._compilationUnits, this._errorListener, 43 LintGenerator(this._compilationUnits, this._errorListener,
38 [Iterable<Linter> linters]) 44 [Iterable<Linter> linters])
39 : _linters = linters != null ? linters : LINTERS; 45 : _linters = linters ?? LINTERS;
40 46
41 void generate() { 47 void generate() {
42 PerformanceStatistics.lint.makeCurrentWhile(() { 48 PerformanceStatistics.lint.makeCurrentWhile(() {
43 _compilationUnits.forEach((cu) { 49 _compilationUnits.forEach((cu) {
44 if (cu.element != null) { 50 if (cu.element != null) {
45 _generate(cu, cu.element.source); 51 _generate(cu, cu.element.source);
46 } 52 }
47 }); 53 });
48 }); 54 });
49 } 55 }
50 56
51 void _generate(CompilationUnit unit, Source source) { 57 void _generate(CompilationUnit unit, Source source) {
52 ErrorReporter errorReporter = new ErrorReporter(_errorListener, source); 58 ErrorReporter errorReporter = new ErrorReporter(_errorListener, source);
53 _linters.forEach((l) => l.reporter = errorReporter); 59 _linters.forEach((l) => l.reporter = errorReporter);
54 Iterable<AstVisitor> visitors = _linters.map((l) => l.getVisitor()); 60 Iterable<AstVisitor> visitors = _linters.map((l) => l.getVisitor());
55 unit.accept(new DelegatingAstVisitor(visitors.where((v) => v != null))); 61 unit.accept(new DelegatingAstVisitor(visitors.where((v) => v != null)));
56 } 62 }
57 } 63 }
OLDNEW
« no previous file with comments | « pkg/analyzer/lib/src/plugin/plugin_configuration.dart ('k') | pkg/analyzer/pubspec.yaml » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698