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

Unified Diff: packages/analyzer/lib/src/services/lint.dart

Issue 2990843002: Removed fixed dependencies (Closed)
Patch Set: Created 3 years, 5 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 side-by-side diff with in-line comments
Download patch
Index: packages/analyzer/lib/src/services/lint.dart
diff --git a/packages/analyzer/lib/src/services/lint.dart b/packages/analyzer/lib/src/services/lint.dart
index a6b55ccbdc4145f6db9ff1806c19eeb46860e0c1..795b0322053fbe68a94c11bdc8185d5ef067ed7b 100644
--- a/packages/analyzer/lib/src/services/lint.dart
+++ b/packages/analyzer/lib/src/services/lint.dart
@@ -2,13 +2,13 @@
// for details. All rights reserved. Use of this source code is governed by a
// BSD-style license that can be found in the LICENSE file.
-library lint;
+library analyzer.src.services.lint;
-import 'package:analyzer/src/generated/ast.dart';
+import 'dart:collection';
+
+import 'package:analyzer/dart/ast/ast.dart';
+import 'package:analyzer/error/listener.dart';
import 'package:analyzer/src/generated/engine.dart';
-import 'package:analyzer/src/generated/error.dart';
-import 'package:analyzer/src/generated/source.dart';
-import 'package:analyzer/src/generated/visitors.dart';
import 'package:analyzer/src/task/model.dart';
import 'package:analyzer/task/model.dart';
@@ -19,6 +19,9 @@ const List<Linter> _noLints = const <Linter>[];
final ResultDescriptor<List<Linter>> CONFIGURED_LINTS_KEY =
new ResultDescriptorImpl('configured.lints', _noLints);
+/// Shared lint registry.
+LintRegistry lintRegistry = new LintRegistry();
+
/// Return lints associated with this [context], or an empty list if there are
/// none.
List<Linter> getLints(AnalysisContext context) =>
@@ -35,41 +38,22 @@ abstract class Linter {
/// NOTE: this is set by the framework before visit begins.
ErrorReporter reporter;
+ /// Linter name.
+ String get name;
+
/// Return a visitor to be passed to compilation units to perform lint
/// analysis.
/// Lint errors are reported via this [Linter]'s error [reporter].
AstVisitor getVisitor();
}
-/// Traverses a library's worth of dart code at a time to generate lint warnings
-/// over the set of sources.
-///
-/// See [LintCode].
-class LintGenerator {
- static const List<Linter> _noLints = const <Linter>[];
-
- final Iterable<CompilationUnit> _compilationUnits;
- final AnalysisErrorListener _errorListener;
- final Iterable<Linter> _linters;
-
- LintGenerator(this._compilationUnits, this._errorListener,
- [Iterable<Linter> linters])
- : _linters = linters ?? _noLints;
-
- void generate() {
- PerformanceStatistics.lint.makeCurrentWhile(() {
- _compilationUnits.forEach((cu) {
- if (cu.element != null) {
- _generate(cu, cu.element.source);
- }
- });
- });
- }
+/// Manages lint timing.
+class LintRegistry {
+ /// Dictionary mapping lints (by name) to timers.
+ final Map<String, Stopwatch> timers = new HashMap<String, Stopwatch>();
- void _generate(CompilationUnit unit, Source source) {
- ErrorReporter errorReporter = new ErrorReporter(_errorListener, source);
- _linters.forEach((l) => l.reporter = errorReporter);
- Iterable<AstVisitor> visitors = _linters.map((l) => l.getVisitor());
- unit.accept(new DelegatingAstVisitor(visitors.where((v) => v != null)));
- }
+ /// Get a timer associated with the given lint rule (or create one if none
+ /// exists).
+ Stopwatch getTimer(Linter linter) =>
+ timers.putIfAbsent(linter.name, () => new Stopwatch());
}
« no previous file with comments | « packages/analyzer/lib/src/plugin/plugin_configuration.dart ('k') | packages/analyzer/lib/src/source/source_resource.dart » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698