From d29c5d3a72aa41fa82dee4a0bbb31320848fa5f7 Mon Sep 17 00:00:00 2001 From: Brian Wilkerson Date: Thu, 29 Jun 2017 13:51:43 -0700 Subject: [PATCH] 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 . --- pkg/analyzer/lib/src/dart/sdk/sdk.dart | 8 +++++++- pkg/analyzer/lib/src/summary/summarize_ast.dart | 3 ++- pkg/analyzer/test/src/context/source_test.dart | 2 -- pkg/analyzer/test/src/dart/sdk/sdk_test.dart | 11 +++++++++++ 4 files changed, 20 insertions(+), 4 deletions(-) diff --git a/pkg/analyzer/lib/src/dart/sdk/sdk.dart b/pkg/analyzer/lib/src/dart/sdk/sdk.dart index a6c49083fde..cfed575fb98 100644 --- a/pkg/analyzer/lib/src/dart/sdk/sdk.dart +++ b/pkg/analyzer/lib/src/dart/sdk/sdk.dart @@ -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 { diff --git a/pkg/analyzer/lib/src/summary/summarize_ast.dart b/pkg/analyzer/lib/src/summary/summarize_ast.dart index 2ca188cf564..e1d45ce408f 100644 --- a/pkg/analyzer/lib/src/summary/summarize_ast.dart +++ b/pkg/analyzer/lib/src/summary/summarize_ast.dart @@ -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; } diff --git a/pkg/analyzer/test/src/context/source_test.dart b/pkg/analyzer/test/src/context/source_test.dart index 7d63c4575bd..2857e8632ed 100644 --- a/pkg/analyzer/test/src/context/source_test.dart +++ b/pkg/analyzer/test/src/context/source_test.dart @@ -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'; diff --git a/pkg/analyzer/test/src/dart/sdk/sdk_test.dart b/pkg/analyzer/test/src/dart/sdk/sdk_test.dart index 3abf7c2625d..e2d9071139b 100644 --- a/pkg/analyzer/test/src/dart/sdk/sdk_test.dart +++ b/pkg/analyzer/test/src/dart/sdk/sdk_test.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;