Skip to content

Commit

Permalink
AnalysisDriverFilesystem: add modificationStamp to _Resource. (#3835
Browse files Browse the repository at this point in the history
)
  • Loading branch information
davidmorgan authored Feb 7, 2025
1 parent 7995cdd commit eb5454c
Show file tree
Hide file tree
Showing 2 changed files with 21 additions and 0 deletions.
12 changes: 12 additions & 0 deletions build_resolvers/lib/src/analysis_driver_filesystem.dart
Original file line number Diff line number Diff line change
Expand Up @@ -156,12 +156,15 @@ class _Resource implements File, Folder {

_Resource(this.filesystem, this.path);

// `File` and `Folder` methods.

@override
bool get exists => filesystem.exists(path);

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

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

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

// `Folder` methods.

@override
Expand Down
9 changes: 9 additions & 0 deletions build_resolvers/test/resolver_test.dart
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,15 @@ void runTests(ResolversFactory resolversFactory) {
}, resolvers: createResolvers());
});

test('provides access to source', () {
return resolveSources({
'a|web/main.dart': ' main() {}',
}, (resolver) async {
var lib = await resolver.libraryFor(entryPoint);
expect(lib.definingCompilationUnit.source.contents.data, ' main() {}');
}, resolvers: createResolvers());
});

test('should follow imports', () {
return resolveSources({
'a|web/main.dart': '''
Expand Down

0 comments on commit eb5454c

Please sign in to comment.