Change ResourceUriResolver to accept any file URI.

We don't really need to check that the corresponding resource is
a file. Now it is a file, or a directory, the moment later it is not.
We will try to read it, if we can - fine, if not - it does not exist.

This makes my Flutter analysis benchmark about 3% faster.

R=brianwilkerson@google.com

Change-Id: I955be276c7a694a408c70f8f2d47dce75594ebc8
Reviewed-on: https://dart-review.googlesource.com/77243
Reviewed-by: Brian Wilkerson <brianwilkerson@google.com>
Commit-Queue: Konstantin Shcheglov <scheglov@google.com>
This commit is contained in:
Konstantin Shcheglov 2018-09-29 17:23:00 +00:00 committed by commit-bot@chromium.org
parent 6c577f0620
commit 25c659934a
4 changed files with 8 additions and 9 deletions

View file

@ -27,11 +27,8 @@ class ResourceUriResolver extends UriResolver {
return null;
}
String path = fileUriToNormalizedPath(_provider.pathContext, uri);
Resource resource = _provider.getResource(path);
if (resource is File) {
return resource.createSource(actualUri ?? uri);
}
return null;
File file = _provider.getFile(path);
return file.createSource(actualUri ?? uri);
}
@override

View file

@ -42,7 +42,9 @@ class ResourceUriResolverTest {
void test_resolveAbsolute_folder() {
var uri = provider.pathContext.toUri(provider.convertPath('/folder'));
Source source = resolver.resolveAbsolute(uri);
expect(source, isNull);
expect(source, isNotNull);
expect(source.exists(), isFalse);
expect(source.fullName, provider.convertPath('/folder'));
}
void test_resolveAbsolute_notFile_dartUri() {

View file

@ -7417,9 +7417,9 @@ unit: b.dart
var library = await checkLibrary('library my.lib; part "foo/";');
checkElementText(library, r'''
library my.lib;
part '<unresolved>';
part '';
--------------------
unit: null
unit: foo
''');
}

View file

@ -895,7 +895,7 @@ library lib;
part '$invalidUri';
'''
});
expect(libraryElement.parts, isEmpty);
expect(libraryElement.parts, hasLength(1));
}
test_perform_isLaunchable_inDefiningUnit() {