| 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 1353 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1364 * Return `true` if the given [type] is a class [InterfaceType]. | 1364 * Return `true` if the given [type] is a class [InterfaceType]. |
| 1365 */ | 1365 */ |
| 1366 static bool _isClassInterfaceType(DartType type) { | 1366 static bool _isClassInterfaceType(DartType type) { |
| 1367 return type is InterfaceType && !type.element.isEnum; | 1367 return type is InterfaceType && !type.element.isEnum; |
| 1368 } | 1368 } |
| 1369 } | 1369 } |
| 1370 | 1370 |
| 1371 /** | 1371 /** |
| 1372 * A concrete implementation of a [CompilationUnitElement]. | 1372 * A concrete implementation of a [CompilationUnitElement]. |
| 1373 */ | 1373 */ |
| 1374 class CompilationUnitElementImpl extends UriReferencedElementImpl | 1374 class CompilationUnitElementImpl extends ElementImpl |
| 1375 implements CompilationUnitElement { | 1375 implements CompilationUnitElement { |
| 1376 /** | 1376 /** |
| 1377 * The context in which this unit is resynthesized, or `null` if the | 1377 * The context in which this unit is resynthesized, or `null` if the |
| 1378 * element is not resynthesized a summary. | 1378 * element is not resynthesized a summary. |
| 1379 */ | 1379 */ |
| 1380 final ResynthesizerContext resynthesizerContext; | 1380 final ResynthesizerContext resynthesizerContext; |
| 1381 | 1381 |
| 1382 /** | 1382 /** |
| 1383 * The unlinked representation of the unit in the summary. | 1383 * The unlinked representation of the unit in the summary. |
| 1384 */ | 1384 */ |
| (...skipping 1955 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 3340 * with the type is implicitly a child of this element and should be visted by | 3340 * with the type is implicitly a child of this element and should be visted by |
| 3341 * the given [visitor]. | 3341 * the given [visitor]. |
| 3342 */ | 3342 */ |
| 3343 void _safelyVisitPossibleChild(DartType type, ElementVisitor visitor) { | 3343 void _safelyVisitPossibleChild(DartType type, ElementVisitor visitor) { |
| 3344 Element element = type?.element; | 3344 Element element = type?.element; |
| 3345 if (element is GenericFunctionTypeElementImpl) { | 3345 if (element is GenericFunctionTypeElementImpl) { |
| 3346 element.accept(visitor); | 3346 element.accept(visitor); |
| 3347 } | 3347 } |
| 3348 } | 3348 } |
| 3349 | 3349 |
| 3350 String _selectUri( |
| 3351 String defaultUri, List<UnlinkedConfiguration> configurations) { |
| 3352 for (UnlinkedConfiguration configuration in configurations) { |
| 3353 if (context.declaredVariables.get(configuration.name) == |
| 3354 configuration.value) { |
| 3355 return configuration.uri; |
| 3356 } |
| 3357 } |
| 3358 return defaultUri; |
| 3359 } |
| 3360 |
| 3350 static int findElementIndexUsingIdentical(List items, Object item) { | 3361 static int findElementIndexUsingIdentical(List items, Object item) { |
| 3351 int length = items.length; | 3362 int length = items.length; |
| 3352 for (int i = 0; i < length; i++) { | 3363 for (int i = 0; i < length; i++) { |
| 3353 if (identical(items[i], item)) { | 3364 if (identical(items[i], item)) { |
| 3354 return i; | 3365 return i; |
| 3355 } | 3366 } |
| 3356 } | 3367 } |
| 3357 throw new StateError('Unable to find $item in $items'); | 3368 throw new StateError('Unable to find $item in $items'); |
| 3358 } | 3369 } |
| 3359 } | 3370 } |
| (...skipping 804 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 4164 super.visitChildren(visitor); | 4175 super.visitChildren(visitor); |
| 4165 _safelyVisitPossibleChild(returnType, visitor); | 4176 _safelyVisitPossibleChild(returnType, visitor); |
| 4166 safelyVisitChildren(typeParameters, visitor); | 4177 safelyVisitChildren(typeParameters, visitor); |
| 4167 safelyVisitChildren(parameters, visitor); | 4178 safelyVisitChildren(parameters, visitor); |
| 4168 } | 4179 } |
| 4169 } | 4180 } |
| 4170 | 4181 |
| 4171 /** | 4182 /** |
| 4172 * A concrete implementation of an [ExportElement]. | 4183 * A concrete implementation of an [ExportElement]. |
| 4173 */ | 4184 */ |
| 4174 class ExportElementImpl extends UriReferencedElementImpl | 4185 class ExportElementImpl extends ElementImpl implements ExportElement { |
| 4175 implements ExportElement { | |
| 4176 /** | 4186 /** |
| 4177 * The unlinked representation of the export in the summary. | 4187 * The unlinked representation of the export in the summary. |
| 4178 */ | 4188 */ |
| 4179 final UnlinkedExportPublic _unlinkedExportPublic; | 4189 final UnlinkedExportPublic _unlinkedExportPublic; |
| 4180 | 4190 |
| 4181 /** | 4191 /** |
| 4182 * The unlinked representation of the export in the summary. | 4192 * The unlinked representation of the export in the summary. |
| 4183 */ | 4193 */ |
| 4184 final UnlinkedExportNonPublic _unlinkedExportNonPublic; | 4194 final UnlinkedExportNonPublic _unlinkedExportNonPublic; |
| 4185 | 4195 |
| (...skipping 38 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 4224 } | 4234 } |
| 4225 | 4235 |
| 4226 void set combinators(List<NamespaceCombinator> combinators) { | 4236 void set combinators(List<NamespaceCombinator> combinators) { |
| 4227 _assertNotResynthesized(_unlinkedExportPublic); | 4237 _assertNotResynthesized(_unlinkedExportPublic); |
| 4228 _combinators = combinators; | 4238 _combinators = combinators; |
| 4229 } | 4239 } |
| 4230 | 4240 |
| 4231 @override | 4241 @override |
| 4232 LibraryElement get exportedLibrary { | 4242 LibraryElement get exportedLibrary { |
| 4233 if (_unlinkedExportNonPublic != null && _exportedLibrary == null) { | 4243 if (_unlinkedExportNonPublic != null && _exportedLibrary == null) { |
| 4244 _selectedUri ??= _selectUri( |
| 4245 _unlinkedExportPublic.uri, _unlinkedExportPublic.configurations); |
| 4234 LibraryElementImpl library = enclosingElement as LibraryElementImpl; | 4246 LibraryElementImpl library = enclosingElement as LibraryElementImpl; |
| 4235 _exportedLibrary = library.resynthesizerContext.buildExportedLibrary(uri); | 4247 _exportedLibrary = |
| 4248 library.resynthesizerContext.buildExportedLibrary(_selectedUri); |
| 4236 } | 4249 } |
| 4237 return _exportedLibrary; | 4250 return _exportedLibrary; |
| 4238 } | 4251 } |
| 4239 | 4252 |
| 4240 void set exportedLibrary(LibraryElement exportedLibrary) { | 4253 void set exportedLibrary(LibraryElement exportedLibrary) { |
| 4241 _assertNotResynthesized(_unlinkedExportNonPublic); | 4254 _assertNotResynthesized(_unlinkedExportNonPublic); |
| 4242 _exportedLibrary = exportedLibrary; | 4255 _exportedLibrary = exportedLibrary; |
| 4243 } | 4256 } |
| 4244 | 4257 |
| 4245 @override | 4258 @override |
| (...skipping 20 matching lines...) Expand all Loading... |
| 4266 @override | 4279 @override |
| 4267 int get nameOffset { | 4280 int get nameOffset { |
| 4268 int offset = super.nameOffset; | 4281 int offset = super.nameOffset; |
| 4269 if (offset == 0 && _unlinkedExportNonPublic != null) { | 4282 if (offset == 0 && _unlinkedExportNonPublic != null) { |
| 4270 return _unlinkedExportNonPublic.offset; | 4283 return _unlinkedExportNonPublic.offset; |
| 4271 } | 4284 } |
| 4272 return offset; | 4285 return offset; |
| 4273 } | 4286 } |
| 4274 | 4287 |
| 4275 @override | 4288 @override |
| 4276 String get uri { | |
| 4277 if (_unlinkedExportPublic != null) { | |
| 4278 return _selectedUri ??= _selectUri( | |
| 4279 _unlinkedExportPublic.uri, _unlinkedExportPublic.configurations); | |
| 4280 } | |
| 4281 return super.uri; | |
| 4282 } | |
| 4283 | |
| 4284 @override | |
| 4285 void set uri(String uri) { | |
| 4286 _assertNotResynthesized(_unlinkedExportPublic); | |
| 4287 super.uri = uri; | |
| 4288 } | |
| 4289 | |
| 4290 @override | |
| 4291 int get uriEnd { | |
| 4292 if (_unlinkedExportNonPublic != null) { | |
| 4293 return _unlinkedExportNonPublic.uriEnd; | |
| 4294 } | |
| 4295 return super.uriEnd; | |
| 4296 } | |
| 4297 | |
| 4298 @override | |
| 4299 void set uriEnd(int uriEnd) { | |
| 4300 _assertNotResynthesized(_unlinkedExportNonPublic); | |
| 4301 super.uriEnd = uriEnd; | |
| 4302 } | |
| 4303 | |
| 4304 @override | |
| 4305 int get uriOffset { | |
| 4306 if (_unlinkedExportNonPublic != null) { | |
| 4307 return _unlinkedExportNonPublic.uriOffset; | |
| 4308 } | |
| 4309 return super.uriOffset; | |
| 4310 } | |
| 4311 | |
| 4312 @override | |
| 4313 void set uriOffset(int uriOffset) { | |
| 4314 _assertNotResynthesized(_unlinkedExportNonPublic); | |
| 4315 super.uriOffset = uriOffset; | |
| 4316 } | |
| 4317 | |
| 4318 @override | |
| 4319 T accept<T>(ElementVisitor<T> visitor) => visitor.visitExportElement(this); | 4289 T accept<T>(ElementVisitor<T> visitor) => visitor.visitExportElement(this); |
| 4320 | 4290 |
| 4321 @override | 4291 @override |
| 4322 void appendTo(StringBuffer buffer) { | 4292 void appendTo(StringBuffer buffer) { |
| 4323 buffer.write("export "); | 4293 buffer.write("export "); |
| 4324 LibraryElementImpl.getImpl(exportedLibrary).appendTo(buffer); | 4294 LibraryElementImpl.getImpl(exportedLibrary).appendTo(buffer); |
| 4325 } | 4295 } |
| 4326 } | 4296 } |
| 4327 | 4297 |
| 4328 /** | 4298 /** |
| (...skipping 1153 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 5482 } | 5452 } |
| 5483 buffer.write(hiddenNames[i]); | 5453 buffer.write(hiddenNames[i]); |
| 5484 } | 5454 } |
| 5485 return buffer.toString(); | 5455 return buffer.toString(); |
| 5486 } | 5456 } |
| 5487 } | 5457 } |
| 5488 | 5458 |
| 5489 /** | 5459 /** |
| 5490 * A concrete implementation of an [ImportElement]. | 5460 * A concrete implementation of an [ImportElement]. |
| 5491 */ | 5461 */ |
| 5492 class ImportElementImpl extends UriReferencedElementImpl | 5462 class ImportElementImpl extends ElementImpl implements ImportElement { |
| 5493 implements ImportElement { | |
| 5494 /** | 5463 /** |
| 5495 * The unlinked representation of the import in the summary. | 5464 * The unlinked representation of the import in the summary. |
| 5496 */ | 5465 */ |
| 5497 final UnlinkedImport _unlinkedImport; | 5466 final UnlinkedImport _unlinkedImport; |
| 5498 | 5467 |
| 5499 /** | 5468 /** |
| 5500 * The index of the dependency in the `imports` list. | 5469 * The index of the dependency in the `imports` list. |
| 5501 */ | 5470 */ |
| 5502 final int _linkedDependency; | 5471 final int _linkedDependency; |
| 5503 | 5472 |
| (...skipping 14 matching lines...) Expand all Loading... |
| 5518 */ | 5487 */ |
| 5519 List<NamespaceCombinator> _combinators; | 5488 List<NamespaceCombinator> _combinators; |
| 5520 | 5489 |
| 5521 /** | 5490 /** |
| 5522 * The prefix that was specified as part of the import directive, or `null` if | 5491 * The prefix that was specified as part of the import directive, or `null` if |
| 5523 * there was no prefix specified. | 5492 * there was no prefix specified. |
| 5524 */ | 5493 */ |
| 5525 PrefixElement _prefix; | 5494 PrefixElement _prefix; |
| 5526 | 5495 |
| 5527 /** | 5496 /** |
| 5528 * The URI that was selected based on the [context] declared variables. | |
| 5529 */ | |
| 5530 String _selectedUri; | |
| 5531 | |
| 5532 /** | |
| 5533 * Initialize a newly created import element at the given [offset]. | 5497 * Initialize a newly created import element at the given [offset]. |
| 5534 * The offset may be `-1` if the import is synthetic. | 5498 * The offset may be `-1` if the import is synthetic. |
| 5535 */ | 5499 */ |
| 5536 ImportElementImpl(int offset) | 5500 ImportElementImpl(int offset) |
| 5537 : _unlinkedImport = null, | 5501 : _unlinkedImport = null, |
| 5538 _linkedDependency = null, | 5502 _linkedDependency = null, |
| 5539 super(null, offset); | 5503 super(null, offset); |
| 5540 | 5504 |
| 5541 /** | 5505 /** |
| 5542 * Initialize using the given serialized information. | 5506 * Initialize using the given serialized information. |
| (...skipping 115 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 5658 } | 5622 } |
| 5659 return _prefixOffset; | 5623 return _prefixOffset; |
| 5660 } | 5624 } |
| 5661 | 5625 |
| 5662 void set prefixOffset(int prefixOffset) { | 5626 void set prefixOffset(int prefixOffset) { |
| 5663 _assertNotResynthesized(_unlinkedImport); | 5627 _assertNotResynthesized(_unlinkedImport); |
| 5664 _prefixOffset = prefixOffset; | 5628 _prefixOffset = prefixOffset; |
| 5665 } | 5629 } |
| 5666 | 5630 |
| 5667 @override | 5631 @override |
| 5668 String get uri { | |
| 5669 if (_unlinkedImport != null) { | |
| 5670 if (_unlinkedImport.isImplicit) { | |
| 5671 return null; | |
| 5672 } | |
| 5673 return _selectedUri ??= | |
| 5674 _selectUri(_unlinkedImport.uri, _unlinkedImport.configurations); | |
| 5675 } | |
| 5676 return super.uri; | |
| 5677 } | |
| 5678 | |
| 5679 @override | |
| 5680 void set uri(String uri) { | |
| 5681 _assertNotResynthesized(_unlinkedImport); | |
| 5682 super.uri = uri; | |
| 5683 } | |
| 5684 | |
| 5685 @override | |
| 5686 int get uriEnd { | |
| 5687 if (_unlinkedImport != null) { | |
| 5688 if (_unlinkedImport.isImplicit) { | |
| 5689 return -1; | |
| 5690 } | |
| 5691 return _unlinkedImport.uriEnd; | |
| 5692 } | |
| 5693 return super.uriEnd; | |
| 5694 } | |
| 5695 | |
| 5696 @override | |
| 5697 void set uriEnd(int uriEnd) { | |
| 5698 _assertNotResynthesized(_unlinkedImport); | |
| 5699 super.uriEnd = uriEnd; | |
| 5700 } | |
| 5701 | |
| 5702 @override | |
| 5703 int get uriOffset { | |
| 5704 if (_unlinkedImport != null) { | |
| 5705 if (_unlinkedImport.isImplicit) { | |
| 5706 return -1; | |
| 5707 } | |
| 5708 return _unlinkedImport.uriOffset; | |
| 5709 } | |
| 5710 return super.uriOffset; | |
| 5711 } | |
| 5712 | |
| 5713 @override | |
| 5714 void set uriOffset(int uriOffset) { | |
| 5715 _assertNotResynthesized(_unlinkedImport); | |
| 5716 super.uriOffset = uriOffset; | |
| 5717 } | |
| 5718 | |
| 5719 @override | |
| 5720 T accept<T>(ElementVisitor<T> visitor) => visitor.visitImportElement(this); | 5632 T accept<T>(ElementVisitor<T> visitor) => visitor.visitImportElement(this); |
| 5721 | 5633 |
| 5722 @override | 5634 @override |
| 5723 void appendTo(StringBuffer buffer) { | 5635 void appendTo(StringBuffer buffer) { |
| 5724 buffer.write("import "); | 5636 buffer.write("import "); |
| 5725 LibraryElementImpl.getImpl(importedLibrary).appendTo(buffer); | 5637 LibraryElementImpl.getImpl(importedLibrary).appendTo(buffer); |
| 5726 } | 5638 } |
| 5727 | 5639 |
| 5728 @override | 5640 @override |
| 5729 void visitChildren(ElementVisitor visitor) { | 5641 void visitChildren(ElementVisitor visitor) { |
| (...skipping 3428 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 9158 final List<PropertyAccessorElementImpl> implicitAccessors = | 9070 final List<PropertyAccessorElementImpl> implicitAccessors = |
| 9159 <PropertyAccessorElementImpl>[]; | 9071 <PropertyAccessorElementImpl>[]; |
| 9160 | 9072 |
| 9161 UnitExplicitTopLevelVariables(int numberOfVariables) | 9073 UnitExplicitTopLevelVariables(int numberOfVariables) |
| 9162 : variables = numberOfVariables != 0 | 9074 : variables = numberOfVariables != 0 |
| 9163 ? new List<TopLevelVariableElementImpl>(numberOfVariables) | 9075 ? new List<TopLevelVariableElementImpl>(numberOfVariables) |
| 9164 : const <TopLevelVariableElementImpl>[]; | 9076 : const <TopLevelVariableElementImpl>[]; |
| 9165 } | 9077 } |
| 9166 | 9078 |
| 9167 /** | 9079 /** |
| 9168 * A concrete implementation of a [UriReferencedElement]. | |
| 9169 */ | |
| 9170 abstract class UriReferencedElementImpl extends ElementImpl | |
| 9171 implements UriReferencedElement { | |
| 9172 /** | |
| 9173 * The offset of the URI in the file, or `-1` if this node is synthetic. | |
| 9174 */ | |
| 9175 int _uriOffset = -1; | |
| 9176 | |
| 9177 /** | |
| 9178 * The offset of the character immediately following the last character of | |
| 9179 * this node's URI, or `-1` if this node is synthetic. | |
| 9180 */ | |
| 9181 int _uriEnd = -1; | |
| 9182 | |
| 9183 /** | |
| 9184 * The URI that is specified by this directive. | |
| 9185 */ | |
| 9186 String _uri; | |
| 9187 | |
| 9188 /** | |
| 9189 * Initialize a newly created import element to have the given [name] and | |
| 9190 * [offset]. The offset may be `-1` if the element is synthetic. | |
| 9191 */ | |
| 9192 UriReferencedElementImpl(String name, int offset) : super(name, offset); | |
| 9193 | |
| 9194 /** | |
| 9195 * Initialize using the given serialized information. | |
| 9196 */ | |
| 9197 UriReferencedElementImpl.forSerialized(ElementImpl enclosingElement) | |
| 9198 : super.forSerialized(enclosingElement); | |
| 9199 | |
| 9200 /** | |
| 9201 * Return the URI that is specified by this directive. | |
| 9202 */ | |
| 9203 String get uri => _uri; | |
| 9204 | |
| 9205 /** | |
| 9206 * Set the URI that is specified by this directive to be the given [uri]. | |
| 9207 */ | |
| 9208 void set uri(String uri) { | |
| 9209 _uri = uri; | |
| 9210 } | |
| 9211 | |
| 9212 /** | |
| 9213 * Return the offset of the character immediately following the last character | |
| 9214 * of this node's URI, or `-1` if this node is synthetic. | |
| 9215 */ | |
| 9216 int get uriEnd => _uriEnd; | |
| 9217 | |
| 9218 /** | |
| 9219 * Set the offset of the character immediately following the last character of | |
| 9220 * this node's URI to the given [offset]. | |
| 9221 */ | |
| 9222 void set uriEnd(int offset) { | |
| 9223 _uriEnd = offset; | |
| 9224 } | |
| 9225 | |
| 9226 /** | |
| 9227 * Return the offset of the URI in the file, or `-1` if this node is synthetic
. | |
| 9228 */ | |
| 9229 int get uriOffset => _uriOffset; | |
| 9230 | |
| 9231 /** | |
| 9232 * Set the offset of the URI in the file to the given [offset]. | |
| 9233 */ | |
| 9234 void set uriOffset(int offset) { | |
| 9235 _uriOffset = offset; | |
| 9236 } | |
| 9237 | |
| 9238 String _selectUri( | |
| 9239 String defaultUri, List<UnlinkedConfiguration> configurations) { | |
| 9240 for (UnlinkedConfiguration configuration in configurations) { | |
| 9241 if (context.declaredVariables.get(configuration.name) == | |
| 9242 configuration.value) { | |
| 9243 return configuration.uri; | |
| 9244 } | |
| 9245 } | |
| 9246 return defaultUri; | |
| 9247 } | |
| 9248 } | |
| 9249 | |
| 9250 /** | |
| 9251 * A concrete implementation of a [VariableElement]. | 9080 * A concrete implementation of a [VariableElement]. |
| 9252 */ | 9081 */ |
| 9253 abstract class VariableElementImpl extends ElementImpl | 9082 abstract class VariableElementImpl extends ElementImpl |
| 9254 implements VariableElement { | 9083 implements VariableElement { |
| 9255 /** | 9084 /** |
| 9256 * The declared type of this variable. | 9085 * The declared type of this variable. |
| 9257 */ | 9086 */ |
| 9258 DartType _declaredType; | 9087 DartType _declaredType; |
| 9259 | 9088 |
| 9260 /** | 9089 /** |
| (...skipping 146 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 9407 | 9236 |
| 9408 @override | 9237 @override |
| 9409 DartObject computeConstantValue() => null; | 9238 DartObject computeConstantValue() => null; |
| 9410 | 9239 |
| 9411 @override | 9240 @override |
| 9412 void visitChildren(ElementVisitor visitor) { | 9241 void visitChildren(ElementVisitor visitor) { |
| 9413 super.visitChildren(visitor); | 9242 super.visitChildren(visitor); |
| 9414 _initializer?.accept(visitor); | 9243 _initializer?.accept(visitor); |
| 9415 } | 9244 } |
| 9416 } | 9245 } |
| OLD | NEW |