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 9563b27f54ee02b4b848e4d9d07c6670b114ce1d..e3be98e5da43eab3faa5f564accfa02fe9de64ab 100644 |
--- a/pkg/analyzer/lib/src/dart/element/element.dart |
+++ b/pkg/analyzer/lib/src/dart/element/element.dart |
@@ -1909,6 +1909,13 @@ class ConstFieldElementImpl extends FieldElementImpl with ConstVariableElement { |
ConstFieldElementImpl(String name, int offset) : super(name, offset); |
/** |
+ * Initialize using the given kernel. |
+ */ |
+ ConstFieldElementImpl.forKernel( |
+ ElementImpl enclosingElement, kernel.Field kernel) |
+ : super.forKernel(enclosingElement, kernel); |
+ |
+ /** |
* Initialize a newly created field element to have the given [name]. |
*/ |
ConstFieldElementImpl.forNode(Identifier name) : super.forNode(name); |
@@ -1919,13 +1926,6 @@ class ConstFieldElementImpl extends FieldElementImpl with ConstVariableElement { |
ConstFieldElementImpl.forSerialized( |
UnlinkedVariable unlinkedVariable, ElementImpl enclosingElement) |
: super.forSerialized(unlinkedVariable, enclosingElement); |
- |
- /** |
- * Initialize using the given kernel. |
- */ |
- ConstFieldElementImpl.forKernel( |
- ElementImpl enclosingElement, kernel.Field kernel) |
- : super.forKernel(enclosingElement, kernel); |
} |
/** |
@@ -5481,6 +5481,11 @@ class ImportElementImpl extends ElementImpl implements ImportElement { |
final int _linkedDependency; |
/** |
+ * The kernel of the element. |
+ */ |
+ final kernel.LibraryDependency _kernel; |
+ |
+ /** |
* The offset of the prefix of this import in the file that contains the this |
* import directive, or `-1` if this import is synthetic. |
*/ |
@@ -5510,14 +5515,24 @@ class ImportElementImpl extends ElementImpl implements ImportElement { |
ImportElementImpl(int offset) |
: _unlinkedImport = null, |
_linkedDependency = null, |
+ _kernel = null, |
super(null, offset); |
/** |
+ * Initialize using the given kernel. |
+ */ |
+ ImportElementImpl.forKernel(LibraryElementImpl enclosingLibrary, this._kernel) |
+ : _unlinkedImport = null, |
+ _linkedDependency = null, |
+ super.forSerialized(enclosingLibrary); |
+ |
+ /** |
* Initialize using the given serialized information. |
*/ |
ImportElementImpl.forSerialized(this._unlinkedImport, this._linkedDependency, |
LibraryElementImpl enclosingLibrary) |
- : super.forSerialized(enclosingLibrary); |
+ : _kernel = null, |
+ super.forSerialized(enclosingLibrary); |
@override |
List<NamespaceCombinator> get combinators { |
@@ -5545,6 +5560,14 @@ class ImportElementImpl extends ElementImpl implements ImportElement { |
@override |
LibraryElement get importedLibrary { |
+ if (_kernel != null) { |
+ if (_importedLibrary == null) { |
+ Uri importedUri = _kernel.targetLibrary.importUri; |
+ String importedUriStr = importedUri.toString(); |
+ LibraryElementImpl library = enclosingElement as LibraryElementImpl; |
+ _importedLibrary = library._kernelContext.getLibrary(importedUriStr); |
+ } |
+ } |
if (_linkedDependency != null) { |
if (_importedLibrary == null) { |
LibraryElementImpl library = enclosingElement as LibraryElementImpl; |
@@ -5690,6 +5713,11 @@ abstract class KernelLibraryResynthesizerContext { |
InterfaceType getInterfaceType(ElementImpl context, kernel.Supertype type); |
/** |
+ * Return the [LibraryElement] for the given absolute [uriStr]. |
+ */ |
+ LibraryElement getLibrary(String uriStr); |
+ |
+ /** |
* Return the [DartType] for the given Kernel [type], or `null` if the [type] |
* does not correspond to a [DartType]. |
*/ |
@@ -6070,21 +6098,30 @@ class LibraryElementImpl extends ElementImpl implements LibraryElement { |
@override |
List<ImportElement> get imports { |
- if (_unlinkedDefiningUnit != null && _imports == null) { |
- List<UnlinkedImport> unlinkedImports = _unlinkedDefiningUnit.imports; |
- int length = unlinkedImports.length; |
- if (length != 0) { |
- List<ImportElement> imports = new List<ImportElement>(); |
- LinkedLibrary linkedLibrary = resynthesizerContext.linkedLibrary; |
- for (int i = 0; i < length; i++) { |
- int dependency = linkedLibrary.importDependencies[i]; |
- ImportElementImpl importElement = new ImportElementImpl.forSerialized( |
- unlinkedImports[i], dependency, library); |
- imports.add(importElement); |
+ if (_imports == null) { |
+ if (_kernelContext != null) { |
+ _imports = _kernelContext.library.dependencies |
+ .where((k) => k.isImport) |
+ .map((k) => new ImportElementImpl.forKernel(this, k)) |
+ .toList(growable: false); |
+ } |
+ if (_unlinkedDefiningUnit != null) { |
+ List<UnlinkedImport> unlinkedImports = _unlinkedDefiningUnit.imports; |
+ int length = unlinkedImports.length; |
+ if (length != 0) { |
+ List<ImportElement> imports = new List<ImportElement>(); |
+ LinkedLibrary linkedLibrary = resynthesizerContext.linkedLibrary; |
+ for (int i = 0; i < length; i++) { |
+ int dependency = linkedLibrary.importDependencies[i]; |
+ ImportElementImpl importElement = |
+ new ImportElementImpl.forSerialized( |
+ unlinkedImports[i], dependency, library); |
+ imports.add(importElement); |
+ } |
+ _imports = imports; |
+ } else { |
+ _imports = const <ImportElement>[]; |
} |
- _imports = imports; |
- } else { |
- _imports = const <ImportElement>[]; |
} |
} |
return _imports ?? ImportElement.EMPTY_LIST; |