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

Unified Diff: pkg/analyzer/lib/src/summary/incremental_cache.dart

Issue 2042883002: Add put/getSourceErrorsInLibrary to IncrementalCache. (Closed) Base URL: git@github.com:dart-lang/sdk.git@master
Patch Set: Fixes for review comments. Created 4 years, 6 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
« no previous file with comments | « pkg/analyzer/lib/src/summary/idl.dart ('k') | pkg/analyzer/test/src/summary/incremental_cache_test.dart » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
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..38f32034b085d545b57e6add288524d9b04d877c 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,33 @@ class IncrementalCache {
}
/**
+ * Return the [AnalysisError] for 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);
+ }
+
+ /**
+ * Return the [CacheAnalysisError] for the given [error].
+ */
+ CacheAnalysisError _convertErrorToCached(AnalysisError error) {
+ return new CacheAnalysisErrorBuilder(
+ errorCodeUniqueName: error.errorCode.uniqueName,
+ offset: error.offset,
+ length: error.length,
+ message: error.message,
+ correction: error.correction);
+ }
+
+ /**
* Get the content based information about the given [source], maybe `null`
* if the information is not in the cache.
*/
@@ -263,6 +326,18 @@ class IncrementalCache {
}
/**
+ * Return the [ErrorCode] of the given [error], throws if not found.
+ */
+ ErrorCode _getErrorCode(CacheAnalysisError error) {
+ String uniqueName = error.errorCodeUniqueName;
+ ErrorCode errorCode = ErrorCode.byUniqueName(uniqueName);
+ if (errorCode != null) {
+ return errorCode;
+ }
+ throw new StateError('Unable to find ErrorCode: $uniqueName');
+ }
+
+ /**
* Get the bundle for the given key.
*/
PackageBundle _getLibraryBundle(String key) {
@@ -328,6 +403,18 @@ class IncrementalCache {
}
/**
+ * Return the key for errors in the [source] in the [librarySource].
+ */
+ 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
* [containingSource], whether or not the resulting source exists, or `null`
« no previous file with comments | « pkg/analyzer/lib/src/summary/idl.dart ('k') | pkg/analyzer/test/src/summary/incremental_cache_test.dart » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698