OLD | NEW |
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 4333 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
4344 /** | 4344 /** |
4345 * Initialize using the given serialized information. | 4345 * Initialize using the given serialized information. |
4346 */ | 4346 */ |
4347 ExportElementImpl.forSerialized(this._unlinkedExportPublic, | 4347 ExportElementImpl.forSerialized(this._unlinkedExportPublic, |
4348 this._unlinkedExportNonPublic, LibraryElementImpl enclosingLibrary) | 4348 this._unlinkedExportNonPublic, LibraryElementImpl enclosingLibrary) |
4349 : _kernel = null, | 4349 : _kernel = null, |
4350 super.forSerialized(enclosingLibrary); | 4350 super.forSerialized(enclosingLibrary); |
4351 | 4351 |
4352 @override | 4352 @override |
4353 List<NamespaceCombinator> get combinators { | 4353 List<NamespaceCombinator> get combinators { |
4354 if (_unlinkedExportPublic != null && _combinators == null) { | 4354 if (_combinators == null) { |
4355 _combinators = ImportElementImpl | 4355 if (_kernel != null) { |
4356 ._buildCombinators(_unlinkedExportPublic.combinators); | 4356 _combinators = |
| 4357 ImportElementImpl._buildCombinatorsForKernel(_kernel.combinators); |
| 4358 } |
| 4359 if (_unlinkedExportPublic != null) { |
| 4360 _combinators = ImportElementImpl |
| 4361 ._buildCombinators(_unlinkedExportPublic.combinators); |
| 4362 } |
4357 } | 4363 } |
4358 return _combinators ?? const <NamespaceCombinator>[]; | 4364 return _combinators ?? const <NamespaceCombinator>[]; |
4359 } | 4365 } |
4360 | 4366 |
4361 void set combinators(List<NamespaceCombinator> combinators) { | 4367 void set combinators(List<NamespaceCombinator> combinators) { |
4362 _assertNotResynthesized(_unlinkedExportPublic); | 4368 _assertNotResynthesized(_unlinkedExportPublic); |
4363 _combinators = combinators; | 4369 _combinators = combinators; |
4364 } | 4370 } |
4365 | 4371 |
4366 @override | 4372 @override |
(...skipping 1226 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
5593 /** | 5599 /** |
5594 * A concrete implementation of a [HideElementCombinator]. | 5600 * A concrete implementation of a [HideElementCombinator]. |
5595 */ | 5601 */ |
5596 class HideElementCombinatorImpl implements HideElementCombinator { | 5602 class HideElementCombinatorImpl implements HideElementCombinator { |
5597 /** | 5603 /** |
5598 * The unlinked representation of the combinator in the summary. | 5604 * The unlinked representation of the combinator in the summary. |
5599 */ | 5605 */ |
5600 final UnlinkedCombinator _unlinkedCombinator; | 5606 final UnlinkedCombinator _unlinkedCombinator; |
5601 | 5607 |
5602 /** | 5608 /** |
| 5609 * The kernel for the element. |
| 5610 */ |
| 5611 final kernel.Combinator _kernel; |
| 5612 |
| 5613 /** |
5603 * The names that are not to be made visible in the importing library even if | 5614 * The names that are not to be made visible in the importing library even if |
5604 * they are defined in the imported library. | 5615 * they are defined in the imported library. |
5605 */ | 5616 */ |
5606 List<String> _hiddenNames; | 5617 List<String> _hiddenNames; |
5607 | 5618 |
5608 HideElementCombinatorImpl() : _unlinkedCombinator = null; | 5619 HideElementCombinatorImpl() |
| 5620 : _unlinkedCombinator = null, |
| 5621 _kernel = null; |
5609 | 5622 |
5610 /** | 5623 /** |
5611 * Initialize using the given serialized information. | 5624 * Initialize using the given serialized information. |
5612 */ | 5625 */ |
5613 HideElementCombinatorImpl.forSerialized(this._unlinkedCombinator); | 5626 HideElementCombinatorImpl.forSerialized(this._unlinkedCombinator) |
| 5627 : _kernel = null; |
| 5628 |
| 5629 /** |
| 5630 * Initialize using the given kernel. |
| 5631 */ |
| 5632 HideElementCombinatorImpl.forKernel(this._kernel) |
| 5633 : _unlinkedCombinator = null; |
5614 | 5634 |
5615 @override | 5635 @override |
5616 List<String> get hiddenNames { | 5636 List<String> get hiddenNames { |
| 5637 if (_kernel != null) { |
| 5638 _hiddenNames ??= _kernel.names; |
| 5639 } |
5617 if (_unlinkedCombinator != null) { | 5640 if (_unlinkedCombinator != null) { |
5618 _hiddenNames ??= _unlinkedCombinator.hides.toList(growable: false); | 5641 _hiddenNames ??= _unlinkedCombinator.hides.toList(growable: false); |
5619 } | 5642 } |
5620 return _hiddenNames ?? const <String>[]; | 5643 return _hiddenNames ?? const <String>[]; |
5621 } | 5644 } |
5622 | 5645 |
5623 void set hiddenNames(List<String> hiddenNames) { | 5646 void set hiddenNames(List<String> hiddenNames) { |
5624 _assertNotResynthesized(_unlinkedCombinator); | 5647 _assertNotResynthesized(_unlinkedCombinator); |
5625 _hiddenNames = hiddenNames; | 5648 _hiddenNames = hiddenNames; |
5626 } | 5649 } |
(...skipping 82 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
5709 /** | 5732 /** |
5710 * Initialize using the given serialized information. | 5733 * Initialize using the given serialized information. |
5711 */ | 5734 */ |
5712 ImportElementImpl.forSerialized(this._unlinkedImport, this._linkedDependency, | 5735 ImportElementImpl.forSerialized(this._unlinkedImport, this._linkedDependency, |
5713 LibraryElementImpl enclosingLibrary) | 5736 LibraryElementImpl enclosingLibrary) |
5714 : _kernel = null, | 5737 : _kernel = null, |
5715 super.forSerialized(enclosingLibrary); | 5738 super.forSerialized(enclosingLibrary); |
5716 | 5739 |
5717 @override | 5740 @override |
5718 List<NamespaceCombinator> get combinators { | 5741 List<NamespaceCombinator> get combinators { |
5719 if (_unlinkedImport != null && _combinators == null) { | 5742 if (_combinators == null) { |
5720 _combinators = _buildCombinators(_unlinkedImport.combinators); | 5743 if (_kernel != null) { |
| 5744 _combinators = _buildCombinatorsForKernel(_kernel.combinators); |
| 5745 } |
| 5746 if (_unlinkedImport != null) { |
| 5747 _combinators = _buildCombinators(_unlinkedImport.combinators); |
| 5748 } |
5721 } | 5749 } |
5722 return _combinators ?? const <NamespaceCombinator>[]; | 5750 return _combinators ?? const <NamespaceCombinator>[]; |
5723 } | 5751 } |
5724 | 5752 |
5725 void set combinators(List<NamespaceCombinator> combinators) { | 5753 void set combinators(List<NamespaceCombinator> combinators) { |
5726 _assertNotResynthesized(_unlinkedImport); | 5754 _assertNotResynthesized(_unlinkedImport); |
5727 _combinators = combinators; | 5755 _combinators = combinators; |
5728 } | 5756 } |
5729 | 5757 |
5730 /** | 5758 /** |
(...skipping 191 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
5922 UnlinkedCombinator unlinkedCombinator = unlinkedCombinators[i]; | 5950 UnlinkedCombinator unlinkedCombinator = unlinkedCombinators[i]; |
5923 combinators[i] = unlinkedCombinator.shows.isNotEmpty | 5951 combinators[i] = unlinkedCombinator.shows.isNotEmpty |
5924 ? new ShowElementCombinatorImpl.forSerialized(unlinkedCombinator) | 5952 ? new ShowElementCombinatorImpl.forSerialized(unlinkedCombinator) |
5925 : new HideElementCombinatorImpl.forSerialized(unlinkedCombinator); | 5953 : new HideElementCombinatorImpl.forSerialized(unlinkedCombinator); |
5926 } | 5954 } |
5927 return combinators; | 5955 return combinators; |
5928 } else { | 5956 } else { |
5929 return const <NamespaceCombinator>[]; | 5957 return const <NamespaceCombinator>[]; |
5930 } | 5958 } |
5931 } | 5959 } |
| 5960 |
| 5961 static List<NamespaceCombinator> _buildCombinatorsForKernel( |
| 5962 List<kernel.Combinator> unlinkedCombinators) { |
| 5963 int length = unlinkedCombinators.length; |
| 5964 if (length != 0) { |
| 5965 List<NamespaceCombinator> combinators = |
| 5966 new List<NamespaceCombinator>(length); |
| 5967 for (int i = 0; i < length; i++) { |
| 5968 kernel.Combinator unlinkedCombinator = unlinkedCombinators[i]; |
| 5969 combinators[i] = unlinkedCombinator.isShow |
| 5970 ? new ShowElementCombinatorImpl.forKernel(unlinkedCombinator) |
| 5971 : new HideElementCombinatorImpl.forKernel(unlinkedCombinator); |
| 5972 } |
| 5973 return combinators; |
| 5974 } else { |
| 5975 return const <NamespaceCombinator>[]; |
| 5976 } |
| 5977 } |
5932 } | 5978 } |
5933 | 5979 |
5934 /** | 5980 /** |
5935 * The kernel context in which a library is resynthesized. | 5981 * The kernel context in which a library is resynthesized. |
5936 */ | 5982 */ |
5937 abstract class KernelLibraryResynthesizerContext { | 5983 abstract class KernelLibraryResynthesizerContext { |
5938 kernel.Library get library; | 5984 kernel.Library get library; |
5939 | 5985 |
5940 /** | 5986 /** |
5941 * Build [ElementAnnotation]s for the given Kernel [annotations]. | 5987 * Build [ElementAnnotation]s for the given Kernel [annotations]. |
(...skipping 3019 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
8961 /** | 9007 /** |
8962 * A concrete implementation of a [ShowElementCombinator]. | 9008 * A concrete implementation of a [ShowElementCombinator]. |
8963 */ | 9009 */ |
8964 class ShowElementCombinatorImpl implements ShowElementCombinator { | 9010 class ShowElementCombinatorImpl implements ShowElementCombinator { |
8965 /** | 9011 /** |
8966 * The unlinked representation of the combinator in the summary. | 9012 * The unlinked representation of the combinator in the summary. |
8967 */ | 9013 */ |
8968 final UnlinkedCombinator _unlinkedCombinator; | 9014 final UnlinkedCombinator _unlinkedCombinator; |
8969 | 9015 |
8970 /** | 9016 /** |
| 9017 * The kernel for the element. |
| 9018 */ |
| 9019 final kernel.Combinator _kernel; |
| 9020 |
| 9021 /** |
8971 * The names that are to be made visible in the importing library if they are | 9022 * The names that are to be made visible in the importing library if they are |
8972 * defined in the imported library. | 9023 * defined in the imported library. |
8973 */ | 9024 */ |
8974 List<String> _shownNames; | 9025 List<String> _shownNames; |
8975 | 9026 |
8976 /** | 9027 /** |
8977 * The offset of the character immediately following the last character of | 9028 * The offset of the character immediately following the last character of |
8978 * this node. | 9029 * this node. |
8979 */ | 9030 */ |
8980 int _end = -1; | 9031 int _end = -1; |
8981 | 9032 |
8982 /** | 9033 /** |
8983 * The offset of the 'show' keyword of this element. | 9034 * The offset of the 'show' keyword of this element. |
8984 */ | 9035 */ |
8985 int _offset = 0; | 9036 int _offset = 0; |
8986 | 9037 |
8987 ShowElementCombinatorImpl() : _unlinkedCombinator = null; | 9038 ShowElementCombinatorImpl() |
| 9039 : _unlinkedCombinator = null, |
| 9040 _kernel = null; |
8988 | 9041 |
8989 /** | 9042 /** |
8990 * Initialize using the given serialized information. | 9043 * Initialize using the given serialized information. |
8991 */ | 9044 */ |
8992 ShowElementCombinatorImpl.forSerialized(this._unlinkedCombinator); | 9045 ShowElementCombinatorImpl.forSerialized(this._unlinkedCombinator) |
| 9046 : _kernel = null; |
| 9047 |
| 9048 /** |
| 9049 * Initialize using the given kernel. |
| 9050 */ |
| 9051 ShowElementCombinatorImpl.forKernel(this._kernel) |
| 9052 : _unlinkedCombinator = null; |
8993 | 9053 |
8994 @override | 9054 @override |
8995 int get end { | 9055 int get end { |
8996 if (_unlinkedCombinator != null) { | 9056 if (_unlinkedCombinator != null) { |
8997 return _unlinkedCombinator.end; | 9057 return _unlinkedCombinator.end; |
8998 } | 9058 } |
8999 return _end; | 9059 return _end; |
9000 } | 9060 } |
9001 | 9061 |
9002 void set end(int end) { | 9062 void set end(int end) { |
9003 _assertNotResynthesized(_unlinkedCombinator); | 9063 _assertNotResynthesized(_unlinkedCombinator); |
9004 _end = end; | 9064 _end = end; |
9005 } | 9065 } |
9006 | 9066 |
9007 @override | 9067 @override |
9008 int get offset { | 9068 int get offset { |
9009 if (_unlinkedCombinator != null) { | 9069 if (_unlinkedCombinator != null) { |
9010 return _unlinkedCombinator.offset; | 9070 return _unlinkedCombinator.offset; |
9011 } | 9071 } |
9012 return _offset; | 9072 return _offset; |
9013 } | 9073 } |
9014 | 9074 |
9015 void set offset(int offset) { | 9075 void set offset(int offset) { |
9016 _assertNotResynthesized(_unlinkedCombinator); | 9076 _assertNotResynthesized(_unlinkedCombinator); |
9017 _offset = offset; | 9077 _offset = offset; |
9018 } | 9078 } |
9019 | 9079 |
9020 @override | 9080 @override |
9021 List<String> get shownNames { | 9081 List<String> get shownNames { |
| 9082 if (_kernel != null) { |
| 9083 _shownNames ??= _kernel.names; |
| 9084 } |
9022 if (_unlinkedCombinator != null) { | 9085 if (_unlinkedCombinator != null) { |
9023 _shownNames ??= _unlinkedCombinator.shows.toList(growable: false); | 9086 _shownNames ??= _unlinkedCombinator.shows.toList(growable: false); |
9024 } | 9087 } |
9025 return _shownNames ?? const <String>[]; | 9088 return _shownNames ?? const <String>[]; |
9026 } | 9089 } |
9027 | 9090 |
9028 void set shownNames(List<String> shownNames) { | 9091 void set shownNames(List<String> shownNames) { |
9029 _assertNotResynthesized(_unlinkedCombinator); | 9092 _assertNotResynthesized(_unlinkedCombinator); |
9030 _shownNames = shownNames; | 9093 _shownNames = shownNames; |
9031 } | 9094 } |
(...skipping 675 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
9707 | 9770 |
9708 @override | 9771 @override |
9709 DartObject computeConstantValue() => null; | 9772 DartObject computeConstantValue() => null; |
9710 | 9773 |
9711 @override | 9774 @override |
9712 void visitChildren(ElementVisitor visitor) { | 9775 void visitChildren(ElementVisitor visitor) { |
9713 super.visitChildren(visitor); | 9776 super.visitChildren(visitor); |
9714 _initializer?.accept(visitor); | 9777 _initializer?.accept(visitor); |
9715 } | 9778 } |
9716 } | 9779 } |
OLD | NEW |