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

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

Issue 850343006: Linter API updates. (Closed) Base URL: http://dart.googlecode.com/svn/branches/bleeding_edge/dart/
Patch Set: Created 5 years, 11 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 | Annotate | Revision Log
OLDNEW
(Empty)
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
3 // BSD-style license that can be found in the LICENSE file.
4
5 library lint;
6
7 import 'package:analyzer/src/generated/ast.dart';
8 import 'package:analyzer/src/generated/utilities_general.dart';
9 import 'package:analyzer/src/generated/engine.dart';
10 import 'package:analyzer/src/generated/error.dart';
11 import 'package:analyzer/src/generated/source.dart';
12 import 'package:analyzer/src/generated/visitors.dart';
13
14
15 /// Implementers contribute lint warnings via the provided error [reporter].
16 abstract class Linter {
17 /// Used to report lint warnings.
18 /// NOTE: this is set by the framework before visit begins.
19 ErrorReporter reporter;
20
21 /// Return a visitor to be passed to compilation units to perform lint
22 /// analysis.
23 /// Lint errors are reported via this [Linter]'s error [reporter].
24 AstVisitor getVisitor();
25 }
26
27 /// Traverses a library's worth of dart code at a time to generate lint warnings
28 /// over the set of sources.
29 ///
30 /// See [LintCode].
31 class LintGenerator {
32
33 /// A global container for contributed linters.
34 static final List<Linter> LINTERS = <Linter>[];
35
36 final Iterable<CompilationUnit> _compilationUnits;
37 final AnalysisErrorListener _errorListener;
38 final Iterable<Linter> _linters;
39
40 LintGenerator(this._compilationUnits, this._errorListener,
41 [Iterable<Linter> linters])
42 : _linters = linters != null ? linters : LINTERS;
43
44 void generate() {
45 TimeCounter_TimeCounterHandle timeCounter =
46 PerformanceStatistics.lint.start();
47 try {
48 _compilationUnits.forEach((cu) {
49 if (cu.element != null) {
50 _generate(cu, cu.element.source);
51 }
52 });
53 } finally {
54 timeCounter.stop();
55 }
56 }
57
58 void _generate(CompilationUnit unit, Source source) {
59 ErrorReporter errorReporter = new ErrorReporter(_errorListener, source);
60 _linters.forEach((l) => l.reporter = errorReporter);
61 Iterable<AstVisitor> visitors = _linters.map((l) => l.getVisitor());
62 unit.accept(new DelegatingAstVisitor(visitors.where((v) => v != null)));
63 }
64 }
OLDNEW
« no previous file with comments | « pkg/analyzer/lib/src/generated/resolver.dart ('k') | pkg/analyzer/test/generated/engine_test.dart » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698