Fix the resolution of uri-based part-of directives in the SDK (issue 29598)

R=scheglov@google.com

Review-Url: https://codereview.chromium.org/2967503002 .
This commit is contained in:
Brian Wilkerson
2017-06-29 13:51:43 -07:00
parent f4750db137
commit d29c5d3a72
4 changed files with 20 additions and 4 deletions
+7 -1
View File
@@ -651,7 +651,13 @@ class FolderBasedDartSdk extends AbstractDartSdk {
try {
File file = libraryDirectory.getChildAssumingFile(library.path);
if (!relativePath.isEmpty) {
file = file.parent.getChildAssumingFile(relativePath);
File relativeFile = file.parent.getChildAssumingFile(relativePath);
if (relativeFile.path == file.path) {
// The relative file is the library, so return a Source for the
// library rather than the part format.
return file.createSource(Uri.parse(library.shortName));
}
file = relativeFile;
}
return file.createSource(Uri.parse(dartUri));
} on FormatException {
@@ -1437,7 +1437,8 @@ class _SummarizeAstVisitor extends RecursiveAstVisitor {
@override
void visitPartOfDirective(PartOfDirective node) {
isCoreLibrary = node.libraryName?.name == 'dart.core';
isCoreLibrary = node.libraryName?.name == 'dart.core' ||
node.uri?.stringValue == 'core.dart';
isPartOf = true;
}
@@ -2,8 +2,6 @@
// for details. All rights reserved. Use of this source code is governed by a
// BSD-style license that can be found in the LICENSE file.
library analyzer.test.src.context.source_test;
import 'package:analyzer/file_system/file_system.dart';
import 'package:analyzer/src/context/source.dart';
import 'package:analyzer/src/generated/source.dart';
@@ -250,6 +250,17 @@ class FolderBasedDartSdkTest {
expect(version.length > 0, isTrue);
}
/**
* The "part" format should result in the same source as the non-part format
* when the file is the library file.
*/
void test_mapDartUri_partFormatForLibrary() {
FolderBasedDartSdk sdk = _createDartSdk();
Source normalSource = sdk.mapDartUri('dart:core');
Source partSource = sdk.mapDartUri('dart:core/core.dart');
expect(partSource, normalSource);
}
void test_useSummary_afterContextCreation() {
FolderBasedDartSdk sdk = _createDartSdk();
sdk.context;