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

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

Issue 2987553002: Add import dependencies to Kernel libraries and use them to resynthesize ImportElement(s) in Analyz… (Closed)
Patch Set: Fixes for review comments. Created 3 years, 5 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/test/src/summary/resynthesize_kernel_test.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 ca7f284106b4cf623d403c55261d78ef57eb12cb..b5682dd18142df2c262691fefe4db34cf4005926 100644
--- a/pkg/analyzer/lib/src/dart/element/element.dart
+++ b/pkg/analyzer/lib/src/dart/element/element.dart
@@ -5502,6 +5502,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.
*/
@@ -5531,14 +5536,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 {
@@ -5566,6 +5581,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;
@@ -5711,6 +5734,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].
*/
@@ -6091,21 +6119,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;
« no previous file with comments | « no previous file | pkg/analyzer/test/src/summary/resynthesize_kernel_test.dart » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698