Skip to content

Commit eb5454c

Browse files
authored
AnalysisDriverFilesystem: add modificationStamp to _Resource. (#3835)
1 parent 7995cdd commit eb5454c

File tree

2 files changed

+21
-0
lines changed

2 files changed

+21
-0
lines changed

build_resolvers/lib/src/analysis_driver_filesystem.dart

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -156,12 +156,15 @@ class _Resource implements File, Folder {
156156

157157
_Resource(this.filesystem, this.path);
158158

159+
// `File` and `Folder` methods.
160+
159161
@override
160162
bool get exists => filesystem.exists(path);
161163

162164
@override
163165
String get shortName => filesystem.pathContext.basename(path);
164166

167+
// `File` methods.
165168
@override
166169
Uint8List readAsBytesSync() {
167170
// TODO(davidmorgan): the analyzer reads as bytes in `FileContentCache`
@@ -173,6 +176,15 @@ class _Resource implements File, Folder {
173176
@override
174177
String readAsStringSync() => filesystem.read(path);
175178

179+
// Analyzer methods such as `CompilationUnitElement.source` provide access to
180+
// source and return a `TimestampedData` with this value.
181+
//
182+
// `build_runner` explicitly notifies the analyzer of changes, so it's not
183+
// needed for analysis; and generators should not try to determine which files
184+
// were modified since the last run. So, just return zero.
185+
@override
186+
int get modificationStamp => 0;
187+
176188
// `Folder` methods.
177189

178190
@override

build_resolvers/test/resolver_test.dart

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -51,6 +51,15 @@ void runTests(ResolversFactory resolversFactory) {
5151
}, resolvers: createResolvers());
5252
});
5353

54+
test('provides access to source', () {
55+
return resolveSources({
56+
'a|web/main.dart': ' main() {}',
57+
}, (resolver) async {
58+
var lib = await resolver.libraryFor(entryPoint);
59+
expect(lib.definingCompilationUnit.source.contents.data, ' main() {}');
60+
}, resolvers: createResolvers());
61+
});
62+
5463
test('should follow imports', () {
5564
return resolveSources({
5665
'a|web/main.dart': '''

0 commit comments

Comments
 (0)