Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Change from subclassing PhysicalResourceProvider #2341

Merged
merged 2 commits into from
Nov 11, 2020
Merged
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
29 changes: 23 additions & 6 deletions lib/src/test_utilities/test_resource_provider.dart
Original file line number Diff line number Diff line change
Expand Up @@ -7,8 +7,10 @@ import 'dart:io';
import 'package:analyzer/file_system/file_system.dart' as file_system;
import 'package:analyzer/file_system/memory_file_system.dart';
import 'package:analyzer/file_system/physical_file_system.dart';

// ignore: implementation_imports
import 'package:analyzer/src/test_utilities/mock_sdk.dart';
import 'package:path/path.dart' as path;

import '../analyzer.dart';

Expand Down Expand Up @@ -36,26 +38,41 @@ DartLinter buildDriver(LintRule rule, File file, {String analysisOptions}) {

/// A resource provider that accesses entities in a MemoryResourceProvider,
/// falling back to the PhysicalResourceProvider when they don't exist.
class TestResourceProvider extends PhysicalResourceProvider {
MemoryResourceProvider memoryResourceProvider;
class TestResourceProvider extends file_system.ResourceProvider {
final MemoryResourceProvider memoryResourceProvider;
final PhysicalResourceProvider physicalResourceProvider =
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Consider static?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

makes sense - done

PhysicalResourceProvider.INSTANCE;

TestResourceProvider(this.memoryResourceProvider) : super(null);
TestResourceProvider(this.memoryResourceProvider);

@override
file_system.File getFile(String path) {
final file = memoryResourceProvider.getFile(path);
return file.exists ? file : super.getFile(path);
return file.exists ? file : physicalResourceProvider.getFile(path);
}

@override
file_system.Folder getFolder(String path) {
final folder = memoryResourceProvider.getFolder(path);
return folder.exists ? folder : super.getFolder(path);
return folder.exists ? folder : physicalResourceProvider.getFolder(path);
}

@override
file_system.Resource getResource(String path) {
final resource = memoryResourceProvider.getResource(path);
return resource.exists ? resource : super.getResource(path);
return resource.exists
? resource
: physicalResourceProvider.getResource(path);
}

@override
Future<List<int>> getModificationTimes(List<Source> sources) =>
physicalResourceProvider.getModificationTimes(sources);

@override
file_system.Folder getStateLocation(String pluginId) =>
physicalResourceProvider.getStateLocation(pluginId);

@override
path.Context get pathContext => physicalResourceProvider.pathContext;
}