Chromium Code Reviews| Index: pkg/analyzer/lib/src/summary/incremental_cache.dart |
| diff --git a/pkg/analyzer/lib/src/summary/incremental_cache.dart b/pkg/analyzer/lib/src/summary/incremental_cache.dart |
| index 379b9ae64d8e2731d48c4227054df9dbc002ee9d..91e1d571038b4b63a7c98ef04d29e347389ff2ca 100644 |
| --- a/pkg/analyzer/lib/src/summary/incremental_cache.dart |
| +++ b/pkg/analyzer/lib/src/summary/incremental_cache.dart |
| @@ -8,6 +8,7 @@ import 'dart:core' hide Resource; |
| import 'package:analyzer/dart/element/element.dart'; |
| import 'package:analyzer/file_system/file_system.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/summary/format.dart'; |
| import 'package:analyzer/src/summary/idl.dart'; |
| @@ -159,6 +160,28 @@ class IncrementalCache { |
| } |
| /** |
| + * Return cached errors in the given [source] in the context of the given |
| + * [librarySource], or `null` if the cache does not have this information. |
| + */ |
| + List<AnalysisError> getSourceErrorsInLibrary( |
| + Source librarySource, Source source) { |
| + try { |
| + String key = _getSourceErrorsKey(librarySource, source); |
| + List<int> bytes = storage.get(key); |
| + if (bytes == null) { |
| + return null; |
| + } |
| + CacheSourceErrorsInLibrary errorsObject = |
| + new CacheSourceErrorsInLibrary.fromBuffer(bytes); |
| + return errorsObject.errors |
| + .map((e) => _convertErrorFromCached(source, e)) |
| + .toList(); |
| + } catch (e) { |
| + return null; |
| + } |
| + } |
| + |
| + /** |
| * Return the kind of the given [source], or `null` if unknown. |
| */ |
| SourceKind getSourceKind(Source source) { |
| @@ -189,6 +212,19 @@ class IncrementalCache { |
| } |
| /** |
| + * Associate the given [errors] with the [source] in the [librarySource]. |
| + */ |
| + void putSourceErrorsInLibrary( |
| + Source librarySource, Source source, List<AnalysisError> errors) { |
| + CacheSourceErrorsInLibraryBuilder builder = |
| + new CacheSourceErrorsInLibraryBuilder( |
| + errors: errors.map(_convertErrorToCached).toList()); |
| + String key = _getSourceErrorsKey(librarySource, source); |
| + List<int> bytes = builder.toBuffer(); |
| + storage.put(key, bytes); |
| + } |
| + |
| + /** |
| * Fill the whole source closure of the library with the given |
| * [librarySource]. It includes defining units and parts of the library and |
| * all its directly or indirectly imported or exported libraries. |
| @@ -236,6 +272,31 @@ class IncrementalCache { |
| } |
| /** |
| + * Return the [AnalysisError] to the given [cachedError]. |
| + */ |
| + AnalysisError _convertErrorFromCached( |
| + Source source, CacheAnalysisError cachedError) { |
| + ErrorCode errorCode = _getErrorCode(cachedError); |
| + return new AnalysisError.forValues( |
| + source, |
| + cachedError.offset, |
| + cachedError.length, |
| + errorCode, |
| + cachedError.message, |
| + cachedError.correction); |
| + } |
| + |
| + CacheAnalysisError _convertErrorToCached(AnalysisError e) { |
| + return new CacheAnalysisErrorBuilder( |
| + errorCodeClass: e.errorCode.runtimeType.toString(), |
| + errorCodeField: e.errorCode.name, |
| + offset: e.offset, |
| + length: e.length, |
| + message: e.message, |
| + correction: e.correction); |
| + } |
| + |
| + /** |
| * Get the content based information about the given [source], maybe `null` |
| * if the information is not in the cache. |
| */ |
| @@ -263,6 +324,19 @@ class IncrementalCache { |
| } |
| /** |
| + * Return the [ErrorCode] reference by the given [error], throws if not found. |
|
Paul Berry
2016/06/06 20:03:31
s/reference/referenced/
scheglov
2016/06/06 20:23:52
Fixed.
|
| + */ |
| + ErrorCode _getErrorCode(CacheAnalysisError error) { |
| + String name = '${error.errorCodeClass}.${error.errorCodeField}'; |
| + for (ErrorCode errorCode in ErrorCode.values) { |
|
Paul Berry
2016/06/06 20:03:31
I'm concerned that this is going to wind up being
scheglov
2016/06/06 20:23:52
Good idea.
I've added the corresponding API to Err
|
| + if (errorCode.uniqueName == name) { |
| + return errorCode; |
| + } |
| + } |
| + throw new StateError('Unable to find ErrorCode: $name'); |
| + } |
| + |
| + /** |
| * Get the bundle for the given key. |
| */ |
| PackageBundle _getLibraryBundle(String key) { |
| @@ -327,6 +401,15 @@ class IncrementalCache { |
| }); |
| } |
| + String _getSourceErrorsKey(Source librarySource, Source source) { |
| + List<int> hash = _computeSaltedMD5OfBytes((ByteConversionSink byteSink) { |
| + byteSink.add(_getLibraryClosureHash(librarySource)); |
| + byteSink.add(_getSourceContentHash(source)); |
| + }); |
| + String hashStr = hex.encode(hash); |
| + return '$hashStr.errorsInLibrary'; |
| + } |
| + |
| /** |
| * Return a source representing the URI that results from resolving the given |
| * (possibly relative) [containedUri] against the URI associated with the |