OLD | NEW |
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:convert'; | 7 import 'dart:convert'; |
8 | 8 |
9 import 'package:analyzer/dart/ast/ast.dart'; | 9 import 'package:analyzer/dart/ast/ast.dart'; |
10 import 'package:analyzer/dart/ast/token.dart'; | 10 import 'package:analyzer/dart/ast/token.dart'; |
(...skipping 108 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
119 * The set of explicitly analyzed files. | 119 * The set of explicitly analyzed files. |
120 */ | 120 */ |
121 final _explicitFiles = new LinkedHashSet<String>(); | 121 final _explicitFiles = new LinkedHashSet<String>(); |
122 | 122 |
123 /** | 123 /** |
124 * The set of files that are currently scheduled for analysis. | 124 * The set of files that are currently scheduled for analysis. |
125 */ | 125 */ |
126 final _filesToAnalyze = new LinkedHashSet<String>(); | 126 final _filesToAnalyze = new LinkedHashSet<String>(); |
127 | 127 |
128 /** | 128 /** |
129 * The mapping of [Uri]s to the mapping of textual URIs to the [Source] | 129 * Cache of URI resolution. The outer map key is the absolute URI of the |
130 * that correspond in the current [_sourceFactory]. | 130 * containing file. The inner map key is the URI text of a directive |
| 131 * contained in that file. The inner map value is the [Source] object which |
| 132 * that URI text resolves to. |
131 */ | 133 */ |
132 final _uriResolutionCache = <Uri, Map<String, Source>>{}; | 134 final _uriResolutionCache = <Uri, Map<String, Source>>{}; |
133 | 135 |
134 /** | 136 /** |
135 * The current file state. | 137 * The current file state. |
136 * | 138 * |
137 * It maps file paths to the MD5 hash of the file content. | 139 * It maps file paths to the MD5 hash of the file content. |
138 */ | 140 */ |
139 final _fileContentHashMap = <String, String>{}; | 141 final _fileContentHashMap = <String, String>{}; |
140 | 142 |
(...skipping 193 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
334 | 336 |
335 AnalysisContext analysisContext = _createAnalysisContext(libraryContext); | 337 AnalysisContext analysisContext = _createAnalysisContext(libraryContext); |
336 analysisContext.setContents(file.source, file.content); | 338 analysisContext.setContents(file.source, file.content); |
337 try { | 339 try { |
338 // Compute resolved unit. | 340 // Compute resolved unit. |
339 // _logger.runTimed('Computed resolved unit', () { | 341 // _logger.runTimed('Computed resolved unit', () { |
340 // analysisContext.resolveCompilationUnit2( | 342 // analysisContext.resolveCompilationUnit2( |
341 // libraryContext.file.source, libraryContext.file.source); | 343 // libraryContext.file.source, libraryContext.file.source); |
342 // }); | 344 // }); |
343 // Compute errors. | 345 // Compute errors. |
344 List<AnalysisError> errors; | 346 List<AnalysisError> errors = _logger.run('Compute errors', () { |
345 try { | 347 return analysisContext.computeErrors(file.source); |
346 errors = _logger.run('Compute errors', () { | 348 }); |
347 return analysisContext.computeErrors(file.source); | |
348 }); | |
349 } catch (e, st) { | |
350 // TODO(scheglov) why does it fail? | |
351 // Caused by Bad state: Unmatched TypeParameterElementImpl T | |
352 errors = []; | |
353 } | |
354 List<String> errorStrings = errors | 349 List<String> errorStrings = errors |
355 .where((error) => error.errorCode is! TodoCode) | 350 .where((error) => error.errorCode is! TodoCode) |
356 .map((error) => error.toString()) | 351 .map((error) => error.toString()) |
357 .toList(); | 352 .toList(); |
358 { | 353 { |
359 fb.Builder fbBuilder = new fb.Builder(); | 354 fb.Builder fbBuilder = new fb.Builder(); |
360 var exportedOffset = fbBuilder.writeList(errorStrings | 355 var exportedOffset = fbBuilder.writeList(errorStrings |
361 .map((errorStr) => fbBuilder.writeString(errorStr)) | 356 .map((errorStr) => fbBuilder.writeString(errorStr)) |
362 .toList()); | 357 .toList()); |
363 fbBuilder.startTable(); | 358 fbBuilder.startTable(); |
(...skipping 430 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
794 | 789 |
795 return _unit; | 790 return _unit; |
796 } | 791 } |
797 | 792 |
798 Uri get uri => source.uri; | 793 Uri get uri => source.uri; |
799 | 794 |
800 /** | 795 /** |
801 * Return the [_File] for the [uri] referenced in this file. | 796 * Return the [_File] for the [uri] referenced in this file. |
802 */ | 797 */ |
803 _File resolveUri(String uri) { | 798 _File resolveUri(String uri) { |
| 799 // TODO(scheglov) Consider removing this caching after implementing other |
| 800 // optimizations, e.g. changeFile() optimization. |
804 Source uriSource = driver._uriResolutionCache | 801 Source uriSource = driver._uriResolutionCache |
805 .putIfAbsent(this.uri, () => <String, Source>{}) | 802 .putIfAbsent(this.uri, () => <String, Source>{}) |
806 .putIfAbsent(uri, () => driver._sourceFactory.resolveUri(source, uri)); | 803 .putIfAbsent(uri, () => driver._sourceFactory.resolveUri(source, uri)); |
807 return new _File(driver, uriSource); | 804 return new _File(driver, uriSource); |
808 } | 805 } |
809 | 806 |
810 @override | 807 @override |
811 String toString() => uri.toString(); | 808 String toString() => uri.toString(); |
812 | 809 |
813 /** | 810 /** |
(...skipping 141 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
955 | 952 |
956 /** | 953 /** |
957 * TODO(scheglov) document | 954 * TODO(scheglov) document |
958 */ | 955 */ |
959 class _ReferencedUris { | 956 class _ReferencedUris { |
960 bool isLibrary = true; | 957 bool isLibrary = true; |
961 final List<String> imported = <String>[]; | 958 final List<String> imported = <String>[]; |
962 final List<String> exported = <String>[]; | 959 final List<String> exported = <String>[]; |
963 final List<String> parted = <String>[]; | 960 final List<String> parted = <String>[]; |
964 } | 961 } |
OLD | NEW |