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

Side by Side 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 unified diff | 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 »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 // Copyright (c) 2014, the Dart project authors. Please see the AUTHORS file 1 // Copyright (c) 2014, the Dart project authors. Please see the AUTHORS file
2 // for details. All rights reserved. Use of this source code is governed by a 2 // for details. All rights reserved. Use of this source code is governed by a
3 // BSD-style license that can be found in the LICENSE file. 3 // BSD-style license that can be found in the LICENSE file.
4 4
5 library analyzer.src.dart.element.element; 5 library analyzer.src.dart.element.element;
6 6
7 import 'dart:collection'; 7 import 'dart:collection';
8 import 'dart:math' show min; 8 import 'dart:math' show min;
9 9
10 import 'package:analyzer/dart/ast/ast.dart'; 10 import 'package:analyzer/dart/ast/ast.dart';
(...skipping 5484 matching lines...) Expand 10 before | Expand all | Expand 10 after
5495 * The unlinked representation of the import in the summary. 5495 * The unlinked representation of the import in the summary.
5496 */ 5496 */
5497 final UnlinkedImport _unlinkedImport; 5497 final UnlinkedImport _unlinkedImport;
5498 5498
5499 /** 5499 /**
5500 * The index of the dependency in the `imports` list. 5500 * The index of the dependency in the `imports` list.
5501 */ 5501 */
5502 final int _linkedDependency; 5502 final int _linkedDependency;
5503 5503
5504 /** 5504 /**
5505 * The kernel of the element.
5506 */
5507 final kernel.LibraryDependency _kernel;
5508
5509 /**
5505 * The offset of the prefix of this import in the file that contains the this 5510 * The offset of the prefix of this import in the file that contains the this
5506 * import directive, or `-1` if this import is synthetic. 5511 * import directive, or `-1` if this import is synthetic.
5507 */ 5512 */
5508 int _prefixOffset = 0; 5513 int _prefixOffset = 0;
5509 5514
5510 /** 5515 /**
5511 * The library that is imported into this library by this import directive. 5516 * The library that is imported into this library by this import directive.
5512 */ 5517 */
5513 LibraryElement _importedLibrary; 5518 LibraryElement _importedLibrary;
5514 5519
5515 /** 5520 /**
5516 * The combinators that were specified as part of the import directive in the 5521 * The combinators that were specified as part of the import directive in the
5517 * order in which they were specified. 5522 * order in which they were specified.
5518 */ 5523 */
5519 List<NamespaceCombinator> _combinators; 5524 List<NamespaceCombinator> _combinators;
5520 5525
5521 /** 5526 /**
5522 * The prefix that was specified as part of the import directive, or `null` if 5527 * The prefix that was specified as part of the import directive, or `null` if
5523 * there was no prefix specified. 5528 * there was no prefix specified.
5524 */ 5529 */
5525 PrefixElement _prefix; 5530 PrefixElement _prefix;
5526 5531
5527 /** 5532 /**
5528 * Initialize a newly created import element at the given [offset]. 5533 * Initialize a newly created import element at the given [offset].
5529 * The offset may be `-1` if the import is synthetic. 5534 * The offset may be `-1` if the import is synthetic.
5530 */ 5535 */
5531 ImportElementImpl(int offset) 5536 ImportElementImpl(int offset)
5532 : _unlinkedImport = null, 5537 : _unlinkedImport = null,
5533 _linkedDependency = null, 5538 _linkedDependency = null,
5539 _kernel = null,
5534 super(null, offset); 5540 super(null, offset);
5535 5541
5536 /** 5542 /**
5543 * Initialize using the given kernel.
5544 */
5545 ImportElementImpl.forKernel(LibraryElementImpl enclosingLibrary, this._kernel)
5546 : _unlinkedImport = null,
5547 _linkedDependency = null,
5548 super.forSerialized(enclosingLibrary);
5549
5550 /**
5537 * Initialize using the given serialized information. 5551 * Initialize using the given serialized information.
5538 */ 5552 */
5539 ImportElementImpl.forSerialized(this._unlinkedImport, this._linkedDependency, 5553 ImportElementImpl.forSerialized(this._unlinkedImport, this._linkedDependency,
5540 LibraryElementImpl enclosingLibrary) 5554 LibraryElementImpl enclosingLibrary)
5541 : super.forSerialized(enclosingLibrary); 5555 : _kernel = null,
5556 super.forSerialized(enclosingLibrary);
5542 5557
5543 @override 5558 @override
5544 List<NamespaceCombinator> get combinators { 5559 List<NamespaceCombinator> get combinators {
5545 if (_unlinkedImport != null && _combinators == null) { 5560 if (_unlinkedImport != null && _combinators == null) {
5546 _combinators = _buildCombinators(_unlinkedImport.combinators); 5561 _combinators = _buildCombinators(_unlinkedImport.combinators);
5547 } 5562 }
5548 return _combinators ?? const <NamespaceCombinator>[]; 5563 return _combinators ?? const <NamespaceCombinator>[];
5549 } 5564 }
5550 5565
5551 void set combinators(List<NamespaceCombinator> combinators) { 5566 void set combinators(List<NamespaceCombinator> combinators) {
5552 _assertNotResynthesized(_unlinkedImport); 5567 _assertNotResynthesized(_unlinkedImport);
5553 _combinators = combinators; 5568 _combinators = combinators;
5554 } 5569 }
5555 5570
5556 /** 5571 /**
5557 * Set whether this import is for a deferred library. 5572 * Set whether this import is for a deferred library.
5558 */ 5573 */
5559 void set deferred(bool isDeferred) { 5574 void set deferred(bool isDeferred) {
5560 _assertNotResynthesized(_unlinkedImport); 5575 _assertNotResynthesized(_unlinkedImport);
5561 setModifier(Modifier.DEFERRED, isDeferred); 5576 setModifier(Modifier.DEFERRED, isDeferred);
5562 } 5577 }
5563 5578
5564 @override 5579 @override
5565 String get identifier => "${importedLibrary.identifier}@$nameOffset"; 5580 String get identifier => "${importedLibrary.identifier}@$nameOffset";
5566 5581
5567 @override 5582 @override
5568 LibraryElement get importedLibrary { 5583 LibraryElement get importedLibrary {
5584 if (_kernel != null) {
5585 if (_importedLibrary == null) {
5586 Uri importedUri = _kernel.targetLibrary.importUri;
5587 String importedUriStr = importedUri.toString();
5588 LibraryElementImpl library = enclosingElement as LibraryElementImpl;
5589 _importedLibrary = library._kernelContext.getLibrary(importedUriStr);
5590 }
5591 }
5569 if (_linkedDependency != null) { 5592 if (_linkedDependency != null) {
5570 if (_importedLibrary == null) { 5593 if (_importedLibrary == null) {
5571 LibraryElementImpl library = enclosingElement as LibraryElementImpl; 5594 LibraryElementImpl library = enclosingElement as LibraryElementImpl;
5572 if (_linkedDependency == 0) { 5595 if (_linkedDependency == 0) {
5573 _importedLibrary = library; 5596 _importedLibrary = library;
5574 } else { 5597 } else {
5575 _importedLibrary = library.resynthesizerContext 5598 _importedLibrary = library.resynthesizerContext
5576 .buildImportedLibrary(_linkedDependency); 5599 .buildImportedLibrary(_linkedDependency);
5577 } 5600 }
5578 } 5601 }
(...skipping 125 matching lines...) Expand 10 before | Expand all | Expand 10 after
5704 */ 5727 */
5705 Expression getExpression(kernel.Expression expression); 5728 Expression getExpression(kernel.Expression expression);
5706 5729
5707 /** 5730 /**
5708 * Return the [InterfaceType] for the given Kernel [type], or `null` if the 5731 * Return the [InterfaceType] for the given Kernel [type], or `null` if the
5709 * [type] does not correspond to an [InterfaceType]. 5732 * [type] does not correspond to an [InterfaceType].
5710 */ 5733 */
5711 InterfaceType getInterfaceType(ElementImpl context, kernel.Supertype type); 5734 InterfaceType getInterfaceType(ElementImpl context, kernel.Supertype type);
5712 5735
5713 /** 5736 /**
5737 * Return the [LibraryElement] for the given absolute [uriStr].
5738 */
5739 LibraryElement getLibrary(String uriStr);
5740
5741 /**
5714 * Return the [DartType] for the given Kernel [type], or `null` if the [type] 5742 * Return the [DartType] for the given Kernel [type], or `null` if the [type]
5715 * does not correspond to a [DartType]. 5743 * does not correspond to a [DartType].
5716 */ 5744 */
5717 DartType getType(ElementImpl context, kernel.DartType type); 5745 DartType getType(ElementImpl context, kernel.DartType type);
5718 } 5746 }
5719 5747
5720 /** 5748 /**
5721 * A concrete implementation of a [LabelElement]. 5749 * A concrete implementation of a [LabelElement].
5722 */ 5750 */
5723 class LabelElementImpl extends ElementImpl implements LabelElement { 5751 class LabelElementImpl extends ElementImpl implements LabelElement {
(...skipping 360 matching lines...) Expand 10 before | Expand all | Expand 10 after
6084 LibraryElement library = element.importedLibrary; 6112 LibraryElement library = element.importedLibrary;
6085 if (library != null) { 6113 if (library != null) {
6086 libraries.add(library); 6114 libraries.add(library);
6087 } 6115 }
6088 } 6116 }
6089 return libraries.toList(growable: false); 6117 return libraries.toList(growable: false);
6090 } 6118 }
6091 6119
6092 @override 6120 @override
6093 List<ImportElement> get imports { 6121 List<ImportElement> get imports {
6094 if (_unlinkedDefiningUnit != null && _imports == null) { 6122 if (_imports == null) {
6095 List<UnlinkedImport> unlinkedImports = _unlinkedDefiningUnit.imports; 6123 if (_kernelContext != null) {
6096 int length = unlinkedImports.length; 6124 _imports = _kernelContext.library.dependencies
6097 if (length != 0) { 6125 .where((k) => k.isImport)
6098 List<ImportElement> imports = new List<ImportElement>(); 6126 .map((k) => new ImportElementImpl.forKernel(this, k))
6099 LinkedLibrary linkedLibrary = resynthesizerContext.linkedLibrary; 6127 .toList(growable: false);
6100 for (int i = 0; i < length; i++) { 6128 }
6101 int dependency = linkedLibrary.importDependencies[i]; 6129 if (_unlinkedDefiningUnit != null) {
6102 ImportElementImpl importElement = new ImportElementImpl.forSerialized( 6130 List<UnlinkedImport> unlinkedImports = _unlinkedDefiningUnit.imports;
6103 unlinkedImports[i], dependency, library); 6131 int length = unlinkedImports.length;
6104 imports.add(importElement); 6132 if (length != 0) {
6133 List<ImportElement> imports = new List<ImportElement>();
6134 LinkedLibrary linkedLibrary = resynthesizerContext.linkedLibrary;
6135 for (int i = 0; i < length; i++) {
6136 int dependency = linkedLibrary.importDependencies[i];
6137 ImportElementImpl importElement =
6138 new ImportElementImpl.forSerialized(
6139 unlinkedImports[i], dependency, library);
6140 imports.add(importElement);
6141 }
6142 _imports = imports;
6143 } else {
6144 _imports = const <ImportElement>[];
6105 } 6145 }
6106 _imports = imports;
6107 } else {
6108 _imports = const <ImportElement>[];
6109 } 6146 }
6110 } 6147 }
6111 return _imports ?? ImportElement.EMPTY_LIST; 6148 return _imports ?? ImportElement.EMPTY_LIST;
6112 } 6149 }
6113 6150
6114 /** 6151 /**
6115 * Set the specifications of all of the imports defined in this library to the 6152 * Set the specifications of all of the imports defined in this library to the
6116 * given list of [imports]. 6153 * given list of [imports].
6117 */ 6154 */
6118 void set imports(List<ImportElement> imports) { 6155 void set imports(List<ImportElement> imports) {
(...skipping 3173 matching lines...) Expand 10 before | Expand all | Expand 10 after
9292 9329
9293 @override 9330 @override
9294 DartObject computeConstantValue() => null; 9331 DartObject computeConstantValue() => null;
9295 9332
9296 @override 9333 @override
9297 void visitChildren(ElementVisitor visitor) { 9334 void visitChildren(ElementVisitor visitor) {
9298 super.visitChildren(visitor); 9335 super.visitChildren(visitor);
9299 _initializer?.accept(visitor); 9336 _initializer?.accept(visitor);
9300 } 9337 }
9301 } 9338 }
OLDNEW
« 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