Fix implementation of isDartCore and isDartAsync.

It's not sufficient to check the name of the library, since a
user-provided library could always name itself `dart.core` or
`dart.async`.

Change-Id: Id99cfc1ec89c5941e16b556e3c4dd175875a673f
Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/104580
Reviewed-by: Brian Wilkerson <brianwilkerson@google.com>
Commit-Queue: Paul Berry <paulberry@google.com>
diff --git a/pkg/analyzer/lib/src/dart/element/element.dart b/pkg/analyzer/lib/src/dart/element/element.dart
index 53cd4f7..0754e01 100644
--- a/pkg/analyzer/lib/src/dart/element/element.dart
+++ b/pkg/analyzer/lib/src/dart/element/element.dart
@@ -6653,10 +6653,16 @@
       entryPoint != null && isOrImportsBrowserLibrary;
 
   @override
-  bool get isDartAsync => name == "dart.async";
+  bool get isDartAsync {
+    var uri = definingCompilationUnit.source?.uri;
+    return uri != null && DartUriResolver.isDartUri(uri) && uri.path == 'async';
+  }
 
   @override
-  bool get isDartCore => name == "dart.core";
+  bool get isDartCore {
+    var uri = definingCompilationUnit.source?.uri;
+    return uri != null && DartUriResolver.isDartUri(uri) && uri.path == 'core';
+  }
 
   @override
   bool get isInSdk {
diff --git a/pkg/analyzer/lib/src/generated/testing/test_type_provider.dart b/pkg/analyzer/lib/src/generated/testing/test_type_provider.dart
index 82a7821..8ea7304 100644
--- a/pkg/analyzer/lib/src/generated/testing/test_type_provider.dart
+++ b/pkg/analyzer/lib/src/generated/testing/test_type_provider.dart
@@ -481,7 +481,8 @@
           _isNonNullableByDefault);
       var unit = new CompilationUnitElementImpl();
       library.definingCompilationUnit = unit;
-      unit.librarySource = unit.source = new StringSource('', null);
+      unit.librarySource =
+          unit.source = new StringSource('', null, uri: Uri.parse('dart:core'));
 
       nullElement.enclosingElement = library;
       _nullType = nullElement.type;
diff --git a/pkg/analyzer/lib/src/string_source.dart b/pkg/analyzer/lib/src/string_source.dart
index c2f5f1f..7663db4 100644
--- a/pkg/analyzer/lib/src/string_source.dart
+++ b/pkg/analyzer/lib/src/string_source.dart
@@ -23,9 +23,9 @@
   @override
   final int modificationStamp;
 
-  StringSource(this._contents, String fullName)
+  StringSource(this._contents, String fullName, {Uri uri})
       : this.fullName = fullName,
-        uri = fullName == null ? null : new Uri.file(fullName),
+        uri = uri ?? (fullName == null ? null : new Uri.file(fullName)),
         modificationStamp = new DateTime.now().millisecondsSinceEpoch;
 
   @override