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

Side by Side Diff: pkg/analyzer/lib/src/dart/element/element.dart

Issue 2991453002: Restore UriReferencedElement and its uri/uriOffset/uriEnd properties. (Closed)
Patch Set: 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
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 1401 matching lines...) Expand 10 before | Expand all | Expand 10 after
1412 * Return `true` if the given [type] is a class [InterfaceType]. 1412 * Return `true` if the given [type] is a class [InterfaceType].
1413 */ 1413 */
1414 static bool _isClassInterfaceType(DartType type) { 1414 static bool _isClassInterfaceType(DartType type) {
1415 return type is InterfaceType && !type.element.isEnum; 1415 return type is InterfaceType && !type.element.isEnum;
1416 } 1416 }
1417 } 1417 }
1418 1418
1419 /** 1419 /**
1420 * A concrete implementation of a [CompilationUnitElement]. 1420 * A concrete implementation of a [CompilationUnitElement].
1421 */ 1421 */
1422 class CompilationUnitElementImpl extends ElementImpl 1422 class CompilationUnitElementImpl extends UriReferencedElementImpl
1423 implements CompilationUnitElement { 1423 implements CompilationUnitElement {
1424 /** 1424 /**
1425 * The context in which this unit is resynthesized, or `null` if the 1425 * The context in which this unit is resynthesized, or `null` if the
1426 * element is not resynthesized a summary. 1426 * element is not resynthesized a summary.
1427 */ 1427 */
1428 final ResynthesizerContext resynthesizerContext; 1428 final ResynthesizerContext resynthesizerContext;
1429 1429
1430 /** 1430 /**
1431 * The unlinked representation of the unit in the summary. 1431 * The unlinked representation of the unit in the summary.
1432 */ 1432 */
(...skipping 1977 matching lines...) Expand 10 before | Expand all | Expand 10 after
3410 * with the type is implicitly a child of this element and should be visted by 3410 * with the type is implicitly a child of this element and should be visted by
3411 * the given [visitor]. 3411 * the given [visitor].
3412 */ 3412 */
3413 void _safelyVisitPossibleChild(DartType type, ElementVisitor visitor) { 3413 void _safelyVisitPossibleChild(DartType type, ElementVisitor visitor) {
3414 Element element = type?.element; 3414 Element element = type?.element;
3415 if (element is GenericFunctionTypeElementImpl) { 3415 if (element is GenericFunctionTypeElementImpl) {
3416 element.accept(visitor); 3416 element.accept(visitor);
3417 } 3417 }
3418 } 3418 }
3419 3419
3420 String _selectUri(
3421 String defaultUri, List<UnlinkedConfiguration> configurations) {
3422 for (UnlinkedConfiguration configuration in configurations) {
3423 if (context.declaredVariables.get(configuration.name) ==
3424 configuration.value) {
3425 return configuration.uri;
3426 }
3427 }
3428 return defaultUri;
3429 }
3430
3431 static int findElementIndexUsingIdentical(List items, Object item) { 3420 static int findElementIndexUsingIdentical(List items, Object item) {
3432 int length = items.length; 3421 int length = items.length;
3433 for (int i = 0; i < length; i++) { 3422 for (int i = 0; i < length; i++) {
3434 if (identical(items[i], item)) { 3423 if (identical(items[i], item)) {
3435 return i; 3424 return i;
3436 } 3425 }
3437 } 3426 }
3438 throw new StateError('Unable to find $item in $items'); 3427 throw new StateError('Unable to find $item in $items');
3439 } 3428 }
3440 } 3429 }
(...skipping 804 matching lines...) Expand 10 before | Expand all | Expand 10 after
4245 super.visitChildren(visitor); 4234 super.visitChildren(visitor);
4246 _safelyVisitPossibleChild(returnType, visitor); 4235 _safelyVisitPossibleChild(returnType, visitor);
4247 safelyVisitChildren(typeParameters, visitor); 4236 safelyVisitChildren(typeParameters, visitor);
4248 safelyVisitChildren(parameters, visitor); 4237 safelyVisitChildren(parameters, visitor);
4249 } 4238 }
4250 } 4239 }
4251 4240
4252 /** 4241 /**
4253 * A concrete implementation of an [ExportElement]. 4242 * A concrete implementation of an [ExportElement].
4254 */ 4243 */
4255 class ExportElementImpl extends ElementImpl implements ExportElement { 4244 class ExportElementImpl extends UriReferencedElementImpl
4245 implements ExportElement {
4256 /** 4246 /**
4257 * The unlinked representation of the export in the summary. 4247 * The unlinked representation of the export in the summary.
4258 */ 4248 */
4259 final UnlinkedExportPublic _unlinkedExportPublic; 4249 final UnlinkedExportPublic _unlinkedExportPublic;
4260 4250
4261 /** 4251 /**
4262 * The unlinked representation of the export in the summary. 4252 * The unlinked representation of the export in the summary.
4263 */ 4253 */
4264 final UnlinkedExportNonPublic _unlinkedExportNonPublic; 4254 final UnlinkedExportNonPublic _unlinkedExportNonPublic;
4265 4255
(...skipping 38 matching lines...) Expand 10 before | Expand all | Expand 10 after
4304 } 4294 }
4305 4295
4306 void set combinators(List<NamespaceCombinator> combinators) { 4296 void set combinators(List<NamespaceCombinator> combinators) {
4307 _assertNotResynthesized(_unlinkedExportPublic); 4297 _assertNotResynthesized(_unlinkedExportPublic);
4308 _combinators = combinators; 4298 _combinators = combinators;
4309 } 4299 }
4310 4300
4311 @override 4301 @override
4312 LibraryElement get exportedLibrary { 4302 LibraryElement get exportedLibrary {
4313 if (_unlinkedExportNonPublic != null && _exportedLibrary == null) { 4303 if (_unlinkedExportNonPublic != null && _exportedLibrary == null) {
4314 _selectedUri ??= _selectUri(
4315 _unlinkedExportPublic.uri, _unlinkedExportPublic.configurations);
4316 LibraryElementImpl library = enclosingElement as LibraryElementImpl; 4304 LibraryElementImpl library = enclosingElement as LibraryElementImpl;
4317 _exportedLibrary = 4305 _exportedLibrary = library.resynthesizerContext.buildExportedLibrary(uri);
4318 library.resynthesizerContext.buildExportedLibrary(_selectedUri);
4319 } 4306 }
4320 return _exportedLibrary; 4307 return _exportedLibrary;
4321 } 4308 }
4322 4309
4323 void set exportedLibrary(LibraryElement exportedLibrary) { 4310 void set exportedLibrary(LibraryElement exportedLibrary) {
4324 _assertNotResynthesized(_unlinkedExportNonPublic); 4311 _assertNotResynthesized(_unlinkedExportNonPublic);
4325 _exportedLibrary = exportedLibrary; 4312 _exportedLibrary = exportedLibrary;
4326 } 4313 }
4327 4314
4328 @override 4315 @override
(...skipping 20 matching lines...) Expand all
4349 @override 4336 @override
4350 int get nameOffset { 4337 int get nameOffset {
4351 int offset = super.nameOffset; 4338 int offset = super.nameOffset;
4352 if (offset == 0 && _unlinkedExportNonPublic != null) { 4339 if (offset == 0 && _unlinkedExportNonPublic != null) {
4353 return _unlinkedExportNonPublic.offset; 4340 return _unlinkedExportNonPublic.offset;
4354 } 4341 }
4355 return offset; 4342 return offset;
4356 } 4343 }
4357 4344
4358 @override 4345 @override
4346 String get uri {
4347 if (_unlinkedExportPublic != null) {
4348 return _selectedUri ??= _selectUri(
4349 _unlinkedExportPublic.uri, _unlinkedExportPublic.configurations);
4350 }
4351 return super.uri;
4352 }
4353
4354 @override
4355 void set uri(String uri) {
4356 _assertNotResynthesized(_unlinkedExportPublic);
4357 super.uri = uri;
4358 }
4359
4360 @override
4361 int get uriEnd {
4362 if (_unlinkedExportNonPublic != null) {
4363 return _unlinkedExportNonPublic.uriEnd;
4364 }
4365 return super.uriEnd;
4366 }
4367
4368 @override
4369 void set uriEnd(int uriEnd) {
4370 _assertNotResynthesized(_unlinkedExportNonPublic);
4371 super.uriEnd = uriEnd;
4372 }
4373
4374 @override
4375 int get uriOffset {
4376 if (_unlinkedExportNonPublic != null) {
4377 return _unlinkedExportNonPublic.uriOffset;
4378 }
4379 return super.uriOffset;
4380 }
4381
4382 @override
4383 void set uriOffset(int uriOffset) {
4384 _assertNotResynthesized(_unlinkedExportNonPublic);
4385 super.uriOffset = uriOffset;
4386 }
4387
4388 @override
4359 T accept<T>(ElementVisitor<T> visitor) => visitor.visitExportElement(this); 4389 T accept<T>(ElementVisitor<T> visitor) => visitor.visitExportElement(this);
4360 4390
4361 @override 4391 @override
4362 void appendTo(StringBuffer buffer) { 4392 void appendTo(StringBuffer buffer) {
4363 buffer.write("export "); 4393 buffer.write("export ");
4364 LibraryElementImpl.getImpl(exportedLibrary).appendTo(buffer); 4394 LibraryElementImpl.getImpl(exportedLibrary).appendTo(buffer);
4365 } 4395 }
4366 } 4396 }
4367 4397
4368 /** 4398 /**
(...skipping 1163 matching lines...) Expand 10 before | Expand all | Expand 10 after
5532 } 5562 }
5533 buffer.write(hiddenNames[i]); 5563 buffer.write(hiddenNames[i]);
5534 } 5564 }
5535 return buffer.toString(); 5565 return buffer.toString();
5536 } 5566 }
5537 } 5567 }
5538 5568
5539 /** 5569 /**
5540 * A concrete implementation of an [ImportElement]. 5570 * A concrete implementation of an [ImportElement].
5541 */ 5571 */
5542 class ImportElementImpl extends ElementImpl implements ImportElement { 5572 class ImportElementImpl extends UriReferencedElementImpl
5573 implements ImportElement {
5543 /** 5574 /**
5544 * The unlinked representation of the import in the summary. 5575 * The unlinked representation of the import in the summary.
5545 */ 5576 */
5546 final UnlinkedImport _unlinkedImport; 5577 final UnlinkedImport _unlinkedImport;
5547 5578
5548 /** 5579 /**
5549 * The index of the dependency in the `imports` list. 5580 * The index of the dependency in the `imports` list.
5550 */ 5581 */
5551 final int _linkedDependency; 5582 final int _linkedDependency;
5552 5583
(...skipping 19 matching lines...) Expand all
5572 */ 5603 */
5573 List<NamespaceCombinator> _combinators; 5604 List<NamespaceCombinator> _combinators;
5574 5605
5575 /** 5606 /**
5576 * The prefix that was specified as part of the import directive, or `null` if 5607 * The prefix that was specified as part of the import directive, or `null` if
5577 * there was no prefix specified. 5608 * there was no prefix specified.
5578 */ 5609 */
5579 PrefixElement _prefix; 5610 PrefixElement _prefix;
5580 5611
5581 /** 5612 /**
5613 * The URI that was selected based on the [context] declared variables.
5614 */
5615 String _selectedUri;
5616
5617 /**
5582 * Initialize a newly created import element at the given [offset]. 5618 * Initialize a newly created import element at the given [offset].
5583 * The offset may be `-1` if the import is synthetic. 5619 * The offset may be `-1` if the import is synthetic.
5584 */ 5620 */
5585 ImportElementImpl(int offset) 5621 ImportElementImpl(int offset)
5586 : _unlinkedImport = null, 5622 : _unlinkedImport = null,
5587 _linkedDependency = null, 5623 _linkedDependency = null,
5588 _kernel = null, 5624 _kernel = null,
5589 super(null, offset); 5625 super(null, offset);
5590 5626
5591 /** 5627 /**
(...skipping 133 matching lines...) Expand 10 before | Expand all | Expand 10 after
5725 } 5761 }
5726 return _prefixOffset; 5762 return _prefixOffset;
5727 } 5763 }
5728 5764
5729 void set prefixOffset(int prefixOffset) { 5765 void set prefixOffset(int prefixOffset) {
5730 _assertNotResynthesized(_unlinkedImport); 5766 _assertNotResynthesized(_unlinkedImport);
5731 _prefixOffset = prefixOffset; 5767 _prefixOffset = prefixOffset;
5732 } 5768 }
5733 5769
5734 @override 5770 @override
5771 String get uri {
5772 if (_unlinkedImport != null) {
5773 if (_unlinkedImport.isImplicit) {
5774 return null;
5775 }
5776 return _selectedUri ??=
5777 _selectUri(_unlinkedImport.uri, _unlinkedImport.configurations);
5778 }
5779 return super.uri;
5780 }
5781
5782 @override
5783 void set uri(String uri) {
5784 _assertNotResynthesized(_unlinkedImport);
5785 super.uri = uri;
5786 }
5787
5788 @override
5789 int get uriEnd {
5790 if (_unlinkedImport != null) {
5791 if (_unlinkedImport.isImplicit) {
5792 return -1;
5793 }
5794 return _unlinkedImport.uriEnd;
5795 }
5796 return super.uriEnd;
5797 }
5798
5799 @override
5800 void set uriEnd(int uriEnd) {
5801 _assertNotResynthesized(_unlinkedImport);
5802 super.uriEnd = uriEnd;
5803 }
5804
5805 @override
5806 int get uriOffset {
5807 if (_unlinkedImport != null) {
5808 if (_unlinkedImport.isImplicit) {
5809 return -1;
5810 }
5811 return _unlinkedImport.uriOffset;
5812 }
5813 return super.uriOffset;
5814 }
5815
5816 @override
5817 void set uriOffset(int uriOffset) {
5818 _assertNotResynthesized(_unlinkedImport);
5819 super.uriOffset = uriOffset;
5820 }
5821
5822 @override
5735 T accept<T>(ElementVisitor<T> visitor) => visitor.visitImportElement(this); 5823 T accept<T>(ElementVisitor<T> visitor) => visitor.visitImportElement(this);
5736 5824
5737 @override 5825 @override
5738 void appendTo(StringBuffer buffer) { 5826 void appendTo(StringBuffer buffer) {
5739 buffer.write("import "); 5827 buffer.write("import ");
5740 LibraryElementImpl.getImpl(importedLibrary).appendTo(buffer); 5828 LibraryElementImpl.getImpl(importedLibrary).appendTo(buffer);
5741 } 5829 }
5742 5830
5743 @override 5831 @override
5744 void visitChildren(ElementVisitor visitor) { 5832 void visitChildren(ElementVisitor visitor) {
(...skipping 3467 matching lines...) Expand 10 before | Expand all | Expand 10 after
9212 final List<PropertyAccessorElementImpl> implicitAccessors = 9300 final List<PropertyAccessorElementImpl> implicitAccessors =
9213 <PropertyAccessorElementImpl>[]; 9301 <PropertyAccessorElementImpl>[];
9214 9302
9215 UnitExplicitTopLevelVariables(int numberOfVariables) 9303 UnitExplicitTopLevelVariables(int numberOfVariables)
9216 : variables = numberOfVariables != 0 9304 : variables = numberOfVariables != 0
9217 ? new List<TopLevelVariableElementImpl>(numberOfVariables) 9305 ? new List<TopLevelVariableElementImpl>(numberOfVariables)
9218 : const <TopLevelVariableElementImpl>[]; 9306 : const <TopLevelVariableElementImpl>[];
9219 } 9307 }
9220 9308
9221 /** 9309 /**
9310 * A concrete implementation of a [UriReferencedElement].
9311 */
9312 abstract class UriReferencedElementImpl extends ElementImpl
9313 implements UriReferencedElement {
9314 /**
9315 * The offset of the URI in the file, or `-1` if this node is synthetic.
9316 */
9317 int _uriOffset = -1;
9318
9319 /**
9320 * The offset of the character immediately following the last character of
9321 * this node's URI, or `-1` if this node is synthetic.
9322 */
9323 int _uriEnd = -1;
9324
9325 /**
9326 * The URI that is specified by this directive.
9327 */
9328 String _uri;
9329
9330 /**
9331 * Initialize a newly created import element to have the given [name] and
9332 * [offset]. The offset may be `-1` if the element is synthetic.
9333 */
9334 UriReferencedElementImpl(String name, int offset) : super(name, offset);
9335
9336 /**
9337 * Initialize using the given serialized information.
9338 */
9339 UriReferencedElementImpl.forSerialized(ElementImpl enclosingElement)
9340 : super.forSerialized(enclosingElement);
9341
9342 /**
9343 * Return the URI that is specified by this directive.
9344 */
9345 String get uri => _uri;
9346
9347 /**
9348 * Set the URI that is specified by this directive to be the given [uri].
9349 */
9350 void set uri(String uri) {
9351 _uri = uri;
9352 }
9353
9354 /**
9355 * Return the offset of the character immediately following the last character
9356 * of this node's URI, or `-1` if this node is synthetic.
9357 */
9358 int get uriEnd => _uriEnd;
9359
9360 /**
9361 * Set the offset of the character immediately following the last character of
9362 * this node's URI to the given [offset].
9363 */
9364 void set uriEnd(int offset) {
9365 _uriEnd = offset;
9366 }
9367
9368 /**
9369 * Return the offset of the URI in the file, or `-1` if this node is synthetic .
9370 */
9371 int get uriOffset => _uriOffset;
9372
9373 /**
9374 * Set the offset of the URI in the file to the given [offset].
9375 */
9376 void set uriOffset(int offset) {
9377 _uriOffset = offset;
9378 }
9379
9380 String _selectUri(
9381 String defaultUri, List<UnlinkedConfiguration> configurations) {
9382 for (UnlinkedConfiguration configuration in configurations) {
9383 if (context.declaredVariables.get(configuration.name) ==
9384 configuration.value) {
9385 return configuration.uri;
9386 }
9387 }
9388 return defaultUri;
9389 }
9390 }
9391
9392 /**
9222 * A concrete implementation of a [VariableElement]. 9393 * A concrete implementation of a [VariableElement].
9223 */ 9394 */
9224 abstract class VariableElementImpl extends ElementImpl 9395 abstract class VariableElementImpl extends ElementImpl
9225 implements VariableElement { 9396 implements VariableElement {
9226 /** 9397 /**
9227 * The declared type of this variable. 9398 * The declared type of this variable.
9228 */ 9399 */
9229 DartType _declaredType; 9400 DartType _declaredType;
9230 9401
9231 /** 9402 /**
(...skipping 146 matching lines...) Expand 10 before | Expand all | Expand 10 after
9378 9549
9379 @override 9550 @override
9380 DartObject computeConstantValue() => null; 9551 DartObject computeConstantValue() => null;
9381 9552
9382 @override 9553 @override
9383 void visitChildren(ElementVisitor visitor) { 9554 void visitChildren(ElementVisitor visitor) {
9384 super.visitChildren(visitor); 9555 super.visitChildren(visitor);
9385 _initializer?.accept(visitor); 9556 _initializer?.accept(visitor);
9386 } 9557 }
9387 } 9558 }
OLDNEW
« no previous file with comments | « pkg/analyzer/lib/src/dart/element/builder.dart ('k') | pkg/analyzer/lib/src/dart/element/handle.dart » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698