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

Unified Diff: pkg/analyzer/lib/src/dart/analysis/file_state.dart

Issue 2473473002: Use FileContentOverlay instead of ContentCache in the new driver. (Closed)
Patch Set: Created 4 years, 1 month 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
Index: pkg/analyzer/lib/src/dart/analysis/file_state.dart
diff --git a/pkg/analyzer/lib/src/dart/analysis/file_state.dart b/pkg/analyzer/lib/src/dart/analysis/file_state.dart
index 4842d2805d683887a85fd0d7f974aa5d26d28a3f..5b172a9633ecdea550c408c4a0b4ea1edf47c70c 100644
--- a/pkg/analyzer/lib/src/dart/analysis/file_state.dart
+++ b/pkg/analyzer/lib/src/dart/analysis/file_state.dart
@@ -22,6 +22,30 @@ import 'package:convert/convert.dart';
import 'package:crypto/crypto.dart';
/**
+ * [FileContentOverlay] is used to temporary override content of files.
+ */
+class FileContentOverlay {
+ final _map = <String, String>{};
+
+ /**
+ * Return the content of the file with the given [path], or `null` the
+ * overlay does not override the content of the file.
+ *
+ * The [path] must be absolute and normalized.
+ */
+ String operator [](String path) => _map[path];
+
+ /**
+ * Return the new [content] of the file with the given [path].
+ *
+ * The [path] must be absolute and normalized.
+ */
+ void operator []=(String path, String content) {
+ _map[path] = content;
Paul Berry 2016/11/01 19:37:31 If content is `null`, we should do `_map.remove(pa
+ }
+}
+
+/**
* Information about a file being analyzed, explicitly or implicitly.
*
* It provides a consistent view on its properties.
@@ -103,8 +127,8 @@ class FileState {
bool refresh() {
// Read the content.
try {
- _content = _fsState._contentCache.getContents(source);
- _content ??= source.contents.data;
+ _content = _fsState._contentOverlay[path];
+ _content ??= _fsState._resourceProvider.getFile(path).readAsStringSync();
} catch (_) {
_content = '';
// TODO(scheglov) We fail to report URI_DOES_NOT_EXIST.
@@ -163,6 +187,9 @@ class FileState {
return apiSignatureChanged;
}
+ @override
+ String toString() => path;
+
/**
* Return the [FileState] for the given [relativeUri].
*/
@@ -219,13 +246,13 @@ class FileSystemState {
final PerformanceLog _logger;
final ResourceProvider _resourceProvider;
final ByteStore _byteStore;
- final ContentCache _contentCache;
+ final FileContentOverlay _contentOverlay;
final SourceFactory _sourceFactory;
final AnalysisOptions _analysisOptions;
final Map<String, FileState> _pathToFile = <String, FileState>{};
- FileSystemState(this._logger, this._byteStore, this._contentCache,
+ FileSystemState(this._logger, this._byteStore, this._contentOverlay,
this._resourceProvider, this._sourceFactory, this._analysisOptions);
/**
« no previous file with comments | « pkg/analyzer/lib/src/dart/analysis/driver.dart ('k') | pkg/analyzer/test/src/dart/analysis/driver_test.dart » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698