Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(22)

Unified Diff: pkg/analyzer/lib/src/dart/element/element.dart

Issue 3000913002: Add implicit dart:core import when resynthsize from Kernel. (Closed)
Patch Set: Created 3 years, 4 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
« no previous file with comments | « no previous file | pkg/analyzer/lib/src/kernel/resynthesize.dart » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: pkg/analyzer/lib/src/dart/element/element.dart
diff --git a/pkg/analyzer/lib/src/dart/element/element.dart b/pkg/analyzer/lib/src/dart/element/element.dart
index 122de77747d5d01faa4d22802c298c7d936616dc..2f2e18798cfb06412e3f5dbb7d9b0a2254165f01 100644
--- a/pkg/analyzer/lib/src/dart/element/element.dart
+++ b/pkg/analyzer/lib/src/dart/element/element.dart
@@ -5785,6 +5785,11 @@ class ImportElementImpl extends UriReferencedElementImpl
*/
final kernel.LibraryDependency _kernel;
+ /**
+ * Whether this import is synthetic.
+ */
+ final bool _kernelSynthetic;
+
/**
* The offset of the prefix of this import in the file that contains the this
* import directive, or `-1` if this import is synthetic.
@@ -5821,14 +5826,17 @@ class ImportElementImpl extends UriReferencedElementImpl
: _unlinkedImport = null,
_linkedDependency = null,
_kernel = null,
+ _kernelSynthetic = false,
super(null, offset);
/**
* Initialize using the given kernel.
*/
- ImportElementImpl.forKernel(LibraryElementImpl enclosingLibrary, this._kernel)
+ ImportElementImpl.forKernel(LibraryElementImpl enclosingLibrary, this._kernel,
+ {bool isSynthetic: false})
: _unlinkedImport = null,
_linkedDependency = null,
+ _kernelSynthetic = isSynthetic,
super.forSerialized(enclosingLibrary);
/**
@@ -5837,6 +5845,7 @@ class ImportElementImpl extends UriReferencedElementImpl
ImportElementImpl.forSerialized(this._unlinkedImport, this._linkedDependency,
LibraryElementImpl enclosingLibrary)
: _kernel = null,
+ _kernelSynthetic = false,
super.forSerialized(enclosingLibrary);
@override
@@ -5907,6 +5916,9 @@ class ImportElementImpl extends UriReferencedElementImpl
@override
bool get isSynthetic {
+ if (_kernel != null) {
+ return _kernelSynthetic;
+ }
if (_unlinkedImport != null) {
return _unlinkedImport.isImplicit;
}
@@ -6083,6 +6095,14 @@ class ImportElementImpl extends UriReferencedElementImpl
* The kernel context in which a library is resynthesized.
*/
abstract class KernelLibraryResynthesizerContext {
+ /**
+ * The Kernel library for `dart:core`.
+ */
+ kernel.Library get coreLibrary;
+
+ /**
+ * The Kernel library being resynthesized.
+ */
kernel.Library get library;
/**
@@ -6234,6 +6254,8 @@ class LabelElementImpl extends ElementImpl implements LabelElement {
* A concrete implementation of a [LibraryElement].
*/
class LibraryElementImpl extends ElementImpl implements LibraryElement {
+ static final Uri _dartCore = Uri.parse('dart:core');
+
/**
* The analysis context in which this library is defined.
*/
@@ -6547,10 +6569,36 @@ class LibraryElementImpl extends ElementImpl implements LibraryElement {
List<ImportElement> get imports {
if (_imports == null) {
if (_kernelContext != null) {
- _imports = _kernelContext.library.dependencies
- .where((k) => k.isImport)
- .map((k) => new ImportElementImpl.forKernel(this, k))
- .toList(growable: false);
+ var dependencies = _kernelContext.library.dependencies;
+ int numOfDependencies = dependencies.length;
+ // Compute the number of import dependencies.
+ bool hasCore = false;
+ int numOfImports = 0;
+ for (int i = 0; i < numOfDependencies; i++) {
+ kernel.LibraryDependency dependency = dependencies[i];
+ if (dependency.isImport) {
+ numOfImports++;
+ if (dependency.targetLibrary.importUri == _dartCore) {
+ hasCore = true;
+ }
+ }
+ }
+ // Create import elements.
+ var imports = new List<ImportElement>(numOfImports + (hasCore ? 0 : 1));
+ for (int i = 0; i < numOfDependencies; i++) {
+ kernel.LibraryDependency dependency = dependencies[i];
+ if (dependency.isImport) {
+ imports[i] = new ImportElementImpl.forKernel(this, dependency);
+ }
+ }
+ // If dart:core is not imported explicitly, import it implicitly.
+ if (!hasCore) {
+ imports[numOfImports] = new ImportElementImpl.forKernel(this,
+ new kernel.LibraryDependency.import(_kernelContext.coreLibrary),
+ isSynthetic: true);
+ }
+ // Set imports into the field.
+ _imports = imports;
}
if (_unlinkedDefiningUnit != null) {
List<UnlinkedImport> unlinkedImports = _unlinkedDefiningUnit.imports;
« no previous file with comments | « no previous file | pkg/analyzer/lib/src/kernel/resynthesize.dart » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698