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

Side by Side 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 unified diff | Download patch
« no previous file with comments | « no previous file | pkg/analyzer/lib/src/kernel/resynthesize.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 5768 matching lines...) Expand 10 before | Expand all | Expand 10 after
5779 * The index of the dependency in the `imports` list. 5779 * The index of the dependency in the `imports` list.
5780 */ 5780 */
5781 final int _linkedDependency; 5781 final int _linkedDependency;
5782 5782
5783 /** 5783 /**
5784 * The kernel of the element. 5784 * The kernel of the element.
5785 */ 5785 */
5786 final kernel.LibraryDependency _kernel; 5786 final kernel.LibraryDependency _kernel;
5787 5787
5788 /** 5788 /**
5789 * Whether this import is synthetic.
5790 */
5791 final bool _kernelSynthetic;
5792
5793 /**
5789 * The offset of the prefix of this import in the file that contains the this 5794 * The offset of the prefix of this import in the file that contains the this
5790 * import directive, or `-1` if this import is synthetic. 5795 * import directive, or `-1` if this import is synthetic.
5791 */ 5796 */
5792 int _prefixOffset = 0; 5797 int _prefixOffset = 0;
5793 5798
5794 /** 5799 /**
5795 * The library that is imported into this library by this import directive. 5800 * The library that is imported into this library by this import directive.
5796 */ 5801 */
5797 LibraryElement _importedLibrary; 5802 LibraryElement _importedLibrary;
5798 5803
(...skipping 15 matching lines...) Expand all
5814 String _selectedUri; 5819 String _selectedUri;
5815 5820
5816 /** 5821 /**
5817 * Initialize a newly created import element at the given [offset]. 5822 * Initialize a newly created import element at the given [offset].
5818 * The offset may be `-1` if the import is synthetic. 5823 * The offset may be `-1` if the import is synthetic.
5819 */ 5824 */
5820 ImportElementImpl(int offset) 5825 ImportElementImpl(int offset)
5821 : _unlinkedImport = null, 5826 : _unlinkedImport = null,
5822 _linkedDependency = null, 5827 _linkedDependency = null,
5823 _kernel = null, 5828 _kernel = null,
5829 _kernelSynthetic = false,
5824 super(null, offset); 5830 super(null, offset);
5825 5831
5826 /** 5832 /**
5827 * Initialize using the given kernel. 5833 * Initialize using the given kernel.
5828 */ 5834 */
5829 ImportElementImpl.forKernel(LibraryElementImpl enclosingLibrary, this._kernel) 5835 ImportElementImpl.forKernel(LibraryElementImpl enclosingLibrary, this._kernel,
5836 {bool isSynthetic: false})
5830 : _unlinkedImport = null, 5837 : _unlinkedImport = null,
5831 _linkedDependency = null, 5838 _linkedDependency = null,
5839 _kernelSynthetic = isSynthetic,
5832 super.forSerialized(enclosingLibrary); 5840 super.forSerialized(enclosingLibrary);
5833 5841
5834 /** 5842 /**
5835 * Initialize using the given serialized information. 5843 * Initialize using the given serialized information.
5836 */ 5844 */
5837 ImportElementImpl.forSerialized(this._unlinkedImport, this._linkedDependency, 5845 ImportElementImpl.forSerialized(this._unlinkedImport, this._linkedDependency,
5838 LibraryElementImpl enclosingLibrary) 5846 LibraryElementImpl enclosingLibrary)
5839 : _kernel = null, 5847 : _kernel = null,
5848 _kernelSynthetic = false,
5840 super.forSerialized(enclosingLibrary); 5849 super.forSerialized(enclosingLibrary);
5841 5850
5842 @override 5851 @override
5843 List<NamespaceCombinator> get combinators { 5852 List<NamespaceCombinator> get combinators {
5844 if (_combinators == null) { 5853 if (_combinators == null) {
5845 if (_kernel != null) { 5854 if (_kernel != null) {
5846 _combinators = _buildCombinatorsForKernel(_kernel.combinators); 5855 _combinators = _buildCombinatorsForKernel(_kernel.combinators);
5847 } 5856 }
5848 if (_unlinkedImport != null) { 5857 if (_unlinkedImport != null) {
5849 _combinators = _buildCombinators(_unlinkedImport.combinators); 5858 _combinators = _buildCombinators(_unlinkedImport.combinators);
(...skipping 50 matching lines...) Expand 10 before | Expand all | Expand 10 after
5900 @override 5909 @override
5901 bool get isDeferred { 5910 bool get isDeferred {
5902 if (_unlinkedImport != null) { 5911 if (_unlinkedImport != null) {
5903 return _unlinkedImport.isDeferred; 5912 return _unlinkedImport.isDeferred;
5904 } 5913 }
5905 return hasModifier(Modifier.DEFERRED); 5914 return hasModifier(Modifier.DEFERRED);
5906 } 5915 }
5907 5916
5908 @override 5917 @override
5909 bool get isSynthetic { 5918 bool get isSynthetic {
5919 if (_kernel != null) {
5920 return _kernelSynthetic;
5921 }
5910 if (_unlinkedImport != null) { 5922 if (_unlinkedImport != null) {
5911 return _unlinkedImport.isImplicit; 5923 return _unlinkedImport.isImplicit;
5912 } 5924 }
5913 return super.isSynthetic; 5925 return super.isSynthetic;
5914 } 5926 }
5915 5927
5916 @override 5928 @override
5917 ElementKind get kind => ElementKind.IMPORT; 5929 ElementKind get kind => ElementKind.IMPORT;
5918 5930
5919 @override 5931 @override
(...skipping 156 matching lines...) Expand 10 before | Expand all | Expand 10 after
6076 } else { 6088 } else {
6077 return const <NamespaceCombinator>[]; 6089 return const <NamespaceCombinator>[];
6078 } 6090 }
6079 } 6091 }
6080 } 6092 }
6081 6093
6082 /** 6094 /**
6083 * The kernel context in which a library is resynthesized. 6095 * The kernel context in which a library is resynthesized.
6084 */ 6096 */
6085 abstract class KernelLibraryResynthesizerContext { 6097 abstract class KernelLibraryResynthesizerContext {
6098 /**
6099 * The Kernel library for `dart:core`.
6100 */
6101 kernel.Library get coreLibrary;
6102
6103 /**
6104 * The Kernel library being resynthesized.
6105 */
6086 kernel.Library get library; 6106 kernel.Library get library;
6087 6107
6088 /** 6108 /**
6089 * Return the [LibraryElement] for the given absolute [uriStr]. 6109 * Return the [LibraryElement] for the given absolute [uriStr].
6090 */ 6110 */
6091 LibraryElement getLibrary(String uriStr); 6111 LibraryElement getLibrary(String uriStr);
6092 } 6112 }
6093 6113
6094 /** 6114 /**
6095 * Top-level declarations of a Kernel library filtered by the unit. 6115 * Top-level declarations of a Kernel library filtered by the unit.
(...skipping 131 matching lines...) Expand 10 before | Expand all | Expand 10 after
6227 ElementKind get kind => ElementKind.LABEL; 6247 ElementKind get kind => ElementKind.LABEL;
6228 6248
6229 @override 6249 @override
6230 T accept<T>(ElementVisitor<T> visitor) => visitor.visitLabelElement(this); 6250 T accept<T>(ElementVisitor<T> visitor) => visitor.visitLabelElement(this);
6231 } 6251 }
6232 6252
6233 /** 6253 /**
6234 * A concrete implementation of a [LibraryElement]. 6254 * A concrete implementation of a [LibraryElement].
6235 */ 6255 */
6236 class LibraryElementImpl extends ElementImpl implements LibraryElement { 6256 class LibraryElementImpl extends ElementImpl implements LibraryElement {
6257 static final Uri _dartCore = Uri.parse('dart:core');
6258
6237 /** 6259 /**
6238 * The analysis context in which this library is defined. 6260 * The analysis context in which this library is defined.
6239 */ 6261 */
6240 final AnalysisContext context; 6262 final AnalysisContext context;
6241 6263
6242 final LibraryResynthesizerContext resynthesizerContext; 6264 final LibraryResynthesizerContext resynthesizerContext;
6243 6265
6244 /** 6266 /**
6245 * The kernel context in which the library is resynthesized. 6267 * The kernel context in which the library is resynthesized.
6246 */ 6268 */
(...skipping 293 matching lines...) Expand 10 before | Expand all | Expand 10 after
6540 libraries.add(library); 6562 libraries.add(library);
6541 } 6563 }
6542 } 6564 }
6543 return libraries.toList(growable: false); 6565 return libraries.toList(growable: false);
6544 } 6566 }
6545 6567
6546 @override 6568 @override
6547 List<ImportElement> get imports { 6569 List<ImportElement> get imports {
6548 if (_imports == null) { 6570 if (_imports == null) {
6549 if (_kernelContext != null) { 6571 if (_kernelContext != null) {
6550 _imports = _kernelContext.library.dependencies 6572 var dependencies = _kernelContext.library.dependencies;
6551 .where((k) => k.isImport) 6573 int numOfDependencies = dependencies.length;
6552 .map((k) => new ImportElementImpl.forKernel(this, k)) 6574 // Compute the number of import dependencies.
6553 .toList(growable: false); 6575 bool hasCore = false;
6576 int numOfImports = 0;
6577 for (int i = 0; i < numOfDependencies; i++) {
6578 kernel.LibraryDependency dependency = dependencies[i];
6579 if (dependency.isImport) {
6580 numOfImports++;
6581 if (dependency.targetLibrary.importUri == _dartCore) {
6582 hasCore = true;
6583 }
6584 }
6585 }
6586 // Create import elements.
6587 var imports = new List<ImportElement>(numOfImports + (hasCore ? 0 : 1));
6588 for (int i = 0; i < numOfDependencies; i++) {
6589 kernel.LibraryDependency dependency = dependencies[i];
6590 if (dependency.isImport) {
6591 imports[i] = new ImportElementImpl.forKernel(this, dependency);
6592 }
6593 }
6594 // If dart:core is not imported explicitly, import it implicitly.
6595 if (!hasCore) {
6596 imports[numOfImports] = new ImportElementImpl.forKernel(this,
6597 new kernel.LibraryDependency.import(_kernelContext.coreLibrary),
6598 isSynthetic: true);
6599 }
6600 // Set imports into the field.
6601 _imports = imports;
6554 } 6602 }
6555 if (_unlinkedDefiningUnit != null) { 6603 if (_unlinkedDefiningUnit != null) {
6556 List<UnlinkedImport> unlinkedImports = _unlinkedDefiningUnit.imports; 6604 List<UnlinkedImport> unlinkedImports = _unlinkedDefiningUnit.imports;
6557 int length = unlinkedImports.length; 6605 int length = unlinkedImports.length;
6558 if (length != 0) { 6606 if (length != 0) {
6559 List<ImportElement> imports = new List<ImportElement>(); 6607 List<ImportElement> imports = new List<ImportElement>();
6560 LinkedLibrary linkedLibrary = resynthesizerContext.linkedLibrary; 6608 LinkedLibrary linkedLibrary = resynthesizerContext.linkedLibrary;
6561 for (int i = 0; i < length; i++) { 6609 for (int i = 0; i < length; i++) {
6562 int dependency = linkedLibrary.importDependencies[i]; 6610 int dependency = linkedLibrary.importDependencies[i];
6563 ImportElementImpl importElement = 6611 ImportElementImpl importElement =
(...skipping 3371 matching lines...) Expand 10 before | Expand all | Expand 10 after
9935 9983
9936 @override 9984 @override
9937 DartObject computeConstantValue() => null; 9985 DartObject computeConstantValue() => null;
9938 9986
9939 @override 9987 @override
9940 void visitChildren(ElementVisitor visitor) { 9988 void visitChildren(ElementVisitor visitor) {
9941 super.visitChildren(visitor); 9989 super.visitChildren(visitor);
9942 _initializer?.accept(visitor); 9990 _initializer?.accept(visitor);
9943 } 9991 }
9944 } 9992 }
OLDNEW
« 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