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

Side by Side Diff: pkg/analyzer/lib/src/dart/analysis/driver.dart

Issue 2545553007: Add support for generating lints when using the new driver (Closed)
Patch Set: Created 4 years 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
OLDNEW
1 // Copyright (c) 2016, the Dart project authors. Please see the AUTHORS file 1 // Copyright (c) 2016, 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 import 'dart:async'; 5 import 'dart:async';
6 import 'dart:collection'; 6 import 'dart:collection';
7 import 'dart:typed_data'; 7 import 'dart:typed_data';
8 8
9 import 'package:analyzer/dart/ast/ast.dart'; 9 import 'package:analyzer/dart/ast/ast.dart';
10 import 'package:analyzer/dart/element/element.dart' show CompilationUnitElement; 10 import 'package:analyzer/dart/element/element.dart' show CompilationUnitElement;
11 import 'package:analyzer/error/error.dart'; 11 import 'package:analyzer/error/error.dart';
12 import 'package:analyzer/error/listener.dart'; 12 import 'package:analyzer/error/listener.dart';
13 import 'package:analyzer/file_system/file_system.dart'; 13 import 'package:analyzer/file_system/file_system.dart';
14 import 'package:analyzer/src/context/context.dart'; 14 import 'package:analyzer/src/context/context.dart';
15 import 'package:analyzer/src/dart/analysis/byte_store.dart'; 15 import 'package:analyzer/src/dart/analysis/byte_store.dart';
16 import 'package:analyzer/src/dart/analysis/file_state.dart'; 16 import 'package:analyzer/src/dart/analysis/file_state.dart';
17 import 'package:analyzer/src/dart/analysis/index.dart'; 17 import 'package:analyzer/src/dart/analysis/index.dart';
18 import 'package:analyzer/src/dart/analysis/search.dart'; 18 import 'package:analyzer/src/dart/analysis/search.dart';
19 import 'package:analyzer/src/dart/analysis/status.dart'; 19 import 'package:analyzer/src/dart/analysis/status.dart';
20 import 'package:analyzer/src/dart/analysis/top_level_declaration.dart'; 20 import 'package:analyzer/src/dart/analysis/top_level_declaration.dart';
21 import 'package:analyzer/src/generated/engine.dart' 21 import 'package:analyzer/src/generated/engine.dart'
22 show AnalysisContext, AnalysisEngine, AnalysisOptions, ChangeSet; 22 show AnalysisContext, AnalysisEngine, AnalysisOptions, ChangeSet;
23 import 'package:analyzer/src/generated/source.dart'; 23 import 'package:analyzer/src/generated/source.dart';
24 import 'package:analyzer/src/services/lint.dart';
24 import 'package:analyzer/src/summary/api_signature.dart'; 25 import 'package:analyzer/src/summary/api_signature.dart';
25 import 'package:analyzer/src/summary/format.dart'; 26 import 'package:analyzer/src/summary/format.dart';
26 import 'package:analyzer/src/summary/idl.dart'; 27 import 'package:analyzer/src/summary/idl.dart';
27 import 'package:analyzer/src/summary/link.dart'; 28 import 'package:analyzer/src/summary/link.dart';
28 import 'package:analyzer/src/summary/package_bundle_reader.dart'; 29 import 'package:analyzer/src/summary/package_bundle_reader.dart';
29 import 'package:analyzer/src/task/dart.dart' show COMPILATION_UNIT_ELEMENT; 30 import 'package:analyzer/src/task/dart.dart' show COMPILATION_UNIT_ELEMENT;
30 import 'package:analyzer/task/dart.dart' show LibrarySpecificUnit; 31 import 'package:analyzer/task/dart.dart' show LibrarySpecificUnit;
31 32
32 /** 33 /**
33 * This class computes [AnalysisResult]s for Dart files. 34 * This class computes [AnalysisResult]s for Dart files.
(...skipping 708 matching lines...) Expand 10 before | Expand all | Expand 10 after
742 /** 743 /**
743 * Load the [AnalysisResult] for the given [file] from the [bytes]. Set 744 * Load the [AnalysisResult] for the given [file] from the [bytes]. Set
744 * optional [content] and [resolvedUnit]. 745 * optional [content] and [resolvedUnit].
745 */ 746 */
746 AnalysisResult _getAnalysisResultFromBytes( 747 AnalysisResult _getAnalysisResultFromBytes(
747 FileState libraryFile, FileState file, List<int> bytes, 748 FileState libraryFile, FileState file, List<int> bytes,
748 {String content, CompilationUnit resolvedUnit}) { 749 {String content, CompilationUnit resolvedUnit}) {
749 var unit = new AnalysisDriverResolvedUnit.fromBuffer(bytes); 750 var unit = new AnalysisDriverResolvedUnit.fromBuffer(bytes);
750 List<AnalysisError> errors = unit.errors.map((error) { 751 List<AnalysisError> errors = unit.errors.map((error) {
751 String errorName = error.uniqueName; 752 String errorName = error.uniqueName;
752 ErrorCode errorCode = errorCodeByUniqueName(errorName); 753 ErrorCode errorCode =
754 errorCodeByUniqueName(errorName) ?? _lintCodeByUniqueName(errorName);
753 if (errorCode == null) { 755 if (errorCode == null) {
756 // This could fail because the error code is no longer defined, or, in
757 // the case of a lint rule, if the lint rule has been disabled since the
758 // errors were written.
754 throw new StateError('No ErrorCode for $errorName in $file'); 759 throw new StateError('No ErrorCode for $errorName in $file');
755 } 760 }
756 return new AnalysisError.forValues(file.source, error.offset, 761 return new AnalysisError.forValues(file.source, error.offset,
757 error.length, errorCode, error.message, error.correction); 762 error.length, errorCode, error.message, error.correction);
758 }).toList(); 763 }).toList();
759 return new AnalysisResult( 764 return new AnalysisResult(
760 libraryFile, 765 libraryFile,
761 file, 766 file,
762 sourceFactory, 767 sourceFactory,
763 file.path, 768 file.path,
(...skipping 13 matching lines...) Expand all
777 */ 782 */
778 String _getResolvedUnitKey(FileState library, FileState file) { 783 String _getResolvedUnitKey(FileState library, FileState file) {
779 ApiSignature signature = new ApiSignature(); 784 ApiSignature signature = new ApiSignature();
780 signature.addUint32List(_salt); 785 signature.addUint32List(_salt);
781 signature.addString(library.transitiveSignature); 786 signature.addString(library.transitiveSignature);
782 signature.addString(file.contentHash); 787 signature.addString(file.contentHash);
783 return '${signature.toHex()}.resolved'; 788 return '${signature.toHex()}.resolved';
784 } 789 }
785 790
786 /** 791 /**
792 * Return the lint code with the given [errorName], or `null` if there is no
793 * lint registered with that name or the lint is not enabled in the analysis
794 * options.
795 */
796 ErrorCode _lintCodeByUniqueName(String errorName) {
797 if (errorName.startsWith('_LintCode.')) {
798 String lintName = errorName.substring(10);
799 List<Linter> lintRules = analysisOptions.lintRules;
800 for (Linter linter in lintRules) {
801 if (linter.name == lintName) {
802 return linter.lintCode;
803 }
804 }
805 }
806 return null;
807 }
808
809 /**
787 * Perform a single chunk of work and produce [results]. 810 * Perform a single chunk of work and produce [results].
788 */ 811 */
789 Future<Null> _performWork() async { 812 Future<Null> _performWork() async {
790 // Verify all changed files one at a time. 813 // Verify all changed files one at a time.
791 if (_changedFiles.isNotEmpty) { 814 if (_changedFiles.isNotEmpty) {
792 String path = _removeFirst(_changedFiles); 815 String path = _removeFirst(_changedFiles);
793 _verifyApiSignature(path); 816 _verifyApiSignature(path);
794 return; 817 return;
795 } 818 }
796 819
(...skipping 170 matching lines...) Expand 10 before | Expand all | Expand 10 after
967 final PerformanceLog _logger; 990 final PerformanceLog _logger;
968 final List<AnalysisDriver> _drivers = []; 991 final List<AnalysisDriver> _drivers = [];
969 final Monitor _hasWork = new Monitor(); 992 final Monitor _hasWork = new Monitor();
970 final StatusSupport _statusSupport = new StatusSupport(); 993 final StatusSupport _statusSupport = new StatusSupport();
971 994
972 bool _started = false; 995 bool _started = false;
973 996
974 AnalysisDriverScheduler(this._logger); 997 AnalysisDriverScheduler(this._logger);
975 998
976 /** 999 /**
1000 * Return `true` if we are currently analyzing code.
1001 */
1002 bool get isAnalyzing =>
1003 _statusSupport.currentStatus == AnalysisStatus.ANALYZING;
1004
1005 /**
977 * Return the stream that produces [AnalysisStatus] events. 1006 * Return the stream that produces [AnalysisStatus] events.
978 */ 1007 */
979 Stream<AnalysisStatus> get status => _statusSupport.stream; 1008 Stream<AnalysisStatus> get status => _statusSupport.stream;
980 1009
981 /** 1010 /**
982 * Start the scheduler, so that any [AnalysisDriver] created before or 1011 * Start the scheduler, so that any [AnalysisDriver] created before or
983 * after will be asked to perform work. 1012 * after will be asked to perform work.
984 */ 1013 */
985 void start() { 1014 void start() {
986 if (_started) { 1015 if (_started) {
(...skipping 406 matching lines...) Expand 10 before | Expand all | Expand 10 after
1393 libraryDeclarations 1422 libraryDeclarations
1394 .add(new TopLevelDeclarationInSource(file.source, declaration)); 1423 .add(new TopLevelDeclarationInSource(file.source, declaration));
1395 } 1424 }
1396 } 1425 }
1397 } 1426 }
1398 1427
1399 // We're not done yet. 1428 // We're not done yet.
1400 return false; 1429 return false;
1401 } 1430 }
1402 } 1431 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698