| OLD | NEW |
| 1 // Copyright (c) 2017, the Dart project authors. Please see the AUTHORS file | 1 // Copyright (c) 2017, 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 'package:analyzer/context/declared_variables.dart'; | 5 import 'package:analyzer/context/declared_variables.dart'; |
| 6 import 'package:analyzer/dart/ast/ast.dart'; | 6 import 'package:analyzer/dart/ast/ast.dart'; |
| 7 import 'package:analyzer/dart/ast/token.dart'; | 7 import 'package:analyzer/dart/ast/token.dart'; |
| 8 import 'package:analyzer/dart/element/element.dart'; | 8 import 'package:analyzer/dart/element/element.dart'; |
| 9 import 'package:analyzer/error/error.dart'; | 9 import 'package:analyzer/error/error.dart'; |
| 10 import 'package:analyzer/error/listener.dart'; | 10 import 'package:analyzer/error/listener.dart'; |
| (...skipping 28 matching lines...) Expand all Loading... |
| 39 final SourceFactory _sourceFactory; | 39 final SourceFactory _sourceFactory; |
| 40 final FileSystemState _fsState; | 40 final FileSystemState _fsState; |
| 41 final SummaryDataStore _store; | 41 final SummaryDataStore _store; |
| 42 final FileState _library; | 42 final FileState _library; |
| 43 | 43 |
| 44 TypeProvider _typeProvider; | 44 TypeProvider _typeProvider; |
| 45 AnalysisContextImpl _context; | 45 AnalysisContextImpl _context; |
| 46 StoreBasedSummaryResynthesizer _resynthesizer; | 46 StoreBasedSummaryResynthesizer _resynthesizer; |
| 47 LibraryElement _libraryElement; | 47 LibraryElement _libraryElement; |
| 48 | 48 |
| 49 final Map<FileState, LineInfo> _fileToLineInfo = {}; |
| 50 final Map<FileState, IgnoreInfo> _fileToIgnoreInfo = {}; |
| 51 |
| 49 final Map<FileState, RecordingErrorListener> _errorListeners = {}; | 52 final Map<FileState, RecordingErrorListener> _errorListeners = {}; |
| 50 final Map<FileState, ErrorReporter> _errorReporters = {}; | 53 final Map<FileState, ErrorReporter> _errorReporters = {}; |
| 51 final List<UsedImportedElements> _usedImportedElementsList = []; | 54 final List<UsedImportedElements> _usedImportedElementsList = []; |
| 52 final List<UsedLocalElements> _usedLocalElementsList = []; | 55 final List<UsedLocalElements> _usedLocalElementsList = []; |
| 53 final List<ConstantEvaluationTarget> _constants = []; | 56 final List<ConstantEvaluationTarget> _constants = []; |
| 54 | 57 |
| 55 AnalyzerImpl(this._analysisOptions, this._declaredVariables, | 58 AnalyzerImpl(this._analysisOptions, this._declaredVariables, |
| 56 this._sourceFactory, this._fsState, this._store, this._library); | 59 this._sourceFactory, this._fsState, this._store, this._library); |
| 57 | 60 |
| 58 /** | 61 /** |
| (...skipping 48 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 107 _computeVerifyErrorsAndHints(file, unit); | 110 _computeVerifyErrorsAndHints(file, unit); |
| 108 }); | 111 }); |
| 109 } finally { | 112 } finally { |
| 110 _context.dispose(); | 113 _context.dispose(); |
| 111 } | 114 } |
| 112 | 115 |
| 113 // Return full results. | 116 // Return full results. |
| 114 Map<FileState, UnitAnalysisResult> results = {}; | 117 Map<FileState, UnitAnalysisResult> results = {}; |
| 115 units.forEach((file, unit) { | 118 units.forEach((file, unit) { |
| 116 List<AnalysisError> errors = _getErrorListener(file).errors; | 119 List<AnalysisError> errors = _getErrorListener(file).errors; |
| 120 errors = _filterIgnoredErrors(file, errors); |
| 117 results[file] = new UnitAnalysisResult(file, unit, errors); | 121 results[file] = new UnitAnalysisResult(file, unit, errors); |
| 118 }); | 122 }); |
| 119 return results; | 123 return results; |
| 120 } | 124 } |
| 121 | 125 |
| 122 /** | 126 /** |
| 123 * Compute [_constants] in all units. | 127 * Compute [_constants] in all units. |
| 124 */ | 128 */ |
| 125 void _computeConstants() { | 129 void _computeConstants() { |
| 126 ConstantEvaluationEngine evaluationEngine = new ConstantEvaluationEngine( | 130 ConstantEvaluationEngine evaluationEngine = new ConstantEvaluationEngine( |
| (...skipping 129 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 256 void _createAnalysisContext() { | 260 void _createAnalysisContext() { |
| 257 AnalysisContextImpl analysisContext = | 261 AnalysisContextImpl analysisContext = |
| 258 AnalysisEngine.instance.createAnalysisContext(); | 262 AnalysisEngine.instance.createAnalysisContext(); |
| 259 analysisContext.analysisOptions = _analysisOptions; | 263 analysisContext.analysisOptions = _analysisOptions; |
| 260 analysisContext.declaredVariables.addAll(_declaredVariables); | 264 analysisContext.declaredVariables.addAll(_declaredVariables); |
| 261 analysisContext.sourceFactory = _sourceFactory.clone(); | 265 analysisContext.sourceFactory = _sourceFactory.clone(); |
| 262 analysisContext.contentCache = new _ContentCacheWrapper(_fsState); | 266 analysisContext.contentCache = new _ContentCacheWrapper(_fsState); |
| 263 this._context = analysisContext; | 267 this._context = analysisContext; |
| 264 } | 268 } |
| 265 | 269 |
| 270 /** |
| 271 * Return a subset of the given [errors] that are not marked as ignored in |
| 272 * the [file]. |
| 273 */ |
| 274 List<AnalysisError> _filterIgnoredErrors( |
| 275 FileState file, List<AnalysisError> errors) { |
| 276 if (errors.isEmpty) { |
| 277 return errors; |
| 278 } |
| 279 |
| 280 IgnoreInfo ignoreInfo = _fileToIgnoreInfo[file]; |
| 281 if (!ignoreInfo.hasIgnores) { |
| 282 return errors; |
| 283 } |
| 284 |
| 285 LineInfo lineInfo = _fileToLineInfo[file]; |
| 286 |
| 287 bool isIgnored(AnalysisError error) { |
| 288 int errorLine = lineInfo.getLocation(error.offset).lineNumber; |
| 289 String errorCode = error.errorCode.name.toLowerCase(); |
| 290 // Ignores can be on the line or just preceding the error. |
| 291 return ignoreInfo.ignoredAt(errorCode, errorLine) || |
| 292 ignoreInfo.ignoredAt(errorCode, errorLine - 1); |
| 293 } |
| 294 |
| 295 return errors.where((AnalysisError e) => !isIgnored(e)).toList(); |
| 296 } |
| 297 |
| 266 RecordingErrorListener _getErrorListener(FileState file) => | 298 RecordingErrorListener _getErrorListener(FileState file) => |
| 267 _errorListeners.putIfAbsent(file, () => new RecordingErrorListener()); | 299 _errorListeners.putIfAbsent(file, () => new RecordingErrorListener()); |
| 268 | 300 |
| 269 ErrorReporter _getErrorReporter(FileState file) { | 301 ErrorReporter _getErrorReporter(FileState file) { |
| 270 return _errorReporters.putIfAbsent(file, () { | 302 return _errorReporters.putIfAbsent(file, () { |
| 271 RecordingErrorListener listener = _getErrorListener(file); | 303 RecordingErrorListener listener = _getErrorListener(file); |
| 272 return new ErrorReporter(listener, file.source); | 304 return new ErrorReporter(listener, file.source); |
| 273 }); | 305 }); |
| 274 } | 306 } |
| 275 | 307 |
| (...skipping 21 matching lines...) Expand all Loading... |
| 297 } | 329 } |
| 298 return null; | 330 return null; |
| 299 } | 331 } |
| 300 | 332 |
| 301 /** | 333 /** |
| 302 * Return a new parsed unresolved [CompilationUnit]. | 334 * Return a new parsed unresolved [CompilationUnit]. |
| 303 */ | 335 */ |
| 304 CompilationUnit _parse(FileState file) { | 336 CompilationUnit _parse(FileState file) { |
| 305 RecordingErrorListener errorListener = _getErrorListener(file); | 337 RecordingErrorListener errorListener = _getErrorListener(file); |
| 306 | 338 |
| 307 CharSequenceReader reader = new CharSequenceReader(file.content); | 339 String content = file.content; |
| 340 |
| 341 CharSequenceReader reader = new CharSequenceReader(content); |
| 308 Scanner scanner = new Scanner(file.source, reader, errorListener); | 342 Scanner scanner = new Scanner(file.source, reader, errorListener); |
| 309 scanner.scanGenericMethodComments = _analysisOptions.strongMode; | 343 scanner.scanGenericMethodComments = _analysisOptions.strongMode; |
| 310 Token token = scanner.tokenize(); | 344 Token token = scanner.tokenize(); |
| 311 LineInfo lineInfo = new LineInfo(scanner.lineStarts); | 345 LineInfo lineInfo = new LineInfo(scanner.lineStarts); |
| 312 | 346 |
| 347 _fileToLineInfo[file] = lineInfo; |
| 348 _fileToIgnoreInfo[file] = IgnoreInfo.calculateIgnores(content, lineInfo); |
| 349 |
| 313 Parser parser = new Parser(file.source, errorListener); | 350 Parser parser = new Parser(file.source, errorListener); |
| 314 parser.parseGenericMethodComments = _analysisOptions.strongMode; | 351 parser.parseGenericMethodComments = _analysisOptions.strongMode; |
| 315 parser.enableUriInPartOf = _analysisOptions.enableUriInPartOf; | 352 parser.enableUriInPartOf = _analysisOptions.enableUriInPartOf; |
| 316 CompilationUnit unit = parser.parseCompilationUnit(token); | 353 CompilationUnit unit = parser.parseCompilationUnit(token); |
| 317 unit.lineInfo = lineInfo; | 354 unit.lineInfo = lineInfo; |
| 318 return unit; | 355 return unit; |
| 319 } | 356 } |
| 320 | 357 |
| 321 void _resolveDirectives(Map<FileState, CompilationUnit> units) { | 358 void _resolveDirectives(Map<FileState, CompilationUnit> units) { |
| 322 CompilationUnit definingCompilationUnit = units[_library]; | 359 CompilationUnit definingCompilationUnit = units[_library]; |
| (...skipping 354 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 677 } | 714 } |
| 678 | 715 |
| 679 /** | 716 /** |
| 680 * Either the name or the source associated with a part-of directive. | 717 * Either the name or the source associated with a part-of directive. |
| 681 */ | 718 */ |
| 682 class _NameOrSource { | 719 class _NameOrSource { |
| 683 final String name; | 720 final String name; |
| 684 final Source source; | 721 final Source source; |
| 685 _NameOrSource(this.name, this.source); | 722 _NameOrSource(this.name, this.source); |
| 686 } | 723 } |
| OLD | NEW |